data-structure-typed 1.20.0 → 1.21.1

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 (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -56
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +11 -18
  4. package/dist/data-structures/binary-tree/abstract-binary-tree.js +52 -74
  5. package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -6
  6. package/dist/data-structures/binary-tree/tree-multiset.js +20 -28
  7. package/dist/data-structures/graph/abstract-graph.d.ts +3 -3
  8. package/dist/data-structures/graph/abstract-graph.js +6 -2
  9. package/dist/data-structures/graph/index.d.ts +1 -0
  10. package/dist/data-structures/graph/index.js +1 -0
  11. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  12. package/dist/data-structures/graph/map-graph.js +111 -0
  13. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +0 -2
  14. package/dist/data-structures/tree/tree.d.ts +1 -1
  15. package/dist/data-structures/types/abstract-binary-tree.d.ts +0 -1
  16. package/dist/data-structures/types/abstract-graph.d.ts +1 -0
  17. package/dist/data-structures/types/index.d.ts +1 -0
  18. package/dist/data-structures/types/index.js +1 -0
  19. package/dist/data-structures/types/map-graph.d.ts +1 -0
  20. package/dist/data-structures/types/map-graph.js +2 -0
  21. package/dist/data-structures/types/tree-multiset.d.ts +1 -3
  22. package/package.json +21 -20
  23. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  24. package/src/data-structures/binary-tree/abstract-binary-tree.ts +0 -1479
  25. package/src/data-structures/binary-tree/avl-tree.ts +0 -301
  26. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  27. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
  28. package/src/data-structures/binary-tree/binary-tree.ts +0 -42
  29. package/src/data-structures/binary-tree/bst.ts +0 -438
  30. package/src/data-structures/binary-tree/index.ts +0 -12
  31. package/src/data-structures/binary-tree/rb-tree.ts +0 -102
  32. package/src/data-structures/binary-tree/segment-tree.ts +0 -243
  33. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  34. package/src/data-structures/binary-tree/tree-multiset.ts +0 -712
  35. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  36. package/src/data-structures/diagrams/README.md +0 -5
  37. package/src/data-structures/graph/abstract-graph.ts +0 -1033
  38. package/src/data-structures/graph/directed-graph.ts +0 -472
  39. package/src/data-structures/graph/index.ts +0 -3
  40. package/src/data-structures/graph/undirected-graph.ts +0 -270
  41. package/src/data-structures/hash/coordinate-map.ts +0 -67
  42. package/src/data-structures/hash/coordinate-set.ts +0 -56
  43. package/src/data-structures/hash/hash-table.ts +0 -3
  44. package/src/data-structures/hash/index.ts +0 -6
  45. package/src/data-structures/hash/pair.ts +0 -3
  46. package/src/data-structures/hash/tree-map.ts +0 -3
  47. package/src/data-structures/hash/tree-set.ts +0 -3
  48. package/src/data-structures/heap/heap.ts +0 -200
  49. package/src/data-structures/heap/index.ts +0 -3
  50. package/src/data-structures/heap/max-heap.ts +0 -31
  51. package/src/data-structures/heap/min-heap.ts +0 -34
  52. package/src/data-structures/index.ts +0 -15
  53. package/src/data-structures/interfaces/abstract-binary-tree.ts +0 -194
  54. package/src/data-structures/interfaces/abstract-graph.ts +0 -40
  55. package/src/data-structures/interfaces/avl-tree.ts +0 -28
  56. package/src/data-structures/interfaces/binary-tree.ts +0 -8
  57. package/src/data-structures/interfaces/bst.ts +0 -32
  58. package/src/data-structures/interfaces/directed-graph.ts +0 -20
  59. package/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
  60. package/src/data-structures/interfaces/heap.ts +0 -1
  61. package/src/data-structures/interfaces/index.ts +0 -15
  62. package/src/data-structures/interfaces/navigator.ts +0 -1
  63. package/src/data-structures/interfaces/priority-queue.ts +0 -1
  64. package/src/data-structures/interfaces/rb-tree.ts +0 -11
  65. package/src/data-structures/interfaces/segment-tree.ts +0 -1
  66. package/src/data-structures/interfaces/singly-linked-list.ts +0 -1
  67. package/src/data-structures/interfaces/tree-multiset.ts +0 -12
  68. package/src/data-structures/interfaces/undirected-graph.ts +0 -6
  69. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  70. package/src/data-structures/linked-list/index.ts +0 -3
  71. package/src/data-structures/linked-list/singly-linked-list.ts +0 -490
  72. package/src/data-structures/linked-list/skip-linked-list.ts +0 -3
  73. package/src/data-structures/matrix/index.ts +0 -4
  74. package/src/data-structures/matrix/matrix.ts +0 -27
  75. package/src/data-structures/matrix/matrix2d.ts +0 -208
  76. package/src/data-structures/matrix/navigator.ts +0 -122
  77. package/src/data-structures/matrix/vector2d.ts +0 -316
  78. package/src/data-structures/priority-queue/index.ts +0 -3
  79. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
  80. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
  81. package/src/data-structures/priority-queue/priority-queue.ts +0 -354
  82. package/src/data-structures/queue/deque.ts +0 -251
  83. package/src/data-structures/queue/index.ts +0 -2
  84. package/src/data-structures/queue/queue.ts +0 -120
  85. package/src/data-structures/stack/index.ts +0 -1
  86. package/src/data-structures/stack/stack.ts +0 -98
  87. package/src/data-structures/tree/index.ts +0 -1
  88. package/src/data-structures/tree/tree.ts +0 -69
  89. package/src/data-structures/trie/index.ts +0 -1
  90. package/src/data-structures/trie/trie.ts +0 -227
  91. package/src/data-structures/types/abstract-binary-tree.ts +0 -41
  92. package/src/data-structures/types/abstract-graph.ts +0 -5
  93. package/src/data-structures/types/avl-tree.ts +0 -5
  94. package/src/data-structures/types/binary-tree.ts +0 -9
  95. package/src/data-structures/types/bst.ts +0 -12
  96. package/src/data-structures/types/directed-graph.ts +0 -8
  97. package/src/data-structures/types/doubly-linked-list.ts +0 -1
  98. package/src/data-structures/types/heap.ts +0 -5
  99. package/src/data-structures/types/helpers.ts +0 -1
  100. package/src/data-structures/types/index.ts +0 -15
  101. package/src/data-structures/types/navigator.ts +0 -13
  102. package/src/data-structures/types/priority-queue.ts +0 -9
  103. package/src/data-structures/types/rb-tree.ts +0 -8
  104. package/src/data-structures/types/segment-tree.ts +0 -1
  105. package/src/data-structures/types/singly-linked-list.ts +0 -1
  106. package/src/data-structures/types/tree-multiset.ts +0 -8
  107. package/src/index.ts +0 -2
  108. package/src/utils/index.ts +0 -3
  109. package/src/utils/types/index.ts +0 -2
  110. package/src/utils/types/utils.ts +0 -6
  111. package/src/utils/types/validate-type.ts +0 -25
  112. package/src/utils/utils.ts +0 -78
  113. package/src/utils/validate-type.ts +0 -69
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -356,13 +356,15 @@ import {UndirectedGraph} from 'data-structure-typed';
356
356
  </table>
357
357
 
358
358
 
359
- ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/dfs-pre-order.webp)
359
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/dfs-pre-order.webp?raw=true&#41;)
360
360
 
361
- ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/test-graphs.webp)
361
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/map-graph.webp?raw=true&#41;)
362
362
 
363
- ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/cut-off-trees-for-golf.webp)
363
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/test-graphs.webp?raw=true&#41;)
364
364
 
365
- ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/parenthesis-check.webp)
365
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/cut-off-trees-for-golf.webp?raw=true&#41;)
366
+
367
+ [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/parenthesis-check.webp?raw=true&#41;)
366
368
 
367
369
 
368
370
  ## API docs & Examples
@@ -373,11 +375,8 @@ import {UndirectedGraph} from 'data-structure-typed';
373
375
 
374
376
  <a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
375
377
 
376
- [//]: # ([Examples Repository]&#40;https://github.com/zrwusa/data-structure-typed-examples&#41;)
377
-
378
378
  <a href="https://github.com/zrwusa/data-structure-typed-examples" target="_blank">Examples Repository</a>
379
379
 
380
-
381
380
  # Why
382
381
 
383
382
  ## Complexities
@@ -643,54 +642,8 @@ import {UndirectedGraph} from 'data-structure-typed';
643
642
  </tbody>
644
643
  </table>
645
644
 
646
- ![overview diagram](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/overview-diagram-of-data-structures.png)
647
-
648
- ![complexities](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/complexities-diff.jpg)
649
-
650
- ![complexities of data structures](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/data-structure-complexities.jpg)
651
-
652
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/binary-tree/bst-rotation.gif&#41;)
653
-
654
- [//]: # ()
655
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/binary-tree/avl-tree-inserting.gif&#41;)
656
-
657
- [//]: # ()
658
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan.webp&#41;)
659
-
660
- [//]: # ()
661
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-list.jpg&#41;)
662
-
663
- [//]: # ()
664
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-list-pros-cons.jpg&#41;)
665
-
666
- [//]: # ()
667
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-matrix.jpg&#41;)
668
-
669
- [//]: # ()
670
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-matrix-pros-cons.jpg&#41;)
671
-
672
- [//]: # ()
673
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/dfs-can-do.jpg&#41;)
674
-
675
- [//]: # ()
676
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/edge-list.jpg&#41;)
677
-
678
- [//]: # ()
679
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/edge-list-pros-cons.jpg&#41;)
680
-
681
- [//]: # ()
682
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/max-flow.jpg&#41;)
683
-
684
- [//]: # ()
685
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/mst.jpg&#41;)
686
-
687
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-articulation-point-bridge.png&#41;)
688
-
689
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-complicate-simple.png&#41;)
690
-
691
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-strongly-connected-component.png&#41;)
692
-
693
-
694
-
645
+ [//]: # (![overview diagram]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/overview-diagram-of-data-structures.png?raw=true&#41;)
695
646
 
647
+ ![complexities](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/complexities-diff.jpg?raw=true)
696
648
 
649
+ ![complexities of data structures](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/data-structure-complexities.jpg?raw=true)
@@ -54,8 +54,6 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
54
54
  get size(): number;
55
55
  private _loopType;
56
56
  get loopType(): LoopType;
57
- private _isMergeDuplicatedNodeById;
58
- get isMergeDuplicatedNodeById(): boolean;
59
57
  private _visitedId;
60
58
  get visitedId(): BinaryTreeNodeId[];
61
59
  private _visitedVal;
@@ -96,16 +94,6 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
96
94
  * @returns The function `add` returns either the inserted node (`N`), `null`, or `undefined`.
97
95
  */
98
96
  add(idOrNode: BinaryTreeNodeId | N | null, val?: N['val']): N | null | undefined;
99
- /**
100
- * The function adds a new node to the left or right child of a parent node, updating the size of the tree if
101
- * necessary.
102
- * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
103
- * either a node object (`N`) or `null`.
104
- * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
105
- * child.
106
- * @returns either the left child node, the right child node, or undefined.
107
- */
108
- addTo(newNode: N | null, parent: N): N | null | undefined;
109
97
  /**
110
98
  * The `addMany` function adds multiple nodes to a tree data structure and returns an array of the inserted nodes or
111
99
  * null/undefined values.
@@ -285,6 +273,17 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
285
273
  * Space complexity of Iterative DFS equals to recursive DFS which is O(n) because of the stack
286
274
  */
287
275
  morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
276
+ /**
277
+ * The function adds a new node to a binary tree if there is an available position.
278
+ * @param {N | null} newNode - The `newNode` parameter is of type `N | null`, which means it can either be a node of
279
+ * type `N` or `null`. It represents the node that you want to add to the binary tree.
280
+ * @param {N} parent - The parent parameter is of type N, which represents a node in a binary tree.
281
+ * @returns either the left or right child node of the parent node, depending on which child is available for adding
282
+ * the new node. If a new node is added, the function also updates the size of the binary tree. If neither the left nor
283
+ * right child is available, the function returns undefined. If the parent node is null, the function also returns
284
+ * undefined.
285
+ */
286
+ protected _addTo(newNode: N | null, parent: N): N | null | undefined;
288
287
  /**
289
288
  * The function sets the loop type for a protected variable.
290
289
  * @param {LoopType} value - The value parameter is of type LoopType.
@@ -310,12 +309,6 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
310
309
  * @param {number[]} value - An array of numbers that represents the visited left sum.
311
310
  */
312
311
  protected _setVisitedLeftSum(value: number[]): void;
313
- /**
314
- * The function sets the value of a protected property called "_isMergeDuplicatedNodeById".
315
- * @param {boolean} value - The value parameter is a boolean value that determines whether the isMergeDuplicatedNodeById
316
- * property should be set to true or false.
317
- */
318
- protected _setIsDuplicatedVal(value: boolean): void;
319
312
  /**
320
313
  * The function sets the root property of an object to a given value, and if the value is not null, it also sets the
321
314
  * parent property of the value to undefined.
@@ -113,21 +113,14 @@ class AbstractBinaryTree {
113
113
  this._root = null;
114
114
  this._size = 0;
115
115
  this._loopType = types_1.LoopType.ITERATIVE;
116
- // TODO this variable may be moved to TreeMultiset
117
- this._isMergeDuplicatedNodeById = true;
118
116
  this._visitedId = [];
119
117
  this._visitedVal = [];
120
118
  this._visitedNode = [];
121
119
  this._visitedLeftSum = [];
122
120
  if (options !== undefined) {
123
- const { loopType = types_1.LoopType.ITERATIVE, isMergeDuplicatedNodeById = true } = options;
124
- this._isMergeDuplicatedNodeById = isMergeDuplicatedNodeById;
121
+ const { loopType = types_1.LoopType.ITERATIVE } = options;
125
122
  this._loopType = loopType;
126
123
  }
127
- else {
128
- this._isMergeDuplicatedNodeById = true;
129
- this._loopType = types_1.LoopType.ITERATIVE;
130
- }
131
124
  this.clear();
132
125
  }
133
126
  get root() {
@@ -139,9 +132,6 @@ class AbstractBinaryTree {
139
132
  get loopType() {
140
133
  return this._loopType;
141
134
  }
142
- get isMergeDuplicatedNodeById() {
143
- return this._isMergeDuplicatedNodeById;
144
- }
145
135
  get visitedId() {
146
136
  return this._visitedId;
147
137
  }
@@ -209,7 +199,9 @@ class AbstractBinaryTree {
209
199
  while (queue.length > 0) {
210
200
  const cur = queue.shift();
211
201
  if (cur) {
212
- const inserted = this.addTo(newNode, cur);
202
+ if (newNode && cur.id === newNode.id)
203
+ return;
204
+ const inserted = this._addTo(newNode, cur);
213
205
  if (inserted !== undefined)
214
206
  return inserted;
215
207
  if (cur.left)
@@ -257,41 +249,6 @@ class AbstractBinaryTree {
257
249
  }
258
250
  return inserted;
259
251
  }
260
- /**
261
- * The function adds a new node to the left or right child of a parent node, updating the size of the tree if
262
- * necessary.
263
- * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
264
- * either a node object (`N`) or `null`.
265
- * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
266
- * child.
267
- * @returns either the left child node, the right child node, or undefined.
268
- */
269
- addTo(newNode, parent) {
270
- if (parent) {
271
- // When all leaf nodes are null, it will no longer be possible to add new entity nodes to this binary tree.
272
- // In this scenario, null nodes serve as "sentinel nodes," "virtual nodes," or "placeholder nodes."
273
- if (parent.left === undefined) {
274
- parent.left = newNode;
275
- if (newNode) {
276
- this._setSize(this.size + 1);
277
- }
278
- return parent.left;
279
- }
280
- else if (parent.right === undefined) {
281
- parent.right = newNode;
282
- if (newNode) {
283
- this._setSize(this.size + 1);
284
- }
285
- return parent.right;
286
- }
287
- else {
288
- return;
289
- }
290
- }
291
- else {
292
- return;
293
- }
294
- }
295
252
  /**
296
253
  * The `addMany` function adds multiple nodes to a tree data structure and returns an array of the inserted nodes or
297
254
  * null/undefined values.
@@ -306,29 +263,22 @@ class AbstractBinaryTree {
306
263
  // TODO not sure addMany not be run multi times
307
264
  const inserted = [];
308
265
  const map = new Map();
309
- if (this.isMergeDuplicatedNodeById) {
310
- for (const idOrNode of idsOrNodes)
311
- map.set(idOrNode, ((_a = map.get(idOrNode)) !== null && _a !== void 0 ? _a : 0) + 1);
312
- }
266
+ for (const idOrNode of idsOrNodes)
267
+ map.set(idOrNode, ((_a = map.get(idOrNode)) !== null && _a !== void 0 ? _a : 0) + 1);
313
268
  for (let i = 0; i < idsOrNodes.length; i++) {
314
269
  const idOrNode = idsOrNodes[i];
315
- if (idOrNode instanceof AbstractBinaryTreeNode) {
316
- inserted.push(this.add(idOrNode.id, idOrNode.val));
317
- continue;
318
- }
319
- if (idOrNode === null) {
320
- inserted.push(this.add(null));
321
- continue;
322
- }
323
- const val = data === null || data === void 0 ? void 0 : data[i];
324
- if (this.isMergeDuplicatedNodeById) {
325
- if (map.has(idOrNode)) {
326
- inserted.push(this.add(idOrNode, val));
327
- map.delete(idOrNode);
270
+ if (map.has(idOrNode)) {
271
+ if (idOrNode instanceof AbstractBinaryTreeNode) {
272
+ inserted.push(this.add(idOrNode.id, idOrNode.val));
273
+ continue;
328
274
  }
329
- }
330
- else {
275
+ if (idOrNode === null) {
276
+ inserted.push(this.add(null));
277
+ continue;
278
+ }
279
+ const val = data === null || data === void 0 ? void 0 : data[i];
331
280
  inserted.push(this.add(idOrNode, val));
281
+ map.delete(idOrNode);
332
282
  }
333
283
  }
334
284
  return inserted;
@@ -1170,6 +1120,42 @@ class AbstractBinaryTree {
1170
1120
  }
1171
1121
  return this._getResultByPropertyName(nodeOrPropertyName);
1172
1122
  }
1123
+ /**
1124
+ * The function adds a new node to a binary tree if there is an available position.
1125
+ * @param {N | null} newNode - The `newNode` parameter is of type `N | null`, which means it can either be a node of
1126
+ * type `N` or `null`. It represents the node that you want to add to the binary tree.
1127
+ * @param {N} parent - The parent parameter is of type N, which represents a node in a binary tree.
1128
+ * @returns either the left or right child node of the parent node, depending on which child is available for adding
1129
+ * the new node. If a new node is added, the function also updates the size of the binary tree. If neither the left nor
1130
+ * right child is available, the function returns undefined. If the parent node is null, the function also returns
1131
+ * undefined.
1132
+ */
1133
+ _addTo(newNode, parent) {
1134
+ if (parent) {
1135
+ // When all leaf nodes are null, it will no longer be possible to add new entity nodes to this binary tree.
1136
+ // In this scenario, null nodes serve as "sentinel nodes," "virtual nodes," or "placeholder nodes."
1137
+ if (parent.left === undefined) {
1138
+ parent.left = newNode;
1139
+ if (newNode) {
1140
+ this._setSize(this.size + 1);
1141
+ }
1142
+ return parent.left;
1143
+ }
1144
+ else if (parent.right === undefined) {
1145
+ parent.right = newNode;
1146
+ if (newNode) {
1147
+ this._setSize(this.size + 1);
1148
+ }
1149
+ return parent.right;
1150
+ }
1151
+ else {
1152
+ return;
1153
+ }
1154
+ }
1155
+ else {
1156
+ return;
1157
+ }
1158
+ }
1173
1159
  /**
1174
1160
  * The function sets the loop type for a protected variable.
1175
1161
  * @param {LoopType} value - The value parameter is of type LoopType.
@@ -1205,14 +1191,6 @@ class AbstractBinaryTree {
1205
1191
  _setVisitedLeftSum(value) {
1206
1192
  this._visitedLeftSum = value;
1207
1193
  }
1208
- /**
1209
- * The function sets the value of a protected property called "_isMergeDuplicatedNodeById".
1210
- * @param {boolean} value - The value parameter is a boolean value that determines whether the isMergeDuplicatedNodeById
1211
- * property should be set to true or false.
1212
- */
1213
- _setIsDuplicatedVal(value) {
1214
- this._isMergeDuplicatedNodeById = value;
1215
- }
1216
1194
  /**
1217
1195
  * The function sets the root property of an object to a given value, and if the value is not null, it also sets the
1218
1196
  * parent property of the value to undefined.
@@ -68,15 +68,15 @@ export declare class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = Tree
68
68
  */
69
69
  add(idOrNode: BinaryTreeNodeId | N | null, val?: N['val'], count?: number): N | null | undefined;
70
70
  /**
71
- * The function adds a new node to a binary tree as the left or right child of a given parent node.
72
- * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
73
- * either a node object (`N`) or `null`.
71
+ * The function adds a new node to a binary tree if there is an available slot on the left or right side of the parent
72
+ * node.
73
+ * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to the tree. It can
74
+ * be either a node object (`N`) or `null`.
74
75
  * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
75
76
  * child.
76
- * @returns either the left or right child node that was added to the parent node. It can also return `null` or
77
- * `undefined` in certain cases.
77
+ * @returns The method returns either the `parent.left`, `parent.right`, or `undefined`.
78
78
  */
79
- addTo(newNode: N | null, parent: N): N | null | undefined;
79
+ _addTo(newNode: N | null, parent: N): N | null | undefined;
80
80
  /**
81
81
  * The `addMany` function adds multiple nodes to a binary tree and returns an array of the inserted nodes.
82
82
  * @param {BinaryTreeNodeId[] | N[]} idsOrNodes - An array of BinaryTreeNodeId objects or N objects. These objects
@@ -37,7 +37,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
37
37
  * TreeMultiset.
38
38
  */
39
39
  constructor(options) {
40
- super(Object.assign(Object.assign({}, options), { isMergeDuplicatedNodeById: true }));
40
+ super(Object.assign({}, options));
41
41
  this._count = 0;
42
42
  }
43
43
  get count() {
@@ -166,15 +166,15 @@ class TreeMultiset extends avl_tree_1.AVLTree {
166
166
  return inserted;
167
167
  }
168
168
  /**
169
- * The function adds a new node to a binary tree as the left or right child of a given parent node.
170
- * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
171
- * either a node object (`N`) or `null`.
169
+ * The function adds a new node to a binary tree if there is an available slot on the left or right side of the parent
170
+ * node.
171
+ * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to the tree. It can
172
+ * be either a node object (`N`) or `null`.
172
173
  * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
173
174
  * child.
174
- * @returns either the left or right child node that was added to the parent node. It can also return `null` or
175
- * `undefined` in certain cases.
175
+ * @returns The method returns either the `parent.left`, `parent.right`, or `undefined`.
176
176
  */
177
- addTo(newNode, parent) {
177
+ _addTo(newNode, parent) {
178
178
  if (parent) {
179
179
  if (parent.left === undefined) {
180
180
  parent.left = newNode;
@@ -213,30 +213,22 @@ class TreeMultiset extends avl_tree_1.AVLTree {
213
213
  // TODO not sure addMany not be run multi times
214
214
  const inserted = [];
215
215
  const map = new Map();
216
- if (this.isMergeDuplicatedNodeById) {
217
- for (const idOrNode of idsOrNodes)
218
- map.set(idOrNode, ((_a = map.get(idOrNode)) !== null && _a !== void 0 ? _a : 0) + 1);
219
- }
216
+ for (const idOrNode of idsOrNodes)
217
+ map.set(idOrNode, ((_a = map.get(idOrNode)) !== null && _a !== void 0 ? _a : 0) + 1);
220
218
  for (let i = 0; i < idsOrNodes.length; i++) {
221
219
  const idOrNode = idsOrNodes[i];
222
- if (idOrNode instanceof TreeMultisetNode) {
223
- inserted.push(this.add(idOrNode.id, idOrNode.val, idOrNode.count));
224
- continue;
225
- }
226
- if (idOrNode === null) {
227
- inserted.push(this.add(NaN, null, 0));
228
- continue;
229
- }
230
- const count = this.isMergeDuplicatedNodeById ? map.get(idOrNode) : 1;
231
- const val = data === null || data === void 0 ? void 0 : data[i];
232
- if (this.isMergeDuplicatedNodeById) {
233
- if (map.has(idOrNode)) {
234
- inserted.push(this.add(idOrNode, val, count));
235
- map.delete(idOrNode);
220
+ if (map.has(idOrNode)) {
221
+ if (idOrNode instanceof TreeMultisetNode) {
222
+ inserted.push(this.add(idOrNode.id, idOrNode.val, idOrNode.count));
223
+ continue;
236
224
  }
237
- }
238
- else {
239
- inserted.push(this.add(idOrNode, val, 1));
225
+ if (idOrNode === null) {
226
+ inserted.push(this.add(NaN, null, 0));
227
+ continue;
228
+ }
229
+ const val = data === null || data === void 0 ? void 0 : data[i], count = map.get(idOrNode);
230
+ inserted.push(this.add(idOrNode, val, count));
231
+ map.delete(idOrNode);
240
232
  }
241
233
  }
242
234
  return inserted;
@@ -1,6 +1,6 @@
1
1
  import type { DijkstraResult, VertexId } from '../types';
2
2
  import { IAbstractGraph } from '../interfaces';
3
- export declare abstract class AbstractVertex<T = number> {
3
+ export declare abstract class AbstractVertex<T = any> {
4
4
  /**
5
5
  * The function is a protected constructor that takes an id and an optional value as parameters.
6
6
  * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
@@ -16,7 +16,7 @@ export declare abstract class AbstractVertex<T = number> {
16
16
  get val(): T | undefined;
17
17
  set val(value: T | undefined);
18
18
  }
19
- export declare abstract class AbstractEdge<T = number> {
19
+ export declare abstract class AbstractEdge<T = any> {
20
20
  /**
21
21
  * The above function is a protected constructor that initializes the weight, value, and hash code properties of an
22
22
  * object.
@@ -46,7 +46,7 @@ export declare abstract class AbstractEdge<T = number> {
46
46
  */
47
47
  protected _setHashCode(v: string): void;
48
48
  }
49
- export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E extends AbstractEdge<any>> implements IAbstractGraph<V, E> {
49
+ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = AbstractVertex<any>, E extends AbstractEdge<any> = AbstractEdge<any>> implements IAbstractGraph<V, E> {
50
50
  private _vertices;
51
51
  get vertices(): Map<VertexId, V>;
52
52
  /**
@@ -520,9 +520,8 @@ class AbstractGraph {
520
520
  const preMap = new Map(); // predecessor
521
521
  const srcVertex = this._getVertex(src);
522
522
  const destVertex = dest ? this._getVertex(dest) : null;
523
- if (!srcVertex) {
523
+ if (!srcVertex)
524
524
  return null;
525
- }
526
525
  for (const vertex of vertices) {
527
526
  const vertexOrId = vertex[1];
528
527
  if (vertexOrId instanceof AbstractVertex)
@@ -532,6 +531,11 @@ class AbstractGraph {
532
531
  heap.add({ id: 0, val: srcVertex });
533
532
  distMap.set(srcVertex, 0);
534
533
  preMap.set(srcVertex, null);
534
+ /**
535
+ * The function `getPaths` retrieves all paths from vertices to a specified minimum vertex.
536
+ * @param {V | null} minV - The parameter `minV` is of type `V | null`. It represents the minimum vertex value or
537
+ * null.
538
+ */
535
539
  const getPaths = (minV) => {
536
540
  for (const vertex of vertices) {
537
541
  const vertexOrId = vertex[1];
@@ -1,3 +1,4 @@
1
1
  export * from './abstract-graph';
2
2
  export * from './directed-graph';
3
3
  export * from './undirected-graph';
4
+ export * from './map-graph';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./abstract-graph"), exports);
18
18
  __exportStar(require("./directed-graph"), exports);
19
19
  __exportStar(require("./undirected-graph"), exports);
20
+ __exportStar(require("./map-graph"), exports);
@@ -0,0 +1,79 @@
1
+ import { MapGraphCoordinate, VertexId } from '../types';
2
+ import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
3
+ export declare class MapVertex<T = any> extends DirectedVertex<T> {
4
+ /**
5
+ * The constructor function initializes an object with an id, latitude, longitude, and an optional value.
6
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex.
7
+ * @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
8
+ * that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
9
+ * values representing points north of the equator and negative values representing points south of the equator.
10
+ * @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
11
+ * coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
12
+ * values ranging from -180 to 180.
13
+ * @param {T} [val] - The "val" parameter is an optional value of type T. It is not required to be provided when
14
+ * creating an instance of the class.
15
+ */
16
+ constructor(id: VertexId, lat: number, long: number, val?: T);
17
+ private _lat;
18
+ get lat(): number;
19
+ set lat(value: number);
20
+ private _long;
21
+ get long(): number;
22
+ set long(value: number);
23
+ }
24
+ export declare class MapEdge<T = any> extends DirectedEdge<T> {
25
+ /**
26
+ * The constructor function initializes a new instance of a class with the given source, destination, weight, and
27
+ * value.
28
+ * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
29
+ * a graph.
30
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
31
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
32
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store additional
33
+ * information or data associated with the edge.
34
+ */
35
+ constructor(src: VertexId, dest: VertexId, weight?: number, val?: T);
36
+ }
37
+ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E extends MapEdge = MapEdge> extends DirectedGraph<V, E> {
38
+ /**
39
+ * The constructor function initializes the origin and bottomRight properties of a MapGraphCoordinate object.
40
+ * @param {MapGraphCoordinate} origin - The `origin` parameter is a `MapGraphCoordinate` object that represents the
41
+ * starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
42
+ * graph.
43
+ * @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
44
+ * `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
45
+ * it will default to `undefined`.
46
+ */
47
+ constructor(origin: MapGraphCoordinate, bottomRight?: MapGraphCoordinate);
48
+ private _origin;
49
+ get origin(): MapGraphCoordinate;
50
+ set origin(value: MapGraphCoordinate);
51
+ private _bottomRight;
52
+ get bottomRight(): MapGraphCoordinate | undefined;
53
+ set bottomRight(value: MapGraphCoordinate | undefined);
54
+ /**
55
+ * The function creates a new vertex with the given id, value, latitude, and longitude.
56
+ * @param {VertexId} id - The id parameter is the unique identifier for the vertex. It is of type VertexId, which could
57
+ * be a string or a number depending on how you define it in your code.
58
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It
59
+ * is of type `V['val']`, which means it should be of the same type as the `val` property of the vertex class `V`.
60
+ * @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
61
+ * position of the vertex on the Earth's surface in the north-south direction.
62
+ * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
63
+ * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
64
+ */
65
+ createVertex(id: VertexId, val?: V['val'], lat?: number, long?: number): V;
66
+ /**
67
+ * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
68
+ * @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
69
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
70
+ * created.
71
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
72
+ * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
73
+ * If the weight is not provided, it can be set to a default value or left undefined.
74
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type,
75
+ * depending on the specific implementation of the `MapEdge` class.
76
+ * @returns a new instance of the `MapEdge` class, casted as type `E`.
77
+ */
78
+ createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
79
+ }