data-structure-typed 2.0.5 → 2.1.0

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 (260) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/COMMANDS.md +17 -0
  3. package/benchmark/report.html +13 -77
  4. package/benchmark/report.json +145 -177
  5. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
  6. package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
  7. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  8. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
  9. package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
  10. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  11. package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
  12. package/dist/cjs/data-structures/base/linear-base.js +137 -274
  13. package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  19. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
  22. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.js +594 -865
  25. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
  27. package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
  28. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
  31. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  32. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
  34. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  35. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  38. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
  39. package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
  40. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
  42. package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
  43. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  44. package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
  45. package/dist/cjs/data-structures/graph/map-graph.js +56 -59
  46. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  47. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
  48. package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
  49. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  50. package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
  51. package/dist/cjs/data-structures/hash/hash-map.js +270 -457
  52. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  53. package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
  54. package/dist/cjs/data-structures/heap/heap.js +340 -349
  55. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  56. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
  57. package/dist/cjs/data-structures/heap/max-heap.js +11 -66
  58. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  59. package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
  60. package/dist/cjs/data-structures/heap/min-heap.js +11 -66
  61. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  62. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  63. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
  64. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  65. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  66. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
  67. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  68. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  69. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
  70. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  71. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  72. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
  73. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  74. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  75. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
  76. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  77. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
  78. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
  79. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  80. package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
  81. package/dist/cjs/data-structures/queue/deque.js +309 -348
  82. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  83. package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
  84. package/dist/cjs/data-structures/queue/queue.js +265 -248
  85. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  86. package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
  87. package/dist/cjs/data-structures/stack/stack.js +181 -125
  88. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  89. package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
  90. package/dist/cjs/data-structures/trie/trie.js +189 -172
  91. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  92. package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
  93. package/dist/cjs/interfaces/graph.d.ts +16 -0
  94. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  95. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
  96. package/dist/cjs/types/utils/utils.d.ts +1 -0
  97. package/dist/cjs/utils/utils.d.ts +1 -1
  98. package/dist/cjs/utils/utils.js +2 -1
  99. package/dist/cjs/utils/utils.js.map +1 -1
  100. package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
  101. package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
  102. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  103. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
  104. package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
  105. package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
  106. package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
  107. package/dist/esm/data-structures/base/linear-base.js +137 -274
  108. package/dist/esm/data-structures/base/linear-base.js.map +1 -1
  109. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  110. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
  111. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  112. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  113. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
  114. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  115. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
  116. package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
  117. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  118. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
  119. package/dist/esm/data-structures/binary-tree/binary-tree.js +598 -874
  120. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  121. package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
  122. package/dist/esm/data-structures/binary-tree/bst.js +507 -487
  123. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  124. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  125. package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
  126. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  127. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
  128. package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
  129. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  130. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  131. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
  132. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  133. package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
  134. package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
  135. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  136. package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
  137. package/dist/esm/data-structures/graph/directed-graph.js +145 -233
  138. package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
  139. package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
  140. package/dist/esm/data-structures/graph/map-graph.js +56 -59
  141. package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
  142. package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
  143. package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
  144. package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
  145. package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
  146. package/dist/esm/data-structures/hash/hash-map.js +270 -457
  147. package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
  148. package/dist/esm/data-structures/heap/heap.d.ts +214 -289
  149. package/dist/esm/data-structures/heap/heap.js +329 -349
  150. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  151. package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
  152. package/dist/esm/data-structures/heap/max-heap.js +11 -66
  153. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  154. package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
  155. package/dist/esm/data-structures/heap/min-heap.js +11 -66
  156. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  157. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  158. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
  159. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  160. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  161. package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
  162. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  163. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  164. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
  165. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
  166. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  167. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
  168. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  169. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  170. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
  171. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  172. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
  173. package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
  174. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  175. package/dist/esm/data-structures/queue/deque.d.ts +227 -254
  176. package/dist/esm/data-structures/queue/deque.js +313 -348
  177. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  178. package/dist/esm/data-structures/queue/queue.d.ts +180 -201
  179. package/dist/esm/data-structures/queue/queue.js +263 -248
  180. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  181. package/dist/esm/data-structures/stack/stack.d.ts +124 -102
  182. package/dist/esm/data-structures/stack/stack.js +181 -125
  183. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  184. package/dist/esm/data-structures/trie/trie.d.ts +164 -165
  185. package/dist/esm/data-structures/trie/trie.js +193 -172
  186. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  187. package/dist/esm/interfaces/binary-tree.d.ts +56 -6
  188. package/dist/esm/interfaces/graph.d.ts +16 -0
  189. package/dist/esm/types/data-structures/base/base.d.ts +1 -1
  190. package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
  191. package/dist/esm/types/utils/utils.d.ts +1 -0
  192. package/dist/esm/utils/utils.d.ts +1 -1
  193. package/dist/esm/utils/utils.js +2 -1
  194. package/dist/esm/utils/utils.js.map +1 -1
  195. package/dist/umd/data-structure-typed.js +4685 -6477
  196. package/dist/umd/data-structure-typed.min.js +8 -6
  197. package/dist/umd/data-structure-typed.min.js.map +1 -1
  198. package/package.json +3 -4
  199. package/src/data-structures/base/iterable-element-base.ts +238 -115
  200. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  201. package/src/data-structures/base/linear-base.ts +271 -277
  202. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  203. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  204. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  205. package/src/data-structures/binary-tree/binary-tree.ts +660 -889
  206. package/src/data-structures/binary-tree/bst.ts +568 -570
  207. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  208. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  209. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  210. package/src/data-structures/graph/abstract-graph.ts +339 -264
  211. package/src/data-structures/graph/directed-graph.ts +146 -236
  212. package/src/data-structures/graph/map-graph.ts +63 -60
  213. package/src/data-structures/graph/undirected-graph.ts +129 -152
  214. package/src/data-structures/hash/hash-map.ts +274 -496
  215. package/src/data-structures/heap/heap.ts +389 -402
  216. package/src/data-structures/heap/max-heap.ts +12 -76
  217. package/src/data-structures/heap/min-heap.ts +13 -76
  218. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  219. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  220. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  221. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  222. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  223. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  224. package/src/data-structures/queue/deque.ts +381 -357
  225. package/src/data-structures/queue/queue.ts +310 -264
  226. package/src/data-structures/stack/stack.ts +217 -131
  227. package/src/data-structures/trie/trie.ts +240 -175
  228. package/src/interfaces/binary-tree.ts +240 -6
  229. package/src/interfaces/graph.ts +37 -0
  230. package/src/types/data-structures/base/base.ts +5 -5
  231. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  232. package/src/types/utils/utils.ts +2 -0
  233. package/src/utils/utils.ts +9 -14
  234. package/test/integration/index.html +1 -1
  235. package/test/performance/benchmark-runner.ts +528 -0
  236. package/test/performance/reportor.mjs +43 -43
  237. package/test/performance/runner-config.json +39 -0
  238. package/test/performance/single-suite-runner.ts +69 -0
  239. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  240. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  241. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  242. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  243. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
  244. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  245. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  246. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
  247. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  248. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  249. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  250. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  251. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  252. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  253. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  254. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  255. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  256. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  257. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  258. package/test/unit/utils/utils.test.ts +0 -1
  259. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  260. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
@@ -5,193 +5,148 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { VertexKey } from '../../types';
8
+ import type { GraphOptions, VertexKey } from '../../types';
9
9
  import { IGraph } from '../../interfaces';
10
10
  import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
11
11
  export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
12
- /**
13
- * The constructor function initializes a vertex with an optional value.
14
- * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
15
- * used to uniquely identify the vertex within a graph or network.
16
- * @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
17
- * vertex. If no value is provided, the vertex will be initialized with a default value.
18
- */
19
12
  constructor(key: VertexKey, value?: V);
20
13
  }
21
14
  export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
22
15
  endpoints: [VertexKey, VertexKey];
23
- /**
24
- * The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
25
- * value.
26
- * @param {VertexKey} v1 - The first vertex ID of the edge.
27
- * @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
28
- * graph edge.
29
- * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
30
- * @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store a value associated
31
- * with the edge.
32
- */
33
16
  constructor(v1: VertexKey, v2: VertexKey, weight?: number, value?: E);
34
17
  }
35
18
  /**
36
- *
19
+ * Undirected graph implementation.
20
+ * @template V - Vertex value type.
21
+ * @template E - Edge value type.
22
+ * @template VO - Concrete vertex class (extends AbstractVertex<V>).
23
+ * @template EO - Concrete edge class (extends AbstractEdge<E>).
24
+ * @remarks Time O(1), Space O(1)
25
+ * @example examples will be generated by unit test
37
26
  */
38
27
  export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVertex<V> = UndirectedVertex<V>, EO extends UndirectedEdge<E> = UndirectedEdge<E>> extends AbstractGraph<V, E, VO, EO> implements IGraph<V, E, VO, EO> {
39
28
  /**
40
- * The constructor initializes a new Map object to store edgeMap.
29
+ * Construct an undirected graph with runtime defaults.
30
+ * @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
31
+ * @remarks Time O(1), Space O(1)
41
32
  */
42
- constructor();
33
+ constructor(options?: Partial<GraphOptions<V>>);
43
34
  protected _edgeMap: Map<VO, EO[]>;
44
35
  get edgeMap(): Map<VO, EO[]>;
45
36
  set edgeMap(v: Map<VO, EO[]>);
46
37
  /**
47
- * The function creates a new vertex with an optional value and returns it.
48
- * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
49
- * vertex from another in the graph.
50
- * @param [value] - The `value` parameter is an optional value that can be assigned to the vertex. If a value is provided,
51
- * it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
52
- * the vertex.
53
- * @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `VO`.
38
+ * Construct an undirected graph from keys with value initializer `v => v`.
39
+ * @template K - Vertex key type.
40
+ * @param keys - Iterable of vertex keys.
41
+ * @returns UndirectedGraph with all keys added.
42
+ * @remarks Time O(V), Space O(V)
43
+ */
44
+ static fromKeys<K extends VertexKey>(keys: Iterable<K>): UndirectedGraph<K, any, UndirectedVertex<K>, UndirectedEdge<any>>;
45
+ /**
46
+ * Construct an undirected graph from `[key, value]` entries.
47
+ * @template V - Vertex value type.
48
+ * @param entries - Iterable of `[key, value]` pairs.
49
+ * @returns UndirectedGraph with all vertices added.
50
+ * @remarks Time O(V), Space O(V)
51
+ */
52
+ static fromEntries<V>(entries: Iterable<[VertexKey, V]>): UndirectedGraph<V, any, UndirectedVertex<V>, UndirectedEdge<any>>;
53
+ /**
54
+ * Create an undirected vertex instance. Does not insert into the graph.
55
+ * @param key - Vertex identifier.
56
+ * @param value - Optional payload.
57
+ * @returns Concrete vertex instance.
58
+ * @remarks Time O(1), Space O(1)
54
59
  */
55
60
  createVertex(key: VertexKey, value?: VO['value']): VO;
56
61
  /**
57
- * The function creates an undirected edge between two vertexMap with an optional weight and value.
58
- * @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
59
- * @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
60
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
61
- * no weight is provided, it defaults to 1.
62
- * @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type and
63
- * is used to store additional information or data associated with the edge.
64
- * @returns a new instance of the `UndirectedEdge` class, which is casted as type `EO`.
62
+ * Create an undirected edge instance. Does not insert into the graph.
63
+ * @param v1 - One endpoint key.
64
+ * @param v2 - The other endpoint key.
65
+ * @param weight - Edge weight; defaults to `defaultEdgeWeight`.
66
+ * @param value - Edge payload.
67
+ * @returns Concrete edge instance.
68
+ * @remarks Time O(1), Space O(1)
65
69
  */
66
70
  createEdge(v1: VertexKey, v2: VertexKey, weight?: number, value?: EO['value']): EO;
67
71
  /**
68
- * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
69
- * Space Complexity: O(1)
70
- *
71
- * The function `getEdge` returns the first edge that connects two endpoints, or undefined if no such edge exists.
72
- * @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
73
- * object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
74
- * @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
75
- * object), `undefined`, or `VertexKey` (vertex ID).
76
- * @returns an edge (EO) or undefined.
72
+ * Get an undirected edge between two vertices, if present.
73
+ * @param v1 - One vertex or key.
74
+ * @param v2 - The other vertex or key.
75
+ * @returns Edge instance or `undefined`.
76
+ * @remarks Time O(1) avg, Space O(1)
77
77
  */
78
78
  getEdge(v1: VO | VertexKey | undefined, v2: VO | VertexKey | undefined): EO | undefined;
79
79
  /**
80
- * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
81
- * Space Complexity: O(1)
82
- *
83
- * The function removes an edge between two vertexMap in a graph and returns the removed edge.
84
- * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
85
- * @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
86
- * (VertexKey). It represents the second vertex of the edge that needs to be removed.
87
- * @returns the removed edge (EO) if it exists, or undefined if either of the endpoints (VO) does not exist.
80
+ * Delete a single undirected edge between two vertices.
81
+ * @param v1 - One vertex or key.
82
+ * @param v2 - The other vertex or key.
83
+ * @returns Removed edge or `undefined`.
84
+ * @remarks Time O(1) avg, Space O(1)
88
85
  */
89
86
  deleteEdgeBetween(v1: VO | VertexKey, v2: VO | VertexKey): EO | undefined;
90
87
  /**
91
- * Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
92
- * Space Complexity: O(1)
93
- *
94
- * The function `deleteEdge` deletes an edge between two endpoints in a graph.
95
- * @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
96
- * either an edge object or a vertex key.
97
- * @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
98
- * parameter that represents the key of the vertex on the other side of the edge. It is used when the
99
- * `edgeOrOneSideVertexKey` parameter is a vertex key, and it specifies the key of the vertex on the
100
- * other side of the
101
- * @returns The `deleteEdge` function returns either the deleted edge object (EO) or `undefined`.
88
+ * Delete an edge by instance or by a pair of keys.
89
+ * @param edgeOrOneSideVertexKey - Edge instance or one endpoint vertex/key.
90
+ * @param otherSideVertexKey - Required second endpoint when deleting by pair.
91
+ * @returns Removed edge or `undefined`.
92
+ * @remarks Time O(1) avg, Space O(1)
102
93
  */
103
94
  deleteEdge(edgeOrOneSideVertexKey: EO | VertexKey, otherSideVertexKey?: VertexKey): EO | undefined;
104
95
  /**
105
- * Time Complexity: O(1) - Constant time for Map operations.
106
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
107
- *
108
- * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
109
- * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
110
- * (`VertexKey`).
111
- * @returns The method is returning a boolean value.
96
+ * Delete a vertex and remove it from all neighbor lists.
97
+ * @param vertexOrKey - Vertex or key.
98
+ * @returns `true` if removed; otherwise `false`.
99
+ * @remarks Time O(deg), Space O(1)
112
100
  */
113
101
  deleteVertex(vertexOrKey: VO | VertexKey): boolean;
114
102
  /**
115
- * Time Complexity: O(1)
116
- * Space Complexity: O(1)
117
- *
118
- * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edgeMap connected to that
119
- * vertex.
120
- * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
121
- * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
122
- * edgeMap connected to that vertex.
103
+ * Degree of a vertex (# of incident undirected edges).
104
+ * @param vertexOrKey - Vertex or key.
105
+ * @returns Non-negative integer.
106
+ * @remarks Time O(1) avg, Space O(1)
123
107
  */
124
108
  degreeOf(vertexOrKey: VertexKey | VO): number;
125
109
  /**
126
- * Time Complexity: O(1)
127
- * Space Complexity: O(1)
128
- *
129
- * The function returns the edgeMap of a given vertex or vertex ID.
130
- * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
131
- * unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
132
- * @returns an array of edgeMap.
110
+ * Incident undirected edges of a vertex.
111
+ * @param vertexOrKey - Vertex or key.
112
+ * @returns Array of incident edges.
113
+ * @remarks Time O(deg), Space O(deg)
133
114
  */
134
115
  edgesOf(vertexOrKey: VertexKey | VO): EO[];
135
116
  /**
136
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
137
- * Space Complexity: O(|E|)
138
- *
139
- * The function "edgeSet" returns an array of unique edgeMap from a set of edgeMap.
140
- * @returns The method `edgeSet()` returns an array of type `EO[]`.
117
+ * Unique set of undirected edges across endpoints.
118
+ * @returns Array of edges.
119
+ * @remarks Time O(E), Space O(E)
141
120
  */
142
121
  edgeSet(): EO[];
143
- /**
144
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
145
- * Space Complexity: O(|E|)
146
- *
147
- * The function "getNeighbors" returns an array of neighboring endpoints for a given vertex or vertex ID.
148
- * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
149
- * (`VertexKey`).
150
- * @returns an array of vertexMap (VO[]).
151
- */
152
122
  getNeighbors(vertexOrKey: VO | VertexKey): VO[];
153
123
  /**
154
- * Time Complexity: O(1)
155
- * Space Complexity: O(1)
156
- *
157
- * The function "getEndsOfEdge" returns the endpoints at the ends of an edge if the edge exists in the graph, otherwise
158
- * it returns undefined.
159
- * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
160
- * @returns The function `getEndsOfEdge` returns an array containing two endpoints `[VO, VO]` if the edge exists in the
161
- * graph. If the edge does not exist, it returns `undefined`.
124
+ * Resolve an edge's two endpoints to vertex instances.
125
+ * @param edge - Edge instance.
126
+ * @returns `[v1, v2]` or `undefined` if either endpoint is missing.
127
+ * @remarks Time O(1), Space O(1)
162
128
  */
163
129
  getEndsOfEdge(edge: EO): [VO, VO] | undefined;
164
130
  /**
165
- * The isEmpty function checks if the graph is empty.
166
- * @return True if the graph is empty and false otherwise
131
+ * Whether the graph has no vertices and no edges.
132
+ * @remarks Time O(1), Space O(1)
167
133
  */
168
134
  isEmpty(): boolean;
169
135
  /**
170
- * Time Complexity: O(1)
171
- * Space Complexity: O(1)
172
- *
173
- * The clear function resets the vertex and edge maps to empty maps.
136
+ * Remove all vertices and edges.
137
+ * @remarks Time O(V + E), Space O(1)
174
138
  */
175
139
  clear(): void;
176
140
  /**
177
- * The clone function creates a new UndirectedGraph object and copies the
178
- * vertexMap and edgeMap from this graph to the new one. This is done by
179
- * assigning each of these properties to their respective counterparts in the
180
- * cloned graph. The clone function returns a reference to this newly created,
181
- * cloned UndirectedGraph object.
182
- *
183
- * @return A new instance of the undirectedgraph class
184
- */
185
- clone(): UndirectedGraph<V, E, VO, EO>;
186
- /**
187
- * Time Complexity: O(V + E)
188
- * Space Complexity: O(V)
189
- * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
190
- * 1. Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time
191
- *
192
- * The function `tarjan` implements the Tarjan's algorithm to find bridges and cut vertices in a
193
- * graph.
194
- * @returns The function `tarjan()` returns an object with the following properties:
141
+ * Deep clone as the same concrete class.
142
+ * @returns A new graph of the same concrete class (`this` type).
143
+ * @remarks Time O(V + E), Space O(V + E)
144
+ */
145
+ clone(): this;
146
+ /**
147
+ * Tarjan-based bridge and articulation point detection.
148
+ * @returns `{ dfnMap, lowMap, bridges, cutVertices }`.
149
+ * @remarks Time O(V + E), Space O(V + E)
195
150
  */
196
151
  tarjan(): {
197
152
  dfnMap: Map<VO, number>;
@@ -200,32 +155,34 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
200
155
  cutVertices: VO[];
201
156
  };
202
157
  /**
203
- * The function "getBridges" returns an array of bridges in a graph using the Tarjan's algorithm.
204
- * @returns The function `getBridges()` is returning the bridges found using the Tarjan's algorithm.
158
+ * Get bridges discovered by `tarjan()`.
159
+ * @returns Array of edges that are bridges.
160
+ * @remarks Time O(B), Space O(1)
205
161
  */
206
162
  getBridges(): EO[];
207
163
  /**
208
- * The function "getCutVertices" returns an array of cut vertices using the Tarjan's algorithm.
209
- * @returns the cut vertices found using the Tarjan's algorithm.
164
+ * Get articulation points discovered by `tarjan()`.
165
+ * @returns Array of cut vertices.
166
+ * @remarks Time O(C), Space O(1)
210
167
  */
211
168
  getCutVertices(): VO[];
212
169
  /**
213
- * The function returns the dfnMap property of the result of the tarjan() function.
214
- * @returns the `dfnMap` property of the result of calling the `tarjan()` function.
170
+ * DFN index map computed by `tarjan()`.
171
+ * @returns Map from vertex to DFN index.
172
+ * @remarks Time O(V), Space O(V)
215
173
  */
216
174
  getDFNMap(): Map<VO, number>;
217
175
  /**
218
- * The function returns the lowMap property of the result of the tarjan() function.
219
- * @returns the lowMap property of the result of calling the tarjan() function.
176
+ * LOW link map computed by `tarjan()`.
177
+ * @returns Map from vertex to LOW value.
178
+ * @remarks Time O(V), Space O(V)
220
179
  */
221
180
  getLowMap(): Map<VO, number>;
222
181
  /**
223
- * Time Complexity: O(1)
224
- * Space Complexity: O(1)
225
- *
226
- * The function adds an edge to the graph by updating the adjacency list with the vertexMap of the edge.
227
- * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
228
- * @returns a boolean value.
182
+ * Internal hook to attach an undirected edge into adjacency maps.
183
+ * @param edge - Edge instance.
184
+ * @returns `true` if both endpoints exist; otherwise `false`.
185
+ * @remarks Time O(1) avg, Space O(1)
229
186
  */
230
187
  protected _addEdge(edge: EO): boolean;
231
188
  }