diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e5b148..bf94394 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.41.5](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming) +## [v1.41.7](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming) ### Changes diff --git a/README.md b/README.md index 70b3652..45d7e3d 100644 --- a/README.md +++ b/README.md @@ -658,37 +658,37 @@ optimal approach to data structure design. [//]: # (Start of Replace Section)
avl-tree
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 add randomly2.21451.50240.009.12e-5
1000 add & delete randomly5.02199.23110.016.31e-4
1000 addMany2.96338.41180.002.09e-4
1000 get2.00499.79260.001.89e-4
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 add randomly2.28438.38230.002.56e-5
1000 add & delete randomly5.16193.94110.017.96e-4
1000 addMany3.05328.30170.003.13e-4
1000 get2.08480.72250.009.01e-5
binary-tree
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 add randomly12.9577.2350.011.82e-4
1000 add & delete randomly15.9462.7340.021.95e-4
1000 addMany10.8192.4850.015.30e-4
1000 get18.1655.0730.022.99e-4
1000 dfs69.5214.3810.070.00
1000 bfs54.8418.2410.057.36e-4
1000 morris38.2626.1320.040.00
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 add randomly12.8877.6550.011.17e-4
1000 add & delete randomly15.9562.7040.021.78e-4
1000 addMany10.6194.2550.011.16e-4
1000 get18.0255.5130.021.59e-4
1000 dfs69.9514.3010.076.49e-4
1000 bfs54.7818.2510.054.98e-4
1000 morris37.2626.8320.042.16e-4
bst
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 add randomly2.22450.51240.006.06e-5
1000 add & delete randomly5.04198.59110.012.52e-4
1000 addMany2.14467.96250.006.00e-5
1000 get2.06486.16250.001.15e-4
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 add randomly2.02496.10250.001.56e-5
1000 add & delete randomly4.60217.31120.004.43e-4
1000 addMany2.23448.71240.002.96e-4
1000 get2.09479.52250.001.27e-5
directed-graph
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 addVertex0.109726.704961.03e-41.60e-6
1000 addEdge6.23160.4690.015.60e-4
1000 getVertex0.052.17e+410974.61e-53.68e-7
1000 getEdge23.5342.4930.020.00
tarjan216.404.6210.220.01
tarjan all218.574.5810.220.00
topologicalSort186.635.3610.190.03
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 addVertex0.109871.965011.01e-47.32e-7
1000 addEdge6.48154.2990.010.00
1000 getVertex0.052.17e+411104.61e-53.80e-7
1000 getEdge24.6540.5730.020.01
tarjan208.004.8110.210.01
tarjan all212.974.7010.210.00
topologicalSort171.495.8310.170.01
heap
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 add & pop0.342927.031493.42e-43.47e-6
1000 fib add & pop3.91255.63130.004.55e-5
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 add & pop0.342929.811493.41e-42.37e-6
1000 fib add & pop3.89257.31140.002.53e-5
doubly-linked-list
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000000 unshift200.254.9910.200.03
1000000 unshift & shift183.255.4610.180.05
1000 insertBefore0.033.64e+420052.75e-58.47e-7
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000000 unshift212.404.7110.210.02
1000000 unshift & shift172.945.7810.170.03
1000 insertBefore0.033.70e+419032.71e-52.38e-6
singly-linked-list
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 push & pop1.79558.34300.006.00e-5
1000 insertBefore2.40417.00220.003.01e-4
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000 push & pop1.75571.73300.005.06e-5
1000 insertBefore2.30434.82220.005.10e-5
max-priority-queue
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
10000 refill & poll11.7784.9850.010.00
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
10000 refill & poll11.4187.6550.011.49e-4
deque
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000000 push224.484.4510.220.03
1000000 shift27.2136.7630.030.00
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000000 push212.514.7110.210.06
1000000 shift24.9840.0430.020.00
queue
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000000 push46.4621.5220.050.01
1000000 push & shift78.8812.6810.080.00
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
1000000 push41.9723.8320.040.01
1000000 push & shift79.0812.6510.080.00
trie
-
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
100000 push54.6218.3110.059.87e-4
100000 getWords89.2611.2010.090.00
+
test nametime taken (ms)executions per secexecuted timessample mean (secs)sample deviation
100000 push54.2418.4410.057.00e-4
100000 getWords96.1210.4010.100.00
[//]: # (End of Replace Section) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f532bbf..d8cdac0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "data-structure-typed", - "version": "1.41.3", + "version": "1.41.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "data-structure-typed", - "version": "1.41.3", + "version": "1.41.6", "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.2", + "avl-tree-typed": "^1.41.6", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.41.2", - "bst-typed": "^1.41.2", + "binary-tree-typed": "^1.41.6", + "bst-typed": "^1.41.6", "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.2", + "heap-typed": "^1.41.6", "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.2", - "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.41.2.tgz", - "integrity": "sha512-J3g1PuuxJdun24hgOgSvFwbOu3xykqabTRGRd78IU9yZBBVNNVTZ+oJkNR5OYWG3bgPhcv5x8dHbWsHi3S5QGQ==", + "version": "1.41.6", + "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.41.6.tgz", + "integrity": "sha512-r7XvaFjgHKR1P/7YD8vC11p4MHgiDVzMU1vmIcQ44q0wxXkQ/YIncJhUSa7oM6PZpSoPRLk33wPpY3+1AUrnKQ==", "dev": true, "dependencies": { - "data-structure-typed": "^1.41.2" + "data-structure-typed": "^1.41.6" } }, "node_modules/babel-jest": { @@ -2988,12 +2988,12 @@ } }, "node_modules/binary-tree-typed": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.41.2.tgz", - "integrity": "sha512-x0nOUvCEWNpJsQXqXbEoGuVFt2dFpL/vRi8xny/sqvqeygDv/Vsw4puoLBXFd+UfmZN3Q/KBULHoy6pKTaXBqw==", + "version": "1.41.6", + "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.41.6.tgz", + "integrity": "sha512-B9FnRYxDIibvnKFnkm+zNwI62AwOPXMv0gQtAI6mvxuBYPUhy8tGGc5bZnQCisT/KFfrWwUj/1T72kgmyl4h1Q==", "dev": true, "dependencies": { - "data-structure-typed": "^1.41.2" + "data-structure-typed": "^1.41.6" } }, "node_modules/brace-expansion": { @@ -3072,12 +3072,12 @@ } }, "node_modules/bst-typed": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.41.2.tgz", - "integrity": "sha512-94a99sgCzWYddsHTPQaB3LzQeEGbQWnte/Wg6EMccH6Dpt42FJMXMQMP6N+3Y373wSppI804kN58EKWemo+4xA==", + "version": "1.41.6", + "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.41.6.tgz", + "integrity": "sha512-GSiJ4JbszYhthcfPpu7+jyXNGzs94Il2111v94s288scZvvRCNjw7cBNUPScf2yAHJ6t4GMlz+ikPu4apoyA5g==", "dev": true, "dependencies": { - "data-structure-typed": "^1.41.2" + "data-structure-typed": "^1.41.6" } }, "node_modules/buffer-from": { @@ -3480,9 +3480,9 @@ } }, "node_modules/data-structure-typed": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.41.2.tgz", - "integrity": "sha512-NqySco4pSZWLD1Y277AxTU+lJgiVIlkGkFSLdMRyYGsWcMCYlqmu2pryzm4E2jgI6FFzIgVqA6FBSTQKmxNchw==", + "version": "1.41.6", + "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.41.6.tgz", + "integrity": "sha512-Yi7Kj5wQtjo/h6vE40dMOOma7BHc5ob3/Y6z0N3+zQjUpTUkYBN5jKl24RhxYVfWBCvWrK434prrxVMonwo0BA==", "dev": true }, "node_modules/debug": { @@ -4847,12 +4847,12 @@ } }, "node_modules/heap-typed": { - "version": "1.41.2", - "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.41.2.tgz", - "integrity": "sha512-fDLjM5HJOqGFS52LJYOh3t5dUebh1ZPdRW83gtgqx3xfV1lVfM0RRFLFMJZ3OAqDVwE3XxKlUirOIfIL/Xfe9Q==", + "version": "1.41.6", + "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.41.6.tgz", + "integrity": "sha512-rrquP8vWOgEGWmF8aUmpYKKwFFu3+mk0eH0kwvlQr/dUybuHXf+JwzjBY9kvtaW1IuP8zhK9kK31mTPTjGs/Zw==", "dev": true, "dependencies": { - "data-structure-typed": "^1.41.2" + "data-structure-typed": "^1.41.6" } }, "node_modules/html-escaper": { diff --git a/package.json b/package.json index 2e7a838..76c5c31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-structure-typed", - "version": "1.41.6", + "version": "1.41.7", "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.2", + "avl-tree-typed": "^1.41.6", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.41.2", - "bst-typed": "^1.41.2", + "binary-tree-typed": "^1.41.6", + "bst-typed": "^1.41.6", "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.2", + "heap-typed": "^1.41.6", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "prettier": "^3.0.3", diff --git a/src/data-structures/graph/abstract-graph.ts b/src/data-structures/graph/abstract-graph.ts index 09bc5b5..1600844 100644 --- a/src/data-structures/graph/abstract-graph.ts +++ b/src/data-structures/graph/abstract-graph.ts @@ -233,8 +233,8 @@ export abstract class AbstractGraph< return []; } - const dfs = (cur: VO, dest: VO, visiting: Map, path: VO[]) => { - visiting.set(cur, true); + const dfs = (cur: VO, dest: VO, visiting: Set, path: VO[]) => { + visiting.add(cur); if (cur === dest) { paths.push([vertex1, ...path]); @@ -242,17 +242,17 @@ export abstract class AbstractGraph< const neighbors = this.getNeighbors(cur); for (const neighbor of neighbors) { - if (!visiting.get(neighbor)) { + if (!visiting.has(neighbor)) { path.push(neighbor); dfs(neighbor, dest, visiting, path); - arrayRemove(path, (vertex: VO) => vertex === neighbor); + path.pop(); } } - visiting.set(cur, false); + visiting.delete(cur); }; - dfs(vertex1, vertex2, new Map(), []); + dfs(vertex1, vertex2, new Set(), []); return paths; } diff --git a/test/unit/data-structures/graph/undirected-graph.test.ts b/test/unit/data-structures/graph/undirected-graph.test.ts index 593ff50..b4f827f 100644 --- a/test/unit/data-structures/graph/undirected-graph.test.ts +++ b/test/unit/data-structures/graph/undirected-graph.test.ts @@ -1,6 +1,6 @@ import {UndirectedEdge, UndirectedGraph, UndirectedVertex} from '../../../../src'; -import saltyVertexes from './SaltyGateStreetIntersections.json'; -import saltyEdges from './SaltyGateStreetConnections.json'; +import saltyVertexes from './salty-vertexes.json'; +import saltyEdges from './salty-edges.json'; describe('UndirectedGraph Operation Test', () => { let graph: UndirectedGraph; @@ -149,17 +149,20 @@ describe('UndirectedGraph', () => { expect(degreeOfC).toBe(1); }); - // it('xxx', () => { - // const start = performance.now(); - // const graph = new UndirectedGraph<{ fromFeatureId: number; name: string; parentName: string; distanceFromParent: number; coordinates: number[]; }, number >() - // for (const v of saltyVertexes) { - // graph.addVertex(v.name, v); - // } - // for (const e of saltyEdges) { - // const [s,d] = e; - // graph.addEdge( s.name, d.name, d.distanceFromParent ); - // } - // const result = graph.getAllPathsBetween('Intersection_1','Intersection_5'); - // console.log('---xxx', performance.now() - start, result) - // }) + it('xxx', () => { + // const start = performance.now(); + const graph = new UndirectedGraph<{ name: string }, number >() + for (const v of saltyVertexes) { + graph.addVertex(v.name, v); + } + for (const e of saltyEdges) { + const [s,d] = e; + graph.addEdge( s.name, d.name, d.weight ); + } + // const result = graph.getAllPathsBetween('Intersection_1','Intersection_5'); + // console.log('---xxx', performance.now() - start, result) + // const result = graph.dijkstra('Intersection_1','Intersection_5', true, true); + // console.log('---xxx', performance.now() - start, result) + + }) });