diff --git a/CHANGELOG.md b/CHANGELOG.md index 412585f..8f772f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - [Semantic Versioning](https://semver.org/spec/v2.0.0.html) - [`auto-changelog`](https://github.com/CookPete/auto-changelog) -## [v1.42.4](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming) +## [v1.42.5](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming) ### Changes diff --git a/README.md b/README.md index 7e1e85e..71bc476 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,105 @@ Now you can use this library in Node.js and browser environments in CommonJS(req ## Built-in classic algorithms -DFS(Depth-First Search), DFSIterative, BFS(Breadth-First Search), morris, Bellman-Ford Algorithm, Dijkstra's Algorithm, -Floyd-Warshall Algorithm, Tarjan's Algorithm. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AlgorithmFunction DescriptionIteration Type
Binary Tree DFSTraverse a binary tree in a depth-first manner, starting from the root node, first visiting the left subtree, + and then the right subtree, using recursion. + Recursion + Iteration
Binary Tree BFSTraverse a binary tree in a breadth-first manner, starting from the root node, visiting nodes level by level + from left to right. + Iteration
Graph DFSTraverse a graph in a depth-first manner, starting from a given node, exploring along one path as deeply as + possible, and backtracking to explore other paths. Used for finding connected components, paths, etc. + Recursion + Iteration
Binary Tree MorrisMorris traversal is an in-order traversal algorithm for binary trees with O(1) space complexity. It allows tree + traversal without additional stack or recursion. + Iteration
Graph BFSTraverse a graph in a breadth-first manner, starting from a given node, first visiting nodes directly connected + to the starting node, and then expanding level by level. Used for finding shortest paths, etc. + Recursion + Iteration
Graph Tarjan's AlgorithmFind strongly connected components in a graph, typically implemented using depth-first search.Recursion
Graph Bellman-Ford AlgorithmFinding the shortest paths from a single source, can handle negative weight edgesIteration
Graph Dijkstra's AlgorithmFinding the shortest paths from a single source, cannot handle negative weight edgesIteration
Graph Floyd-Warshall AlgorithmFinding the shortest paths between all pairs of nodesIteration
Graph getCyclesFind all cycles in a graph or detect the presence of cycles.Recursion
Graph getCutVertexesFind cut vertices in a graph, which are nodes that, when removed, increase the number of connected components in + the graph. + Recursion
Graph getSCCsFind strongly connected components in a graph, which are subgraphs where any two nodes can reach each other. + Recursion
Graph getBridgesFind bridges in a graph, which are edges that, when removed, increase the number of connected components in the + graph. + Recursion
Graph topologicalSortPerform topological sorting on a directed acyclic graph (DAG) to find a linear order of nodes such that all + directed edges go from earlier nodes to later nodes. + Recursion
+ ## Installation and Usage @@ -54,11 +151,12 @@ import { ### CDN +Copy the line below into the head tag in an HTML document. ```html - ``` +Copy the code below into the script tag of your HTML, and you're good to go with your development work. ```js const {Heap} = dataStructureTyped; const { @@ -84,7 +182,7 @@ const { Examples Repository -## Code Snippet +## Code Snippets ### Binary Search Tree (BST) snippet @@ -99,27 +197,40 @@ bst.add(3); bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]); bst.size === 16; // true bst.has(6); // true -const node6 = bst.get(6); // BSTNode +const node6 = bst.getNode(6); // BSTNode bst.getHeight(6) === 2; // true bst.getHeight() === 5; // true bst.getDepth(6) === 3; // true -bst.getLeftMost()?.id === 1; // true +bst.getLeftMost()?.key === 1; // true bst.delete(6); -bst.get(6); // null +bst.get(6); // undefined bst.isAVLBalanced(); // true bst.bfs()[0] === 11; // true -const objBST = new BST>(); -objBST.add(11, {id: 11, keyA: 11}); -objBST.add(3, {id: 3, keyA: 3}); +const objBST = new BST<{height: number, age: number}>(); -objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8}, - {id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2}, - {id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12}, - {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7}, - {id: 10, keyA: 10}, {id: 5, keyA: 5}]); +objBST.add(11, { "name": "Pablo", "age": 15 }); +objBST.add(3, { "name": "Kirk", "age": 1 }); + +objBST.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5], [ + { "name": "Alice", "age": 15 }, + { "name": "Bob", "age": 1 }, + { "name": "Charlie", "age": 8 }, + { "name": "David", "age": 13 }, + { "name": "Emma", "age": 16 }, + { "name": "Frank", "age": 2 }, + { "name": "Grace", "age": 6 }, + { "name": "Hannah", "age": 9 }, + { "name": "Isaac", "age": 12 }, + { "name": "Jack", "age": 14 }, + { "name": "Katie", "age": 4 }, + { "name": "Liam", "age": 7 }, + { "name": "Mia", "age": 10 }, + { "name": "Noah", "age": 5 } + ] +); objBST.delete(11); ``` @@ -133,39 +244,21 @@ const bst = new BST(); bst.add(11); bst.add(3); bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]); -bst.size === 16; // true -bst.has(6); // true -const node6 = bst.get(6); -bst.getHeight(6) === 2; // true -bst.getHeight() === 5; // true -bst.getDepth(6) === 3; // true +bst.size === 16; // true +bst.has(6); // true +const node6 = bst.getNode(6); +bst.getHeight(6) === 2; // true +bst.getHeight() === 5; // true +bst.getDepth(6) === 3; // true const leftMost = bst.getLeftMost(); -leftMost?.id === 1; // true -expect(leftMost?.id).toBe(1); +leftMost?.key === 1; // true + bst.delete(6); -bst.get(6); // null -bst.isAVLBalanced(); // true or false +bst.get(6); // undefined +bst.isAVLBalanced(); // true or false const bfsIDs = bst.bfs(); -bfsIDs[0] === 11; // true -expect(bfsIDs[0]).toBe(11); +bfsIDs[0] === 11; // true -const objBST = new BST(); -objBST.add(11, {id: 11, keyA: 11}); -objBST.add(3, {id: 3, keyA: 3}); - -objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8}, - {id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2}, - {id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12}, - {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7}, - {id: 10, keyA: 10}, {id: 5, keyA: 5}]); - -objBST.delete(11); - -const avlTree = new AVLTree(); -avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]) -avlTree.isAVLBalanced(); // true -avlTree.delete(10); -avlTree.isAVLBalanced(); // true ``` ### AVLTree snippet @@ -222,7 +315,7 @@ graph.addVertex('C'); graph.addEdge('A', 'B'); graph.addEdge('B', 'C'); -const topologicalOrderIds = graph.topologicalSort(); // ['A', 'B', 'C'] +const topologicalOrderKeys = graph.topologicalSort(); // ['A', 'B', 'C'] ``` ### Undirected Graph snippet @@ -242,7 +335,7 @@ graph.addEdge('A', 'B'); graph.addEdge('B', 'D'); const dijkstraResult = graph.dijkstra('A'); -Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D'] +Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', 'D'] ``` ## Data Structures @@ -444,12 +537,6 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D - - Array<E> - vector<T> - ArrayList<E> - list - DoublyLinkedList<E> list<T> @@ -462,6 +549,42 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D - - + + Array<E> + vector<T> + ArrayList<E> + list + + + Queue<E> + queue<T> + Queue<E> + - + + + Deque<E> + deque<T> + - + - + + + PriorityQueue<E> + priority_queue<T> + PriorityQueue<E> + - + + + Heap<E> + priority_queue<T> + PriorityQueue<E> + heapq + + + Stack<E> + stack<T> + Stack<E> + - + Set<E> set<T> @@ -475,46 +598,9 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D dict - Map<K, V> - - - - - OrderedDict - - - - Queue<E> - queue<T> - Queue<E> - - - - - PriorityQueue<E> - priority_queue<T> - PriorityQueue<E> - - - - - Heap<V> - priority_queue<T> - PriorityQueue<E> - heapq - - - Stack<E> - stack<T> - Stack<E> - - - - - Deque<E> - deque<T> - - - - - - - Trie - - - + unordered_set<T> + HashSet<E> - @@ -524,16 +610,10 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D defaultdict - - - multiset<T> - - - - - - - - - multimap<K, V> + Map<K, V> - - + OrderedDict BinaryTree<K, V> @@ -547,6 +627,42 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D - - + + TreeMultimap<K, V> + multimap<K, V> + - + - + + + AVLTree<E> + - + TreeSet<E> + - + + + AVLTree<K, V> + - + TreeMap<K, V> + - + + + AVLTree<E> + set + TreeSet<E> + - + + + Trie + - + - + - + + + - + multiset<T> + - + - + DirectedGraph<V, E> - @@ -577,24 +693,6 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D LinkedHashMap<K, V> - - - AVLTree<E> - - - TreeSet<E> - - - - - AVLTree<K, V> - - - TreeMap<K, V> - - - - - AVLTree<E> - set - TreeSet<E> - - - - unordered_multimap<K, V> @@ -607,12 +705,6 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D - - - - - - unordered_set<T> - HashSet<E> - - - @@ -633,7 +725,7 @@ optimal approach to data structure design. ## Benchmark -[//]: # (Start of Replace Section) +[//]: # (No deletion!!! Start of Replace Section)
avl-tree
test nametime taken (ms)executions per secsample deviation
10,000 add randomly30.5232.763.28e-4
10,000 add & delete randomly66.9614.940.00
10,000 addMany39.7825.143.67e-4
10,000 get27.3836.520.00
@@ -672,4 +764,4 @@ optimal approach to data structure design.
test nametime taken (ms)executions per secsample deviation
100,000 push59.4016.830.01
100,000 getWords90.0711.100.00
-[//]: # (End of Replace Section) \ No newline at end of file +[//]: # (No deletion!!! End of Replace Section) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 77cca0e..c0faebd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "data-structure-typed", - "version": "1.41.8", + "version": "1.42.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "data-structure-typed", - "version": "1.41.8", + "version": "1.42.5", "license": "MIT", "devDependencies": { "@types/benchmark": "^2.1.3", @@ -16,10 +16,10 @@ "@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/parser": "^6.7.4", "auto-changelog": "^2.4.0", - "avl-tree-typed": "^1.41.8", + "avl-tree-typed": "^1.42.5", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.41.8", - "bst-typed": "^1.41.8", + "binary-tree-typed": "^1.42.5", + "bst-typed": "^1.42.5", "dependency-cruiser": "^14.1.0", "eslint": "^8.50.0", "eslint-config-prettier": "^9.0.0", @@ -27,7 +27,7 @@ "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.28.1", "fast-glob": "^3.3.1", - "heap-typed": "^1.41.8", + "heap-typed": "^1.42.5", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "prettier": "^3.0.3", @@ -2789,12 +2789,12 @@ } }, "node_modules/avl-tree-typed": { - "version": "1.41.8", - "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.41.8.tgz", - "integrity": "sha512-tC0yAkPKS3TYj9q/PbEd+I/AgI/TZIcrueDXsKZMlpLwLe87oj2xfks50CRpmvF89iPHBWCgrtGO8YS1oF2/aw==", + "version": "1.42.5", + "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.42.5.tgz", + "integrity": "sha512-El2G/paRXmAkcdTf0OoNqbdcMGy2rzJ1OHI7fvKQyUs3PaWRQwAQFHepJOrUqHTyIG0ei22s/g4PX3hRceW+ag==", "dev": true, "dependencies": { - "data-structure-typed": "^1.41.8" + "data-structure-typed": "^1.42.5" } }, "node_modules/babel-jest": { @@ -2988,12 +2988,12 @@ } }, "node_modules/binary-tree-typed": { - "version": "1.41.8", - "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.41.8.tgz", - "integrity": "sha512-kViP86Bx1RGKz59KbKXZlRQL9KNsxX4rhPpR9Y1bQz0Tpz5JIuOBJk4f19YK+FdGQpIK3TzUPmFRDIJoHJLnxQ==", + "version": "1.42.5", + "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.42.5.tgz", + "integrity": "sha512-E5Ri7tsiVMeBj6uL+SBnwrsnWDcpHFEqBZ4ULfjg7FF2vs+kgjPFTY7HKIBypzBo9qbx9fYx3wXu2H8Y0E+BQw==", "dev": true, "dependencies": { - "data-structure-typed": "^1.41.8" + "data-structure-typed": "^1.42.5" } }, "node_modules/brace-expansion": { @@ -3072,12 +3072,12 @@ } }, "node_modules/bst-typed": { - "version": "1.41.8", - "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.41.8.tgz", - "integrity": "sha512-pOee++rWrVkub9+PSWMeyNNRae17iCVmu4tRy05ttGNCmb88aWgtCZgw+uNrsDj2WDUcwRbSO+usqvvc2kAqOg==", + "version": "1.42.5", + "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.42.5.tgz", + "integrity": "sha512-dqX2DvQC0uE+lFYi6FRDOr7A8p1A65jtemJdmasvEPSbHd9+uNruHql7dm8TLo2Pi1fXVRA6f7Tmnfc+CN7+UQ==", "dev": true, "dependencies": { - "data-structure-typed": "^1.41.8" + "data-structure-typed": "^1.42.5" } }, "node_modules/buffer-from": { @@ -3480,9 +3480,9 @@ } }, "node_modules/data-structure-typed": { - "version": "1.41.8", - "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.41.8.tgz", - "integrity": "sha512-g4gwL7oJH6aMC8uD5Fgwgc/yRWDrVsnLpYtwpVk5A3FFWyIP/FXriQ0kNOdpo4TydSbefyjo/QzapUXHcZ7ZOA==", + "version": "1.42.5", + "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.42.5.tgz", + "integrity": "sha512-LJ+j4yOSgOUq5N0bv3lzxJp31nNz65aT9CTy2EuuRlBzoRXL4DAuE1LkXyPSupEo4rDXs9lDZh+Tb4uQTPClKA==", "dev": true }, "node_modules/debug": { @@ -4847,12 +4847,12 @@ } }, "node_modules/heap-typed": { - "version": "1.41.8", - "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.41.8.tgz", - "integrity": "sha512-eegrUhG3a9EP9QHLCtjKmuWG3Fx6/wCSu4wGBIVgJP2OSSWdoGhp1Lj9BRqhCc6hYCLUlOEa271z458Y0vZmDw==", + "version": "1.42.5", + "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.42.5.tgz", + "integrity": "sha512-Phg3YCLWWVomTBO/74ou1flJRDhtEehSgnRL7/FkMBWZF7PXBgQeSWI7pA27j9gYtVpU+nHvOBv0hw7M5/1LVw==", "dev": true, "dependencies": { - "data-structure-typed": "^1.41.8" + "data-structure-typed": "^1.42.5" } }, "node_modules/html-escaper": { diff --git a/package.json b/package.json index f0d190a..60d3669 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-structure-typed", - "version": "1.42.5", + "version": "1.42.6", "description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.", "main": "dist/cjs/src/index.js", "module": "dist/mjs/src/index.js", @@ -64,10 +64,10 @@ "@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/parser": "^6.7.4", "auto-changelog": "^2.4.0", - "avl-tree-typed": "^1.41.8", + "avl-tree-typed": "^1.42.5", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.41.8", - "bst-typed": "^1.41.8", + "binary-tree-typed": "^1.42.5", + "bst-typed": "^1.42.5", "dependency-cruiser": "^14.1.0", "eslint": "^8.50.0", "eslint-config-prettier": "^9.0.0", @@ -75,7 +75,7 @@ "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.28.1", "fast-glob": "^3.3.1", - "heap-typed": "^1.41.8", + "heap-typed": "^1.42.5", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "prettier": "^3.0.3", @@ -161,6 +161,8 @@ "avl-tree", "tree multiset", "treemultiset", + "tree multimap", + "treemultimap", "tree-multimap", "binary indexed tree", "binaryindexedtree", diff --git a/test/performance/reportor.ts b/test/performance/reportor.ts index 45f380a..91d28c9 100644 --- a/test/performance/reportor.ts +++ b/test/performance/reportor.ts @@ -100,8 +100,8 @@ const composeReport = () => { `; replaceMarkdownContent( - '[//]: # (Start of Replace Section)', // Start tag - '[//]: # (End of Replace Section)', // end identifier + '[//]: # (No deletion!!! Start of Replace Section)', // Start tag + '[//]: # (No deletion!!! End of Replace Section)', // end identifier htmlTables // New content to be inserted ); fs.writeFileSync(htmlFilePath, html);