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