data-structure-typed 2.6.0 → 2.6.2
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/.github/workflows/ci.yml +7 -2
- package/.github/workflows/release-package.yml +9 -2
- package/CHANGELOG.md +9 -1
- package/dist/cjs/binary-tree.cjs +2927 -23688
- package/dist/cjs/graph.cjs +845 -2634
- package/dist/cjs/hash.cjs +185 -616
- package/dist/cjs/heap.cjs +266 -818
- package/dist/cjs/index.cjs +5116 -31358
- package/dist/cjs/linked-list.cjs +644 -2615
- package/dist/cjs/matrix.cjs +220 -535
- package/dist/cjs/priority-queue.cjs +266 -818
- package/dist/cjs/queue.cjs +637 -2343
- package/dist/cjs/stack.cjs +124 -530
- package/dist/cjs/trie.cjs +145 -592
- package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
- package/dist/cjs-legacy/graph.cjs +847 -2636
- package/dist/cjs-legacy/hash.cjs +181 -612
- package/dist/cjs-legacy/heap.cjs +266 -818
- package/dist/cjs-legacy/index.cjs +6657 -32899
- package/dist/cjs-legacy/linked-list.cjs +640 -2611
- package/dist/cjs-legacy/matrix.cjs +220 -535
- package/dist/cjs-legacy/priority-queue.cjs +266 -818
- package/dist/cjs-legacy/queue.cjs +634 -2340
- package/dist/cjs-legacy/stack.cjs +124 -530
- package/dist/cjs-legacy/trie.cjs +145 -592
- package/dist/esm/binary-tree.mjs +2927 -23688
- package/dist/esm/graph.mjs +845 -2634
- package/dist/esm/hash.mjs +185 -616
- package/dist/esm/heap.mjs +266 -818
- package/dist/esm/index.mjs +5116 -31358
- package/dist/esm/linked-list.mjs +644 -2615
- package/dist/esm/matrix.mjs +220 -535
- package/dist/esm/priority-queue.mjs +266 -818
- package/dist/esm/queue.mjs +637 -2343
- package/dist/esm/stack.mjs +124 -530
- package/dist/esm/trie.mjs +145 -592
- package/dist/esm-legacy/binary-tree.mjs +4352 -25113
- package/dist/esm-legacy/graph.mjs +847 -2636
- package/dist/esm-legacy/hash.mjs +181 -612
- package/dist/esm-legacy/heap.mjs +266 -818
- package/dist/esm-legacy/index.mjs +6657 -32899
- package/dist/esm-legacy/linked-list.mjs +640 -2611
- package/dist/esm-legacy/matrix.mjs +220 -535
- package/dist/esm-legacy/priority-queue.mjs +266 -818
- package/dist/esm-legacy/queue.mjs +634 -2340
- package/dist/esm-legacy/stack.mjs +124 -530
- package/dist/esm-legacy/trie.mjs +145 -592
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
- package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
- package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
- package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
- package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
- package/dist/types/data-structures/heap/heap.d.ts +194 -746
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
- package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +196 -804
- package/dist/types/data-structures/queue/queue.d.ts +99 -585
- package/dist/types/data-structures/stack/stack.d.ts +75 -481
- package/dist/types/data-structures/trie/trie.d.ts +98 -584
- package/dist/umd/data-structure-typed.js +6580 -32822
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +253 -101
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +244 -114
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
- package/docs-site-docusaurus/docs/api/classes/Heap.md +119 -64
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +84 -14
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +138 -34
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +149 -41
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +172 -92
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -62
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +120 -70
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -62
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +125 -75
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +119 -64
- package/docs-site-docusaurus/docs/api/classes/Queue.md +158 -74
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +172 -94
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
- package/docs-site-docusaurus/docs/api/classes/Stack.md +112 -50
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +90 -121
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +298 -107
- package/docs-site-docusaurus/docs/api/classes/Trie.md +116 -58
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
- package/package.json +45 -46
- package/src/common/error.ts +15 -32
- package/src/common/index.ts +0 -3
- package/src/data-structures/base/iterable-element-base.ts +0 -3
- package/src/data-structures/base/linear-base.ts +2 -36
- package/src/data-structures/binary-tree/avl-tree.ts +31 -529
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +47 -572
- package/src/data-structures/binary-tree/binary-tree.ts +326 -1311
- package/src/data-structures/binary-tree/bst.ts +158 -1082
- package/src/data-structures/binary-tree/red-black-tree.ts +451 -1290
- package/src/data-structures/binary-tree/segment-tree.ts +73 -351
- package/src/data-structures/binary-tree/tree-map.ts +462 -5124
- package/src/data-structures/binary-tree/tree-multi-map.ts +302 -4914
- package/src/data-structures/binary-tree/tree-multi-set.ts +299 -3983
- package/src/data-structures/binary-tree/tree-set.ts +338 -4836
- package/src/data-structures/graph/abstract-graph.ts +98 -167
- package/src/data-structures/graph/directed-graph.ts +137 -562
- package/src/data-structures/graph/map-graph.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +132 -511
- package/src/data-structures/hash/hash-map.ts +154 -582
- package/src/data-structures/heap/heap.ts +200 -795
- package/src/data-structures/linked-list/doubly-linked-list.ts +121 -865
- package/src/data-structures/linked-list/singly-linked-list.ts +122 -794
- package/src/data-structures/linked-list/skip-linked-list.ts +211 -918
- package/src/data-structures/matrix/matrix.ts +179 -518
- package/src/data-structures/matrix/navigator.ts +0 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -6
- package/src/data-structures/priority-queue/min-priority-queue.ts +6 -11
- package/src/data-structures/priority-queue/priority-queue.ts +1 -2
- package/src/data-structures/queue/deque.ts +214 -882
- package/src/data-structures/queue/queue.ts +102 -625
- package/src/data-structures/stack/stack.ts +76 -505
- package/src/data-structures/trie/trie.ts +98 -628
- package/src/types/common.ts +0 -10
- package/src/types/data-structures/binary-tree/bst.ts +0 -7
- package/src/types/data-structures/binary-tree/red-black-tree.ts +0 -1
- package/src/types/data-structures/graph/abstract-graph.ts +0 -2
- package/src/types/data-structures/hash/hash-map.ts +0 -3
- package/src/types/data-structures/hash/index.ts +0 -1
- package/src/types/data-structures/matrix/navigator.ts +0 -2
- package/src/types/utils/utils.ts +0 -7
- package/src/types/utils/validate-type.ts +0 -7
- package/src/utils/number.ts +0 -2
- package/src/utils/utils.ts +0 -5
|
@@ -174,52 +174,13 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
174
174
|
* @param v2 - The other vertex or key.
|
|
175
175
|
* @returns Edge instance or `undefined`.
|
|
176
176
|
* @remarks Time O(1) avg, Space O(1)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
* @example
|
|
217
|
-
* // Get edge between vertices
|
|
218
|
-
* const g = new UndirectedGraph();
|
|
219
|
-
* g.addVertex('A');
|
|
220
|
-
* g.addVertex('B');
|
|
221
|
-
* g.addEdge('A', 'B', 7);
|
|
222
|
-
* console.log(g.getEdge('A', 'B')?.weight); // 7;
|
|
177
|
+
* @example
|
|
178
|
+
* // Get edge between vertices
|
|
179
|
+
* const g = new UndirectedGraph();
|
|
180
|
+
* g.addVertex('A');
|
|
181
|
+
* g.addVertex('B');
|
|
182
|
+
* g.addEdge('A', 'B', 7);
|
|
183
|
+
* console.log(g.getEdge('A', 'B')?.weight); // 7;
|
|
223
184
|
*/
|
|
224
185
|
getEdge(v1: VO | VertexKey | undefined, v2: VO | VertexKey | undefined): EO | undefined;
|
|
225
186
|
/**
|
|
@@ -236,75 +197,33 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
236
197
|
* @param otherSideVertexKey - Required second endpoint when deleting by pair.
|
|
237
198
|
* @returns Removed edge or `undefined`.
|
|
238
199
|
* @remarks Time O(1) avg, Space O(1)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
* @example
|
|
282
|
-
* // UndirectedGraph deleteEdge and vertex operations
|
|
283
|
-
* const graph = new UndirectedGraph<string>();
|
|
284
|
-
*
|
|
285
|
-
* // Build a simple undirected graph
|
|
286
|
-
* graph.addVertex('X');
|
|
287
|
-
* graph.addVertex('Y');
|
|
288
|
-
* graph.addVertex('Z');
|
|
289
|
-
* graph.addEdge('X', 'Y', 1);
|
|
290
|
-
* graph.addEdge('Y', 'Z', 2);
|
|
291
|
-
* graph.addEdge('X', 'Z', 3);
|
|
292
|
-
*
|
|
293
|
-
* // Delete an edge
|
|
294
|
-
* graph.deleteEdge('X', 'Y');
|
|
295
|
-
* console.log(graph.hasEdge('X', 'Y')); // false;
|
|
296
|
-
*
|
|
297
|
-
* // Bidirectional deletion confirmed
|
|
298
|
-
* console.log(graph.hasEdge('Y', 'X')); // false;
|
|
299
|
-
*
|
|
300
|
-
* // Other edges should remain
|
|
301
|
-
* console.log(graph.hasEdge('Y', 'Z')); // true;
|
|
302
|
-
* console.log(graph.hasEdge('Z', 'Y')); // true;
|
|
303
|
-
*
|
|
304
|
-
* // Delete a vertex
|
|
305
|
-
* graph.deleteVertex('Y');
|
|
306
|
-
* console.log(graph.hasVertex('Y')); // false;
|
|
307
|
-
* console.log(graph.size); // 2;
|
|
200
|
+
* @example
|
|
201
|
+
* // UndirectedGraph deleteEdge and vertex operations
|
|
202
|
+
* const graph = new UndirectedGraph<string>();
|
|
203
|
+
*
|
|
204
|
+
* // Build a simple undirected graph
|
|
205
|
+
* graph.addVertex('X');
|
|
206
|
+
* graph.addVertex('Y');
|
|
207
|
+
* graph.addVertex('Z');
|
|
208
|
+
* graph.addEdge('X', 'Y', 1);
|
|
209
|
+
* graph.addEdge('Y', 'Z', 2);
|
|
210
|
+
* graph.addEdge('X', 'Z', 3);
|
|
211
|
+
*
|
|
212
|
+
* // Delete an edge
|
|
213
|
+
* graph.deleteEdge('X', 'Y');
|
|
214
|
+
* console.log(graph.hasEdge('X', 'Y')); // false;
|
|
215
|
+
*
|
|
216
|
+
* // Bidirectional deletion confirmed
|
|
217
|
+
* console.log(graph.hasEdge('Y', 'X')); // false;
|
|
218
|
+
*
|
|
219
|
+
* // Other edges should remain
|
|
220
|
+
* console.log(graph.hasEdge('Y', 'Z')); // true;
|
|
221
|
+
* console.log(graph.hasEdge('Z', 'Y')); // true;
|
|
222
|
+
*
|
|
223
|
+
* // Delete a vertex
|
|
224
|
+
* graph.deleteVertex('Y');
|
|
225
|
+
* console.log(graph.hasVertex('Y')); // false;
|
|
226
|
+
* console.log(graph.size); // 2;
|
|
308
227
|
*/
|
|
309
228
|
deleteEdge(edgeOrOneSideVertexKey: EO | VertexKey, otherSideVertexKey?: VertexKey): EO | undefined;
|
|
310
229
|
/**
|
|
@@ -312,53 +231,14 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
312
231
|
* @param vertexOrKey - Vertex or key.
|
|
313
232
|
* @returns `true` if removed; otherwise `false`.
|
|
314
233
|
* @remarks Time O(deg), Space O(1)
|
|
315
|
-
|
|
316
|
-
|
|
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
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
* @example
|
|
355
|
-
* // Remove vertex and edges
|
|
356
|
-
* const g = new UndirectedGraph();
|
|
357
|
-
* g.addVertex('A');
|
|
358
|
-
* g.addVertex('B');
|
|
359
|
-
* g.addEdge('A', 'B');
|
|
360
|
-
* g.deleteVertex('A');
|
|
361
|
-
* console.log(g.hasVertex('A')); // false;
|
|
234
|
+
* @example
|
|
235
|
+
* // Remove vertex and edges
|
|
236
|
+
* const g = new UndirectedGraph();
|
|
237
|
+
* g.addVertex('A');
|
|
238
|
+
* g.addVertex('B');
|
|
239
|
+
* g.addEdge('A', 'B');
|
|
240
|
+
* g.deleteVertex('A');
|
|
241
|
+
* console.log(g.hasVertex('A')); // false;
|
|
362
242
|
*/
|
|
363
243
|
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
364
244
|
/**
|
|
@@ -379,131 +259,50 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
379
259
|
* Unique set of undirected edges across endpoints.
|
|
380
260
|
* @returns Array of edges.
|
|
381
261
|
* @remarks Time O(E), Space O(E)
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
* @example
|
|
422
|
-
* // Get all edges
|
|
423
|
-
* const g = new UndirectedGraph();
|
|
424
|
-
* g.addVertex('A');
|
|
425
|
-
* g.addVertex('B');
|
|
426
|
-
* g.addEdge('A', 'B');
|
|
427
|
-
* console.log(g.edgeSet().length); // 1;
|
|
262
|
+
* @example
|
|
263
|
+
* // Get all edges
|
|
264
|
+
* const g = new UndirectedGraph();
|
|
265
|
+
* g.addVertex('A');
|
|
266
|
+
* g.addVertex('B');
|
|
267
|
+
* g.addEdge('A', 'B');
|
|
268
|
+
* console.log(g.edgeSet().length); // 1;
|
|
428
269
|
*/
|
|
429
270
|
edgeSet(): EO[];
|
|
430
271
|
/**
|
|
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
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
* @example
|
|
475
|
-
* // UndirectedGraph connectivity and neighbors
|
|
476
|
-
* const graph = new UndirectedGraph<string>();
|
|
477
|
-
*
|
|
478
|
-
* // Build a friendship network
|
|
479
|
-
* const people = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'];
|
|
480
|
-
* for (const person of people) {
|
|
481
|
-
* graph.addVertex(person);
|
|
482
|
-
* }
|
|
483
|
-
*
|
|
484
|
-
* // Add friendships (undirected edges)
|
|
485
|
-
* graph.addEdge('Alice', 'Bob', 1);
|
|
486
|
-
* graph.addEdge('Alice', 'Charlie', 1);
|
|
487
|
-
* graph.addEdge('Bob', 'Diana', 1);
|
|
488
|
-
* graph.addEdge('Charlie', 'Eve', 1);
|
|
489
|
-
* graph.addEdge('Diana', 'Eve', 1);
|
|
490
|
-
*
|
|
491
|
-
* // Get friends of each person
|
|
492
|
-
* const aliceFriends = graph.getNeighbors('Alice');
|
|
493
|
-
* console.log(aliceFriends[0].key); // 'Bob';
|
|
494
|
-
* console.log(aliceFriends[1].key); // 'Charlie';
|
|
495
|
-
* console.log(aliceFriends.length); // 2;
|
|
496
|
-
*
|
|
497
|
-
* const dianaFriends = graph.getNeighbors('Diana');
|
|
498
|
-
* console.log(dianaFriends[0].key); // 'Bob';
|
|
499
|
-
* console.log(dianaFriends[1].key); // 'Eve';
|
|
500
|
-
* console.log(dianaFriends.length); // 2;
|
|
501
|
-
*
|
|
502
|
-
* // Verify bidirectional friendship
|
|
503
|
-
* const bobFriends = graph.getNeighbors('Bob');
|
|
504
|
-
* console.log(bobFriends[0].key); // 'Alice'; // Alice -> Bob -> Alice ✓
|
|
505
|
-
* console.log(bobFriends[1].key); // 'Diana';
|
|
506
|
-
*/
|
|
272
|
+
* UndirectedGraph connectivity and neighbors
|
|
273
|
+
* @example
|
|
274
|
+
* // UndirectedGraph connectivity and neighbors
|
|
275
|
+
* const graph = new UndirectedGraph<string>();
|
|
276
|
+
*
|
|
277
|
+
* // Build a friendship network
|
|
278
|
+
* const people = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'];
|
|
279
|
+
* for (const person of people) {
|
|
280
|
+
* graph.addVertex(person);
|
|
281
|
+
* }
|
|
282
|
+
*
|
|
283
|
+
* // Add friendships (undirected edges)
|
|
284
|
+
* graph.addEdge('Alice', 'Bob', 1);
|
|
285
|
+
* graph.addEdge('Alice', 'Charlie', 1);
|
|
286
|
+
* graph.addEdge('Bob', 'Diana', 1);
|
|
287
|
+
* graph.addEdge('Charlie', 'Eve', 1);
|
|
288
|
+
* graph.addEdge('Diana', 'Eve', 1);
|
|
289
|
+
*
|
|
290
|
+
* // Get friends of each person
|
|
291
|
+
* const aliceFriends = graph.getNeighbors('Alice');
|
|
292
|
+
* console.log(aliceFriends[0].key); // 'Bob';
|
|
293
|
+
* console.log(aliceFriends[1].key); // 'Charlie';
|
|
294
|
+
* console.log(aliceFriends.length); // 2;
|
|
295
|
+
*
|
|
296
|
+
* const dianaFriends = graph.getNeighbors('Diana');
|
|
297
|
+
* console.log(dianaFriends[0].key); // 'Bob';
|
|
298
|
+
* console.log(dianaFriends[1].key); // 'Eve';
|
|
299
|
+
* console.log(dianaFriends.length); // 2;
|
|
300
|
+
*
|
|
301
|
+
* // Verify bidirectional friendship
|
|
302
|
+
* const bobFriends = graph.getNeighbors('Bob');
|
|
303
|
+
* console.log(bobFriends[0].key); // 'Alice'; // Alice -> Bob -> Alice ✓
|
|
304
|
+
* console.log(bobFriends[1].key); // 'Diana';
|
|
305
|
+
*/
|
|
507
306
|
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
508
307
|
/**
|
|
509
308
|
* Resolve an edge's two endpoints to vertex instances.
|
|
@@ -532,55 +331,16 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
532
331
|
* Tarjan-based bridge and articulation point detection.
|
|
533
332
|
* @returns `{ dfnMap, lowMap, bridges, cutVertices }`.
|
|
534
333
|
* @remarks Time O(V + E), Space O(V + E)
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
* @example
|
|
575
|
-
* // Find articulation points and bridges
|
|
576
|
-
* const g = new UndirectedGraph();
|
|
577
|
-
* g.addVertex('A');
|
|
578
|
-
* g.addVertex('B');
|
|
579
|
-
* g.addVertex('C');
|
|
580
|
-
* g.addEdge('A', 'B');
|
|
581
|
-
* g.addEdge('B', 'C');
|
|
582
|
-
* const result = g.tarjan();
|
|
583
|
-
* console.log(result); // defined;
|
|
334
|
+
* @example
|
|
335
|
+
* // Find articulation points and bridges
|
|
336
|
+
* const g = new UndirectedGraph();
|
|
337
|
+
* g.addVertex('A');
|
|
338
|
+
* g.addVertex('B');
|
|
339
|
+
* g.addVertex('C');
|
|
340
|
+
* g.addEdge('A', 'B');
|
|
341
|
+
* g.addEdge('B', 'C');
|
|
342
|
+
* const result = g.tarjan();
|
|
343
|
+
* console.log(result); // defined;
|
|
584
344
|
*/
|
|
585
345
|
tarjan(): {
|
|
586
346
|
dfnMap: Map<VO, number>;
|
|
@@ -600,167 +360,50 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
|
|
|
600
360
|
* Uses DFS with parent tracking.
|
|
601
361
|
* @returns `true` if a cycle exists, `false` otherwise.
|
|
602
362
|
* @remarks Time O(V + E), Space O(V)
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
* @example
|
|
643
|
-
* // Detect cycle
|
|
644
|
-
* const g = new UndirectedGraph();
|
|
645
|
-
* g.addVertex('A');
|
|
646
|
-
* g.addVertex('B');
|
|
647
|
-
* g.addVertex('C');
|
|
648
|
-
* g.addEdge('A', 'B');
|
|
649
|
-
* g.addEdge('B', 'C');
|
|
650
|
-
* console.log(g.hasCycle()); // false;
|
|
651
|
-
* g.addEdge('C', 'A');
|
|
652
|
-
* console.log(g.hasCycle()); // true;
|
|
363
|
+
* @example
|
|
364
|
+
* // Detect cycle
|
|
365
|
+
* const g = new UndirectedGraph();
|
|
366
|
+
* g.addVertex('A');
|
|
367
|
+
* g.addVertex('B');
|
|
368
|
+
* g.addVertex('C');
|
|
369
|
+
* g.addEdge('A', 'B');
|
|
370
|
+
* g.addEdge('B', 'C');
|
|
371
|
+
* console.log(g.hasCycle()); // false;
|
|
372
|
+
* g.addEdge('C', 'A');
|
|
373
|
+
* console.log(g.hasCycle()); // true;
|
|
653
374
|
*/
|
|
654
375
|
hasCycle(): boolean;
|
|
655
376
|
/**
|
|
656
377
|
* Get bridges discovered by `tarjan()`.
|
|
657
378
|
* @returns Array of edges that are bridges.
|
|
658
379
|
* @remarks Time O(B), Space O(1)
|
|
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
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
* @example
|
|
699
|
-
* // Find bridge edges
|
|
700
|
-
* const g = new UndirectedGraph();
|
|
701
|
-
* g.addVertex('A');
|
|
702
|
-
* g.addVertex('B');
|
|
703
|
-
* g.addVertex('C');
|
|
704
|
-
* g.addEdge('A', 'B');
|
|
705
|
-
* g.addEdge('B', 'C');
|
|
706
|
-
* const bridges = g.getBridges();
|
|
707
|
-
* console.log(bridges.length); // 2;
|
|
380
|
+
* @example
|
|
381
|
+
* // Find bridge edges
|
|
382
|
+
* const g = new UndirectedGraph();
|
|
383
|
+
* g.addVertex('A');
|
|
384
|
+
* g.addVertex('B');
|
|
385
|
+
* g.addVertex('C');
|
|
386
|
+
* g.addEdge('A', 'B');
|
|
387
|
+
* g.addEdge('B', 'C');
|
|
388
|
+
* const bridges = g.getBridges();
|
|
389
|
+
* console.log(bridges.length); // 2;
|
|
708
390
|
*/
|
|
709
391
|
getBridges(): EO[];
|
|
710
392
|
/**
|
|
711
393
|
* Get articulation points discovered by `tarjan()`.
|
|
712
394
|
* @returns Array of cut vertices.
|
|
713
395
|
* @remarks Time O(C), Space O(1)
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
* @example
|
|
754
|
-
* // Find articulation points
|
|
755
|
-
* const g = new UndirectedGraph();
|
|
756
|
-
* g.addVertex('A');
|
|
757
|
-
* g.addVertex('B');
|
|
758
|
-
* g.addVertex('C');
|
|
759
|
-
* g.addEdge('A', 'B');
|
|
760
|
-
* g.addEdge('B', 'C');
|
|
761
|
-
* const cuts = g.getCutVertices();
|
|
762
|
-
* console.log(cuts.length); // 1;
|
|
763
|
-
* console.log(cuts[0].key); // 'B';
|
|
396
|
+
* @example
|
|
397
|
+
* // Find articulation points
|
|
398
|
+
* const g = new UndirectedGraph();
|
|
399
|
+
* g.addVertex('A');
|
|
400
|
+
* g.addVertex('B');
|
|
401
|
+
* g.addVertex('C');
|
|
402
|
+
* g.addEdge('A', 'B');
|
|
403
|
+
* g.addEdge('B', 'C');
|
|
404
|
+
* const cuts = g.getCutVertices();
|
|
405
|
+
* console.log(cuts.length); // 1;
|
|
406
|
+
* console.log(cuts[0].key); // 'B';
|
|
764
407
|
*/
|
|
765
408
|
getCutVertices(): VO[];
|
|
766
409
|
/**
|