doubly-linked-list-typed 2.1.1 → 2.1.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 (281) hide show
  1. package/dist/cjs/index.cjs +1299 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +1294 -0
  4. package/dist/esm/index.mjs.map +1 -0
  5. package/dist/types/data-structures/base/index.d.ts +2 -1
  6. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
  7. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
  8. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
  9. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
  10. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
  11. package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
  12. package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
  17. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
  18. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
  19. package/dist/types/data-structures/graph/index.d.ts +2 -1
  20. package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
  21. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
  22. package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
  23. package/dist/types/data-structures/hash/index.d.ts +0 -1
  24. package/dist/types/data-structures/heap/heap.d.ts +503 -5
  25. package/dist/types/data-structures/heap/index.d.ts +2 -0
  26. package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
  27. package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
  28. package/dist/types/data-structures/index.d.ts +7 -7
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
  32. package/dist/types/data-structures/matrix/index.d.ts +1 -1
  33. package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
  34. package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
  35. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
  36. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
  37. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
  38. package/dist/types/data-structures/queue/deque.d.ts +431 -4
  39. package/dist/types/data-structures/queue/queue.d.ts +308 -4
  40. package/dist/types/data-structures/stack/stack.d.ts +306 -2
  41. package/dist/types/data-structures/tree/tree.d.ts +62 -1
  42. package/dist/types/data-structures/trie/trie.d.ts +350 -4
  43. package/dist/types/index.d.ts +11 -2
  44. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +1 -1
  45. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  46. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  47. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  48. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  49. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  51. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  52. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  53. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  54. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  55. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  56. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  57. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  58. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  59. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  60. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  61. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  62. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  63. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  64. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  65. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  66. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  67. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  68. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  69. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  70. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  71. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  72. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  73. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  74. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  75. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  76. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  77. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  78. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  79. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  80. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  81. package/dist/types/types/index.d.ts +3 -0
  82. package/dist/types/types/utils/index.d.ts +2 -0
  83. package/dist/types/types/utils/utils.d.ts +22 -0
  84. package/dist/types/utils/index.d.ts +1 -1
  85. package/dist/types/utils/utils.d.ts +209 -22
  86. package/dist/umd/doubly-linked-list-typed.js +1302 -0
  87. package/dist/umd/doubly-linked-list-typed.js.map +1 -0
  88. package/dist/umd/doubly-linked-list-typed.min.js +9 -0
  89. package/dist/umd/doubly-linked-list-typed.min.js.map +1 -0
  90. package/package.json +25 -5
  91. package/src/data-structures/binary-tree/avl-tree-counter.ts +4 -4
  92. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  93. package/src/data-structures/binary-tree/avl-tree.ts +2 -2
  94. package/src/data-structures/binary-tree/binary-tree.ts +4 -4
  95. package/src/data-structures/binary-tree/bst.ts +1 -1
  96. package/src/data-structures/binary-tree/red-black-tree.ts +2 -2
  97. package/src/data-structures/binary-tree/tree-counter.ts +4 -4
  98. package/src/data-structures/binary-tree/tree-multi-map.ts +1 -1
  99. package/src/data-structures/heap/heap.ts +5 -5
  100. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  101. package/src/interfaces/binary-tree.ts +1 -1
  102. package/tsconfig.base.json +23 -0
  103. package/tsconfig.json +8 -34
  104. package/tsconfig.test.json +8 -0
  105. package/tsconfig.types.json +15 -0
  106. package/tsup.config.js +28 -0
  107. package/tsup.node.config.js +37 -0
  108. package/dist/common/index.js +0 -28
  109. package/dist/constants/index.js +0 -8
  110. package/dist/data-structures/base/index.d.ts +0 -2
  111. package/dist/data-structures/base/index.js +0 -18
  112. package/dist/data-structures/base/iterable-element-base.js +0 -243
  113. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  114. package/dist/data-structures/base/linear-base.js +0 -415
  115. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  116. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  117. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  118. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  119. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  120. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  121. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  122. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  123. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  124. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  125. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  126. package/dist/data-structures/binary-tree/bst.js +0 -903
  127. package/dist/data-structures/binary-tree/index.js +0 -26
  128. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  129. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  130. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  131. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  132. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  133. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  134. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  135. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  136. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  137. package/dist/data-structures/graph/abstract-graph.js +0 -896
  138. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  139. package/dist/data-structures/graph/directed-graph.js +0 -525
  140. package/dist/data-structures/graph/index.js +0 -20
  141. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  142. package/dist/data-structures/graph/map-graph.js +0 -107
  143. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  144. package/dist/data-structures/graph/undirected-graph.js +0 -424
  145. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  146. package/dist/data-structures/hash/hash-map.js +0 -692
  147. package/dist/data-structures/hash/index.d.ts +0 -1
  148. package/dist/data-structures/hash/index.js +0 -17
  149. package/dist/data-structures/heap/heap.d.ts +0 -503
  150. package/dist/data-structures/heap/heap.js +0 -901
  151. package/dist/data-structures/heap/index.d.ts +0 -3
  152. package/dist/data-structures/heap/index.js +0 -19
  153. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  154. package/dist/data-structures/heap/max-heap.js +0 -40
  155. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  156. package/dist/data-structures/heap/min-heap.js +0 -31
  157. package/dist/data-structures/index.js +0 -28
  158. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  159. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  160. package/dist/data-structures/linked-list/index.js +0 -19
  161. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  162. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  163. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  164. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  165. package/dist/data-structures/matrix/index.js +0 -18
  166. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  167. package/dist/data-structures/matrix/matrix.js +0 -448
  168. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  169. package/dist/data-structures/matrix/navigator.js +0 -111
  170. package/dist/data-structures/priority-queue/index.js +0 -19
  171. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  172. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  173. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  174. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  175. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  176. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  177. package/dist/data-structures/queue/deque.d.ts +0 -431
  178. package/dist/data-structures/queue/deque.js +0 -879
  179. package/dist/data-structures/queue/index.js +0 -18
  180. package/dist/data-structures/queue/queue.d.ts +0 -308
  181. package/dist/data-structures/queue/queue.js +0 -473
  182. package/dist/data-structures/stack/index.js +0 -17
  183. package/dist/data-structures/stack/stack.d.ts +0 -306
  184. package/dist/data-structures/stack/stack.js +0 -401
  185. package/dist/data-structures/tree/index.js +0 -17
  186. package/dist/data-structures/tree/tree.d.ts +0 -62
  187. package/dist/data-structures/tree/tree.js +0 -107
  188. package/dist/data-structures/trie/index.js +0 -17
  189. package/dist/data-structures/trie/trie.d.ts +0 -350
  190. package/dist/data-structures/trie/trie.js +0 -610
  191. package/dist/index.d.ts +0 -12
  192. package/dist/index.js +0 -28
  193. package/dist/interfaces/binary-tree.js +0 -2
  194. package/dist/interfaces/doubly-linked-list.js +0 -2
  195. package/dist/interfaces/graph.js +0 -2
  196. package/dist/interfaces/heap.js +0 -2
  197. package/dist/interfaces/index.js +0 -24
  198. package/dist/interfaces/navigator.js +0 -2
  199. package/dist/interfaces/priority-queue.js +0 -2
  200. package/dist/interfaces/segment-tree.js +0 -2
  201. package/dist/interfaces/singly-linked-list.js +0 -2
  202. package/dist/types/common.js +0 -2
  203. package/dist/types/data-structures/base/base.js +0 -2
  204. package/dist/types/data-structures/base/index.js +0 -17
  205. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  206. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  207. package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
  208. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  209. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
  210. package/dist/types/data-structures/binary-tree/bst.js +0 -2
  211. package/dist/types/data-structures/binary-tree/index.js +0 -25
  212. package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
  213. package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
  214. package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
  215. package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  216. package/dist/types/data-structures/graph/abstract-graph.js +0 -2
  217. package/dist/types/data-structures/graph/directed-graph.js +0 -2
  218. package/dist/types/data-structures/graph/index.js +0 -19
  219. package/dist/types/data-structures/graph/map-graph.js +0 -2
  220. package/dist/types/data-structures/graph/undirected-graph.js +0 -2
  221. package/dist/types/data-structures/hash/hash-map.js +0 -2
  222. package/dist/types/data-structures/hash/index.js +0 -17
  223. package/dist/types/data-structures/heap/heap.js +0 -2
  224. package/dist/types/data-structures/heap/index.js +0 -17
  225. package/dist/types/data-structures/heap/max-heap.js +0 -2
  226. package/dist/types/data-structures/heap/min-heap.js +0 -2
  227. package/dist/types/data-structures/index.js +0 -28
  228. package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  229. package/dist/types/data-structures/linked-list/index.js +0 -19
  230. package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
  231. package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
  232. package/dist/types/data-structures/matrix/index.js +0 -18
  233. package/dist/types/data-structures/matrix/matrix.js +0 -2
  234. package/dist/types/data-structures/matrix/navigator.js +0 -2
  235. package/dist/types/data-structures/priority-queue/index.js +0 -19
  236. package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  237. package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  238. package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
  239. package/dist/types/data-structures/queue/deque.js +0 -2
  240. package/dist/types/data-structures/queue/index.js +0 -18
  241. package/dist/types/data-structures/queue/queue.js +0 -2
  242. package/dist/types/data-structures/stack/index.js +0 -17
  243. package/dist/types/data-structures/stack/stack.js +0 -2
  244. package/dist/types/data-structures/tree/index.js +0 -17
  245. package/dist/types/data-structures/tree/tree.js +0 -2
  246. package/dist/types/data-structures/trie/index.js +0 -17
  247. package/dist/types/data-structures/trie/trie.js +0 -2
  248. package/dist/types/index.js +0 -19
  249. package/dist/types/utils/index.js +0 -18
  250. package/dist/types/utils/utils.js +0 -2
  251. package/dist/types/utils/validate-type.js +0 -2
  252. package/dist/utils/index.d.ts +0 -2
  253. package/dist/utils/index.js +0 -18
  254. package/dist/utils/number.js +0 -24
  255. package/dist/utils/utils.d.ts +0 -209
  256. package/dist/utils/utils.js +0 -353
  257. package/dist/{common → types/common}/index.d.ts +0 -0
  258. package/dist/{constants → types/constants}/index.d.ts +0 -0
  259. package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
  260. package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
  261. package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
  262. package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
  263. package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
  264. package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
  265. package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
  266. package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
  267. package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
  268. package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
  269. package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
  270. package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
  271. package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
  272. package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
  273. package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
  274. package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
  275. /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
  276. /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
  277. /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
  278. /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
  279. /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
  280. /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
  281. /package/dist/{utils → types/utils}/number.d.ts +0 -0
@@ -1,14 +1,340 @@
1
- export type VertexKey = string | number;
2
- export type DijkstraResult<V> = {
3
- distMap: Map<V, number>;
4
- distPaths?: Map<V, V[]>;
5
- preMap: Map<V, V | undefined>;
6
- seen: Set<V>;
7
- paths: V[][];
8
- minDist: number;
9
- minPath: V[];
10
- } | undefined;
11
- export type GraphOptions<V = any> = {
12
- vertexValueInitializer?: (key: VertexKey) => V;
13
- defaultEdgeWeight?: number;
14
- };
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { DijkstraResult, EntryCallback, GraphOptions, VertexKey } from '../../types';
9
+ import { IterableEntryBase } from '../base';
10
+ import { IGraph } from '../../interfaces';
11
+ export declare abstract class AbstractVertex<V = any> {
12
+ key: VertexKey;
13
+ value: V | undefined;
14
+ protected constructor(key: VertexKey, value?: V);
15
+ }
16
+ export declare abstract class AbstractEdge<E = any> {
17
+ value: E | undefined;
18
+ weight: number;
19
+ protected constructor(weight?: number, value?: E);
20
+ protected _hashCode: string;
21
+ get hashCode(): string;
22
+ }
23
+ /**
24
+ * Abstract graph over vertices and edges.
25
+ * @template V - Vertex value type.
26
+ * @template E - Edge value type.
27
+ * @template VO - Concrete vertex subclass (extends AbstractVertex<V>).
28
+ * @template EO - Concrete edge subclass (extends AbstractEdge<E>).
29
+ * @remarks Time O(1), Space O(1)
30
+ * @example examples will be generated by unit test
31
+ */
32
+ export declare abstract class AbstractGraph<V = any, E = any, VO extends AbstractVertex<V> = AbstractVertex<V>, EO extends AbstractEdge<E> = AbstractEdge<E>> extends IterableEntryBase<VertexKey, V | undefined> implements IGraph<V, E, VO, EO> {
33
+ /**
34
+ * Construct a graph with runtime defaults.
35
+ * @param options - `GraphOptions<V>` in `options.graph` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
36
+ * @remarks Time O(1), Space O(1)
37
+ */
38
+ constructor(options?: Partial<Record<string, unknown>>);
39
+ protected _options: GraphOptions<V>;
40
+ get options(): Readonly<GraphOptions<V>>;
41
+ protected _vertexMap: Map<VertexKey, VO>;
42
+ get vertexMap(): Map<VertexKey, VO>;
43
+ set vertexMap(v: Map<VertexKey, VO>);
44
+ get size(): number;
45
+ /**
46
+ * Create a new vertex instance (implementation specific).
47
+ * @param key - Vertex identifier.
48
+ * @param value - Optional payload.
49
+ * @returns Concrete vertex instance.
50
+ * @remarks Time O(1), Space O(1)
51
+ */
52
+ abstract createVertex(key: VertexKey, value?: V): VO;
53
+ /**
54
+ * Create a new edge instance (implementation specific).
55
+ * @param srcOrV1 - Source/endpoint A key.
56
+ * @param destOrV2 - Destination/endpoint B key.
57
+ * @param weight - Edge weight (defaults may apply).
58
+ * @param value - Edge payload.
59
+ * @returns Concrete edge instance.
60
+ * @remarks Time O(1), Space O(1)
61
+ */
62
+ abstract createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
63
+ /**
64
+ * Delete an edge by instance.
65
+ * @param edge - Edge instance.
66
+ * @returns Removed edge or `undefined`.
67
+ * @remarks Time O(1) avg, Space O(1)
68
+ */
69
+ abstract deleteEdge(edge: EO): EO | undefined;
70
+ /**
71
+ * Get an edge between two vertices if present.
72
+ * @param srcOrKey - Source/endpoint A vertex or key.
73
+ * @param destOrKey - Destination/endpoint B vertex or key.
74
+ * @returns Edge instance or `undefined`.
75
+ * @remarks Time O(1) avg, Space O(1)
76
+ */
77
+ abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
78
+ /**
79
+ * Degree of a vertex in this graph model.
80
+ * @param vertexOrKey - Vertex or key.
81
+ * @returns Non-negative integer degree.
82
+ * @remarks Time O(1) avg, Space O(1)
83
+ */
84
+ abstract degreeOf(vertexOrKey: VO | VertexKey): number;
85
+ /**
86
+ * All edges in the graph (unique, order not guaranteed).
87
+ * @returns Array of edges.
88
+ * @remarks Time O(E), Space O(E)
89
+ */
90
+ abstract edgeSet(): EO[];
91
+ /**
92
+ * Incident edges of a vertex.
93
+ * @param vertexOrKey - Vertex or key.
94
+ * @returns Array of incident edges.
95
+ * @remarks Time O(deg), Space O(deg)
96
+ */
97
+ abstract edgesOf(vertexOrKey: VO | VertexKey): EO[];
98
+ /**
99
+ * One-step neighbors of a vertex.
100
+ * @param vertexOrKey - Vertex or key.
101
+ * @returns Array of neighbor vertices.
102
+ * @remarks Time O(deg), Space O(deg)
103
+ */
104
+ abstract getNeighbors(vertexOrKey: VO | VertexKey): VO[];
105
+ /**
106
+ * Resolve endpoints of an edge to vertex instances.
107
+ * @param edge - Edge instance.
108
+ * @returns `[v1, v2]` or `undefined` if missing.
109
+ * @remarks Time O(1), Space O(1)
110
+ */
111
+ abstract getEndsOfEdge(edge: EO): [VO, VO] | undefined;
112
+ /**
113
+ * Get vertex instance by key.
114
+ * @param vertexKey - Vertex key.
115
+ * @returns Vertex instance or `undefined`.
116
+ * @remarks Time O(1), Space O(1)
117
+ */
118
+ getVertex(vertexKey: VertexKey): VO | undefined;
119
+ /**
120
+ * Whether a vertex exists.
121
+ * @param vertexOrKey - Vertex or key.
122
+ * @returns `true` if present, otherwise `false`.
123
+ * @remarks Time O(1) avg, Space O(1)
124
+ */
125
+ hasVertex(vertexOrKey: VO | VertexKey): boolean;
126
+ addVertex(vertex: VO): boolean;
127
+ addVertex(key: VertexKey, value?: V): boolean;
128
+ /**
129
+ * Type guard: check if a value is a valid vertex key.
130
+ * @param potentialKey - Value to test.
131
+ * @returns `true` if string/number; else `false`.
132
+ * @remarks Time O(1), Space O(1)
133
+ */
134
+ isVertexKey(potentialKey: any): potentialKey is VertexKey;
135
+ /**
136
+ * Delete a vertex and its incident edges.
137
+ * @param vertexOrKey - Vertex or key.
138
+ * @returns `true` if removed; otherwise `false`.
139
+ * @remarks Time O(deg), Space O(1)
140
+ */
141
+ abstract deleteVertex(vertexOrKey: VO | VertexKey): boolean;
142
+ /**
143
+ * Delete multiple vertices.
144
+ * @param vertexMap - Array of vertices or keys.
145
+ * @returns `true` if any vertex was removed.
146
+ * @remarks Time O(sum(deg)), Space O(1)
147
+ */
148
+ removeManyVertices(vertexMap: VO[] | VertexKey[]): boolean;
149
+ /**
150
+ * Whether an edge exists between two vertices.
151
+ * @param v1 - Endpoint A vertex or key.
152
+ * @param v2 - Endpoint B vertex or key.
153
+ * @returns `true` if present; otherwise `false`.
154
+ * @remarks Time O(1) avg, Space O(1)
155
+ */
156
+ hasEdge(v1: VertexKey | VO, v2: VertexKey | VO): boolean;
157
+ addEdge(edge: EO): boolean;
158
+ addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number, value?: E): boolean;
159
+ /**
160
+ * Set the weight of an existing edge.
161
+ * @param srcOrKey - Source vertex or key.
162
+ * @param destOrKey - Destination vertex or key.
163
+ * @param weight - New weight.
164
+ * @returns `true` if updated; otherwise `false`.
165
+ * @remarks Time O(1) avg, Space O(1)
166
+ */
167
+ setEdgeWeight(srcOrKey: VertexKey | VO, destOrKey: VertexKey | VO, weight: number): boolean;
168
+ /**
169
+ * Enumerate simple paths up to a limit.
170
+ * @param v1 - Source vertex or key.
171
+ * @param v2 - Destination vertex or key.
172
+ * @param limit - Maximum number of paths to collect.
173
+ * @returns Array of paths (each path is an array of vertices).
174
+ * @remarks Time O(paths) worst-case exponential, Space O(V + paths)
175
+ */
176
+ getAllPathsBetween(v1: VO | VertexKey, v2: VO | VertexKey, limit?: number): VO[][];
177
+ /**
178
+ * Sum the weights along a vertex path.
179
+ * @param path - Sequence of vertices.
180
+ * @returns Path weight sum (0 if empty or edge missing).
181
+ * @remarks Time O(L), Space O(1) where L is path length
182
+ */
183
+ getPathSumWeight(path: VO[]): number;
184
+ /**
185
+ * Minimum hops/weight between two vertices.
186
+ * @param v1 - Source vertex or key.
187
+ * @param v2 - Destination vertex or key.
188
+ * @param isWeight - If `true`, compare by path weight; otherwise by hop count.
189
+ * @returns Minimum cost or `undefined` if missing/unreachable.
190
+ * @remarks Time O((V + E) log V) weighted / O(V + E) unweighted, Space O(V + E)
191
+ */
192
+ getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | undefined;
193
+ /**
194
+ * Minimum path (as vertex sequence) between two vertices.
195
+ * @param v1 - Source vertex or key.
196
+ * @param v2 - Destination vertex or key.
197
+ * @param isWeight - If `true`, compare by path weight; otherwise by hop count.
198
+ * @param isDFS - For weighted mode only: if `true`, brute-force all paths; if `false`, use Dijkstra.
199
+ * @returns Vertex sequence, or `undefined`/empty when unreachable depending on branch.
200
+ * @remarks Time O((V + E) log V) weighted / O(V + E) unweighted, Space O(V + E)
201
+ */
202
+ getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] | undefined;
203
+ /**
204
+ * Dijkstra without heap (array-based selection).
205
+ * @param src - Source vertex or key.
206
+ * @param dest - Optional destination for early stop.
207
+ * @param getMinDist - If `true`, compute global minimum distance.
208
+ * @param genPaths - If `true`, also generate path arrays.
209
+ * @returns Result bag or `undefined` if source missing.
210
+ * @remarks Time O(V^2 + E), Space O(V + E)
211
+ */
212
+ dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO> | undefined;
213
+ dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO> | undefined;
214
+ /**
215
+ * Bellman-Ford single-source shortest paths with option to scan negative cycles.
216
+ * @param src - Source vertex or key.
217
+ * @param scanNegativeCycle - If `true`, also detect negative cycles.
218
+ * @param getMin - If `true`, compute global minimum distance.
219
+ * @param genPath - If `true`, generate path arrays via predecessor map.
220
+ * @returns Result bag including distances, predecessors, and optional cycle flag.
221
+ * @remarks Time O(V * E), Space O(V + E)
222
+ */
223
+ bellmanFord(src: VO | VertexKey, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean): {
224
+ hasNegativeCycle: boolean | undefined;
225
+ distMap: Map<VO, number>;
226
+ preMap: Map<VO, VO>;
227
+ paths: VO[][];
228
+ min: number;
229
+ minPath: VO[];
230
+ };
231
+ /**
232
+ * Floyd–Warshall all-pairs shortest paths.
233
+ * @returns `{ costs, predecessor }` matrices.
234
+ * @remarks Time O(V^3), Space O(V^2)
235
+ */
236
+ floydWarshall(): {
237
+ costs: number[][];
238
+ predecessor: (VO | undefined)[][];
239
+ };
240
+ /**
241
+ * Enumerate simple cycles (may be expensive).
242
+ * @param isInclude2Cycle - If `true`, include 2-cycles when graph semantics allow.
243
+ * @returns Array of cycles (each as array of vertex keys).
244
+ * @remarks Time exponential in worst-case, Space O(V + E)
245
+ */
246
+ getCycles(isInclude2Cycle?: boolean): VertexKey[][];
247
+ /**
248
+ * Induced-subgraph filter: keep vertices where `predicate(key, value)` is true,
249
+ * and only keep edges whose endpoints both survive.
250
+ * @param predicate - `(key, value, index, self) => boolean`.
251
+ * @param thisArg - Optional `this` for callback.
252
+ * @returns A new graph of the same concrete class (`this` type).
253
+ * @remarks Time O(V + E), Space O(V + E)
254
+ */
255
+ filter(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: any): this;
256
+ /**
257
+ * Preserve the old behavior: return filtered entries as an array.
258
+ * @remarks Time O(V), Space O(V)
259
+ */
260
+ filterEntries(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: any): [VertexKey, V | undefined][];
261
+ map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: any): T[];
262
+ /**
263
+ * Create a deep clone of the graph with the same species.
264
+ * @remarks Time O(V + E), Space O(V + E)
265
+ */
266
+ /**
267
+ * Create a deep clone of the graph with the same species.
268
+ * @returns A new graph of the same concrete class (`this` type).
269
+ * @remarks Time O(V + E), Space O(V + E)
270
+ */
271
+ clone(): this;
272
+ /**
273
+ * Internal iterator over `[key, value]` entries in insertion order.
274
+ * @returns Iterator of `[VertexKey, V | undefined]`.
275
+ * @remarks Time O(V), Space O(1)
276
+ */
277
+ protected _getIterator(): IterableIterator<[VertexKey, V | undefined]>;
278
+ /**
279
+ * Capture configuration needed to reproduce the current graph.
280
+ * Currently the graph has no runtime options, so we return an empty object.
281
+ */
282
+ /**
283
+ * Capture configuration needed to reproduce the current graph.
284
+ * @returns Options bag (opaque to callers).
285
+ * @remarks Time O(1), Space O(1)
286
+ */
287
+ protected _snapshotOptions(): Record<string, unknown>;
288
+ /**
289
+ * Create an empty graph instance of the same concrete species (Directed/Undirected/etc).
290
+ * @remarks Time O(1), Space O(1)
291
+ */
292
+ /**
293
+ * Create an empty graph instance of the same concrete species.
294
+ * @param _options - Snapshot options from `_snapshotOptions()`.
295
+ * @returns A new empty graph instance of `this` type.
296
+ * @remarks Time O(1), Space O(1)
297
+ */
298
+ protected _createInstance(_options?: Partial<Record<string, unknown>>): this;
299
+ /**
300
+ * Create a same-species graph populated with the given entries.
301
+ * Also preserves edges between kept vertices from the source graph.
302
+ * @remarks Time O(V + E), Space O(V + E)
303
+ */
304
+ /**
305
+ * Create a same-species graph populated with entries; preserves edges among kept vertices.
306
+ * @param iter - Optional entries to seed the new graph.
307
+ * @param options - Snapshot options.
308
+ * @returns A new graph of `this` type.
309
+ * @remarks Time O(V + E), Space O(V + E)
310
+ */
311
+ protected _createLike(iter?: Iterable<[VertexKey, V | undefined]>, options?: Partial<Record<string, unknown>>): this;
312
+ /**
313
+ * Internal hook to attach an edge into adjacency structures.
314
+ * @param edge - Edge instance.
315
+ * @returns `true` if inserted; otherwise `false`.
316
+ * @remarks Time O(1) avg, Space O(1)
317
+ */
318
+ protected abstract _addEdge(edge: EO): boolean;
319
+ /**
320
+ * Insert a pre-built vertex into the graph.
321
+ * @param newVertex - Concrete vertex instance.
322
+ * @returns `true` if inserted; `false` if key already exists.
323
+ * @remarks Time O(1) avg, Space O(1)
324
+ */
325
+ protected _addVertex(newVertex: VO): boolean;
326
+ /**
327
+ * Resolve a vertex key or instance to the concrete vertex instance.
328
+ * @param vertexOrKey - Vertex key or existing vertex.
329
+ * @returns Vertex instance or `undefined`.
330
+ * @remarks Time O(1), Space O(1)
331
+ */
332
+ protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
333
+ /**
334
+ * Resolve a vertex key from a key or vertex instance.
335
+ * @param vertexOrKey - Vertex key or existing vertex.
336
+ * @returns The vertex key.
337
+ * @remarks Time O(1), Space O(1)
338
+ */
339
+ protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
340
+ }
@@ -1 +1,207 @@
1
- export type TopologicalStatus = 0 | 1 | 2;
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { GraphOptions, VertexKey } from '../../types';
9
+ import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
10
+ import { IGraph } from '../../interfaces';
11
+ export declare class DirectedVertex<V = any> extends AbstractVertex<V> {
12
+ constructor(key: VertexKey, value?: V);
13
+ }
14
+ export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
15
+ src: VertexKey;
16
+ dest: VertexKey;
17
+ constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
18
+ }
19
+ /**
20
+ * Directed graph implementation.
21
+ * @template V - Vertex value type.
22
+ * @template E - Edge value type.
23
+ * @template VO - Concrete vertex class (extends AbstractVertex<V>).
24
+ * @template EO - Concrete edge class (extends AbstractEdge<E>).
25
+ * @remarks Time O(1), Space O(1)
26
+ * @example examples will be generated by unit test
27
+ */
28
+ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V> = DirectedVertex<V>, EO extends DirectedEdge<E> = DirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
29
+ /**
30
+ * Construct a directed graph with runtime defaults.
31
+ * @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
32
+ * @remarks Time O(1), Space O(1)
33
+ */
34
+ constructor(options?: Partial<GraphOptions<V>>);
35
+ protected _outEdgeMap: Map<VO, EO[]>;
36
+ get outEdgeMap(): Map<VO, EO[]>;
37
+ set outEdgeMap(v: Map<VO, EO[]>);
38
+ protected _inEdgeMap: Map<VO, EO[]>;
39
+ get inEdgeMap(): Map<VO, EO[]>;
40
+ set inEdgeMap(v: Map<VO, EO[]>);
41
+ /**
42
+ * Construct a directed graph from keys with value initializer `v => v`.
43
+ * @template K - Vertex key type.
44
+ * @param keys - Iterable of vertex keys.
45
+ * @returns DirectedGraph with all keys added.
46
+ * @remarks Time O(V), Space O(V)
47
+ */
48
+ static fromKeys<K extends VertexKey>(keys: Iterable<K>): DirectedGraph<K, any, DirectedVertex<K>, DirectedEdge<any>>;
49
+ /**
50
+ * Construct a directed graph from `[key, value]` entries.
51
+ * @template V - Vertex value type.
52
+ * @param entries - Iterable of `[key, value]` pairs.
53
+ * @returns DirectedGraph with all vertices added.
54
+ * @remarks Time O(V), Space O(V)
55
+ */
56
+ static fromEntries<V>(entries: Iterable<[VertexKey, V]>): DirectedGraph<V, any, DirectedVertex<V>, DirectedEdge<any>>;
57
+ /**
58
+ * Create a directed vertex instance. Does not insert into the graph.
59
+ * @param key - Vertex identifier.
60
+ * @param value - Optional payload.
61
+ * @returns Concrete vertex instance.
62
+ * @remarks Time O(1), Space O(1)
63
+ */
64
+ createVertex(key: VertexKey, value?: VO['value']): VO;
65
+ /**
66
+ * Create a directed edge instance. Does not insert into the graph.
67
+ * @param src - Source vertex key.
68
+ * @param dest - Destination vertex key.
69
+ * @param weight - Edge weight; defaults to `defaultEdgeWeight`.
70
+ * @param value - Edge payload.
71
+ * @returns Concrete edge instance.
72
+ * @remarks Time O(1), Space O(1)
73
+ */
74
+ createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
75
+ /**
76
+ * Get the unique edge from `src` to `dest`, if present.
77
+ * @param srcOrKey - Source vertex or key.
78
+ * @param destOrKey - Destination vertex or key.
79
+ * @returns Edge instance or `undefined`.
80
+ * @remarks Time O(1) avg, Space O(1)
81
+ */
82
+ getEdge(srcOrKey: VO | VertexKey | undefined, destOrKey: VO | VertexKey | undefined): EO | undefined;
83
+ /**
84
+ * Delete edge `src -> dest` if present.
85
+ * @param srcOrKey - Source vertex or key.
86
+ * @param destOrKey - Destination vertex or key.
87
+ * @returns Removed edge or `undefined`.
88
+ * @remarks Time O(1) avg, Space O(1)
89
+ */
90
+ deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
91
+ /**
92
+ * Delete an edge by instance or by `(srcKey, destKey)`.
93
+ * @param edgeOrSrcVertexKey - Edge instance or source vertex/key.
94
+ * @param destVertexKey - Optional destination vertex/key when deleting by pair.
95
+ * @returns Removed edge or `undefined`.
96
+ * @remarks Time O(1) avg, Space O(1)
97
+ */
98
+ deleteEdge(edgeOrSrcVertexKey: EO | VertexKey, destVertexKey?: VertexKey): EO | undefined;
99
+ deleteVertex(vertexOrKey: VO | VertexKey): boolean;
100
+ deleteEdgesBetween(v1: VertexKey | VO, v2: VertexKey | VO): EO[];
101
+ /**
102
+ * Incoming edges of a vertex.
103
+ * @param vertexOrKey - Vertex or key.
104
+ * @returns Array of incoming edges.
105
+ * @remarks Time O(deg_in), Space O(deg_in)
106
+ */
107
+ incomingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
108
+ /**
109
+ * Outgoing edges of a vertex.
110
+ * @param vertexOrKey - Vertex or key.
111
+ * @returns Array of outgoing edges.
112
+ * @remarks Time O(deg_out), Space O(deg_out)
113
+ */
114
+ outgoingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
115
+ /**
116
+ * Degree (in + out) of a vertex.
117
+ * @param vertexOrKey - Vertex or key.
118
+ * @returns Non-negative integer.
119
+ * @remarks Time O(1) avg, Space O(1)
120
+ */
121
+ degreeOf(vertexOrKey: VertexKey | VO): number;
122
+ inDegreeOf(vertexOrKey: VertexKey | VO): number;
123
+ outDegreeOf(vertexOrKey: VertexKey | VO): number;
124
+ /**
125
+ * All incident edges of a vertex.
126
+ * @param vertexOrKey - Vertex or key.
127
+ * @returns Array of incident edges.
128
+ * @remarks Time O(deg_in + deg_out), Space O(deg_in + deg_out)
129
+ */
130
+ edgesOf(vertexOrKey: VertexKey | VO): EO[];
131
+ getEdgeSrc(e: EO): VO | undefined;
132
+ getEdgeDest(e: EO): VO | undefined;
133
+ /**
134
+ * Direct children reachable by one outgoing edge.
135
+ * @param vertex - Vertex or key.
136
+ * @returns Array of neighbor vertices.
137
+ * @remarks Time O(deg_out), Space O(deg_out)
138
+ */
139
+ getDestinations(vertex: VO | VertexKey | undefined): VO[];
140
+ /**
141
+ * Topological sort if DAG; returns `undefined` if a cycle exists.
142
+ * @param propertyName - `'key'` to map to keys; `'vertex'` to keep instances.
143
+ * @returns Array of keys/vertices, or `undefined` when cycle is found.
144
+ * @remarks Time O(V + E), Space O(V)
145
+ */
146
+ topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | undefined;
147
+ edgeSet(): EO[];
148
+ getNeighbors(vertexOrKey: VO | VertexKey): VO[];
149
+ /**
150
+ * Resolve an edge's `[src, dest]` endpoints to vertex instances.
151
+ * @param edge - Edge instance.
152
+ * @returns `[src, dest]` or `undefined` if either endpoint is missing.
153
+ * @remarks Time O(1), Space O(1)
154
+ */
155
+ getEndsOfEdge(edge: EO): [VO, VO] | undefined;
156
+ /**
157
+ * Whether the graph has no vertices and no edges.
158
+ * @remarks Time O(1), Space O(1)
159
+ */
160
+ isEmpty(): boolean;
161
+ /**
162
+ * Remove all vertices and edges.
163
+ * @remarks Time O(V + E), Space O(1)
164
+ */
165
+ clear(): void;
166
+ /**
167
+ * Deep clone as the same concrete class.
168
+ * @returns A new graph of the same concrete class (`this` type).
169
+ * @remarks Time O(V + E), Space O(V + E)
170
+ */
171
+ clone(): this;
172
+ /**
173
+ * Tarjan's algorithm for strongly connected components.
174
+ * @returns `{ dfnMap, lowMap, SCCs }`.
175
+ * @remarks Time O(V + E), Space O(V + E)
176
+ */
177
+ tarjan(): {
178
+ dfnMap: Map<VO, number>;
179
+ lowMap: Map<VO, number>;
180
+ SCCs: Map<number, VO[]>;
181
+ };
182
+ /**
183
+ * DFN index map computed by `tarjan()`.
184
+ * @returns Map from vertex to DFN index.
185
+ * @remarks Time O(V), Space O(V)
186
+ */
187
+ getDFNMap(): Map<VO, number>;
188
+ /**
189
+ * LOW link map computed by `tarjan()`.
190
+ * @returns Map from vertex to LOW value.
191
+ * @remarks Time O(V), Space O(V)
192
+ */
193
+ getLowMap(): Map<VO, number>;
194
+ /**
195
+ * Strongly connected components computed by `tarjan()`.
196
+ * @returns Map from SCC id to vertices.
197
+ * @remarks Time O(#SCC + V), Space O(V)
198
+ */
199
+ getSCCs(): Map<number, VO[]>;
200
+ /**
201
+ * Internal hook to attach a directed edge into adjacency maps.
202
+ * @param edge - Edge instance.
203
+ * @returns `true` if inserted; otherwise `false`.
204
+ * @remarks Time O(1) avg, Space O(1)
205
+ */
206
+ protected _addEdge(edge: EO): boolean;
207
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './abstract-graph';
2
- export * from './map-graph';
3
2
  export * from './directed-graph';
3
+ export * from './undirected-graph';
4
+ export * from './map-graph';
@@ -1 +1,78 @@
1
- export type MapGraphCoordinate = [number, number];
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { MapGraphCoordinate, VertexKey } from '../../types';
9
+ import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
10
+ export declare class MapVertex<V = any> extends DirectedVertex<V> {
11
+ lat: number;
12
+ long: number;
13
+ constructor(key: VertexKey, value: V, lat: number, long: number);
14
+ }
15
+ export declare class MapEdge<E = any> extends DirectedEdge<E> {
16
+ constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
17
+ }
18
+ /**
19
+ * Directed graph variant carrying geospatial coordinates.
20
+ * @template V - Vertex value type.
21
+ * @template E - Edge value type.
22
+ * @template VO - Concrete vertex class (MapVertex<V>).
23
+ * @template EO - Concrete edge class (MapEdge<E>).
24
+ * @remarks Time O(1), Space O(1)
25
+ * @example examples will be generated by unit test
26
+ */
27
+ export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVertex<V>, EO extends MapEdge<E> = MapEdge<E>> extends DirectedGraph<V, E, VO, EO> {
28
+ /**
29
+ * Construct a MapGraph.
30
+ * @param originCoord - Origin coordinate `[lat, long]` used as default.
31
+ * @param bottomRight - Optional bottom-right coordinate for bounding boxes.
32
+ * @remarks Time O(1), Space O(1)
33
+ */
34
+ constructor(originCoord: MapGraphCoordinate, bottomRight?: MapGraphCoordinate);
35
+ protected _originCoord: MapGraphCoordinate;
36
+ get originCoord(): MapGraphCoordinate;
37
+ protected _bottomRight: MapGraphCoordinate | undefined;
38
+ get bottomRight(): MapGraphCoordinate | undefined;
39
+ /**
40
+ * Create a map vertex with optional coordinates.
41
+ * @param key - Vertex identifier.
42
+ * @param value - Optional payload.
43
+ * @param lat - Latitude (defaults to `originCoord[0]`).
44
+ * @param long - Longitude (defaults to `originCoord[1]`).
45
+ * @returns MapVertex instance.
46
+ * @remarks Time O(1), Space O(1)
47
+ */
48
+ createVertex(key: VertexKey, value?: V, lat?: number, long?: number): VO;
49
+ /**
50
+ * Create a map edge (directed) with optional weight/value.
51
+ * @param src - Source key.
52
+ * @param dest - Destination key.
53
+ * @param weight - Edge weight.
54
+ * @param value - Edge payload.
55
+ * @returns MapEdge instance.
56
+ * @remarks Time O(1), Space O(1)
57
+ */
58
+ createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
59
+ /**
60
+ * Deep clone as the same concrete class.
61
+ * @returns A new graph of the same concrete class (`this` type).
62
+ * @remarks Time O(V + E), Space O(V + E)
63
+ */
64
+ clone(): this;
65
+ /**
66
+ * Include `originCoord` and `bottomRight` so `clone()/filter()` preserve geospatial settings.
67
+ * @returns Options bag extending super snapshot.
68
+ * @remarks Time O(1), Space O(1)
69
+ */
70
+ protected _snapshotOptions(): Record<string, unknown>;
71
+ /**
72
+ * Re-create a same-species MapGraph instance from snapshot options.
73
+ * @param options - Snapshot options providing `originCoord`/`bottomRight`.
74
+ * @returns Empty MapGraph instance of `this` type.
75
+ * @remarks Time O(1), Space O(1)
76
+ */
77
+ protected _createInstance(options?: Partial<Record<string, unknown>>): this;
78
+ }