avl-tree-typed 2.2.2 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/cjs/index.cjs +245 -72
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +246 -72
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +245 -72
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +246 -72
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -2
  10. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -5
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +98 -5
  12. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +103 -7
  13. package/dist/types/data-structures/binary-tree/bst.d.ts +202 -39
  14. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +86 -37
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +4 -5
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +7 -7
  17. package/dist/types/data-structures/graph/directed-graph.d.ts +126 -1
  18. package/dist/types/data-structures/graph/undirected-graph.d.ts +160 -1
  19. package/dist/types/data-structures/hash/hash-map.d.ts +110 -27
  20. package/dist/types/data-structures/heap/heap.d.ts +107 -58
  21. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +72 -404
  22. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -5
  23. package/dist/types/data-structures/queue/deque.d.ts +95 -67
  24. package/dist/types/data-structures/queue/queue.d.ts +90 -34
  25. package/dist/types/data-structures/stack/stack.d.ts +58 -40
  26. package/dist/types/data-structures/trie/trie.d.ts +109 -47
  27. package/dist/types/interfaces/binary-tree.d.ts +1 -0
  28. package/dist/types/types/data-structures/binary-tree/bst.d.ts +5 -5
  29. package/dist/umd/avl-tree-typed.js +246 -72
  30. package/dist/umd/avl-tree-typed.js.map +1 -1
  31. package/dist/umd/avl-tree-typed.min.js +3 -3
  32. package/dist/umd/avl-tree-typed.min.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/data-structures/binary-tree/avl-tree-counter.ts +1 -2
  35. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +7 -8
  36. package/src/data-structures/binary-tree/avl-tree.ts +100 -7
  37. package/src/data-structures/binary-tree/binary-tree.ts +117 -7
  38. package/src/data-structures/binary-tree/bst.ts +431 -93
  39. package/src/data-structures/binary-tree/red-black-tree.ts +85 -37
  40. package/src/data-structures/binary-tree/tree-counter.ts +5 -7
  41. package/src/data-structures/binary-tree/tree-multi-map.ts +9 -10
  42. package/src/data-structures/graph/directed-graph.ts +126 -1
  43. package/src/data-structures/graph/undirected-graph.ts +160 -1
  44. package/src/data-structures/hash/hash-map.ts +110 -27
  45. package/src/data-structures/heap/heap.ts +107 -58
  46. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -404
  47. package/src/data-structures/linked-list/singly-linked-list.ts +121 -5
  48. package/src/data-structures/queue/deque.ts +95 -67
  49. package/src/data-structures/queue/queue.ts +90 -34
  50. package/src/data-structures/stack/stack.ts +58 -40
  51. package/src/data-structures/trie/trie.ts +109 -47
  52. package/src/interfaces/binary-tree.ts +2 -0
  53. package/src/types/data-structures/binary-tree/bst.ts +5 -5
@@ -1461,6 +1461,17 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1461
1461
  }
1462
1462
  return false;
1463
1463
  }
1464
+ /**
1465
+ * Adds or updates a new node to the tree.
1466
+ * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation adds the node at the first available position in a level-order (BFS) traversal. This is NOT a Binary Search Tree insertion. Time O(N), where N is the number of nodes. It must traverse level-by-level to find an empty slot. Space O(N) in the worst case for the BFS queue (e.g., a full last level).
1467
+ *
1468
+ * @param keyNodeOrEntry - The key, node, or entry to add or update.
1469
+ * @param [value] - The value, if providing just a key.
1470
+ * @returns True if the addition was successful, false otherwise.
1471
+ */
1472
+ set(keyNodeOrEntry, value) {
1473
+ return this.add(keyNodeOrEntry, value);
1474
+ }
1464
1475
  /**
1465
1476
  * Adds multiple items to the tree.
1466
1477
  * @remarks Time O(N * M), where N is the number of items to add and M is the size of the tree at insertion (due to O(M) `add` operation). Space O(M) (from `add`) + O(N) (for the `inserted` array).
@@ -1488,6 +1499,17 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1488
1499
  }
1489
1500
  return inserted;
1490
1501
  }
1502
+ /**
1503
+ * Adds or updates multiple items to the tree.
1504
+ * @remarks Time O(N * M), where N is the number of items to add and M is the size of the tree at insertion (due to O(M) `add` operation). Space O(M) (from `add`) + O(N) (for the `inserted` array).
1505
+ *
1506
+ * @param keysNodesEntriesOrRaws - An iterable of items to add or update.
1507
+ * @param [values] - An optional parallel iterable of values.
1508
+ * @returns An array of booleans indicating the success of each individual `add` operation.
1509
+ */
1510
+ setMany(keysNodesEntriesOrRaws, values) {
1511
+ return this.addMany(keysNodesEntriesOrRaws, values);
1512
+ }
1491
1513
  /**
1492
1514
  * Merges another tree into this one by adding all its nodes.
1493
1515
  * @remarks Time O(N * M), same as `addMany`, where N is the size of `anotherTree` and M is the size of this tree. Space O(M) (from `add`).
@@ -2804,36 +2826,20 @@ var _BST = class _BST extends BinaryTree {
2804
2826
  constructor(keysNodesEntriesOrRaws = [], options) {
2805
2827
  super([], options);
2806
2828
  __publicField(this, "_root");
2807
- __publicField(this, "_isReverse", false);
2808
2829
  /**
2809
- * The default comparator function.
2810
- * @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
2811
- */
2812
- __publicField(this, "_comparator", /* @__PURE__ */ __name((a, b) => {
2813
- if (isComparable(a) && isComparable(b)) {
2814
- if (a > b) return 1;
2815
- if (a < b) return -1;
2816
- return 0;
2817
- }
2818
- if (this._specifyComparable) {
2819
- const va = this._specifyComparable(a);
2820
- const vb = this._specifyComparable(b);
2821
- if (va > vb) return 1;
2822
- if (va < vb) return -1;
2823
- return 0;
2824
- }
2825
- if (typeof a === "object" || typeof b === "object") {
2826
- throw TypeError(
2827
- `When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
2828
- );
2829
- }
2830
- return 0;
2831
- }, "_comparator"));
2832
- __publicField(this, "_specifyComparable");
2830
+ * The comparator function used to determine the order of keys in the tree.
2831
+
2832
+ * @remarks Time O(1) Space O(1)
2833
+ */
2834
+ __publicField(this, "_comparator");
2833
2835
  if (options) {
2834
- const { specifyComparable, isReverse } = options;
2835
- if (typeof specifyComparable === "function") this._specifyComparable = specifyComparable;
2836
- if (isReverse !== void 0) this._isReverse = isReverse;
2836
+ if ("comparator" in options && options.comparator !== void 0) {
2837
+ this._comparator = options.comparator;
2838
+ } else {
2839
+ this._comparator = this._createDefaultComparator();
2840
+ }
2841
+ } else {
2842
+ this._comparator = this._createDefaultComparator();
2837
2843
  }
2838
2844
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
2839
2845
  }
@@ -2847,13 +2853,25 @@ var _BST = class _BST extends BinaryTree {
2847
2853
  return this._root;
2848
2854
  }
2849
2855
  /**
2850
- * Gets whether the tree's comparison logic is reversed.
2851
- * @remarks Time O(1)
2852
- *
2853
- * @returns True if the tree is reversed (e.g., a max-heap logic).
2856
+ * (Protected) Creates the default comparator function for keys that don't have a custom comparator.
2857
+ * @remarks Time O(1) Space O(1)
2858
+ * @returns The default comparator function.
2854
2859
  */
2855
- get isReverse() {
2856
- return this._isReverse;
2860
+ _createDefaultComparator() {
2861
+ return (a, b) => {
2862
+ debugger;
2863
+ if (isComparable(a) && isComparable(b)) {
2864
+ if (a > b) return 1;
2865
+ if (a < b) return -1;
2866
+ return 0;
2867
+ }
2868
+ if (typeof a === "object" || typeof b === "object") {
2869
+ throw TypeError(
2870
+ `When comparing object type keys, a custom comparator must be provided in the constructor's options!`
2871
+ );
2872
+ }
2873
+ return 0;
2874
+ };
2857
2875
  }
2858
2876
  /**
2859
2877
  * Gets the comparator function used by the tree.
@@ -2864,15 +2882,6 @@ var _BST = class _BST extends BinaryTree {
2864
2882
  get comparator() {
2865
2883
  return this._comparator;
2866
2884
  }
2867
- /**
2868
- * Gets the function used to extract a comparable value from a complex key.
2869
- * @remarks Time O(1)
2870
- *
2871
- * @returns The key-to-comparable conversion function.
2872
- */
2873
- get specifyComparable() {
2874
- return this._specifyComparable;
2875
- }
2876
2885
  /**
2877
2886
  * (Protected) Creates a new BST node.
2878
2887
  * @remarks Time O(1), Space O(1)
@@ -2914,7 +2923,7 @@ var _BST = class _BST extends BinaryTree {
2914
2923
  * @returns True if the key is valid, false otherwise.
2915
2924
  */
2916
2925
  isValidKey(key) {
2917
- return isComparable(key, this._specifyComparable !== void 0);
2926
+ return isComparable(key);
2918
2927
  }
2919
2928
  /**
2920
2929
  * Performs a Depth-First Search (DFS) traversal.
@@ -3004,8 +3013,8 @@ var _BST = class _BST extends BinaryTree {
3004
3013
  if (!this.isRealNode(cur.left)) return false;
3005
3014
  if (isRange) {
3006
3015
  const range = keyNodeEntryOrPredicate;
3007
- const leftS = this.isReverse ? range.high : range.low;
3008
- const leftI = this.isReverse ? range.includeHigh : range.includeLow;
3016
+ const leftS = range.low;
3017
+ const leftI = range.includeLow;
3009
3018
  return leftI && this._compare(cur.key, leftS) >= 0 || !leftI && this._compare(cur.key, leftS) > 0;
3010
3019
  }
3011
3020
  if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
@@ -3019,8 +3028,8 @@ var _BST = class _BST extends BinaryTree {
3019
3028
  if (!this.isRealNode(cur.right)) return false;
3020
3029
  if (isRange) {
3021
3030
  const range = keyNodeEntryOrPredicate;
3022
- const rightS = this.isReverse ? range.low : range.high;
3023
- const rightI = this.isReverse ? range.includeLow : range.includeHigh;
3031
+ const rightS = range.high;
3032
+ const rightI = range.includeHigh;
3024
3033
  return rightI && this._compare(cur.key, rightS) <= 0 || !rightI && this._compare(cur.key, rightS) < 0;
3025
3034
  }
3026
3035
  if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
@@ -3181,6 +3190,32 @@ var _BST = class _BST extends BinaryTree {
3181
3190
  else _iterate();
3182
3191
  return inserted;
3183
3192
  }
3193
+ /**
3194
+ * Returns the first node with a key greater than or equal to the given key.
3195
+ * This is equivalent to C++ std::lower_bound on a BST.
3196
+ * Supports RECURSIVE and ITERATIVE implementations.
3197
+ * Time Complexity: O(log n) on average, O(h) where h is tree height.
3198
+ * Space Complexity: O(h) for recursion, O(1) for iteration.
3199
+ * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
3200
+ * @param iterationType The iteration type (RECURSIVE or ITERATIVE). Defaults to this.iterationType.
3201
+ * @returns The first node with key >= given key, or undefined if no such node exists.
3202
+ */
3203
+ lowerBound(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
3204
+ return this._bound(keyNodeEntryOrPredicate, true, iterationType);
3205
+ }
3206
+ /**
3207
+ * Returns the first node with a key strictly greater than the given key.
3208
+ * This is equivalent to C++ std::upper_bound on a BST.
3209
+ * Supports RECURSIVE and ITERATIVE implementations.
3210
+ * Time Complexity: O(log n) on average, O(h) where h is tree height.
3211
+ * Space Complexity: O(h) for recursion, O(1) for iteration.
3212
+ * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
3213
+ * @param iterationType The iteration type (RECURSIVE or ITERATIVE). Defaults to this.iterationType.
3214
+ * @returns The first node with key > given key, or undefined if no such node exists.
3215
+ */
3216
+ upperBound(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
3217
+ return this._bound(keyNodeEntryOrPredicate, false, iterationType);
3218
+ }
3184
3219
  /**
3185
3220
  * Traverses the tree and returns nodes that are lesser or greater than a target node.
3186
3221
  * @remarks Time O(N), as it performs a full traversal. Space O(log N) or O(N).
@@ -3315,31 +3350,171 @@ var _BST = class _BST extends BinaryTree {
3315
3350
  return out;
3316
3351
  }
3317
3352
  /**
3318
- * Deletes the first node found that satisfies the predicate.
3319
- * @remarks Performs an in-order traversal. Time O(N) worst-case (O(log N) to find + O(log N) to delete). Space O(log N) for stack.
3353
+ * Deletes nodes that match a key, node, entry, predicate, or range.
3320
3354
  *
3321
- * @param predicate - A function to test each [key, value] pair.
3322
- * @returns True if a node was deleted, false otherwise.
3355
+ * @remarks
3356
+ * Time Complexity: O(N) for search + O(M log N) for M deletions, where N is tree size.
3357
+ * Space Complexity: O(M) for storing matched nodes and result map.
3358
+ *
3359
+ * @template K - The key type.
3360
+ * @template V - The value type.
3361
+ *
3362
+ * @param keyNodeEntryOrPredicate - The search criteria. Can be one of:
3363
+ * - A key (type K): searches for exact key match using the comparator.
3364
+ * - A BSTNode: searches for the matching node in the tree.
3365
+ * - An entry tuple: searches for the key-value pair.
3366
+ * - A NodePredicate function: tests each node and returns true for matches.
3367
+ * - A Range object: searches for nodes whose keys fall within the specified range (inclusive/exclusive based on range settings).
3368
+ * - null or undefined: treated as no match, returns empty results.
3369
+ *
3370
+ * @param onlyOne - If true, stops the search after finding the first match and only deletes that one node.
3371
+ * If false (default), searches for and deletes all matching nodes.
3372
+ *
3373
+ * @param startNode - The node to start the search from. Can be:
3374
+ * - A key, node, or entry: the method resolves it to a node and searches from that subtree.
3375
+ * - null or undefined: defaults to the root, searching the entire tree.
3376
+ * - Default value: this._root (the tree's root).
3377
+ *
3378
+ * @param iterationType - Controls the internal traversal implementation:
3379
+ * - 'RECURSIVE': uses recursive function calls for traversal.
3380
+ * - 'ITERATIVE': uses explicit stack-based iteration.
3381
+ * - Default: this.iterationType (the tree's default iteration mode).
3382
+ *
3383
+ * @returns A Map<K, boolean> containing the deletion results:
3384
+ * - Key: the matched node's key.
3385
+ * - Value: true if the deletion succeeded, false if it failed (e.g., key not found during deletion phase).
3386
+ * - If no nodes match the search criteria, the returned map is empty.
3387
+ */
3388
+ deleteWhere(keyNodeEntryOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
3389
+ const toDelete = this.search(
3390
+ keyNodeEntryOrPredicate,
3391
+ onlyOne,
3392
+ (node) => node,
3393
+ startNode,
3394
+ iterationType
3395
+ );
3396
+ let results = [];
3397
+ for (const node of toDelete) {
3398
+ const deleteInfo = this.delete(node);
3399
+ results = results.concat(deleteInfo);
3400
+ }
3401
+ return results;
3402
+ }
3403
+ /**
3404
+ * (Protected) Core bound search implementation supporting all parameter types.
3405
+ * Unified logic for both lowerBound and upperBound.
3406
+ * Resolves various input types (Key, Node, Entry, Predicate) using parent class utilities.
3407
+ * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
3408
+ * @param isLower - True for lowerBound (>=), false for upperBound (>).
3409
+ * @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
3410
+ * @returns The first matching node, or undefined if no such node exists.
3323
3411
  */
3324
- deleteWhere(predicate) {
3325
- const stack = [];
3326
- let cur = this._root;
3327
- let index = 0;
3328
- while (stack.length > 0 || cur !== void 0) {
3329
- while (cur !== void 0 && cur !== null) {
3330
- stack.push(cur);
3331
- cur = cur.left;
3412
+ _bound(keyNodeEntryOrPredicate, isLower, iterationType) {
3413
+ if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === void 0) {
3414
+ return void 0;
3415
+ }
3416
+ if (this._isPredicate(keyNodeEntryOrPredicate)) {
3417
+ return this._boundByPredicate(keyNodeEntryOrPredicate, iterationType);
3418
+ }
3419
+ let targetKey;
3420
+ if (this.isNode(keyNodeEntryOrPredicate)) {
3421
+ targetKey = keyNodeEntryOrPredicate.key;
3422
+ } else if (this.isEntry(keyNodeEntryOrPredicate)) {
3423
+ const key = keyNodeEntryOrPredicate[0];
3424
+ if (key === null || key === void 0) {
3425
+ return void 0;
3426
+ }
3427
+ targetKey = key;
3428
+ } else {
3429
+ targetKey = keyNodeEntryOrPredicate;
3430
+ }
3431
+ if (targetKey !== void 0) {
3432
+ return this._boundByKey(targetKey, isLower, iterationType);
3433
+ }
3434
+ return void 0;
3435
+ }
3436
+ /**
3437
+ * (Protected) Binary search for bound by key with pruning optimization.
3438
+ * Performs standard BST binary search, choosing left or right subtree based on comparator result.
3439
+ * For lowerBound: finds first node where key >= target.
3440
+ * For upperBound: finds first node where key > target.
3441
+ * @param key - The target key to search for.
3442
+ * @param isLower - True for lowerBound (>=), false for upperBound (>).
3443
+ * @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
3444
+ * @returns The first node matching the bound condition, or undefined if none exists.
3445
+ */
3446
+ _boundByKey(key, isLower, iterationType) {
3447
+ var _a, _b;
3448
+ if (iterationType === "RECURSIVE") {
3449
+ const dfs = /* @__PURE__ */ __name((cur) => {
3450
+ if (!this.isRealNode(cur)) return void 0;
3451
+ const cmp = this.comparator(cur.key, key);
3452
+ const condition = isLower ? cmp >= 0 : cmp > 0;
3453
+ if (condition) {
3454
+ const leftResult = dfs(cur.left);
3455
+ return leftResult != null ? leftResult : cur;
3456
+ } else {
3457
+ return dfs(cur.right);
3458
+ }
3459
+ }, "dfs");
3460
+ return dfs(this.root);
3461
+ } else {
3462
+ let current = this.root;
3463
+ let result = void 0;
3464
+ while (this.isRealNode(current)) {
3465
+ const cmp = this.comparator(current.key, key);
3466
+ const condition = isLower ? cmp >= 0 : cmp > 0;
3467
+ if (condition) {
3468
+ result = current;
3469
+ current = (_a = current.left) != null ? _a : void 0;
3470
+ } else {
3471
+ current = (_b = current.right) != null ? _b : void 0;
3472
+ }
3332
3473
  }
3333
- const node = stack.pop();
3334
- if (!node) break;
3335
- const key = node.key;
3336
- const val = node.value;
3337
- if (predicate(key, val, index++, this)) {
3338
- return this._deleteByKey(key);
3474
+ return result;
3475
+ }
3476
+ }
3477
+ /**
3478
+ * (Protected) In-order traversal search by predicate.
3479
+ * Falls back to linear in-order traversal when predicate-based search is required.
3480
+ * Returns the first node that satisfies the predicate function.
3481
+ * Note: Predicate-based search cannot leverage BST's binary search optimization.
3482
+ * Time Complexity: O(n) since it may visit every node.
3483
+ * @param predicate - The predicate function to test nodes.
3484
+ * @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
3485
+ * @returns The first node satisfying predicate, or undefined if none found.
3486
+ */
3487
+ _boundByPredicate(predicate, iterationType) {
3488
+ if (iterationType === "RECURSIVE") {
3489
+ let result = void 0;
3490
+ const dfs = /* @__PURE__ */ __name((cur) => {
3491
+ if (result || !this.isRealNode(cur)) return;
3492
+ if (this.isRealNode(cur.left)) dfs(cur.left);
3493
+ if (!result && predicate(cur)) {
3494
+ result = cur;
3495
+ }
3496
+ if (!result && this.isRealNode(cur.right)) dfs(cur.right);
3497
+ }, "dfs");
3498
+ dfs(this.root);
3499
+ return result;
3500
+ } else {
3501
+ const stack = [];
3502
+ let current = this.root;
3503
+ while (stack.length > 0 || this.isRealNode(current)) {
3504
+ if (this.isRealNode(current)) {
3505
+ stack.push(current);
3506
+ current = current.left;
3507
+ } else {
3508
+ const node = stack.pop();
3509
+ if (!this.isRealNode(node)) break;
3510
+ if (predicate(node)) {
3511
+ return node;
3512
+ }
3513
+ current = node.right;
3514
+ }
3339
3515
  }
3340
- cur = node.right;
3516
+ return void 0;
3341
3517
  }
3342
- return false;
3343
3518
  }
3344
3519
  /**
3345
3520
  * (Protected) Creates a new, empty instance of the same BST constructor.
@@ -3376,8 +3551,7 @@ var _BST = class _BST extends BinaryTree {
3376
3551
  _snapshotOptions() {
3377
3552
  return {
3378
3553
  ...super._snapshotOptions(),
3379
- specifyComparable: this.specifyComparable,
3380
- isReverse: this.isReverse
3554
+ comparator: this._comparator
3381
3555
  };
3382
3556
  }
3383
3557
  /**
@@ -3405,14 +3579,14 @@ var _BST = class _BST extends BinaryTree {
3405
3579
  }
3406
3580
  /**
3407
3581
  * (Protected) Compares two keys using the tree's comparator and reverse setting.
3408
- * @remarks Time O(1) (or O(C) if `specifyComparable` is used).
3582
+ * @remarks Time O(1) Space O(1)
3409
3583
  *
3410
3584
  * @param a - The first key.
3411
3585
  * @param b - The second key.
3412
3586
  * @returns A number (1, -1, or 0) representing the comparison.
3413
3587
  */
3414
3588
  _compare(a, b) {
3415
- return this._isReverse ? -this._comparator(a, b) : this._comparator(a, b);
3589
+ return this._comparator(a, b);
3416
3590
  }
3417
3591
  /**
3418
3592
  * (Private) Deletes a node by its key.