data-structure-typed 2.4.5 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
- package/CHANGELOG.md +3 -1
- package/README.md +78 -31
- package/dist/cjs/binary-tree.cjs +23698 -0
- package/dist/cjs/graph.cjs +5236 -0
- package/dist/cjs/hash.cjs +1262 -0
- package/dist/cjs/heap.cjs +1540 -0
- package/dist/cjs/index.cjs +24509 -2899
- package/dist/cjs/linked-list.cjs +4370 -0
- package/dist/cjs/matrix.cjs +1042 -0
- package/dist/cjs/priority-queue.cjs +1314 -0
- package/dist/cjs/queue.cjs +4090 -0
- package/dist/cjs/stack.cjs +861 -0
- package/dist/cjs/trie.cjs +1173 -0
- package/dist/cjs-legacy/binary-tree.cjs +23730 -0
- package/dist/cjs-legacy/graph.cjs +5234 -0
- package/dist/cjs-legacy/hash.cjs +1262 -0
- package/dist/cjs-legacy/heap.cjs +1537 -0
- package/dist/cjs-legacy/index.cjs +32555 -10936
- package/dist/cjs-legacy/linked-list.cjs +4376 -0
- package/dist/cjs-legacy/matrix.cjs +1045 -0
- package/dist/cjs-legacy/priority-queue.cjs +1312 -0
- package/dist/cjs-legacy/queue.cjs +4088 -0
- package/dist/cjs-legacy/stack.cjs +861 -0
- package/dist/cjs-legacy/trie.cjs +1172 -0
- package/dist/esm/binary-tree.mjs +23683 -0
- package/dist/esm/graph.mjs +5223 -0
- package/dist/esm/hash.mjs +1259 -0
- package/dist/esm/heap.mjs +1534 -0
- package/dist/esm/index.mjs +24507 -2898
- package/dist/esm/linked-list.mjs +4363 -0
- package/dist/esm/matrix.mjs +1038 -0
- package/dist/esm/priority-queue.mjs +1310 -0
- package/dist/esm/queue.mjs +4086 -0
- package/dist/esm/stack.mjs +859 -0
- package/dist/esm/trie.mjs +1170 -0
- package/dist/esm-legacy/binary-tree.mjs +23715 -0
- package/dist/esm-legacy/graph.mjs +5221 -0
- package/dist/esm-legacy/hash.mjs +1259 -0
- package/dist/esm-legacy/heap.mjs +1531 -0
- package/dist/esm-legacy/index.mjs +32553 -10935
- package/dist/esm-legacy/linked-list.mjs +4369 -0
- package/dist/esm-legacy/matrix.mjs +1041 -0
- package/dist/esm-legacy/priority-queue.mjs +1308 -0
- package/dist/esm-legacy/queue.mjs +4084 -0
- package/dist/esm-legacy/stack.mjs +859 -0
- package/dist/esm-legacy/trie.mjs +1169 -0
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +368 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +473 -147
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +931 -80
- package/dist/types/data-structures/binary-tree/bst.d.ts +792 -29
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +592 -32
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +320 -135
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3662 -6
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3487 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2778 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3414 -6
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +419 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +384 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +462 -89
- package/dist/types/data-structures/heap/heap.d.ts +567 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +631 -49
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +581 -68
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +775 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +491 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +578 -71
- package/dist/types/data-structures/queue/queue.d.ts +451 -42
- package/dist/types/data-structures/stack/stack.d.ts +374 -32
- package/dist/types/data-structures/trie/trie.d.ts +458 -48
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/data-structure-typed.js +32432 -10808
- package/dist/umd/data-structure-typed.min.js +10 -4
- package/docs-site-docusaurus/README.md +41 -0
- package/docs-site-docusaurus/docs/api/README.md +52 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6130 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
- package/docs-site-docusaurus/docs/api/classes/BST.md +5831 -0
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
- package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
- package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
- package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6374 -0
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
- package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1257 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1475 -0
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1117 -0
- package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
- package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/architecture.md +613 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +420 -0
- package/docs-site-docusaurus/docs/guide/guides.md +611 -0
- package/docs-site-docusaurus/docs/guide/installation.md +60 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +823 -0
- package/docs-site-docusaurus/docs/guide/overview.md +638 -0
- package/docs-site-docusaurus/docs/guide/performance.md +833 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +73 -0
- package/docs-site-docusaurus/docusaurus.config.ts +159 -0
- package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
- package/docs-site-docusaurus/package-lock.json +18667 -0
- package/docs-site-docusaurus/package.json +50 -0
- package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
- package/docs-site-docusaurus/sidebars.ts +23 -0
- package/docs-site-docusaurus/sort-protected.mjs +87 -0
- package/docs-site-docusaurus/src/css/custom.css +96 -0
- package/docs-site-docusaurus/src/pages/index.module.css +13 -0
- package/docs-site-docusaurus/src/pages/index.tsx +71 -0
- package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
- package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
- package/docs-site-docusaurus/static/.nojekyll +0 -0
- package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
- package/docs-site-docusaurus/static/img/favicon.ico +0 -0
- package/docs-site-docusaurus/static/img/favicon.png +0 -0
- package/docs-site-docusaurus/static/img/logo-180.png +0 -0
- package/docs-site-docusaurus/static/img/logo.jpg +0 -0
- package/docs-site-docusaurus/static/img/logo.png +0 -0
- package/docs-site-docusaurus/static/img/logo.svg +1 -0
- package/docs-site-docusaurus/static/img/og-image.png +0 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
- package/docs-site-docusaurus/static/robots.txt +4 -0
- package/docs-site-docusaurus/typedoc.json +23 -0
- package/package.json +109 -12
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +386 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
- package/src/data-structures/binary-tree/binary-tree.ts +956 -81
- package/src/data-structures/binary-tree/bst.ts +840 -35
- package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
- package/src/data-structures/binary-tree/segment-tree.ts +498 -249
- package/src/data-structures/binary-tree/tree-map.ts +3784 -7
- package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
- package/src/data-structures/binary-tree/tree-set.ts +3531 -10
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +429 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +393 -59
- package/src/data-structures/hash/hash-map.ts +476 -92
- package/src/data-structures/heap/heap.ts +581 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
- package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
- package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
- package/src/data-structures/matrix/matrix.ts +584 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +592 -70
- package/src/data-structures/queue/queue.ts +463 -42
- package/src/data-structures/stack/stack.ts +384 -32
- package/src/data-structures/trie/trie.ts +470 -48
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
- package/vercel.json +6 -0
- package/dist/leetcode/avl-tree-counter.mjs +0 -2957
- package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
- package/dist/leetcode/avl-tree.mjs +0 -2720
- package/dist/leetcode/binary-tree.mjs +0 -1594
- package/dist/leetcode/bst.mjs +0 -2398
- package/dist/leetcode/deque.mjs +0 -683
- package/dist/leetcode/directed-graph.mjs +0 -1733
- package/dist/leetcode/doubly-linked-list.mjs +0 -709
- package/dist/leetcode/hash-map.mjs +0 -493
- package/dist/leetcode/heap.mjs +0 -542
- package/dist/leetcode/max-heap.mjs +0 -375
- package/dist/leetcode/max-priority-queue.mjs +0 -383
- package/dist/leetcode/min-heap.mjs +0 -363
- package/dist/leetcode/min-priority-queue.mjs +0 -371
- package/dist/leetcode/priority-queue.mjs +0 -363
- package/dist/leetcode/queue.mjs +0 -943
- package/dist/leetcode/red-black-tree.mjs +0 -2765
- package/dist/leetcode/singly-linked-list.mjs +0 -754
- package/dist/leetcode/stack.mjs +0 -217
- package/dist/leetcode/tree-counter.mjs +0 -3039
- package/dist/leetcode/tree-multi-map.mjs +0 -2913
- package/dist/leetcode/trie.mjs +0 -413
- package/dist/leetcode/undirected-graph.mjs +0 -1650
|
@@ -131,7 +131,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
131
131
|
* @returns `true` if string/number; else `false`.
|
|
132
132
|
* @remarks Time O(1), Space O(1)
|
|
133
133
|
*/
|
|
134
|
-
isVertexKey(potentialKey:
|
|
134
|
+
isVertexKey(potentialKey: unknown): potentialKey is VertexKey;
|
|
135
135
|
/**
|
|
136
136
|
* Delete a vertex and its incident edges.
|
|
137
137
|
* @param vertexOrKey - Vertex or key.
|
|
@@ -252,13 +252,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
252
252
|
* @returns A new graph of the same concrete class (`this` type).
|
|
253
253
|
* @remarks Time O(V + E), Space O(V + E)
|
|
254
254
|
*/
|
|
255
|
-
filter(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?:
|
|
255
|
+
filter(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: unknown): this;
|
|
256
256
|
/**
|
|
257
257
|
* Preserve the old behavior: return filtered entries as an array.
|
|
258
258
|
* @remarks Time O(V), Space O(V)
|
|
259
259
|
*/
|
|
260
|
-
filterEntries(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?:
|
|
261
|
-
map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?:
|
|
260
|
+
filterEntries(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: unknown): [VertexKey, V | undefined][];
|
|
261
|
+
map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: unknown): T[];
|
|
262
262
|
/**
|
|
263
263
|
* Create a deep clone of the graph with the same species.
|
|
264
264
|
* @remarks Time O(V + E), Space O(V + E)
|
|
@@ -65,53 +65,6 @@ export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
|
|
|
65
65
|
* console.log(neighborsA[0].key); // 'B';
|
|
66
66
|
* console.log(neighborsA[1].key); // 'C';
|
|
67
67
|
* @example
|
|
68
|
-
* // DirectedGraph deleteEdge and vertex operations
|
|
69
|
-
* const graph = new DirectedGraph<string>();
|
|
70
|
-
*
|
|
71
|
-
* // Build a small graph
|
|
72
|
-
* graph.addVertex('X');
|
|
73
|
-
* graph.addVertex('Y');
|
|
74
|
-
* graph.addVertex('Z');
|
|
75
|
-
* graph.addEdge('X', 'Y', 1);
|
|
76
|
-
* graph.addEdge('Y', 'Z', 2);
|
|
77
|
-
*
|
|
78
|
-
* // Delete an edge
|
|
79
|
-
* graph.deleteEdgeSrcToDest('X', 'Y');
|
|
80
|
-
* console.log(graph.hasEdge('X', 'Y')); // false;
|
|
81
|
-
*
|
|
82
|
-
* // Edge in other direction should not exist
|
|
83
|
-
* console.log(graph.hasEdge('Y', 'X')); // false;
|
|
84
|
-
*
|
|
85
|
-
* // Other edges should remain
|
|
86
|
-
* console.log(graph.hasEdge('Y', 'Z')); // true;
|
|
87
|
-
*
|
|
88
|
-
* // Delete a vertex
|
|
89
|
-
* graph.deleteVertex('Y');
|
|
90
|
-
* console.log(graph.hasVertex('Y')); // false;
|
|
91
|
-
* console.log(graph.size); // 2;
|
|
92
|
-
* @example
|
|
93
|
-
* // DirectedGraph topologicalSort for task scheduling
|
|
94
|
-
* const graph = new DirectedGraph<string>();
|
|
95
|
-
*
|
|
96
|
-
* // Build a DAG (Directed Acyclic Graph) for task dependencies
|
|
97
|
-
* graph.addVertex('Design');
|
|
98
|
-
* graph.addVertex('Implement');
|
|
99
|
-
* graph.addVertex('Test');
|
|
100
|
-
* graph.addVertex('Deploy');
|
|
101
|
-
*
|
|
102
|
-
* // Add dependency edges
|
|
103
|
-
* graph.addEdge('Design', 'Implement', 1); // Design must come before Implement
|
|
104
|
-
* graph.addEdge('Implement', 'Test', 1); // Implement must come before Test
|
|
105
|
-
* graph.addEdge('Test', 'Deploy', 1); // Test must come before Deploy
|
|
106
|
-
*
|
|
107
|
-
* // Topological sort gives valid execution order
|
|
108
|
-
* const executionOrder = graph.topologicalSort();
|
|
109
|
-
* console.log(executionOrder); // defined;
|
|
110
|
-
* console.log(executionOrder); // ['Design', 'Implement', 'Test', 'Deploy'];
|
|
111
|
-
*
|
|
112
|
-
* // All vertices should be included
|
|
113
|
-
* console.log(executionOrder?.length); // 4;
|
|
114
|
-
* @example
|
|
115
68
|
* // DirectedGraph dijkstra shortest path for network routing
|
|
116
69
|
* // Build a weighted directed graph representing network nodes and costs
|
|
117
70
|
* const network = new DirectedGraph<string>();
|
|
@@ -204,6 +157,42 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
204
157
|
* @param destOrKey - Destination vertex or key.
|
|
205
158
|
* @returns Edge instance or `undefined`.
|
|
206
159
|
* @remarks Time O(1) avg, Space O(1)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
* @example
|
|
189
|
+
* // Get edge between vertices
|
|
190
|
+
* const g = new DirectedGraph();
|
|
191
|
+
* g.addVertex('A');
|
|
192
|
+
* g.addVertex('B');
|
|
193
|
+
* g.addEdge('A', 'B', 5);
|
|
194
|
+
* const edge = g.getEdge('A', 'B');
|
|
195
|
+
* console.log(edge?.weight); // 5;
|
|
207
196
|
*/
|
|
208
197
|
getEdge(srcOrKey: VO | VertexKey | undefined, destOrKey: VO | VertexKey | undefined): EO | undefined;
|
|
209
198
|
/**
|
|
@@ -220,8 +209,104 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
220
209
|
* @param destVertexKey - Optional destination vertex/key when deleting by pair.
|
|
221
210
|
* @returns Removed edge or `undefined`.
|
|
222
211
|
* @remarks Time O(1) avg, Space O(1)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
* @example
|
|
244
|
+
* // DirectedGraph deleteEdge and vertex operations
|
|
245
|
+
* const graph = new DirectedGraph<string>();
|
|
246
|
+
*
|
|
247
|
+
* // Build a small graph
|
|
248
|
+
* graph.addVertex('X');
|
|
249
|
+
* graph.addVertex('Y');
|
|
250
|
+
* graph.addVertex('Z');
|
|
251
|
+
* graph.addEdge('X', 'Y', 1);
|
|
252
|
+
* graph.addEdge('Y', 'Z', 2);
|
|
253
|
+
*
|
|
254
|
+
* // Delete an edge
|
|
255
|
+
* graph.deleteEdgeSrcToDest('X', 'Y');
|
|
256
|
+
* console.log(graph.hasEdge('X', 'Y')); // false;
|
|
257
|
+
*
|
|
258
|
+
* // Edge in other direction should not exist
|
|
259
|
+
* console.log(graph.hasEdge('Y', 'X')); // false;
|
|
260
|
+
*
|
|
261
|
+
* // Other edges should remain
|
|
262
|
+
* console.log(graph.hasEdge('Y', 'Z')); // true;
|
|
263
|
+
*
|
|
264
|
+
* // Delete a vertex
|
|
265
|
+
* graph.deleteVertex('Y');
|
|
266
|
+
* console.log(graph.hasVertex('Y')); // false;
|
|
267
|
+
* console.log(graph.size); // 2;
|
|
223
268
|
*/
|
|
224
269
|
deleteEdge(edgeOrSrcVertexKey: EO | VertexKey, destVertexKey?: VertexKey): EO | undefined;
|
|
270
|
+
/**
|
|
271
|
+
* Remove a vertex
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
* @example
|
|
301
|
+
* // Remove a vertex
|
|
302
|
+
* const g = new DirectedGraph();
|
|
303
|
+
* g.addVertex('A');
|
|
304
|
+
* g.addVertex('B');
|
|
305
|
+
* g.addEdge('A', 'B');
|
|
306
|
+
* g.deleteVertex('A');
|
|
307
|
+
* console.log(g.hasVertex('A')); // false;
|
|
308
|
+
* console.log(g.hasEdge('A', 'B')); // false;
|
|
309
|
+
*/
|
|
225
310
|
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
226
311
|
deleteEdgesBetween(v1: VertexKey | VO, v2: VertexKey | VO): EO[];
|
|
227
312
|
/**
|
|
@@ -229,6 +314,43 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
229
314
|
* @param vertexOrKey - Vertex or key.
|
|
230
315
|
* @returns Array of incoming edges.
|
|
231
316
|
* @remarks Time O(deg_in), Space O(deg_in)
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
* @example
|
|
346
|
+
* // Get incoming edges
|
|
347
|
+
* const g = new DirectedGraph();
|
|
348
|
+
* g.addVertex('A');
|
|
349
|
+
* g.addVertex('B');
|
|
350
|
+
* g.addVertex('C');
|
|
351
|
+
* g.addEdge('A', 'C');
|
|
352
|
+
* g.addEdge('B', 'C');
|
|
353
|
+
* console.log(g.incomingEdgesOf('C').length); // 2;
|
|
232
354
|
*/
|
|
233
355
|
incomingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
234
356
|
/**
|
|
@@ -236,6 +358,43 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
236
358
|
* @param vertexOrKey - Vertex or key.
|
|
237
359
|
* @returns Array of outgoing edges.
|
|
238
360
|
* @remarks Time O(deg_out), Space O(deg_out)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
* @example
|
|
390
|
+
* // Get outgoing edges
|
|
391
|
+
* const g = new DirectedGraph();
|
|
392
|
+
* g.addVertex('A');
|
|
393
|
+
* g.addVertex('B');
|
|
394
|
+
* g.addVertex('C');
|
|
395
|
+
* g.addEdge('A', 'B');
|
|
396
|
+
* g.addEdge('A', 'C');
|
|
397
|
+
* console.log(g.outgoingEdgesOf('A').length); // 2;
|
|
239
398
|
*/
|
|
240
399
|
outgoingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
241
400
|
/**
|
|
@@ -268,9 +427,142 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
268
427
|
* @param propertyName - `'key'` to map to keys; `'vertex'` to keep instances.
|
|
269
428
|
* @returns Array of keys/vertices, or `undefined` when cycle is found.
|
|
270
429
|
* @remarks Time O(V + E), Space O(V)
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
* @example
|
|
462
|
+
* // DirectedGraph topologicalSort for task scheduling
|
|
463
|
+
* const graph = new DirectedGraph<string>();
|
|
464
|
+
*
|
|
465
|
+
* // Build a DAG (Directed Acyclic Graph) for task dependencies
|
|
466
|
+
* graph.addVertex('Design');
|
|
467
|
+
* graph.addVertex('Implement');
|
|
468
|
+
* graph.addVertex('Test');
|
|
469
|
+
* graph.addVertex('Deploy');
|
|
470
|
+
*
|
|
471
|
+
* // Add dependency edges
|
|
472
|
+
* graph.addEdge('Design', 'Implement', 1); // Design must come before Implement
|
|
473
|
+
* graph.addEdge('Implement', 'Test', 1); // Implement must come before Test
|
|
474
|
+
* graph.addEdge('Test', 'Deploy', 1); // Test must come before Deploy
|
|
475
|
+
*
|
|
476
|
+
* // Topological sort gives valid execution order
|
|
477
|
+
* const executionOrder = graph.topologicalSort();
|
|
478
|
+
* console.log(executionOrder); // defined;
|
|
479
|
+
* console.log(executionOrder); // ['Design', 'Implement', 'Test', 'Deploy'];
|
|
480
|
+
*
|
|
481
|
+
* // All vertices should be included
|
|
482
|
+
* console.log(executionOrder?.length); // 4;
|
|
271
483
|
*/
|
|
272
484
|
topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | undefined;
|
|
485
|
+
/**
|
|
486
|
+
* Get all edges
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
* @example
|
|
516
|
+
* // Get all edges
|
|
517
|
+
* const g = new DirectedGraph();
|
|
518
|
+
* g.addVertex('A');
|
|
519
|
+
* g.addVertex('B');
|
|
520
|
+
* g.addEdge('A', 'B', 3);
|
|
521
|
+
* console.log(g.edgeSet().length); // 1;
|
|
522
|
+
*/
|
|
273
523
|
edgeSet(): EO[];
|
|
524
|
+
/**
|
|
525
|
+
* Get outgoing neighbors
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
* @example
|
|
556
|
+
* // Get outgoing neighbors
|
|
557
|
+
* const g = new DirectedGraph();
|
|
558
|
+
* g.addVertex('A');
|
|
559
|
+
* g.addVertex('B');
|
|
560
|
+
* g.addVertex('C');
|
|
561
|
+
* g.addEdge('A', 'B');
|
|
562
|
+
* g.addEdge('A', 'C');
|
|
563
|
+
* const neighbors = g.getNeighbors('A');
|
|
564
|
+
* console.log(neighbors.map(v => v.key).sort()); // ['B', 'C'];
|
|
565
|
+
*/
|
|
274
566
|
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
275
567
|
/**
|
|
276
568
|
* Resolve an edge's `[src, dest]` endpoints to vertex instances.
|
|
@@ -299,6 +591,47 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
299
591
|
* Tarjan's algorithm for strongly connected components.
|
|
300
592
|
* @returns `{ dfnMap, lowMap, SCCs }`.
|
|
301
593
|
* @remarks Time O(V + E), Space O(V + E)
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
* @example
|
|
623
|
+
* // Find strongly connected components
|
|
624
|
+
* const g = new DirectedGraph();
|
|
625
|
+
* g.addVertex('A');
|
|
626
|
+
* g.addVertex('B');
|
|
627
|
+
* g.addVertex('C');
|
|
628
|
+
* g.addEdge('A', 'B');
|
|
629
|
+
* g.addEdge('B', 'C');
|
|
630
|
+
* g.addEdge('C', 'A');
|
|
631
|
+
* const { SCCs } = g.tarjan();
|
|
632
|
+
* // A→B→C→A forms one SCC with 3 members
|
|
633
|
+
* const sccArrays = [...SCCs.values()];
|
|
634
|
+
* console.log(sccArrays.some(scc => scc.length === 3)); // true;
|
|
302
635
|
*/
|
|
303
636
|
tarjan(): {
|
|
304
637
|
dfnMap: Map<VO, number>;
|
|
@@ -321,6 +654,45 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
321
654
|
* Strongly connected components computed by `tarjan()`.
|
|
322
655
|
* @returns Map from SCC id to vertices.
|
|
323
656
|
* @remarks Time O(#SCC + V), Space O(V)
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
* @example
|
|
686
|
+
* // Get strongly connected components
|
|
687
|
+
* const g = new DirectedGraph();
|
|
688
|
+
* g.addVertex(1);
|
|
689
|
+
* g.addVertex(2);
|
|
690
|
+
* g.addVertex(3);
|
|
691
|
+
* g.addEdge(1, 2);
|
|
692
|
+
* g.addEdge(2, 3);
|
|
693
|
+
* g.addEdge(3, 1);
|
|
694
|
+
* const sccs = g.getSCCs(); // Map<number, VO[]>
|
|
695
|
+
* console.log(sccs.size); // >= 1;
|
|
324
696
|
*/
|
|
325
697
|
getSCCs(): Map<number, VO[]>;
|
|
326
698
|
/**
|
|
@@ -22,7 +22,65 @@ export declare class MapEdge<E = any> extends DirectedEdge<E> {
|
|
|
22
22
|
* @template VO - Concrete vertex class (MapVertex<V>).
|
|
23
23
|
* @template EO - Concrete edge class (MapEdge<E>).
|
|
24
24
|
* @remarks Time O(1), Space O(1)
|
|
25
|
-
* @example
|
|
25
|
+
* @example
|
|
26
|
+
* // City navigation with shortest path
|
|
27
|
+
* const map = new MapGraph([0, 0], [10, 10]);
|
|
28
|
+
*
|
|
29
|
+
* map.addVertex(new MapVertex('Home', '', 0, 0));
|
|
30
|
+
* map.addVertex(new MapVertex('Office', '', 3, 4));
|
|
31
|
+
* map.addVertex(new MapVertex('Cafe', '', 1, 2));
|
|
32
|
+
* map.addVertex(new MapVertex('Park', '', 2, 1));
|
|
33
|
+
*
|
|
34
|
+
* map.addEdge('Home', 'Cafe', 2.2);
|
|
35
|
+
* map.addEdge('Cafe', 'Office', 3.5);
|
|
36
|
+
* map.addEdge('Home', 'Park', 2.0);
|
|
37
|
+
* map.addEdge('Park', 'Office', 4.0);
|
|
38
|
+
* map.addEdge('Home', 'Office', 7.0);
|
|
39
|
+
*
|
|
40
|
+
* // Find shortest path
|
|
41
|
+
* const result = map.dijkstra('Home', 'Office', true, true);
|
|
42
|
+
* console.log(result?.minDist); // 5.7; // Home → Cafe → Office
|
|
43
|
+
* console.log(result?.minPath.map(v => v.key)); // ['Home', 'Cafe', 'Office'];
|
|
44
|
+
* @example
|
|
45
|
+
* // Delivery route optimization
|
|
46
|
+
* const routes = new MapGraph([0, 0], [10, 10]);
|
|
47
|
+
*
|
|
48
|
+
* routes.addVertex(new MapVertex('Warehouse', '', 0, 0));
|
|
49
|
+
* routes.addVertex(new MapVertex('Customer A', '', 2, 3));
|
|
50
|
+
* routes.addVertex(new MapVertex('Customer B', '', 5, 1));
|
|
51
|
+
* routes.addVertex(new MapVertex('Customer C', '', 3, 5));
|
|
52
|
+
*
|
|
53
|
+
* routes.addEdge('Warehouse', 'Customer A', 3.6);
|
|
54
|
+
* routes.addEdge('Warehouse', 'Customer B', 5.1);
|
|
55
|
+
* routes.addEdge('Customer A', 'Customer C', 2.2);
|
|
56
|
+
* routes.addEdge('Customer A', 'Customer B', 3.6);
|
|
57
|
+
* routes.addEdge('Customer B', 'Customer C', 4.5);
|
|
58
|
+
*
|
|
59
|
+
* // Check outgoing neighbors of Customer A
|
|
60
|
+
* const neighbors = routes.getNeighbors('Customer A');
|
|
61
|
+
* console.log(neighbors.map(n => n.key).sort()); // ['Customer B', 'Customer C'];
|
|
62
|
+
*
|
|
63
|
+
* // Shortest path from Warehouse to Customer C
|
|
64
|
+
* const path = routes.getMinPathBetween('Warehouse', 'Customer C', true);
|
|
65
|
+
* console.log(path?.map(v => v.key)); // ['Warehouse', 'Customer A', 'Customer C'];
|
|
66
|
+
* @example
|
|
67
|
+
* // Campus map with building connections
|
|
68
|
+
* const campus = new MapGraph([0, 0], [5, 5]);
|
|
69
|
+
*
|
|
70
|
+
* campus.addVertex(new MapVertex('Library', '', 0, 0));
|
|
71
|
+
* campus.addVertex(new MapVertex('Lab', '', 1, 1));
|
|
72
|
+
* campus.addVertex(new MapVertex('Cafeteria', '', 2, 0));
|
|
73
|
+
*
|
|
74
|
+
* campus.addEdge('Library', 'Lab', 5);
|
|
75
|
+
* campus.addEdge('Lab', 'Cafeteria', 3);
|
|
76
|
+
* campus.addEdge('Library', 'Cafeteria', 10);
|
|
77
|
+
*
|
|
78
|
+
* console.log(campus.hasVertex('Library')); // true;
|
|
79
|
+
* console.log(campus.hasVertex('Gym')); // false;
|
|
80
|
+
*
|
|
81
|
+
* // Direct distance vs shortest path
|
|
82
|
+
* const direct = campus.dijkstra('Library', 'Cafeteria', true, true);
|
|
83
|
+
* console.log(direct?.minDist); // 8;
|
|
26
84
|
*/
|
|
27
85
|
export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVertex<V>, EO extends MapEdge<E> = MapEdge<E>> extends DirectedGraph<V, E, VO, EO> {
|
|
28
86
|
/**
|