linked-list-typed 1.52.8 → 1.52.9

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.
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, IterationType, BTNEntry } from '../../types';
8
+ import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, IterationType, BTNEntry } from '../../types';
9
9
  import { IBinaryTree } from '../../interfaces';
10
10
  import { AVLTree, AVLTreeNode } from './avl-tree';
11
11
  export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
@@ -127,9 +127,9 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
127
127
  *
128
128
  * The function overrides the delete method in a binary tree data structure, handling deletion of
129
129
  * nodes and maintaining balance in the tree.
130
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
130
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
131
131
  * parameter in the `delete` method is used to specify the condition for deleting a node from the
132
- * binary tree. It can be a key, node, entry, or a custom predicate function that determines which
132
+ * binary tree. It can be a key, node, or entry that determines which
133
133
  * node(s) should be deleted.
134
134
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
135
135
  * boolean flag that determines whether to ignore the count of the node being deleted. If
@@ -140,7 +140,7 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
140
140
  * method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
141
141
  * deleted node and whether balancing is needed in the tree.
142
142
  */
143
- delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
143
+ delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
144
144
  /**
145
145
  * Time Complexity: O(1)
146
146
  * Space Complexity: O(1)
@@ -175,9 +175,9 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
175
175
  *
176
176
  * The function overrides the delete method in a binary tree data structure, handling deletion of
177
177
  * nodes and maintaining balance in the tree.
178
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
178
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
179
179
  * parameter in the `delete` method is used to specify the condition for deleting a node from the
180
- * binary tree. It can be a key, node, entry, or a custom predicate function that determines which
180
+ * binary tree. It can be a key, node, or entry that determines which
181
181
  * node(s) should be deleted.
182
182
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
183
183
  * boolean flag that determines whether to ignore the count of the node being deleted. If
@@ -188,12 +188,12 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
188
188
  * method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
189
189
  * deleted node and whether balancing is needed in the tree.
190
190
  */
191
- delete(predicate, ignoreCount = false) {
191
+ delete(keyOrNodeOrEntryOrRaw, ignoreCount = false) {
192
192
  var _a;
193
193
  const deletedResult = [];
194
194
  if (!this.root)
195
195
  return deletedResult;
196
- const curr = (_a = this.getNode(predicate)) !== null && _a !== void 0 ? _a : undefined;
196
+ const curr = (_a = this.getNode(keyOrNodeOrEntryOrRaw)) !== null && _a !== void 0 ? _a : undefined;
197
197
  if (!curr)
198
198
  return deletedResult;
199
199
  const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : undefined;
@@ -6,7 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, BTNEntry } from '../../types';
9
+ import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNEntry } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
12
12
  /**
@@ -99,14 +99,14 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
99
99
  *
100
100
  * The function overrides the delete method in a TypeScript class, performs deletion, and then
101
101
  * balances the tree if necessary.
102
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
102
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
103
103
  * parameter in the `override delete` method can be one of the following types:
104
104
  * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
105
105
  * method from the superclass (presumably a parent class) with the provided `predicate`, which could
106
106
  * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
107
107
  * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
108
108
  */
109
- delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
109
+ delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
110
110
  /**
111
111
  * Time Complexity: O(1)
112
112
  * Space Complexity: O(1)
@@ -124,15 +124,15 @@ class AVLTree extends bst_1.BST {
124
124
  *
125
125
  * The function overrides the delete method in a TypeScript class, performs deletion, and then
126
126
  * balances the tree if necessary.
127
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
127
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
128
128
  * parameter in the `override delete` method can be one of the following types:
129
129
  * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
130
130
  * method from the superclass (presumably a parent class) with the provided `predicate`, which could
131
131
  * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
132
132
  * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
133
133
  */
134
- delete(predicate) {
135
- const deletedResults = super.delete(predicate);
134
+ delete(keyOrNodeOrEntryOrRaw) {
135
+ const deletedResults = super.delete(keyOrNodeOrEntryOrRaw);
136
136
  for (const { needBalanced } of deletedResults) {
137
137
  if (needBalanced) {
138
138
  this._balancePath(needBalanced);
@@ -235,16 +235,16 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
235
235
  *
236
236
  * The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
237
237
  * the deleted node along with information for tree balancing.
238
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
238
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw
239
239
  * - The `delete` method you provided is used to delete a node from a binary tree based on the key,
240
- * node, entry, raw data, or a custom predicate. The method returns an array of
240
+ * node, entry or raw data. The method returns an array of
241
241
  * `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
242
242
  * balancing is needed.
243
243
  * @returns The `delete` method returns an array of `BinaryTreeDeleteResult` objects. Each object in
244
244
  * the array contains information about the node that was deleted (`deleted`) and the node that may
245
245
  * need to be balanced (`needBalanced`).
246
246
  */
247
- delete(keyOrNodeOrEntryOrRawOrPredicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
247
+ delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
248
248
  /**
249
249
  * Time Complexity: O(n)
250
250
  * Space Complexity: O(k + log n)
@@ -657,8 +657,65 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
657
657
  * binary tree with the specified options.
658
658
  */
659
659
  toVisual(beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, options?: BinaryTreePrintOptions): string;
660
- protected _dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>[];
661
- protected _dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
660
+ /**
661
+ * Time Complexity: O(n)
662
+ * Space Complexity: O(n)
663
+ *
664
+ * The function `print` in TypeScript overrides the default print behavior to log a visual
665
+ * representation of the binary tree to the console.
666
+ * @param {BinaryTreePrintOptions} [options] - The `options` parameter is used to specify the
667
+ * printing options for the binary tree. It is an optional parameter that allows you to customize how
668
+ * the binary tree is printed, such as choosing between different traversal orders or formatting
669
+ * options.
670
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
671
+ * `override print` method is used to specify the starting point for printing the binary tree. It can
672
+ * be either a key, a node, an entry, or the root of the tree. If no specific starting point is
673
+ * provided, the default value is set to
674
+ */
675
+ print(options?: BinaryTreePrintOptions, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R): void;
676
+ /**
677
+ * Time complexity: O(n)
678
+ * Space complexity: O(n)
679
+ *
680
+ * The `_dfs` function performs a depth-first search traversal on a binary tree structure based on
681
+ * the specified order pattern and callback function.
682
+ * @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
683
+ * called on each node visited during the depth-first search traversal. It is of type `C`, which
684
+ * extends `BTNCallback<OptBTNOrNull<NODE>>`. The default value for this parameter is `this._DEFAULT
685
+ * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
686
+ * order in which the nodes are visited during the Depth-First Search traversal. It can have one of
687
+ * the following values:
688
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `_dfs`
689
+ * method is used to specify the starting point for the depth-first search traversal in a binary
690
+ * tree. It can be provided as either a `BTNKeyOrNodeOrEntry` object or a reference to the root node
691
+ * of the tree. If no specific
692
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `_dfs` method
693
+ * specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
694
+ * binary tree. It can have two possible values:
695
+ * @param [includeNull=false] - The `includeNull` parameter in the `_dfs` method is a boolean flag
696
+ * that determines whether null nodes should be included in the depth-first search traversal. If
697
+ * `includeNull` is set to `true`, null nodes will be considered during the traversal process. If it
698
+ * is set to `false`,
699
+ * @param shouldVisitLeft - The `shouldVisitLeft` parameter is a function that takes a node as input
700
+ * and returns a boolean value. It is used to determine whether the left child of a node should be
701
+ * visited during the depth-first search traversal. By default, it checks if the node is truthy (not
702
+ * null or undefined
703
+ * @param shouldVisitRight - The `shouldVisitRight` parameter is a function that takes a node as an
704
+ * argument and returns a boolean value. It is used to determine whether the right child of a node
705
+ * should be visited during the depth-first search traversal. The default implementation checks if
706
+ * the node is truthy before visiting the right child
707
+ * @param shouldVisitRoot - The `shouldVisitRoot` parameter is a function that takes a node as an
708
+ * argument and returns a boolean value. It is used to determine whether the root node should be
709
+ * visited during the depth-first search traversal based on certain conditions. The default
710
+ * implementation checks if the node is a real node or null based
711
+ * @param shouldProcessRoot - The `shouldProcessRoot` parameter is a function that takes a node as an
712
+ * argument and returns a boolean value indicating whether the node should be processed during the
713
+ * depth-first search traversal. The default implementation checks if the node is a real node or null
714
+ * based on the `includeNull` flag. If `
715
+ * @returns The function `_dfs` returns an array of the return type of the callback function provided
716
+ * as input.
717
+ */
718
+ protected _dfs<C extends BTNCallback<OptBTNOrNull<NODE>>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: boolean, shouldVisitLeft?: (node: OptBTNOrNull<NODE>) => boolean, shouldVisitRight?: (node: OptBTNOrNull<NODE>) => boolean, shouldVisitRoot?: (node: OptBTNOrNull<NODE>) => boolean, shouldProcessRoot?: (node: OptBTNOrNull<NODE>) => boolean): ReturnType<C>[];
662
719
  /**
663
720
  * Time Complexity: O(1)
664
721
  * Space Complexity: O(1)
@@ -430,20 +430,20 @@ class BinaryTree extends base_1.IterableEntryBase {
430
430
  *
431
431
  * The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
432
432
  * the deleted node along with information for tree balancing.
433
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
433
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw
434
434
  * - The `delete` method you provided is used to delete a node from a binary tree based on the key,
435
- * node, entry, raw data, or a custom predicate. The method returns an array of
435
+ * node, entry or raw data. The method returns an array of
436
436
  * `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
437
437
  * balancing is needed.
438
438
  * @returns The `delete` method returns an array of `BinaryTreeDeleteResult` objects. Each object in
439
439
  * the array contains information about the node that was deleted (`deleted`) and the node that may
440
440
  * need to be balanced (`needBalanced`).
441
441
  */
442
- delete(keyOrNodeOrEntryOrRawOrPredicate) {
442
+ delete(keyOrNodeOrEntryOrRaw) {
443
443
  const deletedResult = [];
444
444
  if (!this._root)
445
445
  return deletedResult;
446
- const curr = this.getNode(keyOrNodeOrEntryOrRawOrPredicate);
446
+ const curr = this.getNode(keyOrNodeOrEntryOrRaw);
447
447
  if (!curr)
448
448
  return deletedResult;
449
449
  const parent = curr === null || curr === void 0 ? void 0 : curr.parent;
@@ -1492,20 +1492,17 @@ class BinaryTree extends base_1.IterableEntryBase {
1492
1492
  * binary tree with the specified options.
1493
1493
  */
1494
1494
  toVisual(beginRoot = this._root, options) {
1495
- const opts = Object.assign({ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false }, options);
1495
+ const opts = Object.assign({ isShowUndefined: false, isShowNull: true, isShowRedBlackNIL: false }, options);
1496
1496
  beginRoot = this.ensureNode(beginRoot);
1497
1497
  let output = '';
1498
1498
  if (!beginRoot)
1499
1499
  return output;
1500
1500
  if (opts.isShowUndefined)
1501
- output += `U for undefined
1502
- `;
1501
+ output += `U for undefined\n`;
1503
1502
  if (opts.isShowNull)
1504
- output += `N for null
1505
- `;
1503
+ output += `N for null\n`;
1506
1504
  if (opts.isShowRedBlackNIL)
1507
- output += `S for Sentinel Node(NIL)
1508
- `;
1505
+ output += `S for Sentinel Node(NIL)\n`;
1509
1506
  const display = (root) => {
1510
1507
  const [lines, , ,] = this._displayAux(root, opts);
1511
1508
  let paragraph = '';
@@ -1517,6 +1514,24 @@ class BinaryTree extends base_1.IterableEntryBase {
1517
1514
  display(beginRoot);
1518
1515
  return output;
1519
1516
  }
1517
+ /**
1518
+ * Time Complexity: O(n)
1519
+ * Space Complexity: O(n)
1520
+ *
1521
+ * The function `print` in TypeScript overrides the default print behavior to log a visual
1522
+ * representation of the binary tree to the console.
1523
+ * @param {BinaryTreePrintOptions} [options] - The `options` parameter is used to specify the
1524
+ * printing options for the binary tree. It is an optional parameter that allows you to customize how
1525
+ * the binary tree is printed, such as choosing between different traversal orders or formatting
1526
+ * options.
1527
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
1528
+ * `override print` method is used to specify the starting point for printing the binary tree. It can
1529
+ * be either a key, a node, an entry, or the root of the tree. If no specific starting point is
1530
+ * provided, the default value is set to
1531
+ */
1532
+ print(options, beginRoot = this._root) {
1533
+ console.log(this.toVisual(beginRoot, options));
1534
+ }
1520
1535
  /**
1521
1536
  * Time complexity: O(n)
1522
1537
  * Space complexity: O(n)
@@ -246,23 +246,18 @@ class BST extends binary_tree_1.BinaryTree {
246
246
  if (!isBalanceAdd) {
247
247
  for (const kve of keysOrNodesOrEntriesOrRaws) {
248
248
  const value = valuesIterator === null || valuesIterator === void 0 ? void 0 : valuesIterator.next().value;
249
- const nn = this.add(kve, value);
250
- inserted.push(nn);
249
+ inserted.push(this.add(kve, value));
251
250
  }
252
251
  return inserted;
253
252
  }
254
253
  const realBTNExemplars = [];
255
- const isRealBTNExemplar = (kve) => {
256
- if (kve === undefined || kve === null)
257
- return false;
258
- return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null));
259
- };
254
+ let i = 0;
260
255
  for (const kve of keysOrNodesOrEntriesOrRaws) {
261
- if (isRealBTNExemplar(kve))
262
- realBTNExemplars.push(kve);
256
+ realBTNExemplars.push({ key: kve, value: valuesIterator === null || valuesIterator === void 0 ? void 0 : valuesIterator.next().value, orgIndex: i });
257
+ i++;
263
258
  }
264
259
  let sorted = [];
265
- sorted = realBTNExemplars.sort((a, b) => {
260
+ sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
266
261
  let keyA, keyB;
267
262
  if (this.isEntry(a))
268
263
  keyA = a[0];
@@ -293,8 +288,8 @@ class BST extends binary_tree_1.BinaryTree {
293
288
  if (arr.length === 0)
294
289
  return;
295
290
  const mid = Math.floor((arr.length - 1) / 2);
296
- const newNode = this.add(arr[mid]);
297
- inserted.push(newNode);
291
+ const { key, value, orgIndex } = arr[mid];
292
+ inserted[orgIndex] = this.add(key, value);
298
293
  _dfs(arr.slice(0, mid));
299
294
  _dfs(arr.slice(mid + 1));
300
295
  };
@@ -307,8 +302,8 @@ class BST extends binary_tree_1.BinaryTree {
307
302
  const [l, r] = popped;
308
303
  if (l <= r) {
309
304
  const m = l + Math.floor((r - l) / 2);
310
- const newNode = this.add(sorted[m]);
311
- inserted.push(newNode);
305
+ const { key, value, orgIndex } = sorted[m];
306
+ inserted[orgIndex] = this.add(key, value);
312
307
  stack.push([m + 1, r]);
313
308
  stack.push([l, m - 1]);
314
309
  }
@@ -1,4 +1,4 @@
1
- import type { BinaryTreeDeleteResult, BTNKeyOrNodeOrEntry, BTNPredicate, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested, BTNEntry } from '../../types';
1
+ import type { BinaryTreeDeleteResult, BTNKeyOrNodeOrEntry, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested, BTNEntry } from '../../types';
2
2
  import { BST, BSTNode } from './bst';
3
3
  import { IBinaryTree } from '../../interfaces';
4
4
  export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
@@ -107,7 +107,7 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
107
107
  *
108
108
  * The function overrides the delete method in a binary tree data structure to remove a node based on
109
109
  * a given predicate and maintain the binary search tree properties.
110
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
110
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
111
111
  * parameter in the `override delete` method is used to specify the condition or key based on which a
112
112
  * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
113
113
  * function that determines which node(s) should be deleted.
@@ -115,7 +115,7 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
115
115
  * objects. Each object in the array contains information about the deleted node and whether
116
116
  * balancing is needed.
117
117
  */
118
- delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
118
+ delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
119
119
  /**
120
120
  * Time Complexity: O(1)
121
121
  * Space Complexity: O(1)
@@ -184,7 +184,7 @@ class RedBlackTree extends bst_1.BST {
184
184
  *
185
185
  * The function overrides the delete method in a binary tree data structure to remove a node based on
186
186
  * a given predicate and maintain the binary search tree properties.
187
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
187
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
188
188
  * parameter in the `override delete` method is used to specify the condition or key based on which a
189
189
  * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
190
190
  * function that determines which node(s) should be deleted.
@@ -192,15 +192,17 @@ class RedBlackTree extends bst_1.BST {
192
192
  * objects. Each object in the array contains information about the deleted node and whether
193
193
  * balancing is needed.
194
194
  */
195
- delete(predicate) {
196
- if (predicate === null)
195
+ delete(keyOrNodeOrEntryOrRaw) {
196
+ if (keyOrNodeOrEntryOrRaw === null)
197
197
  return [];
198
198
  const results = [];
199
199
  let nodeToDelete;
200
- if (this._isPredicated(predicate))
201
- nodeToDelete = this.getNode(predicate);
200
+ if (this._isPredicated(keyOrNodeOrEntryOrRaw))
201
+ nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw);
202
202
  else
203
- nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
203
+ nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw)
204
+ ? keyOrNodeOrEntryOrRaw
205
+ : this.getNode(keyOrNodeOrEntryOrRaw);
204
206
  if (!nodeToDelete) {
205
207
  return results;
206
208
  }
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions, BTNEntry } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, IterationType, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions, BTNEntry } from '../../types';
9
9
  import { IBinaryTree } from '../../interfaces';
10
10
  import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
11
11
  export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
@@ -128,17 +128,16 @@ export declare class TreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE ext
128
128
  *
129
129
  * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
130
130
  * structure, handling cases where nodes have children and maintaining balance in the tree.
131
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
131
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
132
132
  * parameter in the `delete` method is used to specify the condition or key based on which a node
133
- * should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
134
- * function.
133
+ * should be deleted from the binary tree. It can be a key, a node, or an entry.
135
134
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
136
135
  * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
137
136
  * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
138
137
  * `ignoreCount` is `false
139
138
  * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
140
139
  */
141
- delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
140
+ delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
142
141
  /**
143
142
  * Time Complexity: O(1)
144
143
  * Space Complexity: O(1)
@@ -178,25 +178,26 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
178
178
  *
179
179
  * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
180
180
  * structure, handling cases where nodes have children and maintaining balance in the tree.
181
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
181
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
182
182
  * parameter in the `delete` method is used to specify the condition or key based on which a node
183
- * should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
184
- * function.
183
+ * should be deleted from the binary tree. It can be a key, a node, or an entry.
185
184
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
186
185
  * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
187
186
  * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
188
187
  * `ignoreCount` is `false
189
188
  * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
190
189
  */
191
- delete(predicate, ignoreCount = false) {
192
- if (predicate === null)
190
+ delete(keyOrNodeOrEntryOrRaw, ignoreCount = false) {
191
+ if (keyOrNodeOrEntryOrRaw === null)
193
192
  return [];
194
193
  const results = [];
195
194
  let nodeToDelete;
196
- if (this._isPredicated(predicate))
197
- nodeToDelete = this.getNode(predicate);
195
+ if (this._isPredicated(keyOrNodeOrEntryOrRaw))
196
+ nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw);
198
197
  else
199
- nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
198
+ nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw)
199
+ ? keyOrNodeOrEntryOrRaw
200
+ : this.getNode(keyOrNodeOrEntryOrRaw);
200
201
  if (!nodeToDelete) {
201
202
  return results;
202
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linked-list-typed",
3
- "version": "1.52.8",
3
+ "version": "1.52.9",
4
4
  "description": "Linked List, Doubly Linked List, Singly Linked List. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -66,6 +66,6 @@
66
66
  "typescript": "^4.9.5"
67
67
  },
68
68
  "dependencies": {
69
- "data-structure-typed": "^1.52.8"
69
+ "data-structure-typed": "^1.52.9"
70
70
  }
71
71
  }
@@ -12,7 +12,6 @@ import type {
12
12
  BinaryTreeDeleteResult,
13
13
  BSTNKeyOrNode,
14
14
  BTNKeyOrNodeOrEntry,
15
- BTNPredicate,
16
15
  IterationType,
17
16
  BTNEntry
18
17
  } from '../../types';
@@ -232,9 +231,9 @@ export class AVLTreeMultiMap<
232
231
  *
233
232
  * The function overrides the delete method in a binary tree data structure, handling deletion of
234
233
  * nodes and maintaining balance in the tree.
235
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
234
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
236
235
  * parameter in the `delete` method is used to specify the condition for deleting a node from the
237
- * binary tree. It can be a key, node, entry, or a custom predicate function that determines which
236
+ * binary tree. It can be a key, node, or entry that determines which
238
237
  * node(s) should be deleted.
239
238
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
240
239
  * boolean flag that determines whether to ignore the count of the node being deleted. If
@@ -246,13 +245,13 @@ export class AVLTreeMultiMap<
246
245
  * deleted node and whether balancing is needed in the tree.
247
246
  */
248
247
  override delete(
249
- predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>,
248
+ keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
250
249
  ignoreCount = false
251
250
  ): BinaryTreeDeleteResult<NODE>[] {
252
251
  const deletedResult: BinaryTreeDeleteResult<NODE>[] = [];
253
252
  if (!this.root) return deletedResult;
254
253
 
255
- const curr: NODE | undefined = this.getNode(predicate) ?? undefined;
254
+ const curr: NODE | undefined = this.getNode(keyOrNodeOrEntryOrRaw) ?? undefined;
256
255
  if (!curr) return deletedResult;
257
256
 
258
257
  const parent: NODE | undefined = curr?.parent ? curr.parent : undefined;
@@ -13,7 +13,6 @@ import type {
13
13
  BinaryTreeDeleteResult,
14
14
  BSTNKeyOrNode,
15
15
  BTNKeyOrNodeOrEntry,
16
- BTNPredicate,
17
16
  BTNEntry
18
17
  } from '../../types';
19
18
  import { IBinaryTree } from '../../interfaces';
@@ -160,15 +159,15 @@ export class AVLTree<
160
159
  *
161
160
  * The function overrides the delete method in a TypeScript class, performs deletion, and then
162
161
  * balances the tree if necessary.
163
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
162
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
164
163
  * parameter in the `override delete` method can be one of the following types:
165
164
  * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
166
165
  * method from the superclass (presumably a parent class) with the provided `predicate`, which could
167
166
  * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
168
167
  * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
169
168
  */
170
- override delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[] {
171
- const deletedResults = super.delete(predicate);
169
+ override delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[] {
170
+ const deletedResults = super.delete(keyOrNodeOrEntryOrRaw);
172
171
  for (const { needBalanced } of deletedResults) {
173
172
  if (needBalanced) {
174
173
  this._balancePath(needBalanced);
@@ -515,22 +515,20 @@ export class BinaryTree<
515
515
  *
516
516
  * The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
517
517
  * the deleted node along with information for tree balancing.
518
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
518
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw
519
519
  * - The `delete` method you provided is used to delete a node from a binary tree based on the key,
520
- * node, entry, raw data, or a custom predicate. The method returns an array of
520
+ * node, entry or raw data. The method returns an array of
521
521
  * `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
522
522
  * balancing is needed.
523
523
  * @returns The `delete` method returns an array of `BinaryTreeDeleteResult` objects. Each object in
524
524
  * the array contains information about the node that was deleted (`deleted`) and the node that may
525
525
  * need to be balanced (`needBalanced`).
526
526
  */
527
- delete(
528
- keyOrNodeOrEntryOrRawOrPredicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>
529
- ): BinaryTreeDeleteResult<NODE>[] {
527
+ delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[] {
530
528
  const deletedResult: BinaryTreeDeleteResult<NODE>[] = [];
531
529
  if (!this._root) return deletedResult;
532
530
 
533
- const curr = this.getNode(keyOrNodeOrEntryOrRawOrPredicate);
531
+ const curr = this.getNode(keyOrNodeOrEntryOrRaw);
534
532
  if (!curr) return deletedResult;
535
533
 
536
534
  const parent: NODE | undefined = curr?.parent;
@@ -1683,20 +1681,14 @@ export class BinaryTree<
1683
1681
  beginRoot: BTNKeyOrNodeOrEntry<K, V, NODE> | R = this._root,
1684
1682
  options?: BinaryTreePrintOptions
1685
1683
  ): string {
1686
- const opts = { isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false, ...options };
1684
+ const opts = { isShowUndefined: false, isShowNull: true, isShowRedBlackNIL: false, ...options };
1687
1685
  beginRoot = this.ensureNode(beginRoot);
1688
1686
  let output = '';
1689
1687
  if (!beginRoot) return output;
1690
1688
 
1691
- if (opts.isShowUndefined)
1692
- output += `U for undefined
1693
- `;
1694
- if (opts.isShowNull)
1695
- output += `N for null
1696
- `;
1697
- if (opts.isShowRedBlackNIL)
1698
- output += `S for Sentinel Node(NIL)
1699
- `;
1689
+ if (opts.isShowUndefined) output += `U for undefined\n`;
1690
+ if (opts.isShowNull) output += `N for null\n`;
1691
+ if (opts.isShowRedBlackNIL) output += `S for Sentinel Node(NIL)\n`;
1700
1692
 
1701
1693
  const display = (root: OptBTNOrNull<NODE>): void => {
1702
1694
  const [lines, , ,] = this._displayAux(root, opts);
@@ -1711,20 +1703,24 @@ export class BinaryTree<
1711
1703
  return output;
1712
1704
  }
1713
1705
 
1714
- protected _dfs<C extends BTNCallback<NODE>>(
1715
- callback?: C,
1716
- pattern?: DFSOrderPattern,
1717
- beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
1718
- iterationType?: IterationType
1719
- ): ReturnType<C>[];
1720
-
1721
- protected _dfs<C extends BTNCallback<NODE | null>>(
1722
- callback?: C,
1723
- pattern?: DFSOrderPattern,
1724
- beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
1725
- iterationType?: IterationType,
1726
- includeNull?: boolean
1727
- ): ReturnType<C>[];
1706
+ /**
1707
+ * Time Complexity: O(n)
1708
+ * Space Complexity: O(n)
1709
+ *
1710
+ * The function `print` in TypeScript overrides the default print behavior to log a visual
1711
+ * representation of the binary tree to the console.
1712
+ * @param {BinaryTreePrintOptions} [options] - The `options` parameter is used to specify the
1713
+ * printing options for the binary tree. It is an optional parameter that allows you to customize how
1714
+ * the binary tree is printed, such as choosing between different traversal orders or formatting
1715
+ * options.
1716
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
1717
+ * `override print` method is used to specify the starting point for printing the binary tree. It can
1718
+ * be either a key, a node, an entry, or the root of the tree. If no specific starting point is
1719
+ * provided, the default value is set to
1720
+ */
1721
+ override print(options?: BinaryTreePrintOptions, beginRoot: BTNKeyOrNodeOrEntry<K, V, NODE> | R = this._root) {
1722
+ console.log(this.toVisual(beginRoot, options));
1723
+ }
1728
1724
 
1729
1725
  /**
1730
1726
  * Time complexity: O(n)
@@ -14,7 +14,6 @@ import type {
14
14
  BTNEntry,
15
15
  BTNKeyOrNodeOrEntry,
16
16
  BTNPredicate,
17
- BTNPureKeyOrNodeOrEntry,
18
17
  Comparator,
19
18
  CP,
20
19
  DFSOrderPattern,
@@ -310,28 +309,26 @@ export class BST<
310
309
  if (!isBalanceAdd) {
311
310
  for (const kve of keysOrNodesOrEntriesOrRaws) {
312
311
  const value = valuesIterator?.next().value;
313
- const nn = this.add(kve, value);
314
- inserted.push(nn);
312
+ inserted.push(this.add(kve, value));
315
313
  }
316
314
  return inserted;
317
315
  }
318
316
 
319
- const realBTNExemplars: (R | BTNPureKeyOrNodeOrEntry<K, V, NODE>)[] = [];
320
-
321
- const isRealBTNExemplar = (
322
- kve: BTNKeyOrNodeOrEntry<K, V, NODE> | R
323
- ): kve is BTNPureKeyOrNodeOrEntry<K, V, NODE> => {
324
- if (kve === undefined || kve === null) return false;
325
- return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null));
326
- };
317
+ const realBTNExemplars: {
318
+ key: R | BTNKeyOrNodeOrEntry<K, V, NODE>;
319
+ value: V | undefined;
320
+ orgIndex: number;
321
+ }[] = [];
327
322
 
323
+ let i = 0;
328
324
  for (const kve of keysOrNodesOrEntriesOrRaws) {
329
- if (isRealBTNExemplar(kve)) realBTNExemplars.push(kve);
325
+ realBTNExemplars.push({ key: kve, value: valuesIterator?.next().value, orgIndex: i });
326
+ i++;
330
327
  }
331
328
 
332
- let sorted: (R | BTNPureKeyOrNodeOrEntry<K, V, NODE>)[] = [];
329
+ let sorted: { key: R | BTNKeyOrNodeOrEntry<K, V, NODE>; value: V | undefined; orgIndex: number }[] = [];
333
330
 
334
- sorted = realBTNExemplars.sort((a, b) => {
331
+ sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
335
332
  let keyA: K | undefined | null, keyB: K | undefined | null;
336
333
  if (this.isEntry(a)) keyA = a[0];
337
334
  else if (this.isRealNode(a)) keyA = a.key;
@@ -355,12 +352,12 @@ export class BST<
355
352
  return 0;
356
353
  });
357
354
 
358
- const _dfs = (arr: (R | BTNPureKeyOrNodeOrEntry<K, V, NODE>)[]) => {
355
+ const _dfs = (arr: { key: R | BTNKeyOrNodeOrEntry<K, V, NODE>; value: V | undefined; orgIndex: number }[]) => {
359
356
  if (arr.length === 0) return;
360
357
 
361
358
  const mid = Math.floor((arr.length - 1) / 2);
362
- const newNode = this.add(arr[mid]);
363
- inserted.push(newNode);
359
+ const { key, value, orgIndex } = arr[mid];
360
+ inserted[orgIndex] = this.add(key, value);
364
361
  _dfs(arr.slice(0, mid));
365
362
  _dfs(arr.slice(mid + 1));
366
363
  };
@@ -374,8 +371,8 @@ export class BST<
374
371
  const [l, r] = popped;
375
372
  if (l <= r) {
376
373
  const m = l + Math.floor((r - l) / 2);
377
- const newNode = this.add(sorted[m]);
378
- inserted.push(newNode);
374
+ const { key, value, orgIndex } = sorted[m];
375
+ inserted[orgIndex] = this.add(key, value);
379
376
  stack.push([m + 1, r]);
380
377
  stack.push([l, m - 1]);
381
378
  }
@@ -1,7 +1,6 @@
1
1
  import type {
2
2
  BinaryTreeDeleteResult,
3
3
  BTNKeyOrNodeOrEntry,
4
- BTNPredicate,
5
4
  CRUD,
6
5
  OptBSTN,
7
6
  RBTNColor,
@@ -230,7 +229,7 @@ export class RedBlackTree<
230
229
  *
231
230
  * The function overrides the delete method in a binary tree data structure to remove a node based on
232
231
  * a given predicate and maintain the binary search tree properties.
233
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
232
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
234
233
  * parameter in the `override delete` method is used to specify the condition or key based on which a
235
234
  * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
236
235
  * function that determines which node(s) should be deleted.
@@ -238,13 +237,16 @@ export class RedBlackTree<
238
237
  * objects. Each object in the array contains information about the deleted node and whether
239
238
  * balancing is needed.
240
239
  */
241
- override delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[] {
242
- if (predicate === null) return [];
240
+ override delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[] {
241
+ if (keyOrNodeOrEntryOrRaw === null) return [];
243
242
 
244
243
  const results: BinaryTreeDeleteResult<NODE>[] = [];
245
244
  let nodeToDelete: OptBSTN<NODE>;
246
- if (this._isPredicated(predicate)) nodeToDelete = this.getNode(predicate);
247
- else nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
245
+ if (this._isPredicated(keyOrNodeOrEntryOrRaw)) nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw);
246
+ else
247
+ nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw)
248
+ ? keyOrNodeOrEntryOrRaw
249
+ : this.getNode(keyOrNodeOrEntryOrRaw);
248
250
 
249
251
  if (!nodeToDelete) {
250
252
  return results;
@@ -9,7 +9,6 @@ import type {
9
9
  BinaryTreeDeleteResult,
10
10
  BSTNKeyOrNode,
11
11
  BTNKeyOrNodeOrEntry,
12
- BTNPredicate,
13
12
  IterationType,
14
13
  OptBSTN,
15
14
  RBTNColor,
@@ -232,10 +231,9 @@ export class TreeMultiMap<
232
231
  *
233
232
  * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
234
233
  * structure, handling cases where nodes have children and maintaining balance in the tree.
235
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
234
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
236
235
  * parameter in the `delete` method is used to specify the condition or key based on which a node
237
- * should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
238
- * function.
236
+ * should be deleted from the binary tree. It can be a key, a node, or an entry.
239
237
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
240
238
  * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
241
239
  * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
@@ -243,16 +241,19 @@ export class TreeMultiMap<
243
241
  * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
244
242
  */
245
243
  override delete(
246
- predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>,
244
+ keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R,
247
245
  ignoreCount = false
248
246
  ): BinaryTreeDeleteResult<NODE>[] {
249
- if (predicate === null) return [];
247
+ if (keyOrNodeOrEntryOrRaw === null) return [];
250
248
 
251
249
  const results: BinaryTreeDeleteResult<NODE>[] = [];
252
250
 
253
251
  let nodeToDelete: OptBSTN<NODE>;
254
- if (this._isPredicated(predicate)) nodeToDelete = this.getNode(predicate);
255
- else nodeToDelete = this.isRealNode(predicate) ? predicate : this.getNode(predicate);
252
+ if (this._isPredicated(keyOrNodeOrEntryOrRaw)) nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw);
253
+ else
254
+ nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw)
255
+ ? keyOrNodeOrEntryOrRaw
256
+ : this.getNode(keyOrNodeOrEntryOrRaw);
256
257
 
257
258
  if (!nodeToDelete) {
258
259
  return results;