data-structure-typed 2.5.0 → 2.5.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/.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 +5 -1
- package/README.md +124 -29
- package/dist/cjs/binary-tree.cjs +26282 -0
- package/dist/cjs/graph.cjs +5422 -0
- package/dist/cjs/hash.cjs +1310 -0
- package/dist/cjs/heap.cjs +1602 -0
- package/dist/cjs/index.cjs +31257 -14673
- package/dist/cjs/linked-list.cjs +4576 -0
- package/dist/cjs/matrix.cjs +1080 -0
- package/dist/cjs/priority-queue.cjs +1376 -0
- package/dist/cjs/queue.cjs +4264 -0
- package/dist/cjs/stack.cjs +907 -0
- package/dist/cjs/trie.cjs +1223 -0
- package/dist/cjs-legacy/binary-tree.cjs +26319 -0
- package/dist/cjs-legacy/graph.cjs +5420 -0
- package/dist/cjs-legacy/hash.cjs +1310 -0
- package/dist/cjs-legacy/heap.cjs +1599 -0
- package/dist/cjs-legacy/index.cjs +31268 -14679
- package/dist/cjs-legacy/linked-list.cjs +4582 -0
- package/dist/cjs-legacy/matrix.cjs +1083 -0
- package/dist/cjs-legacy/priority-queue.cjs +1374 -0
- package/dist/cjs-legacy/queue.cjs +4262 -0
- package/dist/cjs-legacy/stack.cjs +907 -0
- package/dist/cjs-legacy/trie.cjs +1222 -0
- package/dist/esm/binary-tree.mjs +26267 -0
- package/dist/esm/graph.mjs +5409 -0
- package/dist/esm/hash.mjs +1307 -0
- package/dist/esm/heap.mjs +1596 -0
- package/dist/esm/index.mjs +31254 -14674
- package/dist/esm/linked-list.mjs +4569 -0
- package/dist/esm/matrix.mjs +1076 -0
- package/dist/esm/priority-queue.mjs +1372 -0
- package/dist/esm/queue.mjs +4260 -0
- package/dist/esm/stack.mjs +905 -0
- package/dist/esm/trie.mjs +1220 -0
- package/dist/esm-legacy/binary-tree.mjs +26304 -0
- package/dist/esm-legacy/graph.mjs +5407 -0
- package/dist/esm-legacy/hash.mjs +1307 -0
- package/dist/esm-legacy/heap.mjs +1593 -0
- package/dist/esm-legacy/index.mjs +31265 -14680
- package/dist/esm-legacy/linked-list.mjs +4575 -0
- package/dist/esm-legacy/matrix.mjs +1079 -0
- package/dist/esm-legacy/priority-queue.mjs +1370 -0
- package/dist/esm-legacy/queue.mjs +4258 -0
- package/dist/esm-legacy/stack.mjs +905 -0
- package/dist/esm-legacy/trie.mjs +1219 -0
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- 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 +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- 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/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- 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 +31196 -14608
- package/dist/umd/data-structure-typed.min.js +11 -5
- 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 +6644 -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 +6293 -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 +6888 -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 +1389 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1591 -0
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1246 -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 +615 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +451 -0
- package/docs-site-docusaurus/docs/guide/faq.md +180 -0
- package/docs-site-docusaurus/docs/guide/guides.md +597 -0
- package/docs-site-docusaurus/docs/guide/installation.md +62 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +825 -0
- package/docs-site-docusaurus/docs/guide/overview.md +645 -0
- package/docs-site-docusaurus/docs/guide/performance.md +835 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +104 -0
- package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
- package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
- package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
- package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
- package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -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 +120 -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/llms.txt +37 -0
- package/docs-site-docusaurus/static/robots.txt +4 -0
- package/docs-site-docusaurus/typedoc.json +23 -0
- package/llms.txt +37 -0
- package/package.json +159 -55
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- 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 +287 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +327 -5
- package/src/data-structures/binary-tree/binary-tree.ts +581 -6
- package/src/data-structures/binary-tree/bst.ts +922 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +453 -0
- package/src/data-structures/binary-tree/segment-tree.ts +139 -2
- package/src/data-structures/binary-tree/tree-map.ts +3300 -495
- package/src/data-structures/binary-tree/tree-multi-map.ts +3384 -563
- package/src/data-structures/binary-tree/tree-multi-set.ts +2757 -493
- package/src/data-structures/binary-tree/tree-set.ts +3122 -440
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +230 -0
- package/src/data-structures/graph/undirected-graph.ts +207 -0
- package/src/data-structures/hash/hash-map.ts +270 -19
- package/src/data-structures/heap/heap.ts +326 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +394 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +348 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +421 -7
- package/src/data-structures/matrix/matrix.ts +194 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +350 -5
- package/src/data-structures/queue/queue.ts +276 -0
- package/src/data-structures/stack/stack.ts +230 -0
- package/src/data-structures/trie/trie.ts +283 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- 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
|
@@ -0,0 +1,2979 @@
|
|
|
1
|
+
[**data-structure-typed**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[data-structure-typed](../README.md) / UndirectedGraph
|
|
6
|
+
|
|
7
|
+
# Class: UndirectedGraph\<V, E, VO, EO\>
|
|
8
|
+
|
|
9
|
+
Defined in: [data-structures/graph/undirected-graph.ts:138](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L138)
|
|
10
|
+
|
|
11
|
+
Undirected graph implementation.
|
|
12
|
+
|
|
13
|
+
## Remarks
|
|
14
|
+
|
|
15
|
+
Time O(1), Space O(1)
|
|
16
|
+
|
|
17
|
+
## Examples
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// basic UndirectedGraph vertex and edge creation
|
|
21
|
+
// Create a simple undirected graph
|
|
22
|
+
const graph = new UndirectedGraph<string>();
|
|
23
|
+
|
|
24
|
+
// Add vertices
|
|
25
|
+
graph.addVertex('A');
|
|
26
|
+
graph.addVertex('B');
|
|
27
|
+
graph.addVertex('C');
|
|
28
|
+
graph.addVertex('D');
|
|
29
|
+
|
|
30
|
+
// Verify vertices exist
|
|
31
|
+
console.log(graph.hasVertex('A')); // true;
|
|
32
|
+
console.log(graph.hasVertex('B')); // true;
|
|
33
|
+
console.log(graph.hasVertex('E')); // false;
|
|
34
|
+
|
|
35
|
+
// Check vertex count
|
|
36
|
+
console.log(graph.size); // 4;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// UndirectedGraph edge operations (bidirectional)
|
|
41
|
+
const graph = new UndirectedGraph<string>();
|
|
42
|
+
|
|
43
|
+
// Add vertices
|
|
44
|
+
graph.addVertex('A');
|
|
45
|
+
graph.addVertex('B');
|
|
46
|
+
graph.addVertex('C');
|
|
47
|
+
|
|
48
|
+
// Add undirected edges (both directions automatically)
|
|
49
|
+
graph.addEdge('A', 'B', 1);
|
|
50
|
+
graph.addEdge('B', 'C', 2);
|
|
51
|
+
graph.addEdge('A', 'C', 3);
|
|
52
|
+
|
|
53
|
+
// Verify edges exist in both directions
|
|
54
|
+
console.log(graph.hasEdge('A', 'B')); // true;
|
|
55
|
+
console.log(graph.hasEdge('B', 'A')); // true; // Bidirectional!
|
|
56
|
+
|
|
57
|
+
console.log(graph.hasEdge('C', 'B')); // true;
|
|
58
|
+
console.log(graph.hasEdge('B', 'C')); // true; // Bidirectional!
|
|
59
|
+
|
|
60
|
+
// Get neighbors of A
|
|
61
|
+
const neighborsA = graph.getNeighbors('A');
|
|
62
|
+
console.log(neighborsA[0].key); // 'B';
|
|
63
|
+
console.log(neighborsA[1].key); // 'C';
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
// UndirectedGraph for social network connectivity analysis
|
|
68
|
+
interface Person {
|
|
69
|
+
id: number;
|
|
70
|
+
name: string;
|
|
71
|
+
location: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// UndirectedGraph is perfect for modeling symmetric relationships
|
|
75
|
+
// (friendships, collaborations, partnerships)
|
|
76
|
+
const socialNetwork = new UndirectedGraph<number, Person>();
|
|
77
|
+
|
|
78
|
+
// Add people as vertices
|
|
79
|
+
const people: [number, Person][] = [
|
|
80
|
+
[1, { id: 1, name: 'Alice', location: 'New York' }],
|
|
81
|
+
[2, { id: 2, name: 'Bob', location: 'San Francisco' }],
|
|
82
|
+
[3, { id: 3, name: 'Charlie', location: 'Boston' }],
|
|
83
|
+
[4, { id: 4, name: 'Diana', location: 'New York' }],
|
|
84
|
+
[5, { id: 5, name: 'Eve', location: 'Seattle' }]
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
for (const [id] of people) {
|
|
88
|
+
socialNetwork.addVertex(id);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Add friendships (automatically bidirectional)
|
|
92
|
+
socialNetwork.addEdge(1, 2, 1); // Alice <-> Bob
|
|
93
|
+
socialNetwork.addEdge(1, 3, 1); // Alice <-> Charlie
|
|
94
|
+
socialNetwork.addEdge(2, 4, 1); // Bob <-> Diana
|
|
95
|
+
socialNetwork.addEdge(3, 5, 1); // Charlie <-> Eve
|
|
96
|
+
socialNetwork.addEdge(4, 5, 1); // Diana <-> Eve
|
|
97
|
+
|
|
98
|
+
console.log(socialNetwork.size); // 5;
|
|
99
|
+
|
|
100
|
+
// Find direct connections for Alice
|
|
101
|
+
const aliceConnections = socialNetwork.getNeighbors(1);
|
|
102
|
+
console.log(aliceConnections[0].key); // 2;
|
|
103
|
+
console.log(aliceConnections[1].key); // 3;
|
|
104
|
+
console.log(aliceConnections.length); // 2;
|
|
105
|
+
|
|
106
|
+
// Verify bidirectional connections
|
|
107
|
+
console.log(socialNetwork.hasEdge(1, 2)); // true;
|
|
108
|
+
console.log(socialNetwork.hasEdge(2, 1)); // true; // Friendship works both ways!
|
|
109
|
+
|
|
110
|
+
// Remove a person from network
|
|
111
|
+
socialNetwork.deleteVertex(2); // Bob leaves
|
|
112
|
+
console.log(socialNetwork.hasVertex(2)); // false;
|
|
113
|
+
console.log(socialNetwork.size); // 4;
|
|
114
|
+
|
|
115
|
+
// Alice loses Bob as a friend
|
|
116
|
+
const updatedAliceConnections = socialNetwork.getNeighbors(1);
|
|
117
|
+
console.log(updatedAliceConnections[0].key); // 3;
|
|
118
|
+
console.log(updatedAliceConnections[1]); // undefined;
|
|
119
|
+
|
|
120
|
+
// Diana loses Bob as a friend
|
|
121
|
+
const dianaConnections = socialNetwork.getNeighbors(4);
|
|
122
|
+
console.log(dianaConnections[0].key); // 5;
|
|
123
|
+
console.log(dianaConnections[1]); // undefined;
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Extends
|
|
127
|
+
|
|
128
|
+
- [`AbstractGraph`](AbstractGraph.md)\<`V`, `E`, `VO`, `EO`\>
|
|
129
|
+
|
|
130
|
+
## Type Parameters
|
|
131
|
+
|
|
132
|
+
### V
|
|
133
|
+
|
|
134
|
+
`V` = `any`
|
|
135
|
+
|
|
136
|
+
Vertex value type.
|
|
137
|
+
|
|
138
|
+
### E
|
|
139
|
+
|
|
140
|
+
`E` = `any`
|
|
141
|
+
|
|
142
|
+
Edge value type.
|
|
143
|
+
|
|
144
|
+
### VO
|
|
145
|
+
|
|
146
|
+
`VO` *extends* `UndirectedVertex`\<`V`\> = `UndirectedVertex`\<`V`\>
|
|
147
|
+
|
|
148
|
+
Concrete vertex class (extends AbstractVertex<V>).
|
|
149
|
+
|
|
150
|
+
### EO
|
|
151
|
+
|
|
152
|
+
`EO` *extends* `UndirectedEdge`\<`E`\> = `UndirectedEdge`\<`E`\>
|
|
153
|
+
|
|
154
|
+
Concrete edge class (extends AbstractEdge<E>).
|
|
155
|
+
|
|
156
|
+
## Implements
|
|
157
|
+
|
|
158
|
+
- `IGraph`\<`V`, `E`, `VO`, `EO`\>
|
|
159
|
+
|
|
160
|
+
## Constructors
|
|
161
|
+
|
|
162
|
+
### Constructor
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
new UndirectedGraph<V, E, VO, EO>(options?): UndirectedGraph<V, E, VO, EO>;
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Defined in: [data-structures/graph/undirected-graph.ts:152](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L152)
|
|
169
|
+
|
|
170
|
+
Construct an undirected graph with runtime defaults.
|
|
171
|
+
|
|
172
|
+
#### Parameters
|
|
173
|
+
|
|
174
|
+
##### options?
|
|
175
|
+
|
|
176
|
+
`Partial`\<`GraphOptions`\<`V`\>\>
|
|
177
|
+
|
|
178
|
+
`GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
|
|
179
|
+
|
|
180
|
+
#### Returns
|
|
181
|
+
|
|
182
|
+
`UndirectedGraph`\<`V`, `E`, `VO`, `EO`\>
|
|
183
|
+
|
|
184
|
+
#### Remarks
|
|
185
|
+
|
|
186
|
+
Time O(1), Space O(1)
|
|
187
|
+
|
|
188
|
+
#### Overrides
|
|
189
|
+
|
|
190
|
+
[`AbstractGraph`](AbstractGraph.md).[`constructor`](AbstractGraph.md#constructor)
|
|
191
|
+
|
|
192
|
+
## Accessors
|
|
193
|
+
|
|
194
|
+
### size
|
|
195
|
+
|
|
196
|
+
#### Get Signature
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
get size(): number;
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Defined in: [data-structures/graph/abstract-graph.ts:89](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L89)
|
|
203
|
+
|
|
204
|
+
Total number of entries.
|
|
205
|
+
|
|
206
|
+
##### Remarks
|
|
207
|
+
|
|
208
|
+
Time O(1), Space O(1)
|
|
209
|
+
|
|
210
|
+
##### Returns
|
|
211
|
+
|
|
212
|
+
`number`
|
|
213
|
+
|
|
214
|
+
Entry count.
|
|
215
|
+
|
|
216
|
+
#### Inherited from
|
|
217
|
+
|
|
218
|
+
[`AbstractGraph`](AbstractGraph.md).[`size`](AbstractGraph.md#size)
|
|
219
|
+
|
|
220
|
+
## Methods
|
|
221
|
+
|
|
222
|
+
### \[iterator\]()
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
iterator: IterableIterator<[VertexKey, V | undefined]>;
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:22](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L22)
|
|
229
|
+
|
|
230
|
+
Default iterator yielding `[key, value]` entries.
|
|
231
|
+
|
|
232
|
+
#### Parameters
|
|
233
|
+
|
|
234
|
+
##### args
|
|
235
|
+
|
|
236
|
+
...`unknown`[]
|
|
237
|
+
|
|
238
|
+
#### Returns
|
|
239
|
+
|
|
240
|
+
`IterableIterator`\<\[`VertexKey`, `V` \| `undefined`\]\>
|
|
241
|
+
|
|
242
|
+
Iterator of `[K, V]`.
|
|
243
|
+
|
|
244
|
+
#### Remarks
|
|
245
|
+
|
|
246
|
+
Time O(n) to iterate, Space O(1)
|
|
247
|
+
|
|
248
|
+
#### Inherited from
|
|
249
|
+
|
|
250
|
+
[`AbstractGraph`](AbstractGraph.md).[`[iterator]`](AbstractGraph.md#iterator)
|
|
251
|
+
|
|
252
|
+
***
|
|
253
|
+
|
|
254
|
+
### addEdge()
|
|
255
|
+
|
|
256
|
+
Add an edge by instance or by `(src, dest, weight?, value?)`.
|
|
257
|
+
|
|
258
|
+
#### Param
|
|
259
|
+
|
|
260
|
+
Edge instance or source vertex/key.
|
|
261
|
+
|
|
262
|
+
#### Param
|
|
263
|
+
|
|
264
|
+
Destination vertex/key (when adding by pair).
|
|
265
|
+
|
|
266
|
+
#### Param
|
|
267
|
+
|
|
268
|
+
Edge weight.
|
|
269
|
+
|
|
270
|
+
#### Param
|
|
271
|
+
|
|
272
|
+
Edge payload.
|
|
273
|
+
|
|
274
|
+
#### Remarks
|
|
275
|
+
|
|
276
|
+
Time O(1) avg, Space O(1)
|
|
277
|
+
|
|
278
|
+
#### Call Signature
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
addEdge(edge): boolean;
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Defined in: [data-structures/graph/abstract-graph.ts:254](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L254)
|
|
285
|
+
|
|
286
|
+
##### Parameters
|
|
287
|
+
|
|
288
|
+
###### edge
|
|
289
|
+
|
|
290
|
+
`EO`
|
|
291
|
+
|
|
292
|
+
##### Returns
|
|
293
|
+
|
|
294
|
+
`boolean`
|
|
295
|
+
|
|
296
|
+
##### Inherited from
|
|
297
|
+
|
|
298
|
+
[`AbstractGraph`](AbstractGraph.md).[`addEdge`](AbstractGraph.md#addedge)
|
|
299
|
+
|
|
300
|
+
#### Call Signature
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
addEdge(
|
|
304
|
+
src,
|
|
305
|
+
dest,
|
|
306
|
+
weight?,
|
|
307
|
+
value?): boolean;
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Defined in: [data-structures/graph/abstract-graph.ts:256](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L256)
|
|
311
|
+
|
|
312
|
+
##### Parameters
|
|
313
|
+
|
|
314
|
+
###### src
|
|
315
|
+
|
|
316
|
+
`VertexKey` \| `VO`
|
|
317
|
+
|
|
318
|
+
###### dest
|
|
319
|
+
|
|
320
|
+
`VertexKey` \| `VO`
|
|
321
|
+
|
|
322
|
+
###### weight?
|
|
323
|
+
|
|
324
|
+
`number`
|
|
325
|
+
|
|
326
|
+
###### value?
|
|
327
|
+
|
|
328
|
+
`E`
|
|
329
|
+
|
|
330
|
+
##### Returns
|
|
331
|
+
|
|
332
|
+
`boolean`
|
|
333
|
+
|
|
334
|
+
##### Inherited from
|
|
335
|
+
|
|
336
|
+
[`AbstractGraph`](AbstractGraph.md).[`addEdge`](AbstractGraph.md#addedge)
|
|
337
|
+
|
|
338
|
+
***
|
|
339
|
+
|
|
340
|
+
### addVertex()
|
|
341
|
+
|
|
342
|
+
Add a vertex by key/value or by pre-built vertex.
|
|
343
|
+
|
|
344
|
+
#### Param
|
|
345
|
+
|
|
346
|
+
Vertex key or existing vertex instance.
|
|
347
|
+
|
|
348
|
+
#### Param
|
|
349
|
+
|
|
350
|
+
Optional payload.
|
|
351
|
+
|
|
352
|
+
#### Remarks
|
|
353
|
+
|
|
354
|
+
Time O(1) avg, Space O(1)
|
|
355
|
+
|
|
356
|
+
#### Call Signature
|
|
357
|
+
|
|
358
|
+
```ts
|
|
359
|
+
addVertex(vertex): boolean;
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Defined in: [data-structures/graph/abstract-graph.ts:189](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L189)
|
|
363
|
+
|
|
364
|
+
##### Parameters
|
|
365
|
+
|
|
366
|
+
###### vertex
|
|
367
|
+
|
|
368
|
+
`VO`
|
|
369
|
+
|
|
370
|
+
##### Returns
|
|
371
|
+
|
|
372
|
+
`boolean`
|
|
373
|
+
|
|
374
|
+
##### Implementation of
|
|
375
|
+
|
|
376
|
+
```ts
|
|
377
|
+
IGraph.addVertex
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
##### Inherited from
|
|
381
|
+
|
|
382
|
+
[`AbstractGraph`](AbstractGraph.md).[`addVertex`](AbstractGraph.md#addvertex)
|
|
383
|
+
|
|
384
|
+
#### Call Signature
|
|
385
|
+
|
|
386
|
+
```ts
|
|
387
|
+
addVertex(key, value?): boolean;
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
Defined in: [data-structures/graph/abstract-graph.ts:191](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L191)
|
|
391
|
+
|
|
392
|
+
##### Parameters
|
|
393
|
+
|
|
394
|
+
###### key
|
|
395
|
+
|
|
396
|
+
`VertexKey`
|
|
397
|
+
|
|
398
|
+
###### value?
|
|
399
|
+
|
|
400
|
+
`V`
|
|
401
|
+
|
|
402
|
+
##### Returns
|
|
403
|
+
|
|
404
|
+
`boolean`
|
|
405
|
+
|
|
406
|
+
##### Implementation of
|
|
407
|
+
|
|
408
|
+
```ts
|
|
409
|
+
IGraph.addVertex
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
##### Inherited from
|
|
413
|
+
|
|
414
|
+
[`AbstractGraph`](AbstractGraph.md).[`addVertex`](AbstractGraph.md#addvertex)
|
|
415
|
+
|
|
416
|
+
***
|
|
417
|
+
|
|
418
|
+
### bellmanFord()
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
bellmanFord(
|
|
422
|
+
src,
|
|
423
|
+
scanNegativeCycle?,
|
|
424
|
+
getMin?,
|
|
425
|
+
genPath?): object;
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
Defined in: [data-structures/graph/abstract-graph.ts:705](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L705)
|
|
429
|
+
|
|
430
|
+
Bellman-Ford single-source shortest paths with option to scan negative cycles.
|
|
431
|
+
|
|
432
|
+
#### Parameters
|
|
433
|
+
|
|
434
|
+
##### src
|
|
435
|
+
|
|
436
|
+
`VertexKey` \| `VO`
|
|
437
|
+
|
|
438
|
+
Source vertex or key.
|
|
439
|
+
|
|
440
|
+
##### scanNegativeCycle?
|
|
441
|
+
|
|
442
|
+
`boolean`
|
|
443
|
+
|
|
444
|
+
If `true`, also detect negative cycles.
|
|
445
|
+
|
|
446
|
+
##### getMin?
|
|
447
|
+
|
|
448
|
+
`boolean`
|
|
449
|
+
|
|
450
|
+
If `true`, compute global minimum distance.
|
|
451
|
+
|
|
452
|
+
##### genPath?
|
|
453
|
+
|
|
454
|
+
`boolean`
|
|
455
|
+
|
|
456
|
+
If `true`, generate path arrays via predecessor map.
|
|
457
|
+
|
|
458
|
+
#### Returns
|
|
459
|
+
|
|
460
|
+
`object`
|
|
461
|
+
|
|
462
|
+
Result bag including distances, predecessors, and optional cycle flag.
|
|
463
|
+
|
|
464
|
+
##### distMap
|
|
465
|
+
|
|
466
|
+
```ts
|
|
467
|
+
distMap: Map<VO, number>;
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
##### hasNegativeCycle
|
|
471
|
+
|
|
472
|
+
```ts
|
|
473
|
+
hasNegativeCycle: boolean | undefined;
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
##### min
|
|
477
|
+
|
|
478
|
+
```ts
|
|
479
|
+
min: number;
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
##### minPath
|
|
483
|
+
|
|
484
|
+
```ts
|
|
485
|
+
minPath: VO[];
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
##### paths
|
|
489
|
+
|
|
490
|
+
```ts
|
|
491
|
+
paths: VO[][];
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
##### preMap
|
|
495
|
+
|
|
496
|
+
```ts
|
|
497
|
+
preMap: Map<VO, VO>;
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
#### Remarks
|
|
501
|
+
|
|
502
|
+
Time O(V * E), Space O(V + E)
|
|
503
|
+
|
|
504
|
+
#### Inherited from
|
|
505
|
+
|
|
506
|
+
[`AbstractGraph`](AbstractGraph.md).[`bellmanFord`](AbstractGraph.md#bellmanford)
|
|
507
|
+
|
|
508
|
+
***
|
|
509
|
+
|
|
510
|
+
### clear()
|
|
511
|
+
|
|
512
|
+
```ts
|
|
513
|
+
clear(): void;
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
Defined in: [data-structures/graph/undirected-graph.ts:682](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L682)
|
|
517
|
+
|
|
518
|
+
Remove all vertices and edges.
|
|
519
|
+
|
|
520
|
+
#### Returns
|
|
521
|
+
|
|
522
|
+
`void`
|
|
523
|
+
|
|
524
|
+
#### Remarks
|
|
525
|
+
|
|
526
|
+
Time O(V + E), Space O(1)
|
|
527
|
+
|
|
528
|
+
#### Implementation of
|
|
529
|
+
|
|
530
|
+
```ts
|
|
531
|
+
IGraph.clear
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
#### Overrides
|
|
535
|
+
|
|
536
|
+
[`AbstractGraph`](AbstractGraph.md).[`clear`](AbstractGraph.md#clear)
|
|
537
|
+
|
|
538
|
+
***
|
|
539
|
+
|
|
540
|
+
### clone()
|
|
541
|
+
|
|
542
|
+
```ts
|
|
543
|
+
clone(): this;
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
Defined in: [data-structures/graph/undirected-graph.ts:692](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L692)
|
|
547
|
+
|
|
548
|
+
Deep clone as the same concrete class.
|
|
549
|
+
|
|
550
|
+
#### Returns
|
|
551
|
+
|
|
552
|
+
`this`
|
|
553
|
+
|
|
554
|
+
A new graph of the same concrete class (`this` type).
|
|
555
|
+
|
|
556
|
+
#### Remarks
|
|
557
|
+
|
|
558
|
+
Time O(V + E), Space O(V + E)
|
|
559
|
+
|
|
560
|
+
#### Implementation of
|
|
561
|
+
|
|
562
|
+
```ts
|
|
563
|
+
IGraph.clone
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
#### Overrides
|
|
567
|
+
|
|
568
|
+
[`AbstractGraph`](AbstractGraph.md).[`clone`](AbstractGraph.md#clone)
|
|
569
|
+
|
|
570
|
+
***
|
|
571
|
+
|
|
572
|
+
### createEdge()
|
|
573
|
+
|
|
574
|
+
```ts
|
|
575
|
+
createEdge(
|
|
576
|
+
v1,
|
|
577
|
+
v2,
|
|
578
|
+
weight?,
|
|
579
|
+
value?): EO;
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
Defined in: [data-structures/graph/undirected-graph.ts:219](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L219)
|
|
583
|
+
|
|
584
|
+
Create an undirected edge instance. Does not insert into the graph.
|
|
585
|
+
|
|
586
|
+
#### Parameters
|
|
587
|
+
|
|
588
|
+
##### v1
|
|
589
|
+
|
|
590
|
+
`VertexKey`
|
|
591
|
+
|
|
592
|
+
One endpoint key.
|
|
593
|
+
|
|
594
|
+
##### v2
|
|
595
|
+
|
|
596
|
+
`VertexKey`
|
|
597
|
+
|
|
598
|
+
The other endpoint key.
|
|
599
|
+
|
|
600
|
+
##### weight?
|
|
601
|
+
|
|
602
|
+
`number`
|
|
603
|
+
|
|
604
|
+
Edge weight; defaults to `defaultEdgeWeight`.
|
|
605
|
+
|
|
606
|
+
##### value?
|
|
607
|
+
|
|
608
|
+
`EO`\[`"value"`\]
|
|
609
|
+
|
|
610
|
+
Edge payload.
|
|
611
|
+
|
|
612
|
+
#### Returns
|
|
613
|
+
|
|
614
|
+
`EO`
|
|
615
|
+
|
|
616
|
+
Concrete edge instance.
|
|
617
|
+
|
|
618
|
+
#### Remarks
|
|
619
|
+
|
|
620
|
+
Time O(1), Space O(1)
|
|
621
|
+
|
|
622
|
+
#### Implementation of
|
|
623
|
+
|
|
624
|
+
```ts
|
|
625
|
+
IGraph.createEdge
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
#### Overrides
|
|
629
|
+
|
|
630
|
+
[`AbstractGraph`](AbstractGraph.md).[`createEdge`](AbstractGraph.md#createedge)
|
|
631
|
+
|
|
632
|
+
***
|
|
633
|
+
|
|
634
|
+
### createVertex()
|
|
635
|
+
|
|
636
|
+
```ts
|
|
637
|
+
createVertex(key, value?): VO;
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
Defined in: [data-structures/graph/undirected-graph.ts:206](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L206)
|
|
641
|
+
|
|
642
|
+
Create an undirected vertex instance. Does not insert into the graph.
|
|
643
|
+
|
|
644
|
+
#### Parameters
|
|
645
|
+
|
|
646
|
+
##### key
|
|
647
|
+
|
|
648
|
+
`VertexKey`
|
|
649
|
+
|
|
650
|
+
Vertex identifier.
|
|
651
|
+
|
|
652
|
+
##### value?
|
|
653
|
+
|
|
654
|
+
`VO`\[`"value"`\]
|
|
655
|
+
|
|
656
|
+
Optional payload.
|
|
657
|
+
|
|
658
|
+
#### Returns
|
|
659
|
+
|
|
660
|
+
`VO`
|
|
661
|
+
|
|
662
|
+
Concrete vertex instance.
|
|
663
|
+
|
|
664
|
+
#### Remarks
|
|
665
|
+
|
|
666
|
+
Time O(1), Space O(1)
|
|
667
|
+
|
|
668
|
+
#### Implementation of
|
|
669
|
+
|
|
670
|
+
```ts
|
|
671
|
+
IGraph.createVertex
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
#### Overrides
|
|
675
|
+
|
|
676
|
+
[`AbstractGraph`](AbstractGraph.md).[`createVertex`](AbstractGraph.md#createvertex)
|
|
677
|
+
|
|
678
|
+
***
|
|
679
|
+
|
|
680
|
+
### degreeOf()
|
|
681
|
+
|
|
682
|
+
```ts
|
|
683
|
+
degreeOf(vertexOrKey): number;
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
Defined in: [data-structures/graph/undirected-graph.ts:488](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L488)
|
|
687
|
+
|
|
688
|
+
Degree of a vertex (# of incident undirected edges).
|
|
689
|
+
|
|
690
|
+
#### Parameters
|
|
691
|
+
|
|
692
|
+
##### vertexOrKey
|
|
693
|
+
|
|
694
|
+
`VertexKey` \| `VO`
|
|
695
|
+
|
|
696
|
+
Vertex or key.
|
|
697
|
+
|
|
698
|
+
#### Returns
|
|
699
|
+
|
|
700
|
+
`number`
|
|
701
|
+
|
|
702
|
+
Non-negative integer.
|
|
703
|
+
|
|
704
|
+
#### Remarks
|
|
705
|
+
|
|
706
|
+
Time O(1) avg, Space O(1)
|
|
707
|
+
|
|
708
|
+
#### Implementation of
|
|
709
|
+
|
|
710
|
+
```ts
|
|
711
|
+
IGraph.degreeOf
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
#### Overrides
|
|
715
|
+
|
|
716
|
+
[`AbstractGraph`](AbstractGraph.md).[`degreeOf`](AbstractGraph.md#degreeof)
|
|
717
|
+
|
|
718
|
+
***
|
|
719
|
+
|
|
720
|
+
### deleteEdge()
|
|
721
|
+
|
|
722
|
+
```ts
|
|
723
|
+
deleteEdge(edgeOrOneSideVertexKey, otherSideVertexKey?): EO | undefined;
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
Defined in: [data-structures/graph/undirected-graph.ts:380](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L380)
|
|
727
|
+
|
|
728
|
+
Delete an edge by instance or by a pair of keys.
|
|
729
|
+
|
|
730
|
+
#### Parameters
|
|
731
|
+
|
|
732
|
+
##### edgeOrOneSideVertexKey
|
|
733
|
+
|
|
734
|
+
`VertexKey` \| `EO`
|
|
735
|
+
|
|
736
|
+
Edge instance or one endpoint vertex/key.
|
|
737
|
+
|
|
738
|
+
##### otherSideVertexKey?
|
|
739
|
+
|
|
740
|
+
`VertexKey`
|
|
741
|
+
|
|
742
|
+
Required second endpoint when deleting by pair.
|
|
743
|
+
|
|
744
|
+
#### Returns
|
|
745
|
+
|
|
746
|
+
`EO` \| `undefined`
|
|
747
|
+
|
|
748
|
+
Removed edge or `undefined`.
|
|
749
|
+
|
|
750
|
+
#### Remarks
|
|
751
|
+
|
|
752
|
+
Time O(1) avg, Space O(1)
|
|
753
|
+
|
|
754
|
+
*
|
|
755
|
+
|
|
756
|
+
#### Example
|
|
757
|
+
|
|
758
|
+
```ts
|
|
759
|
+
// UndirectedGraph deleteEdge and vertex operations
|
|
760
|
+
const graph = new UndirectedGraph<string>();
|
|
761
|
+
|
|
762
|
+
// Build a simple undirected graph
|
|
763
|
+
graph.addVertex('X');
|
|
764
|
+
graph.addVertex('Y');
|
|
765
|
+
graph.addVertex('Z');
|
|
766
|
+
graph.addEdge('X', 'Y', 1);
|
|
767
|
+
graph.addEdge('Y', 'Z', 2);
|
|
768
|
+
graph.addEdge('X', 'Z', 3);
|
|
769
|
+
|
|
770
|
+
// Delete an edge
|
|
771
|
+
graph.deleteEdge('X', 'Y');
|
|
772
|
+
console.log(graph.hasEdge('X', 'Y')); // false;
|
|
773
|
+
|
|
774
|
+
// Bidirectional deletion confirmed
|
|
775
|
+
console.log(graph.hasEdge('Y', 'X')); // false;
|
|
776
|
+
|
|
777
|
+
// Other edges should remain
|
|
778
|
+
console.log(graph.hasEdge('Y', 'Z')); // true;
|
|
779
|
+
console.log(graph.hasEdge('Z', 'Y')); // true;
|
|
780
|
+
|
|
781
|
+
// Delete a vertex
|
|
782
|
+
graph.deleteVertex('Y');
|
|
783
|
+
console.log(graph.hasVertex('Y')); // false;
|
|
784
|
+
console.log(graph.size); // 2;
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
#### Implementation of
|
|
788
|
+
|
|
789
|
+
```ts
|
|
790
|
+
IGraph.deleteEdge
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
#### Overrides
|
|
794
|
+
|
|
795
|
+
[`AbstractGraph`](AbstractGraph.md).[`deleteEdge`](AbstractGraph.md#deleteedge)
|
|
796
|
+
|
|
797
|
+
***
|
|
798
|
+
|
|
799
|
+
### deleteEdgeBetween()
|
|
800
|
+
|
|
801
|
+
```ts
|
|
802
|
+
deleteEdgeBetween(v1, v2): EO | undefined;
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
Defined in: [data-structures/graph/undirected-graph.ts:291](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L291)
|
|
806
|
+
|
|
807
|
+
Delete a single undirected edge between two vertices.
|
|
808
|
+
|
|
809
|
+
#### Parameters
|
|
810
|
+
|
|
811
|
+
##### v1
|
|
812
|
+
|
|
813
|
+
`VertexKey` \| `VO`
|
|
814
|
+
|
|
815
|
+
One vertex or key.
|
|
816
|
+
|
|
817
|
+
##### v2
|
|
818
|
+
|
|
819
|
+
`VertexKey` \| `VO`
|
|
820
|
+
|
|
821
|
+
The other vertex or key.
|
|
822
|
+
|
|
823
|
+
#### Returns
|
|
824
|
+
|
|
825
|
+
`EO` \| `undefined`
|
|
826
|
+
|
|
827
|
+
Removed edge or `undefined`.
|
|
828
|
+
|
|
829
|
+
#### Remarks
|
|
830
|
+
|
|
831
|
+
Time O(1) avg, Space O(1)
|
|
832
|
+
|
|
833
|
+
***
|
|
834
|
+
|
|
835
|
+
### deleteVertex()
|
|
836
|
+
|
|
837
|
+
```ts
|
|
838
|
+
deleteVertex(vertexOrKey): boolean;
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
Defined in: [data-structures/graph/undirected-graph.ts:447](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L447)
|
|
842
|
+
|
|
843
|
+
Delete a vertex and remove it from all neighbor lists.
|
|
844
|
+
|
|
845
|
+
#### Parameters
|
|
846
|
+
|
|
847
|
+
##### vertexOrKey
|
|
848
|
+
|
|
849
|
+
`VertexKey` \| `VO`
|
|
850
|
+
|
|
851
|
+
Vertex or key.
|
|
852
|
+
|
|
853
|
+
#### Returns
|
|
854
|
+
|
|
855
|
+
`boolean`
|
|
856
|
+
|
|
857
|
+
`true` if removed; otherwise `false`.
|
|
858
|
+
|
|
859
|
+
#### Remarks
|
|
860
|
+
|
|
861
|
+
Time O(deg), Space O(1)
|
|
862
|
+
|
|
863
|
+
*
|
|
864
|
+
|
|
865
|
+
#### Example
|
|
866
|
+
|
|
867
|
+
```ts
|
|
868
|
+
// Remove vertex and edges
|
|
869
|
+
const g = new UndirectedGraph();
|
|
870
|
+
g.addVertex('A');
|
|
871
|
+
g.addVertex('B');
|
|
872
|
+
g.addEdge('A', 'B');
|
|
873
|
+
g.deleteVertex('A');
|
|
874
|
+
console.log(g.hasVertex('A')); // false;
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
#### Implementation of
|
|
878
|
+
|
|
879
|
+
```ts
|
|
880
|
+
IGraph.deleteVertex
|
|
881
|
+
```
|
|
882
|
+
|
|
883
|
+
#### Overrides
|
|
884
|
+
|
|
885
|
+
[`AbstractGraph`](AbstractGraph.md).[`deleteVertex`](AbstractGraph.md#deletevertex)
|
|
886
|
+
|
|
887
|
+
***
|
|
888
|
+
|
|
889
|
+
### dijkstraWithoutHeap()
|
|
890
|
+
|
|
891
|
+
```ts
|
|
892
|
+
dijkstraWithoutHeap(
|
|
893
|
+
src,
|
|
894
|
+
dest?,
|
|
895
|
+
getMinDist?,
|
|
896
|
+
genPaths?): DijkstraResult<VO>;
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
Defined in: [data-structures/graph/abstract-graph.ts:484](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L484)
|
|
900
|
+
|
|
901
|
+
Dijkstra without heap (array-based selection).
|
|
902
|
+
|
|
903
|
+
#### Parameters
|
|
904
|
+
|
|
905
|
+
##### src
|
|
906
|
+
|
|
907
|
+
`VertexKey` \| `VO`
|
|
908
|
+
|
|
909
|
+
Source vertex or key.
|
|
910
|
+
|
|
911
|
+
##### dest?
|
|
912
|
+
|
|
913
|
+
`VertexKey` \| `VO` \| `undefined`
|
|
914
|
+
|
|
915
|
+
Optional destination for early stop.
|
|
916
|
+
|
|
917
|
+
##### getMinDist?
|
|
918
|
+
|
|
919
|
+
`boolean` = `false`
|
|
920
|
+
|
|
921
|
+
If `true`, compute global minimum distance.
|
|
922
|
+
|
|
923
|
+
##### genPaths?
|
|
924
|
+
|
|
925
|
+
`boolean` = `false`
|
|
926
|
+
|
|
927
|
+
If `true`, also generate path arrays.
|
|
928
|
+
|
|
929
|
+
#### Returns
|
|
930
|
+
|
|
931
|
+
`DijkstraResult`\<`VO`\>
|
|
932
|
+
|
|
933
|
+
Result bag or `undefined` if source missing.
|
|
934
|
+
|
|
935
|
+
#### Remarks
|
|
936
|
+
|
|
937
|
+
Time O(V^2 + E), Space O(V + E)
|
|
938
|
+
|
|
939
|
+
#### Inherited from
|
|
940
|
+
|
|
941
|
+
[`AbstractGraph`](AbstractGraph.md).[`dijkstraWithoutHeap`](AbstractGraph.md#dijkstrawithoutheap)
|
|
942
|
+
|
|
943
|
+
***
|
|
944
|
+
|
|
945
|
+
### edgeSet()
|
|
946
|
+
|
|
947
|
+
```ts
|
|
948
|
+
edgeSet(): EO[];
|
|
949
|
+
```
|
|
950
|
+
|
|
951
|
+
Defined in: [data-structures/graph/undirected-graph.ts:556](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L556)
|
|
952
|
+
|
|
953
|
+
Unique set of undirected edges across endpoints.
|
|
954
|
+
|
|
955
|
+
#### Returns
|
|
956
|
+
|
|
957
|
+
`EO`[]
|
|
958
|
+
|
|
959
|
+
Array of edges.
|
|
960
|
+
|
|
961
|
+
#### Remarks
|
|
962
|
+
|
|
963
|
+
Time O(E), Space O(E)
|
|
964
|
+
|
|
965
|
+
*
|
|
966
|
+
|
|
967
|
+
#### Example
|
|
968
|
+
|
|
969
|
+
```ts
|
|
970
|
+
// Get all edges
|
|
971
|
+
const g = new UndirectedGraph();
|
|
972
|
+
g.addVertex('A');
|
|
973
|
+
g.addVertex('B');
|
|
974
|
+
g.addEdge('A', 'B');
|
|
975
|
+
console.log(g.edgeSet().length); // 1;
|
|
976
|
+
```
|
|
977
|
+
|
|
978
|
+
#### Implementation of
|
|
979
|
+
|
|
980
|
+
```ts
|
|
981
|
+
IGraph.edgeSet
|
|
982
|
+
```
|
|
983
|
+
|
|
984
|
+
#### Overrides
|
|
985
|
+
|
|
986
|
+
[`AbstractGraph`](AbstractGraph.md).[`edgeSet`](AbstractGraph.md#edgeset)
|
|
987
|
+
|
|
988
|
+
***
|
|
989
|
+
|
|
990
|
+
### edgesOf()
|
|
991
|
+
|
|
992
|
+
```ts
|
|
993
|
+
edgesOf(vertexOrKey): EO[];
|
|
994
|
+
```
|
|
995
|
+
|
|
996
|
+
Defined in: [data-structures/graph/undirected-graph.ts:503](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L503)
|
|
997
|
+
|
|
998
|
+
Incident undirected edges of a vertex.
|
|
999
|
+
|
|
1000
|
+
#### Parameters
|
|
1001
|
+
|
|
1002
|
+
##### vertexOrKey
|
|
1003
|
+
|
|
1004
|
+
`VertexKey` \| `VO`
|
|
1005
|
+
|
|
1006
|
+
Vertex or key.
|
|
1007
|
+
|
|
1008
|
+
#### Returns
|
|
1009
|
+
|
|
1010
|
+
`EO`[]
|
|
1011
|
+
|
|
1012
|
+
Array of incident edges.
|
|
1013
|
+
|
|
1014
|
+
#### Remarks
|
|
1015
|
+
|
|
1016
|
+
Time O(deg), Space O(deg)
|
|
1017
|
+
|
|
1018
|
+
#### Implementation of
|
|
1019
|
+
|
|
1020
|
+
```ts
|
|
1021
|
+
IGraph.edgesOf
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
#### Overrides
|
|
1025
|
+
|
|
1026
|
+
[`AbstractGraph`](AbstractGraph.md).[`edgesOf`](AbstractGraph.md#edgesof)
|
|
1027
|
+
|
|
1028
|
+
***
|
|
1029
|
+
|
|
1030
|
+
### entries()
|
|
1031
|
+
|
|
1032
|
+
```ts
|
|
1033
|
+
entries(): IterableIterator<[VertexKey, V | undefined]>;
|
|
1034
|
+
```
|
|
1035
|
+
|
|
1036
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:31](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L31)
|
|
1037
|
+
|
|
1038
|
+
Iterate over `[key, value]` pairs (may yield `undefined` values).
|
|
1039
|
+
|
|
1040
|
+
#### Returns
|
|
1041
|
+
|
|
1042
|
+
`IterableIterator`\<\[`VertexKey`, `V` \| `undefined`\]\>
|
|
1043
|
+
|
|
1044
|
+
Iterator of `[K, V | undefined]`.
|
|
1045
|
+
|
|
1046
|
+
#### Remarks
|
|
1047
|
+
|
|
1048
|
+
Time O(n), Space O(1)
|
|
1049
|
+
|
|
1050
|
+
#### Inherited from
|
|
1051
|
+
|
|
1052
|
+
[`AbstractGraph`](AbstractGraph.md).[`entries`](AbstractGraph.md#entries)
|
|
1053
|
+
|
|
1054
|
+
***
|
|
1055
|
+
|
|
1056
|
+
### every()
|
|
1057
|
+
|
|
1058
|
+
```ts
|
|
1059
|
+
every(predicate, thisArg?): boolean;
|
|
1060
|
+
```
|
|
1061
|
+
|
|
1062
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:66](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L66)
|
|
1063
|
+
|
|
1064
|
+
Test whether all entries satisfy the predicate.
|
|
1065
|
+
|
|
1066
|
+
#### Parameters
|
|
1067
|
+
|
|
1068
|
+
##### predicate
|
|
1069
|
+
|
|
1070
|
+
`EntryCallback`\<`VertexKey`, `V` \| `undefined`, `boolean`\>
|
|
1071
|
+
|
|
1072
|
+
`(key, value, index, self) => boolean`.
|
|
1073
|
+
|
|
1074
|
+
##### thisArg?
|
|
1075
|
+
|
|
1076
|
+
`unknown`
|
|
1077
|
+
|
|
1078
|
+
Optional `this` for callback.
|
|
1079
|
+
|
|
1080
|
+
#### Returns
|
|
1081
|
+
|
|
1082
|
+
`boolean`
|
|
1083
|
+
|
|
1084
|
+
`true` if all pass; otherwise `false`.
|
|
1085
|
+
|
|
1086
|
+
#### Remarks
|
|
1087
|
+
|
|
1088
|
+
Time O(n), Space O(1)
|
|
1089
|
+
|
|
1090
|
+
#### Inherited from
|
|
1091
|
+
|
|
1092
|
+
[`AbstractGraph`](AbstractGraph.md).[`every`](AbstractGraph.md#every)
|
|
1093
|
+
|
|
1094
|
+
***
|
|
1095
|
+
|
|
1096
|
+
### filter()
|
|
1097
|
+
|
|
1098
|
+
```ts
|
|
1099
|
+
filter(predicate, thisArg?): this;
|
|
1100
|
+
```
|
|
1101
|
+
|
|
1102
|
+
Defined in: [data-structures/graph/abstract-graph.ts:897](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L897)
|
|
1103
|
+
|
|
1104
|
+
Induced-subgraph filter: keep vertices where `predicate(key, value)` is true,
|
|
1105
|
+
and only keep edges whose endpoints both survive.
|
|
1106
|
+
|
|
1107
|
+
#### Parameters
|
|
1108
|
+
|
|
1109
|
+
##### predicate
|
|
1110
|
+
|
|
1111
|
+
`EntryCallback`\<`VertexKey`, `V` \| `undefined`, `boolean`\>
|
|
1112
|
+
|
|
1113
|
+
`(key, value, index, self) => boolean`.
|
|
1114
|
+
|
|
1115
|
+
##### thisArg?
|
|
1116
|
+
|
|
1117
|
+
`unknown`
|
|
1118
|
+
|
|
1119
|
+
Optional `this` for callback.
|
|
1120
|
+
|
|
1121
|
+
#### Returns
|
|
1122
|
+
|
|
1123
|
+
`this`
|
|
1124
|
+
|
|
1125
|
+
A new graph of the same concrete class (`this` type).
|
|
1126
|
+
|
|
1127
|
+
#### Remarks
|
|
1128
|
+
|
|
1129
|
+
Time O(V + E), Space O(V + E)
|
|
1130
|
+
|
|
1131
|
+
#### Implementation of
|
|
1132
|
+
|
|
1133
|
+
```ts
|
|
1134
|
+
IGraph.filter
|
|
1135
|
+
```
|
|
1136
|
+
|
|
1137
|
+
#### Inherited from
|
|
1138
|
+
|
|
1139
|
+
[`AbstractGraph`](AbstractGraph.md).[`filter`](AbstractGraph.md#filter)
|
|
1140
|
+
|
|
1141
|
+
***
|
|
1142
|
+
|
|
1143
|
+
### filterEntries()
|
|
1144
|
+
|
|
1145
|
+
```ts
|
|
1146
|
+
filterEntries(predicate, thisArg?): [VertexKey, V | undefined][];
|
|
1147
|
+
```
|
|
1148
|
+
|
|
1149
|
+
Defined in: [data-structures/graph/abstract-graph.ts:913](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L913)
|
|
1150
|
+
|
|
1151
|
+
Preserve the old behavior: return filtered entries as an array.
|
|
1152
|
+
|
|
1153
|
+
#### Parameters
|
|
1154
|
+
|
|
1155
|
+
##### predicate
|
|
1156
|
+
|
|
1157
|
+
`EntryCallback`\<`VertexKey`, `V` \| `undefined`, `boolean`\>
|
|
1158
|
+
|
|
1159
|
+
##### thisArg?
|
|
1160
|
+
|
|
1161
|
+
`unknown`
|
|
1162
|
+
|
|
1163
|
+
#### Returns
|
|
1164
|
+
|
|
1165
|
+
\[`VertexKey`, `V` \| `undefined`\][]
|
|
1166
|
+
|
|
1167
|
+
#### Remarks
|
|
1168
|
+
|
|
1169
|
+
Time O(V), Space O(V)
|
|
1170
|
+
|
|
1171
|
+
#### Inherited from
|
|
1172
|
+
|
|
1173
|
+
[`AbstractGraph`](AbstractGraph.md).[`filterEntries`](AbstractGraph.md#filterentries)
|
|
1174
|
+
|
|
1175
|
+
***
|
|
1176
|
+
|
|
1177
|
+
### find()
|
|
1178
|
+
|
|
1179
|
+
```ts
|
|
1180
|
+
find(callbackfn, thisArg?): [VertexKey, V | undefined] | undefined;
|
|
1181
|
+
```
|
|
1182
|
+
|
|
1183
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:114](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L114)
|
|
1184
|
+
|
|
1185
|
+
Find the first entry that matches a predicate.
|
|
1186
|
+
|
|
1187
|
+
#### Parameters
|
|
1188
|
+
|
|
1189
|
+
##### callbackfn
|
|
1190
|
+
|
|
1191
|
+
`EntryCallback`\<`VertexKey`, `V` \| `undefined`, `boolean`\>
|
|
1192
|
+
|
|
1193
|
+
`(key, value, index, self) => boolean`.
|
|
1194
|
+
|
|
1195
|
+
##### thisArg?
|
|
1196
|
+
|
|
1197
|
+
`unknown`
|
|
1198
|
+
|
|
1199
|
+
Optional `this` for callback.
|
|
1200
|
+
|
|
1201
|
+
#### Returns
|
|
1202
|
+
|
|
1203
|
+
\[`VertexKey`, `V` \| `undefined`\] \| `undefined`
|
|
1204
|
+
|
|
1205
|
+
Matching `[key, value]` or `undefined`.
|
|
1206
|
+
|
|
1207
|
+
#### Remarks
|
|
1208
|
+
|
|
1209
|
+
Time O(n), Space O(1)
|
|
1210
|
+
|
|
1211
|
+
#### Inherited from
|
|
1212
|
+
|
|
1213
|
+
[`AbstractGraph`](AbstractGraph.md).[`find`](AbstractGraph.md#find)
|
|
1214
|
+
|
|
1215
|
+
***
|
|
1216
|
+
|
|
1217
|
+
### floydWarshall()
|
|
1218
|
+
|
|
1219
|
+
```ts
|
|
1220
|
+
floydWarshall(): object;
|
|
1221
|
+
```
|
|
1222
|
+
|
|
1223
|
+
Defined in: [data-structures/graph/abstract-graph.ts:798](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L798)
|
|
1224
|
+
|
|
1225
|
+
Floyd–Warshall all-pairs shortest paths.
|
|
1226
|
+
|
|
1227
|
+
#### Returns
|
|
1228
|
+
|
|
1229
|
+
`object`
|
|
1230
|
+
|
|
1231
|
+
`{ costs, predecessor }` matrices.
|
|
1232
|
+
|
|
1233
|
+
##### costs
|
|
1234
|
+
|
|
1235
|
+
```ts
|
|
1236
|
+
costs: number[][];
|
|
1237
|
+
```
|
|
1238
|
+
|
|
1239
|
+
##### predecessor
|
|
1240
|
+
|
|
1241
|
+
```ts
|
|
1242
|
+
predecessor: (VO | undefined)[][];
|
|
1243
|
+
```
|
|
1244
|
+
|
|
1245
|
+
#### Remarks
|
|
1246
|
+
|
|
1247
|
+
Time O(V^3), Space O(V^2)
|
|
1248
|
+
|
|
1249
|
+
#### Inherited from
|
|
1250
|
+
|
|
1251
|
+
[`AbstractGraph`](AbstractGraph.md).[`floydWarshall`](AbstractGraph.md#floydwarshall)
|
|
1252
|
+
|
|
1253
|
+
***
|
|
1254
|
+
|
|
1255
|
+
### forEach()
|
|
1256
|
+
|
|
1257
|
+
```ts
|
|
1258
|
+
forEach(callbackfn, thisArg?): void;
|
|
1259
|
+
```
|
|
1260
|
+
|
|
1261
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:99](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L99)
|
|
1262
|
+
|
|
1263
|
+
Visit each entry, left-to-right.
|
|
1264
|
+
|
|
1265
|
+
#### Parameters
|
|
1266
|
+
|
|
1267
|
+
##### callbackfn
|
|
1268
|
+
|
|
1269
|
+
`EntryCallback`\<`VertexKey`, `V` \| `undefined`, `void`\>
|
|
1270
|
+
|
|
1271
|
+
`(key, value, index, self) => void`.
|
|
1272
|
+
|
|
1273
|
+
##### thisArg?
|
|
1274
|
+
|
|
1275
|
+
`unknown`
|
|
1276
|
+
|
|
1277
|
+
Optional `this` for callback.
|
|
1278
|
+
|
|
1279
|
+
#### Returns
|
|
1280
|
+
|
|
1281
|
+
`void`
|
|
1282
|
+
|
|
1283
|
+
#### Remarks
|
|
1284
|
+
|
|
1285
|
+
Time O(n), Space O(1)
|
|
1286
|
+
|
|
1287
|
+
#### Inherited from
|
|
1288
|
+
|
|
1289
|
+
[`AbstractGraph`](AbstractGraph.md).[`forEach`](AbstractGraph.md#foreach)
|
|
1290
|
+
|
|
1291
|
+
***
|
|
1292
|
+
|
|
1293
|
+
### get()
|
|
1294
|
+
|
|
1295
|
+
```ts
|
|
1296
|
+
get(key): V | undefined;
|
|
1297
|
+
```
|
|
1298
|
+
|
|
1299
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:156](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L156)
|
|
1300
|
+
|
|
1301
|
+
Get the value under a key.
|
|
1302
|
+
|
|
1303
|
+
#### Parameters
|
|
1304
|
+
|
|
1305
|
+
##### key
|
|
1306
|
+
|
|
1307
|
+
`VertexKey`
|
|
1308
|
+
|
|
1309
|
+
Key to look up.
|
|
1310
|
+
|
|
1311
|
+
#### Returns
|
|
1312
|
+
|
|
1313
|
+
`V` \| `undefined`
|
|
1314
|
+
|
|
1315
|
+
Value or `undefined`.
|
|
1316
|
+
|
|
1317
|
+
#### Remarks
|
|
1318
|
+
|
|
1319
|
+
Time O(n) generic, Space O(1)
|
|
1320
|
+
|
|
1321
|
+
#### Inherited from
|
|
1322
|
+
|
|
1323
|
+
[`AbstractGraph`](AbstractGraph.md).[`get`](AbstractGraph.md#get)
|
|
1324
|
+
|
|
1325
|
+
***
|
|
1326
|
+
|
|
1327
|
+
### getAllPathsBetween()
|
|
1328
|
+
|
|
1329
|
+
```ts
|
|
1330
|
+
getAllPathsBetween(
|
|
1331
|
+
v1,
|
|
1332
|
+
v2,
|
|
1333
|
+
limit?): VO[][];
|
|
1334
|
+
```
|
|
1335
|
+
|
|
1336
|
+
Defined in: [data-structures/graph/abstract-graph.ts:309](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L309)
|
|
1337
|
+
|
|
1338
|
+
Enumerate simple paths up to a limit.
|
|
1339
|
+
|
|
1340
|
+
#### Parameters
|
|
1341
|
+
|
|
1342
|
+
##### v1
|
|
1343
|
+
|
|
1344
|
+
`VertexKey` \| `VO`
|
|
1345
|
+
|
|
1346
|
+
Source vertex or key.
|
|
1347
|
+
|
|
1348
|
+
##### v2
|
|
1349
|
+
|
|
1350
|
+
`VertexKey` \| `VO`
|
|
1351
|
+
|
|
1352
|
+
Destination vertex or key.
|
|
1353
|
+
|
|
1354
|
+
##### limit?
|
|
1355
|
+
|
|
1356
|
+
`number` = `1000`
|
|
1357
|
+
|
|
1358
|
+
Maximum number of paths to collect.
|
|
1359
|
+
|
|
1360
|
+
#### Returns
|
|
1361
|
+
|
|
1362
|
+
`VO`[][]
|
|
1363
|
+
|
|
1364
|
+
Array of paths (each path is an array of vertices).
|
|
1365
|
+
|
|
1366
|
+
#### Remarks
|
|
1367
|
+
|
|
1368
|
+
Time O(paths) worst-case exponential, Space O(V + paths)
|
|
1369
|
+
|
|
1370
|
+
#### Inherited from
|
|
1371
|
+
|
|
1372
|
+
[`AbstractGraph`](AbstractGraph.md).[`getAllPathsBetween`](AbstractGraph.md#getallpathsbetween)
|
|
1373
|
+
|
|
1374
|
+
***
|
|
1375
|
+
|
|
1376
|
+
### getBiconnectedComponents()
|
|
1377
|
+
|
|
1378
|
+
```ts
|
|
1379
|
+
getBiconnectedComponents(): EO[][];
|
|
1380
|
+
```
|
|
1381
|
+
|
|
1382
|
+
Defined in: [data-structures/graph/undirected-graph.ts:808](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L808)
|
|
1383
|
+
|
|
1384
|
+
Find biconnected components using edge-stack Tarjan variant.
|
|
1385
|
+
A biconnected component is a maximal biconnected subgraph.
|
|
1386
|
+
|
|
1387
|
+
#### Returns
|
|
1388
|
+
|
|
1389
|
+
`EO`[][]
|
|
1390
|
+
|
|
1391
|
+
Array of edge arrays, each representing a biconnected component.
|
|
1392
|
+
|
|
1393
|
+
#### Remarks
|
|
1394
|
+
|
|
1395
|
+
Time O(V + E), Space O(V + E)
|
|
1396
|
+
|
|
1397
|
+
***
|
|
1398
|
+
|
|
1399
|
+
### getBridges()
|
|
1400
|
+
|
|
1401
|
+
```ts
|
|
1402
|
+
getBridges(): EO[];
|
|
1403
|
+
```
|
|
1404
|
+
|
|
1405
|
+
Defined in: [data-structures/graph/undirected-graph.ts:987](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L987)
|
|
1406
|
+
|
|
1407
|
+
Get bridges discovered by `tarjan()`.
|
|
1408
|
+
|
|
1409
|
+
#### Returns
|
|
1410
|
+
|
|
1411
|
+
`EO`[]
|
|
1412
|
+
|
|
1413
|
+
Array of edges that are bridges.
|
|
1414
|
+
|
|
1415
|
+
#### Remarks
|
|
1416
|
+
|
|
1417
|
+
Time O(B), Space O(1)
|
|
1418
|
+
|
|
1419
|
+
*
|
|
1420
|
+
|
|
1421
|
+
#### Example
|
|
1422
|
+
|
|
1423
|
+
```ts
|
|
1424
|
+
// Find bridge edges
|
|
1425
|
+
const g = new UndirectedGraph();
|
|
1426
|
+
g.addVertex('A');
|
|
1427
|
+
g.addVertex('B');
|
|
1428
|
+
g.addVertex('C');
|
|
1429
|
+
g.addEdge('A', 'B');
|
|
1430
|
+
g.addEdge('B', 'C');
|
|
1431
|
+
const bridges = g.getBridges();
|
|
1432
|
+
console.log(bridges.length); // 2;
|
|
1433
|
+
```
|
|
1434
|
+
|
|
1435
|
+
***
|
|
1436
|
+
|
|
1437
|
+
### getCutVertices()
|
|
1438
|
+
|
|
1439
|
+
```ts
|
|
1440
|
+
getCutVertices(): VO[];
|
|
1441
|
+
```
|
|
1442
|
+
|
|
1443
|
+
Defined in: [data-structures/graph/undirected-graph.ts:1039](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L1039)
|
|
1444
|
+
|
|
1445
|
+
Get articulation points discovered by `tarjan()`.
|
|
1446
|
+
|
|
1447
|
+
#### Returns
|
|
1448
|
+
|
|
1449
|
+
`VO`[]
|
|
1450
|
+
|
|
1451
|
+
Array of cut vertices.
|
|
1452
|
+
|
|
1453
|
+
#### Remarks
|
|
1454
|
+
|
|
1455
|
+
Time O(C), Space O(1)
|
|
1456
|
+
|
|
1457
|
+
*
|
|
1458
|
+
|
|
1459
|
+
#### Example
|
|
1460
|
+
|
|
1461
|
+
```ts
|
|
1462
|
+
// Find articulation points
|
|
1463
|
+
const g = new UndirectedGraph();
|
|
1464
|
+
g.addVertex('A');
|
|
1465
|
+
g.addVertex('B');
|
|
1466
|
+
g.addVertex('C');
|
|
1467
|
+
g.addEdge('A', 'B');
|
|
1468
|
+
g.addEdge('B', 'C');
|
|
1469
|
+
const cuts = g.getCutVertices();
|
|
1470
|
+
console.log(cuts.length); // 1;
|
|
1471
|
+
console.log(cuts[0].key); // 'B';
|
|
1472
|
+
```
|
|
1473
|
+
|
|
1474
|
+
***
|
|
1475
|
+
|
|
1476
|
+
### getCycles()
|
|
1477
|
+
|
|
1478
|
+
```ts
|
|
1479
|
+
getCycles(isInclude2Cycle?): VertexKey[][];
|
|
1480
|
+
```
|
|
1481
|
+
|
|
1482
|
+
Defined in: [data-structures/graph/abstract-graph.ts:838](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L838)
|
|
1483
|
+
|
|
1484
|
+
Enumerate simple cycles (may be expensive).
|
|
1485
|
+
|
|
1486
|
+
#### Parameters
|
|
1487
|
+
|
|
1488
|
+
##### isInclude2Cycle?
|
|
1489
|
+
|
|
1490
|
+
`boolean` = `false`
|
|
1491
|
+
|
|
1492
|
+
If `true`, include 2-cycles when graph semantics allow.
|
|
1493
|
+
|
|
1494
|
+
#### Returns
|
|
1495
|
+
|
|
1496
|
+
`VertexKey`[][]
|
|
1497
|
+
|
|
1498
|
+
Array of cycles (each as array of vertex keys).
|
|
1499
|
+
|
|
1500
|
+
#### Remarks
|
|
1501
|
+
|
|
1502
|
+
Time exponential in worst-case, Space O(V + E)
|
|
1503
|
+
|
|
1504
|
+
#### Inherited from
|
|
1505
|
+
|
|
1506
|
+
[`AbstractGraph`](AbstractGraph.md).[`getCycles`](AbstractGraph.md#getcycles)
|
|
1507
|
+
|
|
1508
|
+
***
|
|
1509
|
+
|
|
1510
|
+
### getDFNMap()
|
|
1511
|
+
|
|
1512
|
+
```ts
|
|
1513
|
+
getDFNMap(): Map<VO, number>;
|
|
1514
|
+
```
|
|
1515
|
+
|
|
1516
|
+
Defined in: [data-structures/graph/undirected-graph.ts:1048](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L1048)
|
|
1517
|
+
|
|
1518
|
+
DFN index map computed by `tarjan()`.
|
|
1519
|
+
|
|
1520
|
+
#### Returns
|
|
1521
|
+
|
|
1522
|
+
`Map`\<`VO`, `number`\>
|
|
1523
|
+
|
|
1524
|
+
Map from vertex to DFN index.
|
|
1525
|
+
|
|
1526
|
+
#### Remarks
|
|
1527
|
+
|
|
1528
|
+
Time O(V), Space O(V)
|
|
1529
|
+
|
|
1530
|
+
***
|
|
1531
|
+
|
|
1532
|
+
### getEdge()
|
|
1533
|
+
|
|
1534
|
+
```ts
|
|
1535
|
+
getEdge(v1, v2): EO | undefined;
|
|
1536
|
+
```
|
|
1537
|
+
|
|
1538
|
+
Defined in: [data-structures/graph/undirected-graph.ts:269](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L269)
|
|
1539
|
+
|
|
1540
|
+
Get an undirected edge between two vertices, if present.
|
|
1541
|
+
|
|
1542
|
+
#### Parameters
|
|
1543
|
+
|
|
1544
|
+
##### v1
|
|
1545
|
+
|
|
1546
|
+
`VertexKey` \| `VO` \| `undefined`
|
|
1547
|
+
|
|
1548
|
+
One vertex or key.
|
|
1549
|
+
|
|
1550
|
+
##### v2
|
|
1551
|
+
|
|
1552
|
+
`VertexKey` \| `VO` \| `undefined`
|
|
1553
|
+
|
|
1554
|
+
The other vertex or key.
|
|
1555
|
+
|
|
1556
|
+
#### Returns
|
|
1557
|
+
|
|
1558
|
+
`EO` \| `undefined`
|
|
1559
|
+
|
|
1560
|
+
Edge instance or `undefined`.
|
|
1561
|
+
|
|
1562
|
+
#### Remarks
|
|
1563
|
+
|
|
1564
|
+
Time O(1) avg, Space O(1)
|
|
1565
|
+
|
|
1566
|
+
*
|
|
1567
|
+
|
|
1568
|
+
#### Example
|
|
1569
|
+
|
|
1570
|
+
```ts
|
|
1571
|
+
// Get edge between vertices
|
|
1572
|
+
const g = new UndirectedGraph();
|
|
1573
|
+
g.addVertex('A');
|
|
1574
|
+
g.addVertex('B');
|
|
1575
|
+
g.addEdge('A', 'B', 7);
|
|
1576
|
+
console.log(g.getEdge('A', 'B')?.weight); // 7;
|
|
1577
|
+
```
|
|
1578
|
+
|
|
1579
|
+
#### Implementation of
|
|
1580
|
+
|
|
1581
|
+
```ts
|
|
1582
|
+
IGraph.getEdge
|
|
1583
|
+
```
|
|
1584
|
+
|
|
1585
|
+
#### Overrides
|
|
1586
|
+
|
|
1587
|
+
[`AbstractGraph`](AbstractGraph.md).[`getEdge`](AbstractGraph.md#getedge)
|
|
1588
|
+
|
|
1589
|
+
***
|
|
1590
|
+
|
|
1591
|
+
### getEndsOfEdge()
|
|
1592
|
+
|
|
1593
|
+
```ts
|
|
1594
|
+
getEndsOfEdge(edge): [VO, VO] | undefined;
|
|
1595
|
+
```
|
|
1596
|
+
|
|
1597
|
+
Defined in: [data-structures/graph/undirected-graph.ts:657](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L657)
|
|
1598
|
+
|
|
1599
|
+
Resolve an edge's two endpoints to vertex instances.
|
|
1600
|
+
|
|
1601
|
+
#### Parameters
|
|
1602
|
+
|
|
1603
|
+
##### edge
|
|
1604
|
+
|
|
1605
|
+
`EO`
|
|
1606
|
+
|
|
1607
|
+
Edge instance.
|
|
1608
|
+
|
|
1609
|
+
#### Returns
|
|
1610
|
+
|
|
1611
|
+
\[`VO`, `VO`\] \| `undefined`
|
|
1612
|
+
|
|
1613
|
+
`[v1, v2]` or `undefined` if either endpoint is missing.
|
|
1614
|
+
|
|
1615
|
+
#### Remarks
|
|
1616
|
+
|
|
1617
|
+
Time O(1), Space O(1)
|
|
1618
|
+
|
|
1619
|
+
#### Implementation of
|
|
1620
|
+
|
|
1621
|
+
```ts
|
|
1622
|
+
IGraph.getEndsOfEdge
|
|
1623
|
+
```
|
|
1624
|
+
|
|
1625
|
+
#### Overrides
|
|
1626
|
+
|
|
1627
|
+
[`AbstractGraph`](AbstractGraph.md).[`getEndsOfEdge`](AbstractGraph.md#getendsofedge)
|
|
1628
|
+
|
|
1629
|
+
***
|
|
1630
|
+
|
|
1631
|
+
### getLowMap()
|
|
1632
|
+
|
|
1633
|
+
```ts
|
|
1634
|
+
getLowMap(): Map<VO, number>;
|
|
1635
|
+
```
|
|
1636
|
+
|
|
1637
|
+
Defined in: [data-structures/graph/undirected-graph.ts:1057](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L1057)
|
|
1638
|
+
|
|
1639
|
+
LOW link map computed by `tarjan()`.
|
|
1640
|
+
|
|
1641
|
+
#### Returns
|
|
1642
|
+
|
|
1643
|
+
`Map`\<`VO`, `number`\>
|
|
1644
|
+
|
|
1645
|
+
Map from vertex to LOW value.
|
|
1646
|
+
|
|
1647
|
+
#### Remarks
|
|
1648
|
+
|
|
1649
|
+
Time O(V), Space O(V)
|
|
1650
|
+
|
|
1651
|
+
***
|
|
1652
|
+
|
|
1653
|
+
### getMinCostBetween()
|
|
1654
|
+
|
|
1655
|
+
```ts
|
|
1656
|
+
getMinCostBetween(
|
|
1657
|
+
v1,
|
|
1658
|
+
v2,
|
|
1659
|
+
isWeight?): number | undefined;
|
|
1660
|
+
```
|
|
1661
|
+
|
|
1662
|
+
Defined in: [data-structures/graph/abstract-graph.ts:362](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L362)
|
|
1663
|
+
|
|
1664
|
+
Minimum hops/weight between two vertices.
|
|
1665
|
+
|
|
1666
|
+
#### Parameters
|
|
1667
|
+
|
|
1668
|
+
##### v1
|
|
1669
|
+
|
|
1670
|
+
`VertexKey` \| `VO`
|
|
1671
|
+
|
|
1672
|
+
Source vertex or key.
|
|
1673
|
+
|
|
1674
|
+
##### v2
|
|
1675
|
+
|
|
1676
|
+
`VertexKey` \| `VO`
|
|
1677
|
+
|
|
1678
|
+
Destination vertex or key.
|
|
1679
|
+
|
|
1680
|
+
##### isWeight?
|
|
1681
|
+
|
|
1682
|
+
`boolean`
|
|
1683
|
+
|
|
1684
|
+
If `true`, compare by path weight; otherwise by hop count.
|
|
1685
|
+
|
|
1686
|
+
#### Returns
|
|
1687
|
+
|
|
1688
|
+
`number` \| `undefined`
|
|
1689
|
+
|
|
1690
|
+
Minimum cost or `undefined` if missing/unreachable.
|
|
1691
|
+
|
|
1692
|
+
#### Remarks
|
|
1693
|
+
|
|
1694
|
+
Time O((V + E) log V) weighted / O(V + E) unweighted, Space O(V + E)
|
|
1695
|
+
|
|
1696
|
+
#### Inherited from
|
|
1697
|
+
|
|
1698
|
+
[`AbstractGraph`](AbstractGraph.md).[`getMinCostBetween`](AbstractGraph.md#getmincostbetween)
|
|
1699
|
+
|
|
1700
|
+
***
|
|
1701
|
+
|
|
1702
|
+
### getMinPathBetween()
|
|
1703
|
+
|
|
1704
|
+
```ts
|
|
1705
|
+
getMinPathBetween(
|
|
1706
|
+
v1,
|
|
1707
|
+
v2,
|
|
1708
|
+
isWeight?,
|
|
1709
|
+
isDFS?): VO[] | undefined;
|
|
1710
|
+
```
|
|
1711
|
+
|
|
1712
|
+
Defined in: [data-structures/graph/abstract-graph.ts:415](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L415)
|
|
1713
|
+
|
|
1714
|
+
Minimum path (as vertex sequence) between two vertices.
|
|
1715
|
+
|
|
1716
|
+
#### Parameters
|
|
1717
|
+
|
|
1718
|
+
##### v1
|
|
1719
|
+
|
|
1720
|
+
`VertexKey` \| `VO`
|
|
1721
|
+
|
|
1722
|
+
Source vertex or key.
|
|
1723
|
+
|
|
1724
|
+
##### v2
|
|
1725
|
+
|
|
1726
|
+
`VertexKey` \| `VO`
|
|
1727
|
+
|
|
1728
|
+
Destination vertex or key.
|
|
1729
|
+
|
|
1730
|
+
##### isWeight?
|
|
1731
|
+
|
|
1732
|
+
`boolean`
|
|
1733
|
+
|
|
1734
|
+
If `true`, compare by path weight; otherwise by hop count.
|
|
1735
|
+
|
|
1736
|
+
##### isDFS?
|
|
1737
|
+
|
|
1738
|
+
`boolean` = `false`
|
|
1739
|
+
|
|
1740
|
+
For weighted mode only: if `true`, brute-force all paths; if `false`, use Dijkstra.
|
|
1741
|
+
|
|
1742
|
+
#### Returns
|
|
1743
|
+
|
|
1744
|
+
`VO`[] \| `undefined`
|
|
1745
|
+
|
|
1746
|
+
Vertex sequence, or `undefined`/empty when unreachable depending on branch.
|
|
1747
|
+
|
|
1748
|
+
#### Remarks
|
|
1749
|
+
|
|
1750
|
+
Time O((V + E) log V) weighted / O(V + E) unweighted, Space O(V + E)
|
|
1751
|
+
|
|
1752
|
+
#### Inherited from
|
|
1753
|
+
|
|
1754
|
+
[`AbstractGraph`](AbstractGraph.md).[`getMinPathBetween`](AbstractGraph.md#getminpathbetween)
|
|
1755
|
+
|
|
1756
|
+
***
|
|
1757
|
+
|
|
1758
|
+
### getNeighbors()
|
|
1759
|
+
|
|
1760
|
+
```ts
|
|
1761
|
+
getNeighbors(vertexOrKey): VO[];
|
|
1762
|
+
```
|
|
1763
|
+
|
|
1764
|
+
Defined in: [data-structures/graph/undirected-graph.ts:636](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L636)
|
|
1765
|
+
|
|
1766
|
+
UndirectedGraph connectivity and neighbors
|
|
1767
|
+
|
|
1768
|
+
*
|
|
1769
|
+
|
|
1770
|
+
#### Parameters
|
|
1771
|
+
|
|
1772
|
+
##### vertexOrKey
|
|
1773
|
+
|
|
1774
|
+
`VertexKey` \| `VO`
|
|
1775
|
+
|
|
1776
|
+
#### Returns
|
|
1777
|
+
|
|
1778
|
+
`VO`[]
|
|
1779
|
+
|
|
1780
|
+
#### Example
|
|
1781
|
+
|
|
1782
|
+
```ts
|
|
1783
|
+
// UndirectedGraph connectivity and neighbors
|
|
1784
|
+
const graph = new UndirectedGraph<string>();
|
|
1785
|
+
|
|
1786
|
+
// Build a friendship network
|
|
1787
|
+
const people = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'];
|
|
1788
|
+
for (const person of people) {
|
|
1789
|
+
graph.addVertex(person);
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
// Add friendships (undirected edges)
|
|
1793
|
+
graph.addEdge('Alice', 'Bob', 1);
|
|
1794
|
+
graph.addEdge('Alice', 'Charlie', 1);
|
|
1795
|
+
graph.addEdge('Bob', 'Diana', 1);
|
|
1796
|
+
graph.addEdge('Charlie', 'Eve', 1);
|
|
1797
|
+
graph.addEdge('Diana', 'Eve', 1);
|
|
1798
|
+
|
|
1799
|
+
// Get friends of each person
|
|
1800
|
+
const aliceFriends = graph.getNeighbors('Alice');
|
|
1801
|
+
console.log(aliceFriends[0].key); // 'Bob';
|
|
1802
|
+
console.log(aliceFriends[1].key); // 'Charlie';
|
|
1803
|
+
console.log(aliceFriends.length); // 2;
|
|
1804
|
+
|
|
1805
|
+
const dianaFriends = graph.getNeighbors('Diana');
|
|
1806
|
+
console.log(dianaFriends[0].key); // 'Bob';
|
|
1807
|
+
console.log(dianaFriends[1].key); // 'Eve';
|
|
1808
|
+
console.log(dianaFriends.length); // 2;
|
|
1809
|
+
|
|
1810
|
+
// Verify bidirectional friendship
|
|
1811
|
+
const bobFriends = graph.getNeighbors('Bob');
|
|
1812
|
+
console.log(bobFriends[0].key); // 'Alice'; // Alice -> Bob -> Alice ✓
|
|
1813
|
+
console.log(bobFriends[1].key); // 'Diana';
|
|
1814
|
+
```
|
|
1815
|
+
|
|
1816
|
+
#### Implementation of
|
|
1817
|
+
|
|
1818
|
+
```ts
|
|
1819
|
+
IGraph.getNeighbors
|
|
1820
|
+
```
|
|
1821
|
+
|
|
1822
|
+
#### Overrides
|
|
1823
|
+
|
|
1824
|
+
[`AbstractGraph`](AbstractGraph.md).[`getNeighbors`](AbstractGraph.md#getneighbors)
|
|
1825
|
+
|
|
1826
|
+
***
|
|
1827
|
+
|
|
1828
|
+
### getPathSumWeight()
|
|
1829
|
+
|
|
1830
|
+
```ts
|
|
1831
|
+
getPathSumWeight(path): number;
|
|
1832
|
+
```
|
|
1833
|
+
|
|
1834
|
+
Defined in: [data-structures/graph/abstract-graph.ts:346](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L346)
|
|
1835
|
+
|
|
1836
|
+
Sum the weights along a vertex path.
|
|
1837
|
+
|
|
1838
|
+
#### Parameters
|
|
1839
|
+
|
|
1840
|
+
##### path
|
|
1841
|
+
|
|
1842
|
+
`VO`[]
|
|
1843
|
+
|
|
1844
|
+
Sequence of vertices.
|
|
1845
|
+
|
|
1846
|
+
#### Returns
|
|
1847
|
+
|
|
1848
|
+
`number`
|
|
1849
|
+
|
|
1850
|
+
Path weight sum (0 if empty or edge missing).
|
|
1851
|
+
|
|
1852
|
+
#### Remarks
|
|
1853
|
+
|
|
1854
|
+
Time O(L), Space O(1) where L is path length
|
|
1855
|
+
|
|
1856
|
+
#### Inherited from
|
|
1857
|
+
|
|
1858
|
+
[`AbstractGraph`](AbstractGraph.md).[`getPathSumWeight`](AbstractGraph.md#getpathsumweight)
|
|
1859
|
+
|
|
1860
|
+
***
|
|
1861
|
+
|
|
1862
|
+
### getVertex()
|
|
1863
|
+
|
|
1864
|
+
```ts
|
|
1865
|
+
getVertex(vertexKey): VO | undefined;
|
|
1866
|
+
```
|
|
1867
|
+
|
|
1868
|
+
Defined in: [data-structures/graph/abstract-graph.ts:175](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L175)
|
|
1869
|
+
|
|
1870
|
+
Get vertex instance by key.
|
|
1871
|
+
|
|
1872
|
+
#### Parameters
|
|
1873
|
+
|
|
1874
|
+
##### vertexKey
|
|
1875
|
+
|
|
1876
|
+
`VertexKey`
|
|
1877
|
+
|
|
1878
|
+
Vertex key.
|
|
1879
|
+
|
|
1880
|
+
#### Returns
|
|
1881
|
+
|
|
1882
|
+
`VO` \| `undefined`
|
|
1883
|
+
|
|
1884
|
+
Vertex instance or `undefined`.
|
|
1885
|
+
|
|
1886
|
+
#### Remarks
|
|
1887
|
+
|
|
1888
|
+
Time O(1), Space O(1)
|
|
1889
|
+
|
|
1890
|
+
#### Implementation of
|
|
1891
|
+
|
|
1892
|
+
```ts
|
|
1893
|
+
IGraph.getVertex
|
|
1894
|
+
```
|
|
1895
|
+
|
|
1896
|
+
#### Inherited from
|
|
1897
|
+
|
|
1898
|
+
[`AbstractGraph`](AbstractGraph.md).[`getVertex`](AbstractGraph.md#getvertex)
|
|
1899
|
+
|
|
1900
|
+
***
|
|
1901
|
+
|
|
1902
|
+
### has()
|
|
1903
|
+
|
|
1904
|
+
```ts
|
|
1905
|
+
has(key): boolean;
|
|
1906
|
+
```
|
|
1907
|
+
|
|
1908
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:129](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L129)
|
|
1909
|
+
|
|
1910
|
+
Whether the given key exists.
|
|
1911
|
+
|
|
1912
|
+
#### Parameters
|
|
1913
|
+
|
|
1914
|
+
##### key
|
|
1915
|
+
|
|
1916
|
+
`VertexKey`
|
|
1917
|
+
|
|
1918
|
+
Key to test.
|
|
1919
|
+
|
|
1920
|
+
#### Returns
|
|
1921
|
+
|
|
1922
|
+
`boolean`
|
|
1923
|
+
|
|
1924
|
+
`true` if found; otherwise `false`.
|
|
1925
|
+
|
|
1926
|
+
#### Remarks
|
|
1927
|
+
|
|
1928
|
+
Time O(n) generic, Space O(1)
|
|
1929
|
+
|
|
1930
|
+
#### Inherited from
|
|
1931
|
+
|
|
1932
|
+
[`AbstractGraph`](AbstractGraph.md).[`has`](AbstractGraph.md#has)
|
|
1933
|
+
|
|
1934
|
+
***
|
|
1935
|
+
|
|
1936
|
+
### hasCycle()
|
|
1937
|
+
|
|
1938
|
+
```ts
|
|
1939
|
+
hasCycle(): boolean;
|
|
1940
|
+
```
|
|
1941
|
+
|
|
1942
|
+
Defined in: [data-structures/graph/undirected-graph.ts:917](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L917)
|
|
1943
|
+
|
|
1944
|
+
Detect whether the graph contains a cycle.
|
|
1945
|
+
Uses DFS with parent tracking.
|
|
1946
|
+
|
|
1947
|
+
#### Returns
|
|
1948
|
+
|
|
1949
|
+
`boolean`
|
|
1950
|
+
|
|
1951
|
+
`true` if a cycle exists, `false` otherwise.
|
|
1952
|
+
|
|
1953
|
+
#### Remarks
|
|
1954
|
+
|
|
1955
|
+
Time O(V + E), Space O(V)
|
|
1956
|
+
|
|
1957
|
+
*
|
|
1958
|
+
|
|
1959
|
+
#### Example
|
|
1960
|
+
|
|
1961
|
+
```ts
|
|
1962
|
+
// Detect cycle
|
|
1963
|
+
const g = new UndirectedGraph();
|
|
1964
|
+
g.addVertex('A');
|
|
1965
|
+
g.addVertex('B');
|
|
1966
|
+
g.addVertex('C');
|
|
1967
|
+
g.addEdge('A', 'B');
|
|
1968
|
+
g.addEdge('B', 'C');
|
|
1969
|
+
console.log(g.hasCycle()); // false;
|
|
1970
|
+
g.addEdge('C', 'A');
|
|
1971
|
+
console.log(g.hasCycle()); // true;
|
|
1972
|
+
```
|
|
1973
|
+
|
|
1974
|
+
***
|
|
1975
|
+
|
|
1976
|
+
### hasEdge()
|
|
1977
|
+
|
|
1978
|
+
```ts
|
|
1979
|
+
hasEdge(v1, v2): boolean;
|
|
1980
|
+
```
|
|
1981
|
+
|
|
1982
|
+
Defined in: [data-structures/graph/abstract-graph.ts:249](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L249)
|
|
1983
|
+
|
|
1984
|
+
Whether an edge exists between two vertices.
|
|
1985
|
+
|
|
1986
|
+
#### Parameters
|
|
1987
|
+
|
|
1988
|
+
##### v1
|
|
1989
|
+
|
|
1990
|
+
`VertexKey` \| `VO`
|
|
1991
|
+
|
|
1992
|
+
Endpoint A vertex or key.
|
|
1993
|
+
|
|
1994
|
+
##### v2
|
|
1995
|
+
|
|
1996
|
+
`VertexKey` \| `VO`
|
|
1997
|
+
|
|
1998
|
+
Endpoint B vertex or key.
|
|
1999
|
+
|
|
2000
|
+
#### Returns
|
|
2001
|
+
|
|
2002
|
+
`boolean`
|
|
2003
|
+
|
|
2004
|
+
`true` if present; otherwise `false`.
|
|
2005
|
+
|
|
2006
|
+
#### Remarks
|
|
2007
|
+
|
|
2008
|
+
Time O(1) avg, Space O(1)
|
|
2009
|
+
|
|
2010
|
+
#### Inherited from
|
|
2011
|
+
|
|
2012
|
+
[`AbstractGraph`](AbstractGraph.md).[`hasEdge`](AbstractGraph.md#hasedge)
|
|
2013
|
+
|
|
2014
|
+
***
|
|
2015
|
+
|
|
2016
|
+
### hasValue()
|
|
2017
|
+
|
|
2018
|
+
```ts
|
|
2019
|
+
hasValue(value): boolean;
|
|
2020
|
+
```
|
|
2021
|
+
|
|
2022
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:143](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L143)
|
|
2023
|
+
|
|
2024
|
+
Whether there exists an entry with the given value.
|
|
2025
|
+
|
|
2026
|
+
#### Parameters
|
|
2027
|
+
|
|
2028
|
+
##### value
|
|
2029
|
+
|
|
2030
|
+
`V` \| `undefined`
|
|
2031
|
+
|
|
2032
|
+
Value to test.
|
|
2033
|
+
|
|
2034
|
+
#### Returns
|
|
2035
|
+
|
|
2036
|
+
`boolean`
|
|
2037
|
+
|
|
2038
|
+
`true` if found; otherwise `false`.
|
|
2039
|
+
|
|
2040
|
+
#### Remarks
|
|
2041
|
+
|
|
2042
|
+
Time O(n), Space O(1)
|
|
2043
|
+
|
|
2044
|
+
#### Inherited from
|
|
2045
|
+
|
|
2046
|
+
[`AbstractGraph`](AbstractGraph.md).[`hasValue`](AbstractGraph.md#hasvalue)
|
|
2047
|
+
|
|
2048
|
+
***
|
|
2049
|
+
|
|
2050
|
+
### hasVertex()
|
|
2051
|
+
|
|
2052
|
+
```ts
|
|
2053
|
+
hasVertex(vertexOrKey): boolean;
|
|
2054
|
+
```
|
|
2055
|
+
|
|
2056
|
+
Defined in: [data-structures/graph/abstract-graph.ts:185](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L185)
|
|
2057
|
+
|
|
2058
|
+
Whether a vertex exists.
|
|
2059
|
+
|
|
2060
|
+
#### Parameters
|
|
2061
|
+
|
|
2062
|
+
##### vertexOrKey
|
|
2063
|
+
|
|
2064
|
+
`VertexKey` \| `VO`
|
|
2065
|
+
|
|
2066
|
+
Vertex or key.
|
|
2067
|
+
|
|
2068
|
+
#### Returns
|
|
2069
|
+
|
|
2070
|
+
`boolean`
|
|
2071
|
+
|
|
2072
|
+
`true` if present, otherwise `false`.
|
|
2073
|
+
|
|
2074
|
+
#### Remarks
|
|
2075
|
+
|
|
2076
|
+
Time O(1) avg, Space O(1)
|
|
2077
|
+
|
|
2078
|
+
#### Implementation of
|
|
2079
|
+
|
|
2080
|
+
```ts
|
|
2081
|
+
IGraph.hasVertex
|
|
2082
|
+
```
|
|
2083
|
+
|
|
2084
|
+
#### Inherited from
|
|
2085
|
+
|
|
2086
|
+
[`AbstractGraph`](AbstractGraph.md).[`hasVertex`](AbstractGraph.md#hasvertex)
|
|
2087
|
+
|
|
2088
|
+
***
|
|
2089
|
+
|
|
2090
|
+
### isEmpty()
|
|
2091
|
+
|
|
2092
|
+
```ts
|
|
2093
|
+
isEmpty(): boolean;
|
|
2094
|
+
```
|
|
2095
|
+
|
|
2096
|
+
Defined in: [data-structures/graph/undirected-graph.ts:674](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L674)
|
|
2097
|
+
|
|
2098
|
+
Whether the graph has no vertices and no edges.
|
|
2099
|
+
|
|
2100
|
+
#### Returns
|
|
2101
|
+
|
|
2102
|
+
`boolean`
|
|
2103
|
+
|
|
2104
|
+
#### Remarks
|
|
2105
|
+
|
|
2106
|
+
Time O(1), Space O(1)
|
|
2107
|
+
|
|
2108
|
+
#### Implementation of
|
|
2109
|
+
|
|
2110
|
+
```ts
|
|
2111
|
+
IGraph.isEmpty
|
|
2112
|
+
```
|
|
2113
|
+
|
|
2114
|
+
#### Overrides
|
|
2115
|
+
|
|
2116
|
+
[`AbstractGraph`](AbstractGraph.md).[`isEmpty`](AbstractGraph.md#isempty)
|
|
2117
|
+
|
|
2118
|
+
***
|
|
2119
|
+
|
|
2120
|
+
### isVertexKey()
|
|
2121
|
+
|
|
2122
|
+
```ts
|
|
2123
|
+
isVertexKey(potentialKey): potentialKey is VertexKey;
|
|
2124
|
+
```
|
|
2125
|
+
|
|
2126
|
+
Defined in: [data-structures/graph/abstract-graph.ts:215](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L215)
|
|
2127
|
+
|
|
2128
|
+
Type guard: check if a value is a valid vertex key.
|
|
2129
|
+
|
|
2130
|
+
#### Parameters
|
|
2131
|
+
|
|
2132
|
+
##### potentialKey
|
|
2133
|
+
|
|
2134
|
+
`unknown`
|
|
2135
|
+
|
|
2136
|
+
Value to test.
|
|
2137
|
+
|
|
2138
|
+
#### Returns
|
|
2139
|
+
|
|
2140
|
+
`potentialKey is VertexKey`
|
|
2141
|
+
|
|
2142
|
+
`true` if string/number; else `false`.
|
|
2143
|
+
|
|
2144
|
+
#### Remarks
|
|
2145
|
+
|
|
2146
|
+
Time O(1), Space O(1)
|
|
2147
|
+
|
|
2148
|
+
#### Inherited from
|
|
2149
|
+
|
|
2150
|
+
[`AbstractGraph`](AbstractGraph.md).[`isVertexKey`](AbstractGraph.md#isvertexkey)
|
|
2151
|
+
|
|
2152
|
+
***
|
|
2153
|
+
|
|
2154
|
+
### keys()
|
|
2155
|
+
|
|
2156
|
+
```ts
|
|
2157
|
+
keys(): IterableIterator<VertexKey>;
|
|
2158
|
+
```
|
|
2159
|
+
|
|
2160
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:42](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L42)
|
|
2161
|
+
|
|
2162
|
+
Iterate over keys only.
|
|
2163
|
+
|
|
2164
|
+
#### Returns
|
|
2165
|
+
|
|
2166
|
+
`IterableIterator`\<`VertexKey`\>
|
|
2167
|
+
|
|
2168
|
+
Iterator of keys.
|
|
2169
|
+
|
|
2170
|
+
#### Remarks
|
|
2171
|
+
|
|
2172
|
+
Time O(n), Space O(1)
|
|
2173
|
+
|
|
2174
|
+
#### Inherited from
|
|
2175
|
+
|
|
2176
|
+
[`AbstractGraph`](AbstractGraph.md).[`keys`](AbstractGraph.md#keys)
|
|
2177
|
+
|
|
2178
|
+
***
|
|
2179
|
+
|
|
2180
|
+
### map()
|
|
2181
|
+
|
|
2182
|
+
```ts
|
|
2183
|
+
map<T>(callback, thisArg?): T[];
|
|
2184
|
+
```
|
|
2185
|
+
|
|
2186
|
+
Defined in: [data-structures/graph/abstract-graph.ts:928](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L928)
|
|
2187
|
+
|
|
2188
|
+
Map entries using an implementation-specific strategy.
|
|
2189
|
+
|
|
2190
|
+
#### Type Parameters
|
|
2191
|
+
|
|
2192
|
+
##### T
|
|
2193
|
+
|
|
2194
|
+
`T`
|
|
2195
|
+
|
|
2196
|
+
#### Parameters
|
|
2197
|
+
|
|
2198
|
+
##### callback
|
|
2199
|
+
|
|
2200
|
+
`EntryCallback`\<`VertexKey`, `V` \| `undefined`, `T`\>
|
|
2201
|
+
|
|
2202
|
+
##### thisArg?
|
|
2203
|
+
|
|
2204
|
+
`unknown`
|
|
2205
|
+
|
|
2206
|
+
#### Returns
|
|
2207
|
+
|
|
2208
|
+
`T`[]
|
|
2209
|
+
|
|
2210
|
+
#### Remarks
|
|
2211
|
+
|
|
2212
|
+
Time O(n), Space O(n)
|
|
2213
|
+
|
|
2214
|
+
#### Inherited from
|
|
2215
|
+
|
|
2216
|
+
[`AbstractGraph`](AbstractGraph.md).[`map`](AbstractGraph.md#map)
|
|
2217
|
+
|
|
2218
|
+
***
|
|
2219
|
+
|
|
2220
|
+
### print()
|
|
2221
|
+
|
|
2222
|
+
```ts
|
|
2223
|
+
print(options?): void;
|
|
2224
|
+
```
|
|
2225
|
+
|
|
2226
|
+
Defined in: [data-structures/graph/abstract-graph.ts:1183](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L1183)
|
|
2227
|
+
|
|
2228
|
+
Print the graph to console.
|
|
2229
|
+
|
|
2230
|
+
#### Parameters
|
|
2231
|
+
|
|
2232
|
+
##### options?
|
|
2233
|
+
|
|
2234
|
+
Display settings passed to `toVisual`.
|
|
2235
|
+
|
|
2236
|
+
###### showWeight?
|
|
2237
|
+
|
|
2238
|
+
`boolean`
|
|
2239
|
+
|
|
2240
|
+
#### Returns
|
|
2241
|
+
|
|
2242
|
+
`void`
|
|
2243
|
+
|
|
2244
|
+
#### Inherited from
|
|
2245
|
+
|
|
2246
|
+
[`AbstractGraph`](AbstractGraph.md).[`print`](AbstractGraph.md#print)
|
|
2247
|
+
|
|
2248
|
+
***
|
|
2249
|
+
|
|
2250
|
+
### reduce()
|
|
2251
|
+
|
|
2252
|
+
```ts
|
|
2253
|
+
reduce<U>(callbackfn, initialValue): U;
|
|
2254
|
+
```
|
|
2255
|
+
|
|
2256
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:171](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L171)
|
|
2257
|
+
|
|
2258
|
+
Reduce entries into a single accumulator.
|
|
2259
|
+
|
|
2260
|
+
#### Type Parameters
|
|
2261
|
+
|
|
2262
|
+
##### U
|
|
2263
|
+
|
|
2264
|
+
`U`
|
|
2265
|
+
|
|
2266
|
+
#### Parameters
|
|
2267
|
+
|
|
2268
|
+
##### callbackfn
|
|
2269
|
+
|
|
2270
|
+
`ReduceEntryCallback`\<`VertexKey`, `V` \| `undefined`, `U`\>
|
|
2271
|
+
|
|
2272
|
+
`(acc, value, key, index, self) => acc`.
|
|
2273
|
+
|
|
2274
|
+
##### initialValue
|
|
2275
|
+
|
|
2276
|
+
`U`
|
|
2277
|
+
|
|
2278
|
+
Initial accumulator.
|
|
2279
|
+
|
|
2280
|
+
#### Returns
|
|
2281
|
+
|
|
2282
|
+
`U`
|
|
2283
|
+
|
|
2284
|
+
Final accumulator.
|
|
2285
|
+
|
|
2286
|
+
#### Remarks
|
|
2287
|
+
|
|
2288
|
+
Time O(n), Space O(1)
|
|
2289
|
+
|
|
2290
|
+
#### Inherited from
|
|
2291
|
+
|
|
2292
|
+
[`AbstractGraph`](AbstractGraph.md).[`reduce`](AbstractGraph.md#reduce)
|
|
2293
|
+
|
|
2294
|
+
***
|
|
2295
|
+
|
|
2296
|
+
### removeManyVertices()
|
|
2297
|
+
|
|
2298
|
+
```ts
|
|
2299
|
+
removeManyVertices(vertexMap): boolean;
|
|
2300
|
+
```
|
|
2301
|
+
|
|
2302
|
+
Defined in: [data-structures/graph/abstract-graph.ts:234](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L234)
|
|
2303
|
+
|
|
2304
|
+
Delete multiple vertices.
|
|
2305
|
+
|
|
2306
|
+
#### Parameters
|
|
2307
|
+
|
|
2308
|
+
##### vertexMap
|
|
2309
|
+
|
|
2310
|
+
`VertexKey`[] \| `VO`[]
|
|
2311
|
+
|
|
2312
|
+
Array of vertices or keys.
|
|
2313
|
+
|
|
2314
|
+
#### Returns
|
|
2315
|
+
|
|
2316
|
+
`boolean`
|
|
2317
|
+
|
|
2318
|
+
`true` if any vertex was removed.
|
|
2319
|
+
|
|
2320
|
+
#### Remarks
|
|
2321
|
+
|
|
2322
|
+
Time O(sum(deg)), Space O(1)
|
|
2323
|
+
|
|
2324
|
+
#### Inherited from
|
|
2325
|
+
|
|
2326
|
+
[`AbstractGraph`](AbstractGraph.md).[`removeManyVertices`](AbstractGraph.md#removemanyvertices)
|
|
2327
|
+
|
|
2328
|
+
***
|
|
2329
|
+
|
|
2330
|
+
### setEdgeWeight()
|
|
2331
|
+
|
|
2332
|
+
```ts
|
|
2333
|
+
setEdgeWeight(
|
|
2334
|
+
srcOrKey,
|
|
2335
|
+
destOrKey,
|
|
2336
|
+
weight): boolean;
|
|
2337
|
+
```
|
|
2338
|
+
|
|
2339
|
+
Defined in: [data-structures/graph/abstract-graph.ts:291](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L291)
|
|
2340
|
+
|
|
2341
|
+
Set the weight of an existing edge.
|
|
2342
|
+
|
|
2343
|
+
#### Parameters
|
|
2344
|
+
|
|
2345
|
+
##### srcOrKey
|
|
2346
|
+
|
|
2347
|
+
`VertexKey` \| `VO`
|
|
2348
|
+
|
|
2349
|
+
Source vertex or key.
|
|
2350
|
+
|
|
2351
|
+
##### destOrKey
|
|
2352
|
+
|
|
2353
|
+
`VertexKey` \| `VO`
|
|
2354
|
+
|
|
2355
|
+
Destination vertex or key.
|
|
2356
|
+
|
|
2357
|
+
##### weight
|
|
2358
|
+
|
|
2359
|
+
`number`
|
|
2360
|
+
|
|
2361
|
+
New weight.
|
|
2362
|
+
|
|
2363
|
+
#### Returns
|
|
2364
|
+
|
|
2365
|
+
`boolean`
|
|
2366
|
+
|
|
2367
|
+
`true` if updated; otherwise `false`.
|
|
2368
|
+
|
|
2369
|
+
#### Remarks
|
|
2370
|
+
|
|
2371
|
+
Time O(1) avg, Space O(1)
|
|
2372
|
+
|
|
2373
|
+
#### Inherited from
|
|
2374
|
+
|
|
2375
|
+
[`AbstractGraph`](AbstractGraph.md).[`setEdgeWeight`](AbstractGraph.md#setedgeweight)
|
|
2376
|
+
|
|
2377
|
+
***
|
|
2378
|
+
|
|
2379
|
+
### some()
|
|
2380
|
+
|
|
2381
|
+
```ts
|
|
2382
|
+
some(predicate, thisArg?): boolean;
|
|
2383
|
+
```
|
|
2384
|
+
|
|
2385
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:83](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L83)
|
|
2386
|
+
|
|
2387
|
+
Test whether any entry satisfies the predicate.
|
|
2388
|
+
|
|
2389
|
+
#### Parameters
|
|
2390
|
+
|
|
2391
|
+
##### predicate
|
|
2392
|
+
|
|
2393
|
+
`EntryCallback`\<`VertexKey`, `V` \| `undefined`, `boolean`\>
|
|
2394
|
+
|
|
2395
|
+
`(key, value, index, self) => boolean`.
|
|
2396
|
+
|
|
2397
|
+
##### thisArg?
|
|
2398
|
+
|
|
2399
|
+
`unknown`
|
|
2400
|
+
|
|
2401
|
+
Optional `this` for callback.
|
|
2402
|
+
|
|
2403
|
+
#### Returns
|
|
2404
|
+
|
|
2405
|
+
`boolean`
|
|
2406
|
+
|
|
2407
|
+
`true` if any passes; otherwise `false`.
|
|
2408
|
+
|
|
2409
|
+
#### Remarks
|
|
2410
|
+
|
|
2411
|
+
Time O(n), Space O(1)
|
|
2412
|
+
|
|
2413
|
+
#### Inherited from
|
|
2414
|
+
|
|
2415
|
+
[`AbstractGraph`](AbstractGraph.md).[`some`](AbstractGraph.md#some)
|
|
2416
|
+
|
|
2417
|
+
***
|
|
2418
|
+
|
|
2419
|
+
### tarjan()
|
|
2420
|
+
|
|
2421
|
+
```ts
|
|
2422
|
+
tarjan(): object;
|
|
2423
|
+
```
|
|
2424
|
+
|
|
2425
|
+
Defined in: [data-structures/graph/undirected-graph.ts:743](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L743)
|
|
2426
|
+
|
|
2427
|
+
Tarjan-based bridge and articulation point detection.
|
|
2428
|
+
|
|
2429
|
+
#### Returns
|
|
2430
|
+
|
|
2431
|
+
`object`
|
|
2432
|
+
|
|
2433
|
+
`{ dfnMap, lowMap, bridges, cutVertices }`.
|
|
2434
|
+
|
|
2435
|
+
##### bridges
|
|
2436
|
+
|
|
2437
|
+
```ts
|
|
2438
|
+
bridges: EO[];
|
|
2439
|
+
```
|
|
2440
|
+
|
|
2441
|
+
##### cutVertices
|
|
2442
|
+
|
|
2443
|
+
```ts
|
|
2444
|
+
cutVertices: VO[];
|
|
2445
|
+
```
|
|
2446
|
+
|
|
2447
|
+
##### dfnMap
|
|
2448
|
+
|
|
2449
|
+
```ts
|
|
2450
|
+
dfnMap: Map<VO, number>;
|
|
2451
|
+
```
|
|
2452
|
+
|
|
2453
|
+
##### lowMap
|
|
2454
|
+
|
|
2455
|
+
```ts
|
|
2456
|
+
lowMap: Map<VO, number>;
|
|
2457
|
+
```
|
|
2458
|
+
|
|
2459
|
+
#### Remarks
|
|
2460
|
+
|
|
2461
|
+
Time O(V + E), Space O(V + E)
|
|
2462
|
+
|
|
2463
|
+
*
|
|
2464
|
+
|
|
2465
|
+
#### Example
|
|
2466
|
+
|
|
2467
|
+
```ts
|
|
2468
|
+
// Find articulation points and bridges
|
|
2469
|
+
const g = new UndirectedGraph();
|
|
2470
|
+
g.addVertex('A');
|
|
2471
|
+
g.addVertex('B');
|
|
2472
|
+
g.addVertex('C');
|
|
2473
|
+
g.addEdge('A', 'B');
|
|
2474
|
+
g.addEdge('B', 'C');
|
|
2475
|
+
const result = g.tarjan();
|
|
2476
|
+
console.log(result); // defined;
|
|
2477
|
+
```
|
|
2478
|
+
|
|
2479
|
+
***
|
|
2480
|
+
|
|
2481
|
+
### toArray()
|
|
2482
|
+
|
|
2483
|
+
```ts
|
|
2484
|
+
toArray(): [VertexKey, V | undefined][];
|
|
2485
|
+
```
|
|
2486
|
+
|
|
2487
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:186](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L186)
|
|
2488
|
+
|
|
2489
|
+
Converts data structure to `[key, value]` pairs.
|
|
2490
|
+
|
|
2491
|
+
#### Returns
|
|
2492
|
+
|
|
2493
|
+
\[`VertexKey`, `V` \| `undefined`\][]
|
|
2494
|
+
|
|
2495
|
+
Array of entries.
|
|
2496
|
+
|
|
2497
|
+
#### Remarks
|
|
2498
|
+
|
|
2499
|
+
Time O(n), Space O(n)
|
|
2500
|
+
|
|
2501
|
+
#### Inherited from
|
|
2502
|
+
|
|
2503
|
+
[`AbstractGraph`](AbstractGraph.md).[`toArray`](AbstractGraph.md#toarray)
|
|
2504
|
+
|
|
2505
|
+
***
|
|
2506
|
+
|
|
2507
|
+
### toDot()
|
|
2508
|
+
|
|
2509
|
+
```ts
|
|
2510
|
+
toDot(options?): string;
|
|
2511
|
+
```
|
|
2512
|
+
|
|
2513
|
+
Defined in: [data-structures/graph/abstract-graph.ts:1143](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L1143)
|
|
2514
|
+
|
|
2515
|
+
Generate DOT language representation for Graphviz.
|
|
2516
|
+
|
|
2517
|
+
#### Parameters
|
|
2518
|
+
|
|
2519
|
+
##### options?
|
|
2520
|
+
|
|
2521
|
+
Optional display settings.
|
|
2522
|
+
|
|
2523
|
+
###### name?
|
|
2524
|
+
|
|
2525
|
+
`string`
|
|
2526
|
+
|
|
2527
|
+
Graph name (default: 'G').
|
|
2528
|
+
|
|
2529
|
+
###### showWeight?
|
|
2530
|
+
|
|
2531
|
+
`boolean`
|
|
2532
|
+
|
|
2533
|
+
Whether to label edges with weight (default: true).
|
|
2534
|
+
|
|
2535
|
+
#### Returns
|
|
2536
|
+
|
|
2537
|
+
`string`
|
|
2538
|
+
|
|
2539
|
+
DOT format string.
|
|
2540
|
+
|
|
2541
|
+
#### Inherited from
|
|
2542
|
+
|
|
2543
|
+
[`AbstractGraph`](AbstractGraph.md).[`toDot`](AbstractGraph.md#todot)
|
|
2544
|
+
|
|
2545
|
+
***
|
|
2546
|
+
|
|
2547
|
+
### toVisual()
|
|
2548
|
+
|
|
2549
|
+
```ts
|
|
2550
|
+
toVisual(options?): string;
|
|
2551
|
+
```
|
|
2552
|
+
|
|
2553
|
+
Defined in: [data-structures/graph/abstract-graph.ts:1108](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L1108)
|
|
2554
|
+
|
|
2555
|
+
Generate a text-based visual representation of the graph.
|
|
2556
|
+
|
|
2557
|
+
**Adjacency list format:**
|
|
2558
|
+
```
|
|
2559
|
+
Graph (5 vertices, 6 edges):
|
|
2560
|
+
A -> B (1), C (2)
|
|
2561
|
+
B -> D (3)
|
|
2562
|
+
C -> (no outgoing edges)
|
|
2563
|
+
D -> A (1)
|
|
2564
|
+
E (isolated)
|
|
2565
|
+
```
|
|
2566
|
+
|
|
2567
|
+
#### Parameters
|
|
2568
|
+
|
|
2569
|
+
##### options?
|
|
2570
|
+
|
|
2571
|
+
Optional display settings.
|
|
2572
|
+
|
|
2573
|
+
###### showWeight?
|
|
2574
|
+
|
|
2575
|
+
`boolean`
|
|
2576
|
+
|
|
2577
|
+
Whether to show edge weights (default: true).
|
|
2578
|
+
|
|
2579
|
+
#### Returns
|
|
2580
|
+
|
|
2581
|
+
`string`
|
|
2582
|
+
|
|
2583
|
+
The visual string.
|
|
2584
|
+
|
|
2585
|
+
#### Inherited from
|
|
2586
|
+
|
|
2587
|
+
[`AbstractGraph`](AbstractGraph.md).[`toVisual`](AbstractGraph.md#tovisual)
|
|
2588
|
+
|
|
2589
|
+
***
|
|
2590
|
+
|
|
2591
|
+
### values()
|
|
2592
|
+
|
|
2593
|
+
```ts
|
|
2594
|
+
values(): IterableIterator<V | undefined>;
|
|
2595
|
+
```
|
|
2596
|
+
|
|
2597
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:53](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/base/iterable-entry-base.ts#L53)
|
|
2598
|
+
|
|
2599
|
+
Iterate over values only.
|
|
2600
|
+
|
|
2601
|
+
#### Returns
|
|
2602
|
+
|
|
2603
|
+
`IterableIterator`\<`V` \| `undefined`\>
|
|
2604
|
+
|
|
2605
|
+
Iterator of values.
|
|
2606
|
+
|
|
2607
|
+
#### Remarks
|
|
2608
|
+
|
|
2609
|
+
Time O(n), Space O(1)
|
|
2610
|
+
|
|
2611
|
+
#### Inherited from
|
|
2612
|
+
|
|
2613
|
+
[`AbstractGraph`](AbstractGraph.md).[`values`](AbstractGraph.md#values)
|
|
2614
|
+
|
|
2615
|
+
***
|
|
2616
|
+
|
|
2617
|
+
### fromEntries()
|
|
2618
|
+
|
|
2619
|
+
```ts
|
|
2620
|
+
static fromEntries<V>(entries): UndirectedGraph<V, undefined, UndirectedVertex<V>, UndirectedEdge<undefined>>;
|
|
2621
|
+
```
|
|
2622
|
+
|
|
2623
|
+
Defined in: [data-structures/graph/undirected-graph.ts:191](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L191)
|
|
2624
|
+
|
|
2625
|
+
Construct an undirected graph from `[key, value]` entries.
|
|
2626
|
+
|
|
2627
|
+
#### Type Parameters
|
|
2628
|
+
|
|
2629
|
+
##### V
|
|
2630
|
+
|
|
2631
|
+
`V`
|
|
2632
|
+
|
|
2633
|
+
Vertex value type.
|
|
2634
|
+
|
|
2635
|
+
#### Parameters
|
|
2636
|
+
|
|
2637
|
+
##### entries
|
|
2638
|
+
|
|
2639
|
+
`Iterable`\<\[`VertexKey`, `V`\]\>
|
|
2640
|
+
|
|
2641
|
+
Iterable of `[key, value]` pairs.
|
|
2642
|
+
|
|
2643
|
+
#### Returns
|
|
2644
|
+
|
|
2645
|
+
`UndirectedGraph`\<`V`, `undefined`, `UndirectedVertex`\<`V`\>, `UndirectedEdge`\<`undefined`\>\>
|
|
2646
|
+
|
|
2647
|
+
UndirectedGraph with all vertices added.
|
|
2648
|
+
|
|
2649
|
+
#### Remarks
|
|
2650
|
+
|
|
2651
|
+
Time O(V), Space O(V)
|
|
2652
|
+
|
|
2653
|
+
***
|
|
2654
|
+
|
|
2655
|
+
### fromKeys()
|
|
2656
|
+
|
|
2657
|
+
```ts
|
|
2658
|
+
static fromKeys<K>(keys): UndirectedGraph<K, undefined, UndirectedVertex<K>, UndirectedEdge<undefined>>;
|
|
2659
|
+
```
|
|
2660
|
+
|
|
2661
|
+
Defined in: [data-structures/graph/undirected-graph.ts:174](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L174)
|
|
2662
|
+
|
|
2663
|
+
Construct an undirected graph from keys with value initializer `v => v`.
|
|
2664
|
+
|
|
2665
|
+
#### Type Parameters
|
|
2666
|
+
|
|
2667
|
+
##### K
|
|
2668
|
+
|
|
2669
|
+
`K` *extends* `VertexKey`
|
|
2670
|
+
|
|
2671
|
+
Vertex key type.
|
|
2672
|
+
|
|
2673
|
+
#### Parameters
|
|
2674
|
+
|
|
2675
|
+
##### keys
|
|
2676
|
+
|
|
2677
|
+
`Iterable`\<`K`\>
|
|
2678
|
+
|
|
2679
|
+
Iterable of vertex keys.
|
|
2680
|
+
|
|
2681
|
+
#### Returns
|
|
2682
|
+
|
|
2683
|
+
`UndirectedGraph`\<`K`, `undefined`, `UndirectedVertex`\<`K`\>, `UndirectedEdge`\<`undefined`\>\>
|
|
2684
|
+
|
|
2685
|
+
UndirectedGraph with all keys added.
|
|
2686
|
+
|
|
2687
|
+
#### Remarks
|
|
2688
|
+
|
|
2689
|
+
Time O(V), Space O(V)
|
|
2690
|
+
|
|
2691
|
+
|
|
2692
|
+
---
|
|
2693
|
+
|
|
2694
|
+
## Protected Members
|
|
2695
|
+
|
|
2696
|
+
### \_edgeConnector
|
|
2697
|
+
|
|
2698
|
+
#### Get Signature
|
|
2699
|
+
|
|
2700
|
+
```ts
|
|
2701
|
+
get protected _edgeConnector(): string;
|
|
2702
|
+
```
|
|
2703
|
+
|
|
2704
|
+
Defined in: [data-structures/graph/abstract-graph.ts:1087](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L1087)
|
|
2705
|
+
|
|
2706
|
+
The edge connector string used in visual output.
|
|
2707
|
+
Override in subclasses (e.g., '--' for undirected, '->' for directed).
|
|
2708
|
+
|
|
2709
|
+
##### Returns
|
|
2710
|
+
|
|
2711
|
+
`string`
|
|
2712
|
+
|
|
2713
|
+
#### Inherited from
|
|
2714
|
+
|
|
2715
|
+
[`AbstractGraph`](AbstractGraph.md).[`_edgeConnector`](AbstractGraph.md#_edgeconnector)
|
|
2716
|
+
|
|
2717
|
+
***
|
|
2718
|
+
|
|
2719
|
+
### \_addEdge()
|
|
2720
|
+
|
|
2721
|
+
```ts
|
|
2722
|
+
protected _addEdge(edge): boolean;
|
|
2723
|
+
```
|
|
2724
|
+
|
|
2725
|
+
Defined in: [data-structures/graph/undirected-graph.ts:1067](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/undirected-graph.ts#L1067)
|
|
2726
|
+
|
|
2727
|
+
Internal hook to attach an undirected edge into adjacency maps.
|
|
2728
|
+
|
|
2729
|
+
#### Parameters
|
|
2730
|
+
|
|
2731
|
+
##### edge
|
|
2732
|
+
|
|
2733
|
+
`EO`
|
|
2734
|
+
|
|
2735
|
+
Edge instance.
|
|
2736
|
+
|
|
2737
|
+
#### Returns
|
|
2738
|
+
|
|
2739
|
+
`boolean`
|
|
2740
|
+
|
|
2741
|
+
`true` if both endpoints exist; otherwise `false`.
|
|
2742
|
+
|
|
2743
|
+
#### Remarks
|
|
2744
|
+
|
|
2745
|
+
Time O(1) avg, Space O(1)
|
|
2746
|
+
|
|
2747
|
+
#### Overrides
|
|
2748
|
+
|
|
2749
|
+
[`AbstractGraph`](AbstractGraph.md).[`_addEdge`](AbstractGraph.md#_addedge)
|
|
2750
|
+
|
|
2751
|
+
***
|
|
2752
|
+
|
|
2753
|
+
### \_addVertex()
|
|
2754
|
+
|
|
2755
|
+
```ts
|
|
2756
|
+
protected _addVertex(newVertex): boolean;
|
|
2757
|
+
```
|
|
2758
|
+
|
|
2759
|
+
Defined in: [data-structures/graph/abstract-graph.ts:1054](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L1054)
|
|
2760
|
+
|
|
2761
|
+
Insert a pre-built vertex into the graph.
|
|
2762
|
+
|
|
2763
|
+
#### Parameters
|
|
2764
|
+
|
|
2765
|
+
##### newVertex
|
|
2766
|
+
|
|
2767
|
+
`VO`
|
|
2768
|
+
|
|
2769
|
+
Concrete vertex instance.
|
|
2770
|
+
|
|
2771
|
+
#### Returns
|
|
2772
|
+
|
|
2773
|
+
`boolean`
|
|
2774
|
+
|
|
2775
|
+
`true` if inserted; `false` if key already exists.
|
|
2776
|
+
|
|
2777
|
+
#### Remarks
|
|
2778
|
+
|
|
2779
|
+
Time O(1) avg, Space O(1)
|
|
2780
|
+
|
|
2781
|
+
#### Inherited from
|
|
2782
|
+
|
|
2783
|
+
[`AbstractGraph`](AbstractGraph.md).[`_addVertex`](AbstractGraph.md#_addvertex)
|
|
2784
|
+
|
|
2785
|
+
***
|
|
2786
|
+
|
|
2787
|
+
### \_createInstance()
|
|
2788
|
+
|
|
2789
|
+
```ts
|
|
2790
|
+
protected _createInstance(_options?): this;
|
|
2791
|
+
```
|
|
2792
|
+
|
|
2793
|
+
Defined in: [data-structures/graph/abstract-graph.ts:987](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L987)
|
|
2794
|
+
|
|
2795
|
+
Create an empty graph instance of the same concrete species.
|
|
2796
|
+
|
|
2797
|
+
#### Parameters
|
|
2798
|
+
|
|
2799
|
+
##### \_options?
|
|
2800
|
+
|
|
2801
|
+
`Partial`\<`Record`\<`string`, `unknown`\>\>
|
|
2802
|
+
|
|
2803
|
+
Snapshot options from `_snapshotOptions()`.
|
|
2804
|
+
|
|
2805
|
+
#### Returns
|
|
2806
|
+
|
|
2807
|
+
`this`
|
|
2808
|
+
|
|
2809
|
+
A new empty graph instance of `this` type.
|
|
2810
|
+
|
|
2811
|
+
#### Remarks
|
|
2812
|
+
|
|
2813
|
+
Time O(1), Space O(1)
|
|
2814
|
+
|
|
2815
|
+
#### Inherited from
|
|
2816
|
+
|
|
2817
|
+
[`AbstractGraph`](AbstractGraph.md).[`_createInstance`](AbstractGraph.md#_createinstance)
|
|
2818
|
+
|
|
2819
|
+
***
|
|
2820
|
+
|
|
2821
|
+
### \_createLike()
|
|
2822
|
+
|
|
2823
|
+
```ts
|
|
2824
|
+
protected _createLike(iter?, options?): this;
|
|
2825
|
+
```
|
|
2826
|
+
|
|
2827
|
+
Defined in: [data-structures/graph/abstract-graph.ts:1009](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L1009)
|
|
2828
|
+
|
|
2829
|
+
Create a same-species graph populated with entries; preserves edges among kept vertices.
|
|
2830
|
+
|
|
2831
|
+
#### Parameters
|
|
2832
|
+
|
|
2833
|
+
##### iter?
|
|
2834
|
+
|
|
2835
|
+
`Iterable`\<\[`VertexKey`, `V` \| `undefined`\], `any`, `any`\>
|
|
2836
|
+
|
|
2837
|
+
Optional entries to seed the new graph.
|
|
2838
|
+
|
|
2839
|
+
##### options?
|
|
2840
|
+
|
|
2841
|
+
`Partial`\<`Record`\<`string`, `unknown`\>\>
|
|
2842
|
+
|
|
2843
|
+
Snapshot options.
|
|
2844
|
+
|
|
2845
|
+
#### Returns
|
|
2846
|
+
|
|
2847
|
+
`this`
|
|
2848
|
+
|
|
2849
|
+
A new graph of `this` type.
|
|
2850
|
+
|
|
2851
|
+
#### Remarks
|
|
2852
|
+
|
|
2853
|
+
Time O(V + E), Space O(V + E)
|
|
2854
|
+
|
|
2855
|
+
#### Inherited from
|
|
2856
|
+
|
|
2857
|
+
[`AbstractGraph`](AbstractGraph.md).[`_createLike`](AbstractGraph.md#_createlike)
|
|
2858
|
+
|
|
2859
|
+
***
|
|
2860
|
+
|
|
2861
|
+
### \_getIterator()
|
|
2862
|
+
|
|
2863
|
+
```ts
|
|
2864
|
+
protected _getIterator(): IterableIterator<[VertexKey, V | undefined]>;
|
|
2865
|
+
```
|
|
2866
|
+
|
|
2867
|
+
Defined in: [data-structures/graph/abstract-graph.ts:958](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L958)
|
|
2868
|
+
|
|
2869
|
+
Internal iterator over `[key, value]` entries in insertion order.
|
|
2870
|
+
|
|
2871
|
+
#### Returns
|
|
2872
|
+
|
|
2873
|
+
`IterableIterator`\<\[`VertexKey`, `V` \| `undefined`\]\>
|
|
2874
|
+
|
|
2875
|
+
Iterator of `[VertexKey, V | undefined]`.
|
|
2876
|
+
|
|
2877
|
+
#### Remarks
|
|
2878
|
+
|
|
2879
|
+
Time O(V), Space O(1)
|
|
2880
|
+
|
|
2881
|
+
#### Inherited from
|
|
2882
|
+
|
|
2883
|
+
[`AbstractGraph`](AbstractGraph.md).[`_getIterator`](AbstractGraph.md#_getiterator)
|
|
2884
|
+
|
|
2885
|
+
***
|
|
2886
|
+
|
|
2887
|
+
### \_getVertex()
|
|
2888
|
+
|
|
2889
|
+
```ts
|
|
2890
|
+
protected _getVertex(vertexOrKey): VO | undefined;
|
|
2891
|
+
```
|
|
2892
|
+
|
|
2893
|
+
Defined in: [data-structures/graph/abstract-graph.ts:1068](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L1068)
|
|
2894
|
+
|
|
2895
|
+
Resolve a vertex key or instance to the concrete vertex instance.
|
|
2896
|
+
|
|
2897
|
+
#### Parameters
|
|
2898
|
+
|
|
2899
|
+
##### vertexOrKey
|
|
2900
|
+
|
|
2901
|
+
`VertexKey` \| `VO`
|
|
2902
|
+
|
|
2903
|
+
Vertex key or existing vertex.
|
|
2904
|
+
|
|
2905
|
+
#### Returns
|
|
2906
|
+
|
|
2907
|
+
`VO` \| `undefined`
|
|
2908
|
+
|
|
2909
|
+
Vertex instance or `undefined`.
|
|
2910
|
+
|
|
2911
|
+
#### Remarks
|
|
2912
|
+
|
|
2913
|
+
Time O(1), Space O(1)
|
|
2914
|
+
|
|
2915
|
+
#### Inherited from
|
|
2916
|
+
|
|
2917
|
+
[`AbstractGraph`](AbstractGraph.md).[`_getVertex`](AbstractGraph.md#_getvertex)
|
|
2918
|
+
|
|
2919
|
+
***
|
|
2920
|
+
|
|
2921
|
+
### \_getVertexKey()
|
|
2922
|
+
|
|
2923
|
+
```ts
|
|
2924
|
+
protected _getVertexKey(vertexOrKey): VertexKey;
|
|
2925
|
+
```
|
|
2926
|
+
|
|
2927
|
+
Defined in: [data-structures/graph/abstract-graph.ts:1079](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L1079)
|
|
2928
|
+
|
|
2929
|
+
Resolve a vertex key from a key or vertex instance.
|
|
2930
|
+
|
|
2931
|
+
#### Parameters
|
|
2932
|
+
|
|
2933
|
+
##### vertexOrKey
|
|
2934
|
+
|
|
2935
|
+
`VertexKey` \| `VO`
|
|
2936
|
+
|
|
2937
|
+
Vertex key or existing vertex.
|
|
2938
|
+
|
|
2939
|
+
#### Returns
|
|
2940
|
+
|
|
2941
|
+
`VertexKey`
|
|
2942
|
+
|
|
2943
|
+
The vertex key.
|
|
2944
|
+
|
|
2945
|
+
#### Remarks
|
|
2946
|
+
|
|
2947
|
+
Time O(1), Space O(1)
|
|
2948
|
+
|
|
2949
|
+
#### Inherited from
|
|
2950
|
+
|
|
2951
|
+
[`AbstractGraph`](AbstractGraph.md).[`_getVertexKey`](AbstractGraph.md#_getvertexkey)
|
|
2952
|
+
|
|
2953
|
+
***
|
|
2954
|
+
|
|
2955
|
+
### \_snapshotOptions()
|
|
2956
|
+
|
|
2957
|
+
```ts
|
|
2958
|
+
protected _snapshotOptions(): Record<string, unknown>;
|
|
2959
|
+
```
|
|
2960
|
+
|
|
2961
|
+
Defined in: [data-structures/graph/abstract-graph.ts:973](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/graph/abstract-graph.ts#L973)
|
|
2962
|
+
|
|
2963
|
+
Capture configuration needed to reproduce the current graph.
|
|
2964
|
+
|
|
2965
|
+
#### Returns
|
|
2966
|
+
|
|
2967
|
+
`Record`\<`string`, `unknown`\>
|
|
2968
|
+
|
|
2969
|
+
Options bag (opaque to callers).
|
|
2970
|
+
|
|
2971
|
+
#### Remarks
|
|
2972
|
+
|
|
2973
|
+
Time O(1), Space O(1)
|
|
2974
|
+
|
|
2975
|
+
#### Inherited from
|
|
2976
|
+
|
|
2977
|
+
[`AbstractGraph`](AbstractGraph.md).[`_snapshotOptions`](AbstractGraph.md#_snapshotoptions)
|
|
2978
|
+
|
|
2979
|
+
***
|