min-heap-typed 1.41.5 → 1.41.7

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.
@@ -50,7 +50,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
50
50
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
51
51
  * value. This value is compared with the `identifier` parameter to determine if the node should be
52
52
  * included in the result. The `callback` parameter has a default value of
53
- * `((node: N) => node.key)`
53
+ * `this.defaultOneParamCallback`
54
54
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
55
55
  */
56
56
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeletedResult<N>[];
@@ -62,10 +62,10 @@ class AVLTree extends bst_1.BST {
62
62
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
63
63
  * value. This value is compared with the `identifier` parameter to determine if the node should be
64
64
  * included in the result. The `callback` parameter has a default value of
65
- * `((node: N) => node.key)`
65
+ * `this.defaultOneParamCallback`
66
66
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
67
67
  */
68
- delete(identifier, callback = ((node) => node.key)) {
68
+ delete(identifier, callback = this.defaultOneParamCallback) {
69
69
  if (identifier instanceof AVLTreeNode)
70
70
  callback = (node => node);
71
71
  const deletedResults = super.delete(identifier, callback);
@@ -79,6 +79,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
79
79
  * Get the number of nodes in the binary tree.
80
80
  */
81
81
  get size(): number;
82
+ protected defaultOneParamCallback: (node: N) => number;
82
83
  /**
83
84
  * Creates a new instance of BinaryTreeNode with the given key and value.
84
85
  * @param {BTNKey} key - The key for the new node.
@@ -257,7 +258,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
257
258
  * function on each node according to a specified order pattern.
258
259
  * @param callback - The `callback` parameter is a function that will be called on each node during
259
260
  * the depth-first search traversal. It takes a node as input and returns a value. The default value
260
- * is `((node: N) => node.key)`, which is a callback function defined elsewhere in the code.
261
+ * is `this.defaultOneParamCallback`, which is a callback function defined elsewhere in the code.
261
262
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
262
263
  * nodes are visited during the depth-first search. There are three possible values for `pattern`:
263
264
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the depth-first
@@ -273,7 +274,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
273
274
  * function on each node.
274
275
  * @param callback - The `callback` parameter is a function that will be called for each node in the
275
276
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
276
- * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `((node: N) => node.key)
277
+ * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `this.defaultOneParamCallback
277
278
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
278
279
  * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
279
280
  * will not be performed and an empty array will be returned.
@@ -317,7 +318,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
317
318
  * algorithm and returns an array of values obtained by applying a callback function to each node.
318
319
  * @param callback - The `callback` parameter is a function that will be called on each node in the
319
320
  * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The
320
- * default value for this parameter is `((node: N) => node.key)`.
321
+ * default value for this parameter is `this.defaultOneParamCallback`.
321
322
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
322
323
  * determines the order in which the nodes of a binary tree are traversed. It can have one of the
323
324
  * following values:
@@ -90,6 +90,7 @@ class BinaryTree {
90
90
  this.iterationType = types_1.IterationType.ITERATIVE;
91
91
  this._root = null;
92
92
  this._size = 0;
93
+ this.defaultOneParamCallback = (node) => node.key;
93
94
  if (options !== undefined) {
94
95
  const { iterationType = types_1.IterationType.ITERATIVE } = options;
95
96
  this.iterationType = iterationType;
@@ -242,9 +243,9 @@ class BinaryTree {
242
243
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
243
244
  * value. This value is compared with the `identifier` parameter to determine if the node should be
244
245
  * included in the result. The `callback` parameter has a default value of
245
- * `((node: N) => node.key)`, which
246
+ * `this.defaultOneParamCallback`, which
246
247
  */
247
- delete(identifier, callback = ((node) => node.key)) {
248
+ delete(identifier, callback = this.defaultOneParamCallback) {
248
249
  const bstDeletedResult = [];
249
250
  if (!this.root)
250
251
  return bstDeletedResult;
@@ -435,7 +436,7 @@ class BinaryTree {
435
436
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
436
437
  * value. This value is compared with the `identifier` parameter to determine if the node should be
437
438
  * included in the result. The `callback` parameter has a default value of
438
- * `((node: N) => node.key)`, which
439
+ * `this.defaultOneParamCallback`, which
439
440
  * @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the
440
441
  * first node that matches the identifier. If set to true, the function will return an array with
441
442
  * only one element (or an empty array if no matching node is found). If set to false (default), the
@@ -447,7 +448,7 @@ class BinaryTree {
447
448
  * traverse the binary tree. It can have two possible values:
448
449
  * @returns The function `getNodes` returns an array of nodes (`N[]`).
449
450
  */
450
- getNodes(identifier, callback = ((node) => node.key), onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
451
+ getNodes(identifier, callback = this.defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
451
452
  if (!beginRoot)
452
453
  return [];
453
454
  if (identifier instanceof BinaryTreeNode)
@@ -492,7 +493,7 @@ class BinaryTree {
492
493
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
493
494
  * matches the desired criteria. It takes a node as input and returns a boolean value indicating
494
495
  * whether the node matches the criteria or not. The default callback function
495
- * `((node: N) => node.key)` is used if no callback function is
496
+ * `this.defaultOneParamCallback` is used if no callback function is
496
497
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
497
498
  * the node from which the search should begin. By default, it is set to `this.root`, which means the
498
499
  * search will start from the root node of the binary tree. However, you can provide a different node
@@ -501,7 +502,7 @@ class BinaryTree {
501
502
  * performed when searching for nodes in the binary tree. It can have one of the following values:
502
503
  * @returns a boolean value.
503
504
  */
504
- has(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
505
+ has(identifier, callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
505
506
  if (identifier instanceof BinaryTreeNode)
506
507
  callback = (node => node);
507
508
  return this.getNodes(identifier, callback, true, beginRoot, iterationType).length > 0;
@@ -514,14 +515,14 @@ class BinaryTree {
514
515
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
515
516
  * matches the desired criteria. It takes a node as input and returns a boolean value indicating
516
517
  * whether the node matches the criteria or not. The default callback function
517
- * (`((node: N) => node.key)`) is used if no callback function is
518
+ * (`this.defaultOneParamCallback`) is used if no callback function is
518
519
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
519
520
  * the root node from which the search should begin.
520
521
  * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
521
522
  * performed when searching for a node in the binary tree. It can have one of the following values:
522
523
  * @returns either the found node (of type N) or null if no node is found.
523
524
  */
524
- getNode(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
525
+ getNode(identifier, callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
525
526
  var _a;
526
527
  if (identifier instanceof BinaryTreeNode)
527
528
  callback = (node => node);
@@ -535,14 +536,14 @@ class BinaryTree {
535
536
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
536
537
  * matches the desired criteria. It takes a node as input and returns a boolean value indicating
537
538
  * whether the node matches the criteria or not. The default callback function
538
- * (`((node: N) => node.key)`) is used if no callback function is
539
+ * (`this.defaultOneParamCallback`) is used if no callback function is
539
540
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
540
541
  * the root node from which the search should begin.
541
542
  * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
542
543
  * performed when searching for a node in the binary tree. It can have one of the following values:
543
544
  * @returns either the found value (of type V) or undefined if no node value is found.
544
545
  */
545
- get(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
546
+ get(identifier, callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
546
547
  var _a, _b;
547
548
  if (identifier instanceof BinaryTreeNode)
548
549
  callback = (node => node);
@@ -704,7 +705,7 @@ class BinaryTree {
704
705
  * performed on the binary tree. It can have two possible values:
705
706
  * @returns The function `subTreeTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
706
707
  */
707
- subTreeTraverse(callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
708
+ subTreeTraverse(callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
708
709
  if (typeof beginRoot === 'number')
709
710
  beginRoot = this.getNode(beginRoot);
710
711
  const ans = [];
@@ -734,7 +735,7 @@ class BinaryTree {
734
735
  * function on each node according to a specified order pattern.
735
736
  * @param callback - The `callback` parameter is a function that will be called on each node during
736
737
  * the depth-first search traversal. It takes a node as input and returns a value. The default value
737
- * is `((node: N) => node.key)`, which is a callback function defined elsewhere in the code.
738
+ * is `this.defaultOneParamCallback`, which is a callback function defined elsewhere in the code.
738
739
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
739
740
  * nodes are visited during the depth-first search. There are three possible values for `pattern`:
740
741
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the depth-first
@@ -744,7 +745,7 @@ class BinaryTree {
744
745
  * iteration used in the depth-first search algorithm. It can have two possible values:
745
746
  * @returns The function `dfs` returns an array of `ReturnType<BTNCallback<N>>` values.
746
747
  */
747
- dfs(callback = ((node) => node.key), pattern = 'in', beginRoot = this.root, iterationType = types_1.IterationType.ITERATIVE) {
748
+ dfs(callback = this.defaultOneParamCallback, pattern = 'in', beginRoot = this.root, iterationType = types_1.IterationType.ITERATIVE) {
748
749
  if (!beginRoot)
749
750
  return [];
750
751
  const ans = [];
@@ -819,7 +820,7 @@ class BinaryTree {
819
820
  * function on each node.
820
821
  * @param callback - The `callback` parameter is a function that will be called for each node in the
821
822
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
822
- * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `((node: N) => node.key)
823
+ * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `this.defaultOneParamCallback
823
824
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
824
825
  * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
825
826
  * will not be performed and an empty array will be returned.
@@ -827,7 +828,7 @@ class BinaryTree {
827
828
  * in the breadth-first search (BFS) algorithm. It can have two possible values:
828
829
  * @returns The function `bfs` returns an array of `ReturnType<BTNCallback<N>>[]`.
829
830
  */
830
- bfs(callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
831
+ bfs(callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
831
832
  if (!beginRoot)
832
833
  return [];
833
834
  const ans = [];
@@ -877,7 +878,7 @@ class BinaryTree {
877
878
  * level in a binary tree. Each inner array contains the return type of the provided callback
878
879
  * function `C` applied to the nodes at that level.
879
880
  */
880
- listLevels(callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
881
+ listLevels(callback = this.defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
881
882
  if (!beginRoot)
882
883
  return [];
883
884
  const levelsNodes = [];
@@ -952,7 +953,7 @@ class BinaryTree {
952
953
  * algorithm and returns an array of values obtained by applying a callback function to each node.
953
954
  * @param callback - The `callback` parameter is a function that will be called on each node in the
954
955
  * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The
955
- * default value for this parameter is `((node: N) => node.key)`.
956
+ * default value for this parameter is `this.defaultOneParamCallback`.
956
957
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
957
958
  * determines the order in which the nodes of a binary tree are traversed. It can have one of the
958
959
  * following values:
@@ -961,7 +962,7 @@ class BinaryTree {
961
962
  * `beginRoot` is `null`, an empty array will be returned.
962
963
  * @returns The `morris` function returns an array of `ReturnType<BTNCallback<N>>` values.
963
964
  */
964
- morris(callback = ((node) => node.key), pattern = 'in', beginRoot = this.root) {
965
+ morris(callback = this.defaultOneParamCallback, pattern = 'in', beginRoot = this.root) {
965
966
  if (beginRoot === null)
966
967
  return [];
967
968
  const ans = [];
@@ -54,25 +54,6 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
54
54
  * @returns The `addMany` function returns an array of `N`, `null`, or `undefined` values.
55
55
  */
56
56
  addMany(keysOrNodes: (BTNKey | null)[] | (N | null)[], data?: V[], isBalanceAdd?: boolean, iterationType?: IterationType): (N | null | undefined)[];
57
- /**
58
- * The function returns the first node in the binary tree that matches the given node property and
59
- * callback.
60
- * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
61
- * property of the binary tree node that you want to search for. It can be either a specific key
62
- * value (`BTNKey`) or a custom callback function (`BTNCallback<N>`) that determines
63
- * whether a node matches the desired property.
64
- * @param callback - The `callback` parameter is a function that is used to determine whether a node
65
- * matches the desired property. It takes a node as input and returns a boolean value indicating
66
- * whether the node matches the property or not. If no callback function is provided, the default
67
- * callback function `_defaultCallbackByKey` is used
68
- * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
69
- * the root node from which the search should begin.
70
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
71
- * be performed when searching for nodes in the binary tree. It can have one of the following values:
72
- * @returns either the first node that matches the given nodeProperty and callback, or null if no
73
- * matching node is found.
74
- */
75
- getNode<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
76
57
  /**
77
58
  * The function `lastKey` returns the key of the rightmost node if the comparison result is less
78
59
  * than, the key of the leftmost node if the comparison result is greater than, and the key of the
@@ -97,7 +78,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
97
78
  * generic type `N`.
98
79
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
99
80
  * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
100
- * included in the result. The default value for `callback` is `((node: N) => node.key)`, which is
81
+ * included in the result. The default value for `callback` is `this.defaultOneParamCallback`, which is
101
82
  * a
102
83
  * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
103
84
  * the first node that matches the nodeProperty. If set to true, the function will return an array
@@ -205,28 +205,6 @@ class BST extends binary_tree_1.BinaryTree {
205
205
  }
206
206
  return inserted;
207
207
  }
208
- /**
209
- * The function returns the first node in the binary tree that matches the given node property and
210
- * callback.
211
- * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
212
- * property of the binary tree node that you want to search for. It can be either a specific key
213
- * value (`BTNKey`) or a custom callback function (`BTNCallback<N>`) that determines
214
- * whether a node matches the desired property.
215
- * @param callback - The `callback` parameter is a function that is used to determine whether a node
216
- * matches the desired property. It takes a node as input and returns a boolean value indicating
217
- * whether the node matches the property or not. If no callback function is provided, the default
218
- * callback function `_defaultCallbackByKey` is used
219
- * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
220
- * the root node from which the search should begin.
221
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
222
- * be performed when searching for nodes in the binary tree. It can have one of the following values:
223
- * @returns either the first node that matches the given nodeProperty and callback, or null if no
224
- * matching node is found.
225
- */
226
- getNode(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
227
- var _a;
228
- return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : null;
229
- }
230
208
  /**
231
209
  * The function `lastKey` returns the key of the rightmost node if the comparison result is less
232
210
  * than, the key of the leftmost node if the comparison result is greater than, and the key of the
@@ -259,7 +237,7 @@ class BST extends binary_tree_1.BinaryTree {
259
237
  * generic type `N`.
260
238
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
261
239
  * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
262
- * included in the result. The default value for `callback` is `((node: N) => node.key)`, which is
240
+ * included in the result. The default value for `callback` is `this.defaultOneParamCallback`, which is
263
241
  * a
264
242
  * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
265
243
  * the first node that matches the nodeProperty. If set to true, the function will return an array
@@ -272,7 +250,7 @@ class BST extends binary_tree_1.BinaryTree {
272
250
  * traverse the binary tree. It can have one of the following values:
273
251
  * @returns an array of nodes (N[]).
274
252
  */
275
- getNodes(identifier, callback = ((node) => node.key), onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
253
+ getNodes(identifier, callback = this.defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
276
254
  if (!beginRoot)
277
255
  return [];
278
256
  const ans = [];
@@ -287,7 +265,7 @@ class BST extends binary_tree_1.BinaryTree {
287
265
  if (!cur.left && !cur.right)
288
266
  return;
289
267
  // TODO potential bug
290
- if (callback === ((node) => node.key)) {
268
+ if (callback === this.defaultOneParamCallback) {
291
269
  if (this._compare(cur.key, identifier) === types_1.CP.gt)
292
270
  cur.left && _traverse(cur.left);
293
271
  if (this._compare(cur.key, identifier) === types_1.CP.lt)
@@ -312,7 +290,7 @@ class BST extends binary_tree_1.BinaryTree {
312
290
  return ans;
313
291
  }
314
292
  // TODO potential bug
315
- if (callback === ((node) => node.key)) {
293
+ if (callback === this.defaultOneParamCallback) {
316
294
  if (this._compare(cur.key, identifier) === types_1.CP.gt)
317
295
  cur.left && queue.push(cur.left);
318
296
  if (this._compare(cur.key, identifier) === types_1.CP.lt)
@@ -345,7 +323,7 @@ class BST extends binary_tree_1.BinaryTree {
345
323
  * done recursively or iteratively. It can have two possible values:
346
324
  * @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
347
325
  */
348
- lesserOrGreaterTraverse(callback = ((node) => node.key), lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) {
326
+ lesserOrGreaterTraverse(callback = this.defaultOneParamCallback, lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) {
349
327
  if (typeof targetNode === 'number')
350
328
  targetNode = this.getNode(targetNode);
351
329
  const ans = [];
@@ -98,7 +98,7 @@ export declare class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = Tr
98
98
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
99
99
  * value. This value is compared with the `identifier` parameter to determine if the node should be
100
100
  * included in the result. The `callback` parameter has a default value of
101
- * `((node: N) => node.key)`
101
+ * `this.defaultOneParamCallback`
102
102
  * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
103
103
  * being deleted. If set to true, the count of the node will not be considered and the node will be
104
104
  * deleted regardless of its count. If set to false (default), the count of the node will be
@@ -251,14 +251,14 @@ class TreeMultiset extends avl_tree_1.AVLTree {
251
251
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
252
252
  * value. This value is compared with the `identifier` parameter to determine if the node should be
253
253
  * included in the result. The `callback` parameter has a default value of
254
- * `((node: N) => node.key)`
254
+ * `this.defaultOneParamCallback`
255
255
  * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
256
256
  * being deleted. If set to true, the count of the node will not be considered and the node will be
257
257
  * deleted regardless of its count. If set to false (default), the count of the node will be
258
258
  * decremented by 1 and
259
259
  * @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
260
260
  */
261
- delete(identifier, callback = ((node) => node.key), ignoreCount = false) {
261
+ delete(identifier, callback = this.defaultOneParamCallback, ignoreCount = false) {
262
262
  const bstDeletedResult = [];
263
263
  if (!this.root)
264
264
  return bstDeletedResult;
@@ -172,21 +172,21 @@ class AbstractGraph {
172
172
  return [];
173
173
  }
174
174
  const dfs = (cur, dest, visiting, path) => {
175
- visiting.set(cur, true);
175
+ visiting.add(cur);
176
176
  if (cur === dest) {
177
177
  paths.push([vertex1, ...path]);
178
178
  }
179
179
  const neighbors = this.getNeighbors(cur);
180
180
  for (const neighbor of neighbors) {
181
- if (!visiting.get(neighbor)) {
181
+ if (!visiting.has(neighbor)) {
182
182
  path.push(neighbor);
183
183
  dfs(neighbor, dest, visiting, path);
184
- (0, utils_1.arrayRemove)(path, (vertex) => vertex === neighbor);
184
+ path.pop();
185
185
  }
186
186
  }
187
- visiting.set(cur, false);
187
+ visiting.delete(cur);
188
188
  };
189
- dfs(vertex1, vertex2, new Map(), []);
189
+ dfs(vertex1, vertex2, new Set(), []);
190
190
  return paths;
191
191
  }
192
192
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "min-heap-typed",
3
- "version": "1.41.5",
3
+ "version": "1.41.7",
4
4
  "description": "Min Heap. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -132,6 +132,6 @@
132
132
  "typescript": "^4.9.5"
133
133
  },
134
134
  "dependencies": {
135
- "data-structure-typed": "^1.41.5"
135
+ "data-structure-typed": "^1.41.7"
136
136
  }
137
137
  }
@@ -70,12 +70,12 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
70
70
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
71
71
  * value. This value is compared with the `identifier` parameter to determine if the node should be
72
72
  * included in the result. The `callback` parameter has a default value of
73
- * `((node: N) => node.key)`
73
+ * `this.defaultOneParamCallback`
74
74
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
75
75
  */
76
76
  override delete<C extends BTNCallback<N>>(
77
77
  identifier: ReturnType<C>,
78
- callback: C = ((node: N) => node.key) as C
78
+ callback: C = this.defaultOneParamCallback as C
79
79
  ): BinaryTreeDeletedResult<N>[] {
80
80
  if ((identifier as any) instanceof AVLTreeNode) callback = (node => node) as C;
81
81
  const deletedResults = super.delete(identifier, callback);
@@ -141,6 +141,8 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
141
141
  return this._size;
142
142
  }
143
143
 
144
+ protected defaultOneParamCallback = (node: N) => node.key;
145
+
144
146
  /**
145
147
  * Creates a new instance of BinaryTreeNode with the given key and value.
146
148
  * @param {BTNKey} key - The key for the new node.
@@ -284,11 +286,11 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
284
286
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
285
287
  * value. This value is compared with the `identifier` parameter to determine if the node should be
286
288
  * included in the result. The `callback` parameter has a default value of
287
- * `((node: N) => node.key)`, which
289
+ * `this.defaultOneParamCallback`, which
288
290
  */
289
291
  delete<C extends BTNCallback<N>>(
290
292
  identifier: ReturnType<C> | null,
291
- callback: C = ((node: N) => node.key) as C
293
+ callback: C = this.defaultOneParamCallback as C
292
294
  ): BinaryTreeDeletedResult<N>[] {
293
295
  const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
294
296
  if (!this.root) return bstDeletedResult;
@@ -506,7 +508,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
506
508
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
507
509
  * value. This value is compared with the `identifier` parameter to determine if the node should be
508
510
  * included in the result. The `callback` parameter has a default value of
509
- * `((node: N) => node.key)`, which
511
+ * `this.defaultOneParamCallback`, which
510
512
  * @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the
511
513
  * first node that matches the identifier. If set to true, the function will return an array with
512
514
  * only one element (or an empty array if no matching node is found). If set to false (default), the
@@ -520,7 +522,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
520
522
  */
521
523
  getNodes<C extends BTNCallback<N>>(
522
524
  identifier: ReturnType<C> | null,
523
- callback: C = ((node: N) => node.key) as C,
525
+ callback: C = this.defaultOneParamCallback as C,
524
526
  onlyOne = false,
525
527
  beginRoot: N | null = this.root,
526
528
  iterationType = this.iterationType
@@ -588,7 +590,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
588
590
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
589
591
  * matches the desired criteria. It takes a node as input and returns a boolean value indicating
590
592
  * whether the node matches the criteria or not. The default callback function
591
- * `((node: N) => node.key)` is used if no callback function is
593
+ * `this.defaultOneParamCallback` is used if no callback function is
592
594
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
593
595
  * the node from which the search should begin. By default, it is set to `this.root`, which means the
594
596
  * search will start from the root node of the binary tree. However, you can provide a different node
@@ -599,7 +601,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
599
601
  */
600
602
  has<C extends BTNCallback<N>>(
601
603
  identifier: ReturnType<C> | null,
602
- callback: C = ((node: N) => node.key) as C,
604
+ callback: C = this.defaultOneParamCallback as C,
603
605
  beginRoot = this.root,
604
606
  iterationType = this.iterationType
605
607
  ): boolean {
@@ -637,7 +639,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
637
639
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
638
640
  * matches the desired criteria. It takes a node as input and returns a boolean value indicating
639
641
  * whether the node matches the criteria or not. The default callback function
640
- * (`((node: N) => node.key)`) is used if no callback function is
642
+ * (`this.defaultOneParamCallback`) is used if no callback function is
641
643
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
642
644
  * the root node from which the search should begin.
643
645
  * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
@@ -646,7 +648,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
646
648
  */
647
649
  getNode<C extends BTNCallback<N>>(
648
650
  identifier: ReturnType<C> | null,
649
- callback: C = ((node: N) => node.key) as C,
651
+ callback: C = this.defaultOneParamCallback as C,
650
652
  beginRoot = this.root,
651
653
  iterationType = this.iterationType
652
654
  ): N | null {
@@ -684,7 +686,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
684
686
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
685
687
  * matches the desired criteria. It takes a node as input and returns a boolean value indicating
686
688
  * whether the node matches the criteria or not. The default callback function
687
- * (`((node: N) => node.key)`) is used if no callback function is
689
+ * (`this.defaultOneParamCallback`) is used if no callback function is
688
690
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
689
691
  * the root node from which the search should begin.
690
692
  * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
@@ -693,7 +695,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
693
695
  */
694
696
  get<C extends BTNCallback<N>>(
695
697
  identifier: ReturnType<C> | null,
696
- callback: C = ((node: N) => node.key) as C,
698
+ callback: C = this.defaultOneParamCallback as C,
697
699
  beginRoot = this.root,
698
700
  iterationType = this.iterationType
699
701
  ): V | undefined {
@@ -859,7 +861,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
859
861
  * @returns The function `subTreeTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
860
862
  */
861
863
  subTreeTraverse<C extends BTNCallback<N>>(
862
- callback: C = ((node: N) => node.key) as C,
864
+ callback: C = this.defaultOneParamCallback as C,
863
865
  beginRoot: BTNKey | N | null = this.root,
864
866
  iterationType = this.iterationType
865
867
  ): ReturnType<C>[] {
@@ -895,7 +897,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
895
897
  * function on each node according to a specified order pattern.
896
898
  * @param callback - The `callback` parameter is a function that will be called on each node during
897
899
  * the depth-first search traversal. It takes a node as input and returns a value. The default value
898
- * is `((node: N) => node.key)`, which is a callback function defined elsewhere in the code.
900
+ * is `this.defaultOneParamCallback`, which is a callback function defined elsewhere in the code.
899
901
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
900
902
  * nodes are visited during the depth-first search. There are three possible values for `pattern`:
901
903
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the depth-first
@@ -906,7 +908,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
906
908
  * @returns The function `dfs` returns an array of `ReturnType<BTNCallback<N>>` values.
907
909
  */
908
910
  dfs<C extends BTNCallback<N>>(
909
- callback: C = ((node: N) => node.key) as C,
911
+ callback: C = this.defaultOneParamCallback as C,
910
912
  pattern: DFSOrderPattern = 'in',
911
913
  beginRoot: N | null = this.root,
912
914
  iterationType: IterationType = IterationType.ITERATIVE
@@ -981,7 +983,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
981
983
  * function on each node.
982
984
  * @param callback - The `callback` parameter is a function that will be called for each node in the
983
985
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
984
- * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `((node: N) => node.key)
986
+ * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `this.defaultOneParamCallback
985
987
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
986
988
  * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
987
989
  * will not be performed and an empty array will be returned.
@@ -990,7 +992,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
990
992
  * @returns The function `bfs` returns an array of `ReturnType<BTNCallback<N>>[]`.
991
993
  */
992
994
  bfs<C extends BTNCallback<N>>(
993
- callback: C = ((node: N) => node.key) as C,
995
+ callback: C = this.defaultOneParamCallback as C,
994
996
  beginRoot: N | null = this.root,
995
997
  iterationType = this.iterationType
996
998
  ): ReturnType<C>[] {
@@ -1047,7 +1049,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1047
1049
  * function `C` applied to the nodes at that level.
1048
1050
  */
1049
1051
  listLevels<C extends BTNCallback<N>>(
1050
- callback: C = ((node: N) => node.key) as C,
1052
+ callback: C = this.defaultOneParamCallback as C,
1051
1053
  beginRoot: N | null = this.root,
1052
1054
  iterationType = this.iterationType
1053
1055
  ): ReturnType<C>[][] {
@@ -1126,7 +1128,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1126
1128
  * algorithm and returns an array of values obtained by applying a callback function to each node.
1127
1129
  * @param callback - The `callback` parameter is a function that will be called on each node in the
1128
1130
  * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The
1129
- * default value for this parameter is `((node: N) => node.key)`.
1131
+ * default value for this parameter is `this.defaultOneParamCallback`.
1130
1132
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
1131
1133
  * determines the order in which the nodes of a binary tree are traversed. It can have one of the
1132
1134
  * following values:
@@ -1136,7 +1138,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
1136
1138
  * @returns The `morris` function returns an array of `ReturnType<BTNCallback<N>>` values.
1137
1139
  */
1138
1140
  morris<C extends BTNCallback<N>>(
1139
- callback: C = ((node: N) => node.key) as C,
1141
+ callback: C = this.defaultOneParamCallback as C,
1140
1142
  pattern: DFSOrderPattern = 'in',
1141
1143
  beginRoot: N | null = this.root
1142
1144
  ): ReturnType<C>[] {
@@ -36,7 +36,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
36
36
  }
37
37
  }
38
38
  }
39
-
39
+
40
40
  /**
41
41
  * The function creates a new binary search tree node with the given key and value.
42
42
  * @param {BTNKey} key - The key parameter is the key value that will be associated with
@@ -216,33 +216,6 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
216
216
  return inserted;
217
217
  }
218
218
 
219
- /**
220
- * The function returns the first node in the binary tree that matches the given node property and
221
- * callback.
222
- * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
223
- * property of the binary tree node that you want to search for. It can be either a specific key
224
- * value (`BTNKey`) or a custom callback function (`BTNCallback<N>`) that determines
225
- * whether a node matches the desired property.
226
- * @param callback - The `callback` parameter is a function that is used to determine whether a node
227
- * matches the desired property. It takes a node as input and returns a boolean value indicating
228
- * whether the node matches the property or not. If no callback function is provided, the default
229
- * callback function `_defaultCallbackByKey` is used
230
- * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
231
- * the root node from which the search should begin.
232
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
233
- * be performed when searching for nodes in the binary tree. It can have one of the following values:
234
- * @returns either the first node that matches the given nodeProperty and callback, or null if no
235
- * matching node is found.
236
- */
237
- override getNode<C extends BTNCallback<N>>(
238
- identifier: ReturnType<C> | null,
239
- callback: C = ((node: N) => node.key) as C,
240
- beginRoot = this.root,
241
- iterationType = this.iterationType
242
- ): N | null {
243
- return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? null;
244
- }
245
-
246
219
  /**
247
220
  * The function `lastKey` returns the key of the rightmost node if the comparison result is less
248
221
  * than, the key of the leftmost node if the comparison result is greater than, and the key of the
@@ -272,7 +245,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
272
245
  * generic type `N`.
273
246
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
274
247
  * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
275
- * included in the result. The default value for `callback` is `((node: N) => node.key)`, which is
248
+ * included in the result. The default value for `callback` is `this.defaultOneParamCallback`, which is
276
249
  * a
277
250
  * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
278
251
  * the first node that matches the nodeProperty. If set to true, the function will return an array
@@ -287,7 +260,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
287
260
  */
288
261
  override getNodes<C extends BTNCallback<N>>(
289
262
  identifier: ReturnType<C> | null,
290
- callback: C = ((node: N) => node.key) as C,
263
+ callback: C = this.defaultOneParamCallback as C,
291
264
  onlyOne = false,
292
265
  beginRoot: N | null = this.root,
293
266
  iterationType = this.iterationType
@@ -305,7 +278,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
305
278
 
306
279
  if (!cur.left && !cur.right) return;
307
280
  // TODO potential bug
308
- if (callback === ((node: N) => node.key)) {
281
+ if (callback === this.defaultOneParamCallback) {
309
282
  if (this._compare(cur.key, identifier as number) === CP.gt) cur.left && _traverse(cur.left);
310
283
  if (this._compare(cur.key, identifier as number) === CP.lt) cur.right && _traverse(cur.right);
311
284
  } else {
@@ -326,7 +299,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
326
299
  if (onlyOne) return ans;
327
300
  }
328
301
  // TODO potential bug
329
- if (callback === ((node: N) => node.key)) {
302
+ if (callback === this.defaultOneParamCallback) {
330
303
  if (this._compare(cur.key, identifier as number) === CP.gt) cur.left && queue.push(cur.left);
331
304
  if (this._compare(cur.key, identifier as number) === CP.lt) cur.right && queue.push(cur.right);
332
305
  } else {
@@ -360,7 +333,7 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
360
333
  * @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
361
334
  */
362
335
  lesserOrGreaterTraverse<C extends BTNCallback<N>>(
363
- callback: C = ((node: N) => node.key) as C,
336
+ callback: C = this.defaultOneParamCallback as C,
364
337
  lesserOrGreater: CP = CP.lt,
365
338
  targetNode: BTNKey | N | null = this.root,
366
339
  iterationType = this.iterationType
@@ -268,7 +268,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
268
268
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
269
269
  * value. This value is compared with the `identifier` parameter to determine if the node should be
270
270
  * included in the result. The `callback` parameter has a default value of
271
- * `((node: N) => node.key)`
271
+ * `this.defaultOneParamCallback`
272
272
  * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
273
273
  * being deleted. If set to true, the count of the node will not be considered and the node will be
274
274
  * deleted regardless of its count. If set to false (default), the count of the node will be
@@ -277,7 +277,7 @@ export class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = TreeMultis
277
277
  */
278
278
  override delete<C extends BTNCallback<N>>(
279
279
  identifier: ReturnType<C>,
280
- callback: C = ((node: N) => node.key) as C,
280
+ callback: C = this.defaultOneParamCallback as C,
281
281
  ignoreCount = false
282
282
  ): BinaryTreeDeletedResult<N>[] {
283
283
  const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
@@ -233,8 +233,8 @@ export abstract class AbstractGraph<
233
233
  return [];
234
234
  }
235
235
 
236
- const dfs = (cur: VO, dest: VO, visiting: Map<VO, boolean>, path: VO[]) => {
237
- visiting.set(cur, true);
236
+ const dfs = (cur: VO, dest: VO, visiting: Set<VO>, path: VO[]) => {
237
+ visiting.add(cur);
238
238
 
239
239
  if (cur === dest) {
240
240
  paths.push([vertex1, ...path]);
@@ -242,17 +242,17 @@ export abstract class AbstractGraph<
242
242
 
243
243
  const neighbors = this.getNeighbors(cur);
244
244
  for (const neighbor of neighbors) {
245
- if (!visiting.get(neighbor)) {
245
+ if (!visiting.has(neighbor)) {
246
246
  path.push(neighbor);
247
247
  dfs(neighbor, dest, visiting, path);
248
- arrayRemove(path, (vertex: VO) => vertex === neighbor);
248
+ path.pop();
249
249
  }
250
250
  }
251
251
 
252
- visiting.set(cur, false);
252
+ visiting.delete(cur);
253
253
  };
254
254
 
255
- dfs(vertex1, vertex2, new Map<VO, boolean>(), []);
255
+ dfs(vertex1, vertex2, new Set<VO>(), []);
256
256
  return paths;
257
257
  }
258
258