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 name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 add randomly | 2.21 | 451.50 | 24 | 0.00 | 9.12e-5 |
1000 add & delete randomly | 5.02 | 199.23 | 11 | 0.01 | 6.31e-4 |
1000 addMany | 2.96 | 338.41 | 18 | 0.00 | 2.09e-4 |
1000 get | 2.00 | 499.79 | 26 | 0.00 | 1.89e-4 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 add randomly | 2.28 | 438.38 | 23 | 0.00 | 2.56e-5 |
1000 add & delete randomly | 5.16 | 193.94 | 11 | 0.01 | 7.96e-4 |
1000 addMany | 3.05 | 328.30 | 17 | 0.00 | 3.13e-4 |
1000 get | 2.08 | 480.72 | 25 | 0.00 | 9.01e-5 |
binary-tree
-
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 add randomly | 12.95 | 77.23 | 5 | 0.01 | 1.82e-4 |
1000 add & delete randomly | 15.94 | 62.73 | 4 | 0.02 | 1.95e-4 |
1000 addMany | 10.81 | 92.48 | 5 | 0.01 | 5.30e-4 |
1000 get | 18.16 | 55.07 | 3 | 0.02 | 2.99e-4 |
1000 dfs | 69.52 | 14.38 | 1 | 0.07 | 0.00 |
1000 bfs | 54.84 | 18.24 | 1 | 0.05 | 7.36e-4 |
1000 morris | 38.26 | 26.13 | 2 | 0.04 | 0.00 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 add randomly | 12.88 | 77.65 | 5 | 0.01 | 1.17e-4 |
1000 add & delete randomly | 15.95 | 62.70 | 4 | 0.02 | 1.78e-4 |
1000 addMany | 10.61 | 94.25 | 5 | 0.01 | 1.16e-4 |
1000 get | 18.02 | 55.51 | 3 | 0.02 | 1.59e-4 |
1000 dfs | 69.95 | 14.30 | 1 | 0.07 | 6.49e-4 |
1000 bfs | 54.78 | 18.25 | 1 | 0.05 | 4.98e-4 |
1000 morris | 37.26 | 26.83 | 2 | 0.04 | 2.16e-4 |
bst
-
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 add randomly | 2.22 | 450.51 | 24 | 0.00 | 6.06e-5 |
1000 add & delete randomly | 5.04 | 198.59 | 11 | 0.01 | 2.52e-4 |
1000 addMany | 2.14 | 467.96 | 25 | 0.00 | 6.00e-5 |
1000 get | 2.06 | 486.16 | 25 | 0.00 | 1.15e-4 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 add randomly | 2.02 | 496.10 | 25 | 0.00 | 1.56e-5 |
1000 add & delete randomly | 4.60 | 217.31 | 12 | 0.00 | 4.43e-4 |
1000 addMany | 2.23 | 448.71 | 24 | 0.00 | 2.96e-4 |
1000 get | 2.09 | 479.52 | 25 | 0.00 | 1.27e-5 |
directed-graph
-
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 addVertex | 0.10 | 9726.70 | 496 | 1.03e-4 | 1.60e-6 |
1000 addEdge | 6.23 | 160.46 | 9 | 0.01 | 5.60e-4 |
1000 getVertex | 0.05 | 2.17e+4 | 1097 | 4.61e-5 | 3.68e-7 |
1000 getEdge | 23.53 | 42.49 | 3 | 0.02 | 0.00 |
tarjan | 216.40 | 4.62 | 1 | 0.22 | 0.01 |
tarjan all | 218.57 | 4.58 | 1 | 0.22 | 0.00 |
topologicalSort | 186.63 | 5.36 | 1 | 0.19 | 0.03 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 addVertex | 0.10 | 9871.96 | 501 | 1.01e-4 | 7.32e-7 |
1000 addEdge | 6.48 | 154.29 | 9 | 0.01 | 0.00 |
1000 getVertex | 0.05 | 2.17e+4 | 1110 | 4.61e-5 | 3.80e-7 |
1000 getEdge | 24.65 | 40.57 | 3 | 0.02 | 0.01 |
tarjan | 208.00 | 4.81 | 1 | 0.21 | 0.01 |
tarjan all | 212.97 | 4.70 | 1 | 0.21 | 0.00 |
topologicalSort | 171.49 | 5.83 | 1 | 0.17 | 0.01 |
heap
-
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 add & pop | 0.34 | 2927.03 | 149 | 3.42e-4 | 3.47e-6 |
1000 fib add & pop | 3.91 | 255.63 | 13 | 0.00 | 4.55e-5 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 add & pop | 0.34 | 2929.81 | 149 | 3.41e-4 | 2.37e-6 |
1000 fib add & pop | 3.89 | 257.31 | 14 | 0.00 | 2.53e-5 |
doubly-linked-list
-
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000000 unshift | 200.25 | 4.99 | 1 | 0.20 | 0.03 |
1000000 unshift & shift | 183.25 | 5.46 | 1 | 0.18 | 0.05 |
1000 insertBefore | 0.03 | 3.64e+4 | 2005 | 2.75e-5 | 8.47e-7 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000000 unshift | 212.40 | 4.71 | 1 | 0.21 | 0.02 |
1000000 unshift & shift | 172.94 | 5.78 | 1 | 0.17 | 0.03 |
1000 insertBefore | 0.03 | 3.70e+4 | 1903 | 2.71e-5 | 2.38e-6 |
singly-linked-list
-
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 push & pop | 1.79 | 558.34 | 30 | 0.00 | 6.00e-5 |
1000 insertBefore | 2.40 | 417.00 | 22 | 0.00 | 3.01e-4 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000 push & pop | 1.75 | 571.73 | 30 | 0.00 | 5.06e-5 |
1000 insertBefore | 2.30 | 434.82 | 22 | 0.00 | 5.10e-5 |
max-priority-queue
-
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
10000 refill & poll | 11.77 | 84.98 | 5 | 0.01 | 0.00 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
10000 refill & poll | 11.41 | 87.65 | 5 | 0.01 | 1.49e-4 |
deque
-
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000000 push | 224.48 | 4.45 | 1 | 0.22 | 0.03 |
1000000 shift | 27.21 | 36.76 | 3 | 0.03 | 0.00 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000000 push | 212.51 | 4.71 | 1 | 0.21 | 0.06 |
1000000 shift | 24.98 | 40.04 | 3 | 0.02 | 0.00 |
queue
-
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000000 push | 46.46 | 21.52 | 2 | 0.05 | 0.01 |
1000000 push & shift | 78.88 | 12.68 | 1 | 0.08 | 0.00 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
1000000 push | 41.97 | 23.83 | 2 | 0.04 | 0.01 |
1000000 push & shift | 79.08 | 12.65 | 1 | 0.08 | 0.00 |
trie
-
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
100000 push | 54.62 | 18.31 | 1 | 0.05 | 9.87e-4 |
100000 getWords | 89.26 | 11.20 | 1 | 0.09 | 0.00 |
+
test name | time taken (ms) | executions per sec | executed times | sample mean (secs) | sample deviation |
---|
100000 push | 54.24 | 18.44 | 1 | 0.05 | 7.00e-4 |
100000 getWords | 96.12 | 10.40 | 1 | 0.10 | 0.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)
+
+ })
});