data-structure-typed 1.52.4 → 1.52.5

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 (181) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +13 -13
  3. package/README_zh-CN.md +216 -26
  4. package/benchmark/report.html +13 -13
  5. package/benchmark/report.json +158 -158
  6. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +1 -37
  7. package/dist/cjs/data-structures/base/iterable-element-base.js +1 -37
  8. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  9. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +2 -54
  10. package/dist/cjs/data-structures/base/iterable-entry-base.js +1 -49
  11. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
  13. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -46
  16. package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -46
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +82 -147
  19. package/dist/cjs/data-structures/binary-tree/binary-tree.js +299 -331
  20. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/bst.d.ts +1 -40
  22. package/dist/cjs/data-structures/binary-tree/bst.js +12 -44
  23. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +0 -48
  25. package/dist/cjs/data-structures/binary-tree/rb-tree.js +2 -50
  26. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  27. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
  28. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +9 -41
  29. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  30. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -75
  31. package/dist/cjs/data-structures/graph/abstract-graph.js +0 -75
  32. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  33. package/dist/cjs/data-structures/graph/directed-graph.d.ts +0 -98
  34. package/dist/cjs/data-structures/graph/directed-graph.js +0 -98
  35. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  36. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +0 -50
  37. package/dist/cjs/data-structures/graph/undirected-graph.js +0 -50
  38. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  39. package/dist/cjs/data-structures/hash/hash-map.d.ts +5 -92
  40. package/dist/cjs/data-structures/hash/hash-map.js +27 -111
  41. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  42. package/dist/cjs/data-structures/heap/heap.d.ts +0 -32
  43. package/dist/cjs/data-structures/heap/heap.js +0 -32
  44. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  45. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
  46. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +5 -88
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  48. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +1 -83
  49. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +2 -84
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  51. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +1 -35
  52. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +1 -35
  53. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  54. package/dist/cjs/data-structures/queue/deque.d.ts +1 -98
  55. package/dist/cjs/data-structures/queue/deque.js +3 -99
  56. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  57. package/dist/cjs/data-structures/queue/queue.d.ts +1 -54
  58. package/dist/cjs/data-structures/queue/queue.js +0 -53
  59. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  60. package/dist/cjs/data-structures/stack/stack.d.ts +1 -34
  61. package/dist/cjs/data-structures/stack/stack.js +1 -34
  62. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  63. package/dist/cjs/data-structures/tree/tree.js +0 -1
  64. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  65. package/dist/cjs/data-structures/trie/trie.d.ts +0 -64
  66. package/dist/cjs/data-structures/trie/trie.js +0 -64
  67. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  68. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
  69. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +6 -0
  70. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
  71. package/dist/cjs/types/utils/utils.d.ts +13 -12
  72. package/dist/cjs/utils/number.d.ts +13 -0
  73. package/dist/cjs/utils/number.js +13 -0
  74. package/dist/cjs/utils/number.js.map +1 -1
  75. package/dist/cjs/utils/utils.d.ts +125 -3
  76. package/dist/cjs/utils/utils.js +177 -21
  77. package/dist/cjs/utils/utils.js.map +1 -1
  78. package/dist/mjs/data-structures/base/iterable-element-base.d.ts +1 -37
  79. package/dist/mjs/data-structures/base/iterable-element-base.js +1 -37
  80. package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +2 -54
  81. package/dist/mjs/data-structures/base/iterable-entry-base.js +1 -49
  82. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
  83. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
  84. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -46
  85. package/dist/mjs/data-structures/binary-tree/avl-tree.js +0 -46
  86. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +82 -147
  87. package/dist/mjs/data-structures/binary-tree/binary-tree.js +298 -332
  88. package/dist/mjs/data-structures/binary-tree/bst.d.ts +1 -40
  89. package/dist/mjs/data-structures/binary-tree/bst.js +12 -44
  90. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +0 -48
  91. package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -50
  92. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
  93. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +9 -41
  94. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -75
  95. package/dist/mjs/data-structures/graph/abstract-graph.js +0 -75
  96. package/dist/mjs/data-structures/graph/directed-graph.d.ts +0 -98
  97. package/dist/mjs/data-structures/graph/directed-graph.js +0 -98
  98. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +0 -50
  99. package/dist/mjs/data-structures/graph/undirected-graph.js +0 -50
  100. package/dist/mjs/data-structures/hash/hash-map.d.ts +5 -92
  101. package/dist/mjs/data-structures/hash/hash-map.js +27 -111
  102. package/dist/mjs/data-structures/heap/heap.d.ts +0 -32
  103. package/dist/mjs/data-structures/heap/heap.js +0 -32
  104. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
  105. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +5 -88
  106. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +1 -83
  107. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +2 -84
  108. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +1 -35
  109. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +1 -35
  110. package/dist/mjs/data-structures/queue/deque.d.ts +1 -98
  111. package/dist/mjs/data-structures/queue/deque.js +3 -99
  112. package/dist/mjs/data-structures/queue/queue.d.ts +1 -54
  113. package/dist/mjs/data-structures/queue/queue.js +0 -53
  114. package/dist/mjs/data-structures/stack/stack.d.ts +1 -34
  115. package/dist/mjs/data-structures/stack/stack.js +1 -34
  116. package/dist/mjs/data-structures/tree/tree.js +0 -1
  117. package/dist/mjs/data-structures/trie/trie.d.ts +0 -64
  118. package/dist/mjs/data-structures/trie/trie.js +0 -64
  119. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
  120. package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +5 -1
  121. package/dist/mjs/types/utils/utils.d.ts +13 -12
  122. package/dist/mjs/utils/number.d.ts +13 -0
  123. package/dist/mjs/utils/number.js +13 -0
  124. package/dist/mjs/utils/utils.d.ts +125 -3
  125. package/dist/mjs/utils/utils.js +177 -21
  126. package/dist/umd/data-structure-typed.js +408 -1474
  127. package/dist/umd/data-structure-typed.min.js +5 -4
  128. package/dist/umd/data-structure-typed.min.js.map +1 -1
  129. package/package.json +6 -6
  130. package/src/data-structures/base/iterable-element-base.ts +2 -42
  131. package/src/data-structures/base/iterable-entry-base.ts +3 -62
  132. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
  133. package/src/data-structures/binary-tree/avl-tree.ts +0 -57
  134. package/src/data-structures/binary-tree/binary-tree.ts +329 -358
  135. package/src/data-structures/binary-tree/bst.ts +11 -54
  136. package/src/data-structures/binary-tree/rb-tree.ts +2 -62
  137. package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
  138. package/src/data-structures/graph/abstract-graph.ts +0 -92
  139. package/src/data-structures/graph/directed-graph.ts +0 -122
  140. package/src/data-structures/graph/undirected-graph.ts +0 -62
  141. package/src/data-structures/hash/hash-map.ts +29 -133
  142. package/src/data-structures/heap/heap.ts +0 -40
  143. package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
  144. package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
  145. package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
  146. package/src/data-structures/queue/deque.ts +2 -125
  147. package/src/data-structures/queue/queue.ts +1 -68
  148. package/src/data-structures/stack/stack.ts +1 -43
  149. package/src/data-structures/tree/tree.ts +1 -1
  150. package/src/data-structures/trie/trie.ts +0 -80
  151. package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
  152. package/src/types/utils/utils.ts +17 -15
  153. package/src/utils/number.ts +13 -0
  154. package/src/utils/utils.ts +174 -18
  155. package/test/config.ts +8 -0
  156. package/test/integration/all-in-one.test.ts +1 -1
  157. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +13 -13
  158. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +18 -13
  159. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +471 -64
  160. package/test/unit/data-structures/binary-tree/bst.test.ts +167 -23
  161. package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
  162. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +136 -13
  163. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +18 -13
  164. package/test/unit/data-structures/graph/directed-graph.test.ts +46 -32
  165. package/test/unit/data-structures/graph/map-graph.test.ts +24 -2
  166. package/test/unit/data-structures/graph/undirected-graph.test.ts +24 -24
  167. package/test/unit/data-structures/hash/hash-map.test.ts +225 -35
  168. package/test/unit/data-structures/heap/heap.test.ts +47 -39
  169. package/test/unit/data-structures/heap/min-heap.test.ts +5 -5
  170. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +34 -4
  171. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +32 -0
  172. package/test/unit/data-structures/matrix/matrix.test.ts +35 -5
  173. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +31 -0
  174. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +18 -0
  175. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +17 -0
  176. package/test/unit/data-structures/queue/deque.test.ts +288 -47
  177. package/test/unit/data-structures/queue/queue.test.ts +62 -37
  178. package/test/unit/data-structures/stack/stack.test.ts +30 -5
  179. package/test/unit/data-structures/tree/tree.test.ts +58 -0
  180. package/test/unit/data-structures/trie/trie.test.ts +46 -5
  181. package/test/unit/utils/utils.test.ts +169 -0
@@ -57,10 +57,6 @@ export class TreeMultiMap extends RedBlackTree {
57
57
  get count() {
58
58
  return this._count;
59
59
  }
60
- /**
61
- * Time Complexity: O(n)
62
- * Space Complexity: O(1)
63
- */
64
60
  /**
65
61
  * Time Complexity: O(n)
66
62
  * Space Complexity: O(1)
@@ -121,17 +117,17 @@ export class TreeMultiMap extends RedBlackTree {
121
117
  return;
122
118
  if (this.isNode(keyOrNodeOrEntryOrRawElement))
123
119
  return keyOrNodeOrEntryOrRawElement;
124
- if (this.toEntryFn) {
125
- const [key] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
126
- if (key)
127
- return this.getNodeByKey(key);
128
- }
129
120
  if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
130
- const [key, value] = keyOrNodeOrEntryOrRawElement;
121
+ const [key, entryValue] = keyOrNodeOrEntryOrRawElement;
131
122
  if (key === undefined || key === null)
132
123
  return;
133
- else
134
- return this.createNode(key, value, 'BLACK', count);
124
+ if (this.isKey(key))
125
+ return this.createNode(key, value ?? entryValue, 'BLACK', count);
126
+ }
127
+ if (this.toEntryFn) {
128
+ const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
129
+ if (this.isKey(key))
130
+ return this.createNode(key, value ?? entryValue, 'BLACK', count);
135
131
  }
136
132
  if (this.isKey(keyOrNodeOrEntryOrRawElement))
137
133
  return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'BLACK', count);
@@ -147,10 +143,6 @@ export class TreeMultiMap extends RedBlackTree {
147
143
  isNode(keyOrNodeOrEntryOrRawElement) {
148
144
  return keyOrNodeOrEntryOrRawElement instanceof TreeMultiMapNode;
149
145
  }
150
- /**
151
- * Time Complexity: O(log n)
152
- * Space Complexity: O(1)
153
- */
154
146
  /**
155
147
  * Time Complexity: O(log n)
156
148
  * Space Complexity: O(1)
@@ -179,10 +171,6 @@ export class TreeMultiMap extends RedBlackTree {
179
171
  return false;
180
172
  }
181
173
  }
182
- /**
183
- * Time Complexity: O(log n)
184
- * Space Complexity: O(1)
185
- */
186
174
  /**
187
175
  * Time Complexity: O(log n)
188
176
  * Space Complexity: O(1)
@@ -239,7 +227,7 @@ export class TreeMultiMap extends RedBlackTree {
239
227
  }
240
228
  }
241
229
  else {
242
- const successor = this.getLeftMost(nodeToDelete.right);
230
+ const successor = this.getLeftMost(node => node, nodeToDelete.right);
243
231
  if (successor) {
244
232
  originalColor = successor.color;
245
233
  replacementNode = successor.right;
@@ -289,10 +277,6 @@ export class TreeMultiMap extends RedBlackTree {
289
277
  results.push({ deleted: nodeToDelete, needBalanced: undefined });
290
278
  return results;
291
279
  }
292
- /**
293
- * Time Complexity: O(1)
294
- * Space Complexity: O(1)
295
- */
296
280
  /**
297
281
  * Time Complexity: O(1)
298
282
  * Space Complexity: O(1)
@@ -304,10 +288,6 @@ export class TreeMultiMap extends RedBlackTree {
304
288
  super.clear();
305
289
  this._count = 0;
306
290
  }
307
- /**
308
- * Time Complexity: O(n log n)
309
- * Space Complexity: O(log n)
310
- */
311
291
  /**
312
292
  * Time Complexity: O(n log n)
313
293
  * Space Complexity: O(log n)
@@ -357,10 +337,6 @@ export class TreeMultiMap extends RedBlackTree {
357
337
  return true;
358
338
  }
359
339
  }
360
- /**
361
- * Time complexity: O(n)
362
- * Space complexity: O(n)
363
- */
364
340
  /**
365
341
  * Time complexity: O(n)
366
342
  * Space complexity: O(n)
@@ -373,10 +349,6 @@ export class TreeMultiMap extends RedBlackTree {
373
349
  this.bfs(node => cloned.add(node.key, node.value, node.count));
374
350
  return cloned;
375
351
  }
376
- /**
377
- * Time Complexity: O(1)
378
- * Space Complexity: O(1)
379
- */
380
352
  /**
381
353
  * Time Complexity: O(1)
382
354
  * Space Complexity: O(1)
@@ -412,10 +384,6 @@ export class TreeMultiMap extends RedBlackTree {
412
384
  }
413
385
  return undefined;
414
386
  }
415
- /**
416
- * Time Complexity: O(1)
417
- * Space Complexity: O(1)
418
- */
419
387
  /**
420
388
  * Time Complexity: O(1)
421
389
  * Space Complexity: O(1)
@@ -65,10 +65,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
65
65
  abstract edgesOf(vertexOrKey: VO | VertexKey): EO[];
66
66
  abstract getNeighbors(vertexOrKey: VO | VertexKey): VO[];
67
67
  abstract getEndsOfEdge(edge: EO): [VO, VO] | undefined;
68
- /**
69
- * Time Complexity: O(1) - Constant time for Map lookup.
70
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
71
- */
72
68
  /**
73
69
  * Time Complexity: O(1) - Constant time for Map lookup.
74
70
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -80,10 +76,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
80
76
  * map. If the vertex does not exist, it returns `undefined`.
81
77
  */
82
78
  getVertex(vertexKey: VertexKey): VO | undefined;
83
- /**
84
- * Time Complexity: O(1) - Constant time for Map lookup.
85
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
86
- */
87
79
  /**
88
80
  * Time Complexity: O(1) - Constant time for Map lookup.
89
81
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -102,10 +94,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
102
94
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
103
95
  */
104
96
  abstract deleteVertex(vertexOrKey: VO | VertexKey): boolean;
105
- /**
106
- * Time Complexity: O(K), where K is the number of vertexMap to be removed.
107
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
108
- */
109
97
  /**
110
98
  * Time Complexity: O(K), where K is the number of vertexMap to be removed.
111
99
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -117,10 +105,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
117
105
  * were removed.
118
106
  */
119
107
  removeManyVertices(vertexMap: VO[] | VertexKey[]): boolean;
120
- /**
121
- * Time Complexity: O(1) - Depends on the implementation in the concrete class.
122
- * Space Complexity: O(1) - Depends on the implementation in the concrete class.
123
- */
124
108
  /**
125
109
  * Time Complexity: O(1) - Depends on the implementation in the concrete class.
126
110
  * Space Complexity: O(1) - Depends on the implementation in the concrete class.
@@ -135,10 +119,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
135
119
  hasEdge(v1: VertexKey | VO, v2: VertexKey | VO): boolean;
136
120
  addEdge(edge: EO): boolean;
137
121
  addEdge(src: VO | VertexKey, dest: VO | VertexKey, weight?: number, value?: E): boolean;
138
- /**
139
- * Time Complexity: O(1) - Constant time for Map and Edge operations.
140
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
141
- */
142
122
  /**
143
123
  * Time Complexity: O(1) - Constant time for Map and Edge operations.
144
124
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -154,10 +134,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
154
134
  * the weight of the edge and return true. If the edge does not exist, the function will return false.
155
135
  */
156
136
  setEdgeWeight(srcOrKey: VertexKey | VO, destOrKey: VertexKey | VO, weight: number): boolean;
157
- /**
158
- * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
159
- * Space Complexity: O(P) - Linear space, where P is the number of paths found.
160
- */
161
137
  /**
162
138
  * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
163
139
  * Space Complexity: O(P) - Linear space, where P is the number of paths found.
@@ -170,10 +146,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
170
146
  * @returns The function `getAllPathsBetween` returns an array of arrays of vertexMap (`VO[][]`).
171
147
  */
172
148
  getAllPathsBetween(v1: VO | VertexKey, v2: VO | VertexKey, limit?: number): VO[][];
173
- /**
174
- * Time Complexity: O(L), where L is the length of the path.
175
- * Space Complexity: O(1) - Constant space.
176
- */
177
149
  /**
178
150
  * Time Complexity: O(L), where L is the length of the path.
179
151
  * Space Complexity: O(1) - Constant space.
@@ -183,10 +155,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
183
155
  * @returns The function `getPathSumWeight` returns the sum of the weights of the edgeMap in the given path.
184
156
  */
185
157
  getPathSumWeight(path: VO[]): number;
186
- /**
187
- * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
188
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
189
- */
190
158
  /**
191
159
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
192
160
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
@@ -205,10 +173,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
205
173
  * minimum number of
206
174
  */
207
175
  getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | undefined;
208
- /**
209
- * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
210
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
211
- */
212
176
  /**
213
177
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
214
178
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
@@ -229,13 +193,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
229
193
  * two vertexMap (`v1` and `v2`). If there is no path between the vertexMap, it returns `undefined`.
230
194
  */
231
195
  getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] | undefined;
232
- /**
233
- * Dijkstra algorithm time: O(VE) space: O(VO + EO)
234
- */
235
- /**
236
- * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
237
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
238
- */
239
196
  /**
240
197
  * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
241
198
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
@@ -256,18 +213,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
256
213
  * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
257
214
  */
258
215
  dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
259
- /**
260
- * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
261
- *
262
- * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
263
- * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edgeMap.
264
- * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
265
- *
266
- */
267
- /**
268
- * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
269
- * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
270
- */
271
216
  /**
272
217
  * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
273
218
  * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
@@ -289,11 +234,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
289
234
  * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
290
235
  */
291
236
  dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
292
- /**
293
- * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
294
- * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
295
- * one to rest pairs
296
- */
297
237
  /**
298
238
  * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
299
239
  * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
@@ -333,13 +273,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
333
273
  * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
334
274
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
335
275
  */
336
- /**
337
- * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
338
- * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
339
- * Not support graph with negative weight cycle
340
- * all pairs
341
- * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
342
- */
343
276
  /**
344
277
  * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
345
278
  * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
@@ -363,10 +296,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
363
296
  * O(V+C)
364
297
  */
365
298
  getCycles(isInclude2Cycle?: boolean): VertexKey[][];
366
- /**
367
- * Time Complexity: O(n)
368
- * Space Complexity: O(n)
369
- */
370
299
  /**
371
300
  * Time Complexity: O(n)
372
301
  * Space Complexity: O(n)
@@ -384,10 +313,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
384
313
  * that satisfy the given predicate function.
385
314
  */
386
315
  filter(predicate: EntryCallback<VertexKey, V | undefined, boolean>, thisArg?: any): [VertexKey, V | undefined][];
387
- /**
388
- * Time Complexity: O(n)
389
- * Space Complexity: O(n)
390
- */
391
316
  /**
392
317
  * Time Complexity: O(n)
393
318
  * Space Complexity: O(n)
@@ -53,10 +53,6 @@ export class AbstractGraph extends IterableEntryBase {
53
53
  get size() {
54
54
  return this._vertexMap.size;
55
55
  }
56
- /**
57
- * Time Complexity: O(1) - Constant time for Map lookup.
58
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
59
- */
60
56
  /**
61
57
  * Time Complexity: O(1) - Constant time for Map lookup.
62
58
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -70,10 +66,6 @@ export class AbstractGraph extends IterableEntryBase {
70
66
  getVertex(vertexKey) {
71
67
  return this._vertexMap.get(vertexKey) || undefined;
72
68
  }
73
- /**
74
- * Time Complexity: O(1) - Constant time for Map lookup.
75
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
76
- */
77
69
  /**
78
70
  * Time Complexity: O(1) - Constant time for Map lookup.
79
71
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -103,10 +95,6 @@ export class AbstractGraph extends IterableEntryBase {
103
95
  const potentialKeyType = typeof potentialKey;
104
96
  return potentialKeyType === 'string' || potentialKeyType === 'number';
105
97
  }
106
- /**
107
- * Time Complexity: O(K), where K is the number of vertexMap to be removed.
108
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
109
- */
110
98
  /**
111
99
  * Time Complexity: O(K), where K is the number of vertexMap to be removed.
112
100
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -124,10 +112,6 @@ export class AbstractGraph extends IterableEntryBase {
124
112
  }
125
113
  return removed.length > 0;
126
114
  }
127
- /**
128
- * Time Complexity: O(1) - Depends on the implementation in the concrete class.
129
- * Space Complexity: O(1) - Depends on the implementation in the concrete class.
130
- */
131
115
  /**
132
116
  * Time Complexity: O(1) - Depends on the implementation in the concrete class.
133
117
  * Space Complexity: O(1) - Depends on the implementation in the concrete class.
@@ -167,10 +151,6 @@ export class AbstractGraph extends IterableEntryBase {
167
151
  }
168
152
  }
169
153
  }
170
- /**
171
- * Time Complexity: O(1) - Constant time for Map and Edge operations.
172
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
173
- */
174
154
  /**
175
155
  * Time Complexity: O(1) - Constant time for Map and Edge operations.
176
156
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -195,10 +175,6 @@ export class AbstractGraph extends IterableEntryBase {
195
175
  return false;
196
176
  }
197
177
  }
198
- /**
199
- * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
200
- * Space Complexity: O(P) - Linear space, where P is the number of paths found.
201
- */
202
178
  /**
203
179
  * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
204
180
  * Space Complexity: O(P) - Linear space, where P is the number of paths found.
@@ -236,10 +212,6 @@ export class AbstractGraph extends IterableEntryBase {
236
212
  }
237
213
  return paths;
238
214
  }
239
- /**
240
- * Time Complexity: O(L), where L is the length of the path.
241
- * Space Complexity: O(1) - Constant space.
242
- */
243
215
  /**
244
216
  * Time Complexity: O(L), where L is the length of the path.
245
217
  * Space Complexity: O(1) - Constant space.
@@ -255,10 +227,6 @@ export class AbstractGraph extends IterableEntryBase {
255
227
  }
256
228
  return sum;
257
229
  }
258
- /**
259
- * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
260
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
261
- */
262
230
  /**
263
231
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
264
232
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
@@ -320,10 +288,6 @@ export class AbstractGraph extends IterableEntryBase {
320
288
  return undefined;
321
289
  }
322
290
  }
323
- /**
324
- * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
325
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
326
- */
327
291
  /**
328
292
  * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
329
293
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
@@ -393,13 +357,6 @@ export class AbstractGraph extends IterableEntryBase {
393
357
  return minPath;
394
358
  }
395
359
  }
396
- /**
397
- * Dijkstra algorithm time: O(VE) space: O(VO + EO)
398
- */
399
- /**
400
- * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
401
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
402
- */
403
360
  /**
404
361
  * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
405
362
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
@@ -515,18 +472,6 @@ export class AbstractGraph extends IterableEntryBase {
515
472
  genPaths && getPaths(minDest);
516
473
  return { distMap, preMap, seen, paths, minDist, minPath };
517
474
  }
518
- /**
519
- * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
520
- *
521
- * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
522
- * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edgeMap.
523
- * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
524
- *
525
- */
526
- /**
527
- * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
528
- * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
529
- */
530
475
  /**
531
476
  * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
532
477
  * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
@@ -642,11 +587,6 @@ export class AbstractGraph extends IterableEntryBase {
642
587
  }
643
588
  return { distMap, preMap, seen, paths, minDist, minPath };
644
589
  }
645
- /**
646
- * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
647
- * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
648
- * one to rest pairs
649
- */
650
590
  /**
651
591
  * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
652
592
  * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
@@ -763,13 +703,6 @@ export class AbstractGraph extends IterableEntryBase {
763
703
  * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
764
704
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
765
705
  */
766
- /**
767
- * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
768
- * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
769
- * Not support graph with negative weight cycle
770
- * all pairs
771
- * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
772
- */
773
706
  /**
774
707
  * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
775
708
  * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
@@ -853,10 +786,6 @@ export class AbstractGraph extends IterableEntryBase {
853
786
  // Convert the unique cycles back to an array
854
787
  return [...uniqueCycles].map(cycleString => cycleString[1]);
855
788
  }
856
- /**
857
- * Time Complexity: O(n)
858
- * Space Complexity: O(n)
859
- */
860
789
  /**
861
790
  * Time Complexity: O(n)
862
791
  * Space Complexity: O(n)
@@ -884,10 +813,6 @@ export class AbstractGraph extends IterableEntryBase {
884
813
  }
885
814
  return filtered;
886
815
  }
887
- /**
888
- * Time Complexity: O(n)
889
- * Space Complexity: O(n)
890
- */
891
816
  /**
892
817
  * Time Complexity: O(n)
893
818
  * Space Complexity: O(n)