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