data-structure-typed 1.38.9 → 1.39.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 (153) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +9 -9
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +2 -2
  4. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
  6. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +17 -0
  7. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +86 -32
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js +8 -8
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
  12. package/dist/cjs/data-structures/binary-tree/bst.js +2 -2
  13. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +2 -2
  16. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  17. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +4 -4
  18. package/dist/cjs/data-structures/graph/abstract-graph.js +5 -5
  19. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/directed-graph.d.ts +4 -4
  21. package/dist/cjs/data-structures/graph/directed-graph.js +6 -6
  22. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
  24. package/dist/cjs/data-structures/graph/map-graph.js +1 -1
  25. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +3 -3
  27. package/dist/cjs/data-structures/graph/undirected-graph.js +4 -4
  28. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  30. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  31. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  32. package/dist/cjs/data-structures/heap/heap.d.ts +10 -5
  33. package/dist/cjs/data-structures/heap/heap.js +10 -10
  34. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  35. package/dist/cjs/data-structures/heap/max-heap.d.ts +4 -1
  36. package/dist/cjs/data-structures/heap/max-heap.js +9 -7
  37. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  38. package/dist/cjs/data-structures/heap/min-heap.d.ts +4 -1
  39. package/dist/cjs/data-structures/heap/min-heap.js +9 -7
  40. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  41. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  42. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  43. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +1 -2
  44. package/dist/cjs/data-structures/matrix/matrix2d.js +3 -7
  45. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
  46. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -1
  47. package/dist/cjs/data-structures/matrix/vector2d.js +0 -1
  48. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  49. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +4 -1
  50. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +9 -7
  51. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  52. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +4 -1
  53. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +9 -7
  54. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  55. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +5 -2
  56. package/dist/cjs/data-structures/priority-queue/priority-queue.js +2 -2
  57. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  58. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  59. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  60. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  61. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
  62. package/dist/cjs/types/helpers.d.ts +1 -4
  63. package/dist/cjs/types/helpers.js.map +1 -1
  64. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +2 -2
  65. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
  66. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +17 -0
  67. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +86 -32
  68. package/dist/mjs/data-structures/binary-tree/binary-tree.js +8 -8
  69. package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
  70. package/dist/mjs/data-structures/binary-tree/bst.js +2 -2
  71. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +2 -2
  72. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +4 -4
  73. package/dist/mjs/data-structures/graph/abstract-graph.js +5 -5
  74. package/dist/mjs/data-structures/graph/directed-graph.d.ts +4 -4
  75. package/dist/mjs/data-structures/graph/directed-graph.js +6 -6
  76. package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
  77. package/dist/mjs/data-structures/graph/map-graph.js +1 -1
  78. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +3 -3
  79. package/dist/mjs/data-structures/graph/undirected-graph.js +4 -4
  80. package/dist/mjs/data-structures/heap/heap.d.ts +10 -5
  81. package/dist/mjs/data-structures/heap/heap.js +10 -10
  82. package/dist/mjs/data-structures/heap/max-heap.d.ts +4 -1
  83. package/dist/mjs/data-structures/heap/max-heap.js +9 -7
  84. package/dist/mjs/data-structures/heap/min-heap.d.ts +4 -1
  85. package/dist/mjs/data-structures/heap/min-heap.js +9 -7
  86. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +1 -2
  87. package/dist/mjs/data-structures/matrix/matrix2d.js +3 -7
  88. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -1
  89. package/dist/mjs/data-structures/matrix/vector2d.js +0 -1
  90. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +4 -1
  91. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +9 -7
  92. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +4 -1
  93. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +9 -7
  94. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +5 -2
  95. package/dist/mjs/data-structures/priority-queue/priority-queue.js +2 -2
  96. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  97. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
  98. package/dist/mjs/types/helpers.d.ts +1 -4
  99. package/dist/umd/data-structure-typed.min.js +1 -1
  100. package/dist/umd/data-structure-typed.min.js.map +1 -1
  101. package/package.json +5 -5
  102. package/src/data-structures/binary-tree/avl-tree.ts +5 -4
  103. package/src/data-structures/binary-tree/binary-indexed-tree.ts +21 -1
  104. package/src/data-structures/binary-tree/binary-tree.ts +37 -93
  105. package/src/data-structures/binary-tree/bst.ts +11 -17
  106. package/src/data-structures/binary-tree/rb-tree.ts +2 -1
  107. package/src/data-structures/binary-tree/tree-multiset.ts +4 -3
  108. package/src/data-structures/graph/abstract-graph.ts +16 -15
  109. package/src/data-structures/graph/directed-graph.ts +8 -7
  110. package/src/data-structures/graph/map-graph.ts +2 -2
  111. package/src/data-structures/graph/undirected-graph.ts +9 -8
  112. package/src/data-structures/hash/hash-map.ts +1 -1
  113. package/src/data-structures/hash/tree-map.ts +1 -2
  114. package/src/data-structures/hash/tree-set.ts +1 -2
  115. package/src/data-structures/heap/heap.ts +12 -12
  116. package/src/data-structures/heap/max-heap.ts +8 -6
  117. package/src/data-structures/heap/min-heap.ts +8 -6
  118. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  119. package/src/data-structures/matrix/matrix.ts +1 -1
  120. package/src/data-structures/matrix/matrix2d.ts +1 -3
  121. package/src/data-structures/matrix/vector2d.ts +1 -4
  122. package/src/data-structures/priority-queue/max-priority-queue.ts +8 -6
  123. package/src/data-structures/priority-queue/min-priority-queue.ts +8 -6
  124. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  125. package/src/data-structures/queue/deque.ts +4 -5
  126. package/src/data-structures/queue/queue.ts +1 -1
  127. package/src/interfaces/binary-tree.ts +2 -2
  128. package/src/types/data-structures/binary-tree/binary-tree.ts +0 -4
  129. package/src/types/data-structures/matrix/navigator.ts +1 -1
  130. package/src/types/helpers.ts +1 -7
  131. package/src/types/utils/utils.ts +1 -1
  132. package/src/types/utils/validate-type.ts +2 -2
  133. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +141 -1
  134. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +35 -0
  135. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +269 -47
  136. package/test/unit/data-structures/binary-tree/bst.test.ts +391 -1
  137. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +73 -7
  138. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +241 -186
  139. package/test/unit/data-structures/graph/directed-graph.test.ts +37 -7
  140. package/test/unit/data-structures/graph/map-graph.test.ts +82 -1
  141. package/test/unit/data-structures/graph/overall.test.ts +2 -2
  142. package/test/unit/data-structures/graph/undirected-graph.test.ts +84 -2
  143. package/test/unit/data-structures/heap/heap.test.ts +2 -2
  144. package/test/unit/data-structures/heap/max-heap.test.ts +1 -1
  145. package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
  146. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +1 -1
  147. package/test/unit/data-structures/matrix/matrix2d.test.ts +207 -0
  148. package/test/unit/data-structures/matrix/navigator.test.ts +166 -1
  149. package/test/unit/data-structures/matrix/vector2d.test.ts +171 -0
  150. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +3 -3
  151. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +10 -10
  152. package/test/unit/data-structures/queue/deque.test.ts +264 -1
  153. package/test/unit/data-structures/queue/queue.test.ts +3 -1
@@ -1,9 +1,6 @@
1
- import { BinaryTreeNodeKey } from './data-structures';
2
1
  export type Comparator<T> = (a: T, b: T) => number;
3
2
  export type DFSOrderPattern = 'pre' | 'in' | 'post';
4
- export type MapCallback<N, D = any> = (node: N) => D;
5
- export type DefaultMapCallback<N, D = BinaryTreeNodeKey> = (node: N) => D;
6
- export type MapCallbackReturn<N> = ReturnType<MapCallback<N>>;
3
+ export type OneParamCallback<N, D = any> = (node: N) => D;
7
4
  export declare enum CP {
8
5
  lt = "lt",
9
6
  eq = "eq",
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/types/helpers.ts"],"names":[],"mappings":";;;AAYA,IAAY,EAIX;AAJD,WAAY,EAAE;IACZ,eAAS,CAAA;IACT,eAAS,CAAA;IACT,eAAS,CAAA;AACX,CAAC,EAJW,EAAE,kBAAF,EAAE,QAIb"}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/types/helpers.ts"],"names":[],"mappings":";;;AAMA,IAAY,EAIX;AAJD,WAAY,EAAE;IACZ,eAAS,CAAA;IACT,eAAS,CAAA;IACT,eAAS,CAAA;AACX,CAAC,EAJW,EAAE,kBAAF,EAAE,QAIb"}
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
9
  import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../../types';
10
- import { MapCallback } from '../../types';
10
+ import { OneParamCallback } from '../../types';
11
11
  import { IBinaryTree } from '../../interfaces';
12
12
  export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
13
13
  height: number;
@@ -53,7 +53,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
53
53
  * `this._defaultCallbackByKey`
54
54
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
55
55
  */
56
- delete<C extends MapCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeletedResult<N>[];
56
+ delete<C extends OneParamCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeletedResult<N>[];
57
57
  /**
58
58
  * The function swaps the key, value, and height properties between two nodes in a binary tree.
59
59
  * @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
@@ -69,6 +69,14 @@ export declare class BinaryIndexedTree {
69
69
  * @returns The upperBound function is returning a number.
70
70
  */
71
71
  upperBound(sum: number): number;
72
+ /**
73
+ * The function calculates the prefix sum of an array using a binary indexed tree.
74
+ * @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
75
+ * array for which we want to calculate the prefix sum.
76
+ * @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
77
+ * `i`.
78
+ */
79
+ getPrefixSum(i: number): number;
72
80
  /**
73
81
  * The function returns the value of a specific index in a freqMap data structure, or a default value if
74
82
  * the index is not found.
@@ -125,6 +125,23 @@ class BinaryIndexedTree {
125
125
  }
126
126
  return this._binarySearch(sum, (x, y) => x <= y);
127
127
  }
128
+ /**
129
+ * The function calculates the prefix sum of an array using a binary indexed tree.
130
+ * @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
131
+ * array for which we want to calculate the prefix sum.
132
+ * @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
133
+ * `i`.
134
+ */
135
+ getPrefixSum(i) {
136
+ this._checkIndex(i);
137
+ i++; // Convert to 1-based index
138
+ let sum = 0;
139
+ while (i > 0) {
140
+ sum += this._getFrequency(i);
141
+ i -= i & -i;
142
+ }
143
+ return sum;
144
+ }
128
145
  /**
129
146
  * The function returns the value of a specific index in a freqMap data structure, or a default value if
130
147
  * the index is not found.
@@ -5,8 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BFSCallback, BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions, MapCallback } from '../../types';
9
- import { BinaryTreeDeletedResult, DefaultMapCallback, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
8
+ import type { OneParamCallback, BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions } from '../../types';
9
+ import { BinaryTreeDeletedResult, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  /**
12
12
  * Represents a node in a binary tree.
@@ -132,8 +132,21 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
132
132
  * @returns The method is returning a boolean value.
133
133
  */
134
134
  refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: Array<V>): boolean;
135
- delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N): BinaryTreeDeletedResult<N>[];
136
- delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): BinaryTreeDeletedResult<N>[];
135
+ /**
136
+ * The `delete` function removes a node from a binary search tree and returns the deleted node along
137
+ * with the parent node that needs to be balanced.
138
+ * a key (`BinaryTreeNodeKey`). If it is a key, the function will find the corresponding node in the
139
+ * binary tree.
140
+ * @returns an array of `BinaryTreeDeletedResult<N>` objects.
141
+ * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
142
+ * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
143
+ * searching for. It can be a specific key value or any other property of the node.
144
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
145
+ * value. This value is compared with the `identifier` parameter to determine if the node should be
146
+ * included in the result. The `callback` parameter has a default value of
147
+ * `this._defaultCallbackByKey`, which
148
+ */
149
+ delete<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C): BinaryTreeDeletedResult<N>[];
137
150
  /**
138
151
  * The function `getDepth` calculates the depth of a given node in a binary tree relative to a
139
152
  * specified root node.
@@ -179,21 +192,62 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
179
192
  * @returns The method is returning a boolean value.
180
193
  */
181
194
  isPerfectlyBalanced(beginRoot?: N | null): boolean;
182
- getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N): N[];
183
- getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): N[];
184
- getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, onlyOne: boolean): N[];
185
- getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, onlyOne: boolean): N[];
186
- getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, onlyOne: boolean, beginRoot: N | null): N[];
187
- getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, onlyOne: boolean, beginRoot: N | null, iterationType: IterationType): N[];
188
- has<C extends MapCallback<N>>(identifier: ReturnType<C> | N): boolean;
189
- has<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): boolean;
190
- has<C extends MapCallback<N>>(identifier: ReturnType<C> | N, beginRoot: N | null): boolean;
191
- has<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, beginRoot: N | null): boolean;
192
- get<C extends MapCallback<N>>(identifier: ReturnType<C> | N): N | null;
193
- get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): N | null;
194
- get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, beginRoot: N | null): N | null;
195
- get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, beginRoot: N | null): N | null;
196
- get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, beginRoot: N | null, iterationType: IterationType): N | null;
195
+ /**
196
+ * The function `getNodes` returns an array of nodes that match a given node property, using either
197
+ * recursive or iterative traversal.
198
+ * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
199
+ * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
200
+ * searching for. It can be a specific key value or any other property of the node.
201
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
202
+ * value. This value is compared with the `identifier` parameter to determine if the node should be
203
+ * included in the result. The `callback` parameter has a default value of
204
+ * `this._defaultCallbackByKey`, which
205
+ * @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the
206
+ * first node that matches the identifier. If set to true, the function will return an array with
207
+ * only one element (or an empty array if no matching node is found). If set to false (default), the
208
+ * function will continue searching for all
209
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node from which the
210
+ * traversal of the binary tree will begin. It is optional and defaults to the root of the binary
211
+ * tree.
212
+ * @param iterationType - The `iterationType` parameter determines the type of iteration used to
213
+ * traverse the binary tree. It can have two possible values:
214
+ * @returns The function `getNodes` returns an array of nodes (`N[]`).
215
+ */
216
+ getNodes<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
217
+ /**
218
+ * The function checks if a binary tree has a node with a given property or key.
219
+ * @param {BinaryTreeNodeKey | N} identifier - The `identifier` parameter is the key or value of
220
+ * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or a
221
+ * generic type `N`.
222
+ * @param callback - The `callback` parameter is a function that is used to determine whether a node
223
+ * matches the desired criteria. It takes a node as input and returns a boolean value indicating
224
+ * whether the node matches the criteria or not. The default callback function
225
+ * `this._defaultCallbackByKey` is used if no callback function is
226
+ * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
227
+ * the node from which the search should begin. By default, it is set to `this.root`, which means the
228
+ * search will start from the root node of the binary tree. However, you can provide a different node
229
+ * as
230
+ * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
231
+ * performed when searching for nodes in the binary tree. It can have one of the following values:
232
+ * @returns a boolean value.
233
+ */
234
+ has<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): boolean;
235
+ /**
236
+ * The function `get` returns the first node in a binary tree that matches the given property or key.
237
+ * @param {BinaryTreeNodeKey | N} identifier - The `identifier` parameter is the key or value of
238
+ * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or `N`
239
+ * type.
240
+ * @param callback - The `callback` parameter is a function that is used to determine whether a node
241
+ * matches the desired criteria. It takes a node as input and returns a boolean value indicating
242
+ * whether the node matches the criteria or not. The default callback function
243
+ * (`this._defaultCallbackByKey`) is used if no callback function is
244
+ * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
245
+ * the root node from which the search should begin.
246
+ * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
247
+ * performed when searching for a node in the binary tree. It can have one of the following values:
248
+ * @returns either the found node (of type N) or null if no node is found.
249
+ */
250
+ get<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
197
251
  /**
198
252
  * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
199
253
  * up to the root node, with the option to reverse the order of the nodes.
@@ -238,7 +292,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
238
292
  * possible values:
239
293
  * @returns The function `isSubtreeBST` returns a boolean value.
240
294
  */
241
- isSubtreeBST(beginRoot: N, iterationType?: IterationType): boolean;
295
+ isSubtreeBST(beginRoot: N | null, iterationType?: IterationType): boolean;
242
296
  /**
243
297
  * The function checks if a binary tree is a binary search tree.
244
298
  * @param iterationType - The parameter "iterationType" is used to specify the type of iteration to
@@ -260,9 +314,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
260
314
  * start from the root of the tree.
261
315
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
262
316
  * performed on the binary tree. It can have two possible values:
263
- * @returns The function `subTreeTraverse` returns an array of `MapCallbackReturn<N>`.
317
+ * @returns The function `subTreeTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
264
318
  */
265
- subTreeTraverse<C extends MapCallback<N>>(callback?: C, beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
319
+ subTreeTraverse<C extends OneParamCallback<N>>(callback?: C, beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
266
320
  /**
267
321
  * The `dfs` function performs a depth-first search traversal on a binary tree, executing a callback
268
322
  * function on each node according to a specified order pattern.
@@ -276,23 +330,23 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
276
330
  * is `null`, an empty array will be returned.
277
331
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
278
332
  * iteration used in the depth-first search algorithm. It can have two possible values:
279
- * @returns The function `dfs` returns an array of `MapCallbackReturn<N>` values.
333
+ * @returns The function `dfs` returns an array of `ReturnType<OneParamCallback<N>>` values.
280
334
  */
281
- dfs<C extends MapCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
335
+ dfs<C extends OneParamCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
282
336
  /**
283
337
  * The bfs function performs a breadth-first search traversal on a binary tree, executing a callback
284
338
  * function on each node.
285
339
  * @param callback - The `callback` parameter is a function that will be called for each node in the
286
340
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
287
- * `BFSCallbackReturn<N>`. The default value for this parameter is `this._defaultCallbackByKey
341
+ * `ReturnType<OneParamCallback<N>>`. The default value for this parameter is `this._defaultCallbackByKey
288
342
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
289
343
  * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
290
344
  * will not be performed and an empty array will be returned.
291
345
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be used
292
346
  * in the breadth-first search (BFS) algorithm. It can have two possible values:
293
- * @returns The function `bfs` returns an array of `BFSCallbackReturn<N>[]`.
347
+ * @returns The function `bfs` returns an array of `ReturnType<OneParamCallback<N>>[]`.
294
348
  */
295
- bfs<C extends BFSCallback<N> = BFSCallback<N, BinaryTreeNodeKey>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
349
+ bfs<C extends OneParamCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
296
350
  /**
297
351
  * The `listLevels` function takes a binary tree node and a callback function, and returns an array
298
352
  * of arrays representing the levels of the tree.
@@ -308,7 +362,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
308
362
  * level in a binary tree. Each inner array contains the return type of the provided callback
309
363
  * function `C` applied to the nodes at that level.
310
364
  */
311
- listLevels<C extends BFSCallback<N> = BFSCallback<N, BinaryTreeNodeKey>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[][];
365
+ listLevels<C extends OneParamCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[][];
312
366
  /**
313
367
  * The function returns the predecessor node of a given node in a binary tree.
314
368
  * @param {N} node - The parameter "node" represents a node in a binary tree.
@@ -319,7 +373,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
319
373
  * The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
320
374
  * algorithm and returns an array of values obtained by applying a callback function to each node.
321
375
  * @param callback - The `callback` parameter is a function that will be called on each node in the
322
- * tree. It takes a node of type `N` as input and returns a value of type `MapCallbackReturn<N>`. The
376
+ * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<OneParamCallback<N>>`. The
323
377
  * default value for this parameter is `this._defaultCallbackByKey`.
324
378
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
325
379
  * determines the order in which the nodes of a binary tree are traversed. It can have one of the
@@ -327,9 +381,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
327
381
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the Morris
328
382
  * traversal. It specifies the root node of the tree from which the traversal should begin. If
329
383
  * `beginRoot` is `null`, an empty array will be returned.
330
- * @returns The `morris` function returns an array of `MapCallbackReturn<N>` values.
384
+ * @returns The `morris` function returns an array of `ReturnType<OneParamCallback<N>>` values.
331
385
  */
332
- morris<C extends MapCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
386
+ morris<C extends OneParamCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
333
387
  /**
334
388
  * Swap the data of two nodes in the binary tree.
335
389
  * @param {N} srcNode - The source node to swap.
@@ -344,7 +398,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
344
398
  * the tree's structure should be restored to its original state to maintain the tree's integrity.
345
399
  * This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
346
400
  */
347
- protected _defaultCallbackByKey: DefaultMapCallback<N>;
401
+ protected _defaultCallbackByKey: OneParamCallback<N, BinaryTreeNodeKey>;
348
402
  /**
349
403
  * The function `_addTo` adds a new node to a binary tree if there is an available position.
350
404
  * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to
@@ -283,8 +283,8 @@ class BinaryTree {
283
283
  let needBalanced = null, orgCurrent = curr;
284
284
  if (!curr.left) {
285
285
  if (!parent) {
286
- if (curr.right !== undefined)
287
- this._setRoot(curr.right);
286
+ // Handle the case when there's only one root node
287
+ this._setRoot(null);
288
288
  }
289
289
  else {
290
290
  const { familyPosition: fp } = curr;
@@ -707,7 +707,7 @@ class BinaryTree {
707
707
  * start from the root of the tree.
708
708
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
709
709
  * performed on the binary tree. It can have two possible values:
710
- * @returns The function `subTreeTraverse` returns an array of `MapCallbackReturn<N>`.
710
+ * @returns The function `subTreeTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
711
711
  */
712
712
  subTreeTraverse(callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
713
713
  if (typeof beginRoot === 'number')
@@ -747,7 +747,7 @@ class BinaryTree {
747
747
  * is `null`, an empty array will be returned.
748
748
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
749
749
  * iteration used in the depth-first search algorithm. It can have two possible values:
750
- * @returns The function `dfs` returns an array of `MapCallbackReturn<N>` values.
750
+ * @returns The function `dfs` returns an array of `ReturnType<OneParamCallback<N>>` values.
751
751
  */
752
752
  dfs(callback = this._defaultCallbackByKey, pattern = 'in', beginRoot = this.root, iterationType = types_1.IterationType.ITERATIVE) {
753
753
  if (!beginRoot)
@@ -824,13 +824,13 @@ class BinaryTree {
824
824
  * function on each node.
825
825
  * @param callback - The `callback` parameter is a function that will be called for each node in the
826
826
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
827
- * `BFSCallbackReturn<N>`. The default value for this parameter is `this._defaultCallbackByKey
827
+ * `ReturnType<OneParamCallback<N>>`. The default value for this parameter is `this._defaultCallbackByKey
828
828
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
829
829
  * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
830
830
  * will not be performed and an empty array will be returned.
831
831
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be used
832
832
  * in the breadth-first search (BFS) algorithm. It can have two possible values:
833
- * @returns The function `bfs` returns an array of `BFSCallbackReturn<N>[]`.
833
+ * @returns The function `bfs` returns an array of `ReturnType<OneParamCallback<N>>[]`.
834
834
  */
835
835
  bfs(callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
836
836
  if (!beginRoot)
@@ -938,7 +938,7 @@ class BinaryTree {
938
938
  * The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
939
939
  * algorithm and returns an array of values obtained by applying a callback function to each node.
940
940
  * @param callback - The `callback` parameter is a function that will be called on each node in the
941
- * tree. It takes a node of type `N` as input and returns a value of type `MapCallbackReturn<N>`. The
941
+ * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<OneParamCallback<N>>`. The
942
942
  * default value for this parameter is `this._defaultCallbackByKey`.
943
943
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
944
944
  * determines the order in which the nodes of a binary tree are traversed. It can have one of the
@@ -946,7 +946,7 @@ class BinaryTree {
946
946
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the Morris
947
947
  * traversal. It specifies the root node of the tree from which the traversal should begin. If
948
948
  * `beginRoot` is `null`, an empty array will be returned.
949
- * @returns The `morris` function returns an array of `MapCallbackReturn<N>` values.
949
+ * @returns The `morris` function returns an array of `ReturnType<OneParamCallback<N>>` values.
950
950
  */
951
951
  morris(callback = this._defaultCallbackByKey, pattern = 'in', beginRoot = this.root) {
952
952
  if (beginRoot === null)
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeNodeKey, BSTComparator, BSTNodeNested, BSTOptions, MapCallback } from '../../types';
8
+ import type { BinaryTreeNodeKey, BSTComparator, BSTNodeNested, BSTOptions, OneParamCallback } from '../../types';
9
9
  import { CP, IterationType } from '../../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBinaryTree } from '../../interfaces';
@@ -59,7 +59,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
59
59
  * callback.
60
60
  * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
61
61
  * property of the binary tree node that you want to search for. It can be either a specific key
62
- * value (`BinaryTreeNodeKey`) or a custom callback function (`MapCallback<N>`) that determines
62
+ * value (`BinaryTreeNodeKey`) or a custom callback function (`OneParamCallback<N>`) that determines
63
63
  * whether a node matches the desired property.
64
64
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
65
65
  * matches the desired property. It takes a node as input and returns a boolean value indicating
@@ -72,7 +72,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
72
72
  * @returns either the first node that matches the given nodeProperty and callback, or null if no
73
73
  * matching node is found.
74
74
  */
75
- get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
75
+ get<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
76
76
  /**
77
77
  * The function `lastKey` returns the key of the rightmost node if the comparison result is less
78
78
  * than, the key of the leftmost node if the comparison result is greater than, and the key of the
@@ -110,7 +110,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
110
110
  * traverse the binary tree. It can have one of the following values:
111
111
  * @returns an array of nodes (N[]).
112
112
  */
113
- getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
113
+ getNodes<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
114
114
  /**
115
115
  * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
116
116
  * nodes that have a key value lesser or greater than a target key value.
@@ -126,9 +126,9 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
126
126
  * (`BinaryTreeNodeKey`), or `null` to
127
127
  * @param iterationType - The `iterationType` parameter determines whether the traversal should be
128
128
  * done recursively or iteratively. It can have two possible values:
129
- * @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
129
+ * @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
130
130
  */
131
- lesserOrGreaterTraverse<C extends MapCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
131
+ lesserOrGreaterTraverse<C extends OneParamCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
132
132
  /**
133
133
  * Balancing Adjustment:
134
134
  * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
@@ -209,7 +209,7 @@ class BST extends binary_tree_1.BinaryTree {
209
209
  * callback.
210
210
  * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
211
211
  * property of the binary tree node that you want to search for. It can be either a specific key
212
- * value (`BinaryTreeNodeKey`) or a custom callback function (`MapCallback<N>`) that determines
212
+ * value (`BinaryTreeNodeKey`) or a custom callback function (`OneParamCallback<N>`) that determines
213
213
  * whether a node matches the desired property.
214
214
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
215
215
  * matches the desired property. It takes a node as input and returns a boolean value indicating
@@ -340,7 +340,7 @@ class BST extends binary_tree_1.BinaryTree {
340
340
  * (`BinaryTreeNodeKey`), or `null` to
341
341
  * @param iterationType - The `iterationType` parameter determines whether the traversal should be
342
342
  * done recursively or iteratively. It can have two possible values:
343
- * @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
343
+ * @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
344
344
  */
345
345
  lesserOrGreaterTraverse(callback = this._defaultCallbackByKey, lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) {
346
346
  if (typeof targetNode === 'number')
@@ -6,7 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import type { BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions } from '../../types';
9
- import { BinaryTreeDeletedResult, IterationType, MapCallback } from '../../types';
9
+ import { BinaryTreeDeletedResult, IterationType, OneParamCallback } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
12
12
  export declare class TreeMultisetNode<V = any, N extends TreeMultisetNode<V, N> = TreeMultisetNodeNested<V>> extends AVLTreeNode<V, N> {
@@ -105,7 +105,7 @@ export declare class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = Tr
105
105
  * decremented by 1 and
106
106
  * @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
107
107
  */
108
- delete<C extends MapCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
108
+ delete<C extends OneParamCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
109
109
  /**
110
110
  * The clear() function clears the contents of a data structure and sets the count to zero.
111
111
  */
@@ -65,7 +65,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
65
65
  * @param val
66
66
  */
67
67
  abstract createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
68
- abstract removeEdge(edge: E): E | null;
68
+ abstract deleteEdge(edge: E): E | null;
69
69
  abstract getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
70
70
  abstract degreeOf(vertexOrKey: V | VertexKey): number;
71
71
  abstract edgeSet(): E[];
@@ -90,12 +90,12 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
90
90
  addVertex(vertex: V): boolean;
91
91
  addVertex(key: VertexKey, val?: V['val']): boolean;
92
92
  /**
93
- * The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
93
+ * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
94
94
  * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
95
95
  * (`VertexKey`).
96
96
  * @returns The method is returning a boolean value.
97
97
  */
98
- removeVertex(vertexOrKey: V | VertexKey): boolean;
98
+ deleteVertex(vertexOrKey: V | VertexKey): boolean;
99
99
  /**
100
100
  * The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
101
101
  * @param {V[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
@@ -103,7 +103,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
103
103
  * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
104
104
  * were removed.
105
105
  */
106
- removeAllVertices(vertices: V[] | VertexKey[]): boolean;
106
+ removeManyVertices(vertices: V[] | VertexKey[]): boolean;
107
107
  /**
108
108
  * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
109
109
  * @param {VertexKey | V} v1 - The parameter v1 can be either a VertexKey or a V. A VertexKey represents the unique
@@ -120,12 +120,12 @@ class AbstractGraph {
120
120
  }
121
121
  }
122
122
  /**
123
- * The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
123
+ * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
124
124
  * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
125
125
  * (`VertexKey`).
126
126
  * @returns The method is returning a boolean value.
127
127
  */
128
- removeVertex(vertexOrKey) {
128
+ deleteVertex(vertexOrKey) {
129
129
  const vertexKey = this._getVertexKey(vertexOrKey);
130
130
  return this._vertices.delete(vertexKey);
131
131
  }
@@ -136,10 +136,10 @@ class AbstractGraph {
136
136
  * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
137
137
  * were removed.
138
138
  */
139
- removeAllVertices(vertices) {
139
+ removeManyVertices(vertices) {
140
140
  const removed = [];
141
141
  for (const v of vertices) {
142
- removed.push(this.removeVertex(v));
142
+ removed.push(this.deleteVertex(v));
143
143
  }
144
144
  return removed.length > 0;
145
145
  }
@@ -530,7 +530,7 @@ class AbstractGraph {
530
530
  if (vertexOrKey instanceof AbstractVertex)
531
531
  distMap.set(vertexOrKey, Infinity);
532
532
  }
533
- const heap = new priority_queue_1.PriorityQueue((a, b) => a.key - b.key);
533
+ const heap = new priority_queue_1.PriorityQueue({ comparator: (a, b) => a.key - b.key });
534
534
  heap.add({ key: 0, val: srcVertex });
535
535
  distMap.set(srcVertex, 0);
536
536
  preMap.set(srcVertex, null);
@@ -84,14 +84,14 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
84
84
  * @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
85
85
  * @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
86
86
  */
87
- removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
87
+ deleteEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
88
88
  /**
89
89
  * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
90
90
  * @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
91
91
  * and `dest`, which represent the source and destination vertices of the edge, respectively.
92
- * @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
92
+ * @returns The method `deleteEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
93
93
  */
94
- removeEdge(edge: E): E | null;
94
+ deleteEdge(edge: E): E | null;
95
95
  /**
96
96
  * The function removes edges between two vertices and returns the removed edges.
97
97
  * @param {VertexKey | V} v1 - The parameter `v1` can be either a `VertexKey` or a `V`. A `VertexKey` represents the
@@ -100,7 +100,7 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
100
100
  * the second vertex in the edge that needs to be removed.
101
101
  * @returns an array of removed edges (E[]).
102
102
  */
103
- removeEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[];
103
+ deleteEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[];
104
104
  /**
105
105
  * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
106
106
  * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
@@ -132,7 +132,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
132
132
  * @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
133
133
  * @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
134
134
  */
135
- removeEdgeSrcToDest(srcOrKey, destOrKey) {
135
+ deleteEdgeSrcToDest(srcOrKey, destOrKey) {
136
136
  const src = this._getVertex(srcOrKey);
137
137
  const dest = this._getVertex(destOrKey);
138
138
  let removed = null;
@@ -153,9 +153,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
153
153
  * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
154
154
  * @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
155
155
  * and `dest`, which represent the source and destination vertices of the edge, respectively.
156
- * @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
156
+ * @returns The method `deleteEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
157
157
  */
158
- removeEdge(edge) {
158
+ deleteEdge(edge) {
159
159
  let removed = null;
160
160
  const src = this._getVertex(edge.src);
161
161
  const dest = this._getVertex(edge.dest);
@@ -179,11 +179,11 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
179
179
  * the second vertex in the edge that needs to be removed.
180
180
  * @returns an array of removed edges (E[]).
181
181
  */
182
- removeEdgesBetween(v1, v2) {
182
+ deleteEdgesBetween(v1, v2) {
183
183
  const removed = [];
184
184
  if (v1 && v2) {
185
- const v1ToV2 = this.removeEdgeSrcToDest(v1, v2);
186
- const v2ToV1 = this.removeEdgeSrcToDest(v2, v1);
185
+ const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2);
186
+ const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1);
187
187
  v1ToV2 && removed.push(v1ToV2);
188
188
  v2ToV1 && removed.push(v2ToV1);
189
189
  }
@@ -62,7 +62,7 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
62
62
  * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
63
63
  * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
64
64
  */
65
- createVertex(key: VertexKey, val?: V['val'], lat?: number, long?: number): V;
65
+ createVertex(key: VertexKey, lat?: number, long?: number, val?: V['val']): V;
66
66
  /**
67
67
  * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
68
68
  * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
@@ -92,7 +92,7 @@ class MapGraph extends directed_graph_1.DirectedGraph {
92
92
  * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
93
93
  * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
94
94
  */
95
- createVertex(key, val, lat = this.origin[0], long = this.origin[1]) {
95
+ createVertex(key, lat = this.origin[0], long = this.origin[1], val) {
96
96
  return new MapVertex(key, lat, long, val);
97
97
  }
98
98
  /**
@@ -71,13 +71,13 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
71
71
  * (VertexKey). It represents the second vertex of the edge that needs to be removed.
72
72
  * @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
73
73
  */
74
- removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
74
+ deleteEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
75
75
  /**
76
- * The removeEdge function removes an edge between two vertices in a graph.
76
+ * The deleteEdge function removes an edge between two vertices in a graph.
77
77
  * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
78
78
  * @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
79
79
  */
80
- removeEdge(edge: E): E | null;
80
+ deleteEdge(edge: E): E | null;
81
81
  /**
82
82
  * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
83
83
  * vertex.