data-structure-typed 2.2.3 → 2.2.5

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 (36) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/README.md +70 -11
  3. package/dist/cjs/index.cjs +341 -75
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs-legacy/index.cjs +343 -75
  6. package/dist/cjs-legacy/index.cjs.map +1 -1
  7. package/dist/esm/index.mjs +341 -75
  8. package/dist/esm/index.mjs.map +1 -1
  9. package/dist/esm-legacy/index.mjs +343 -75
  10. package/dist/esm-legacy/index.mjs.map +1 -1
  11. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -2
  12. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -5
  13. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +142 -28
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +2 -2
  16. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +4 -5
  17. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -5
  18. package/dist/types/types/data-structures/binary-tree/bst.d.ts +5 -5
  19. package/dist/umd/data-structure-typed.js +343 -75
  20. package/dist/umd/data-structure-typed.js.map +1 -1
  21. package/dist/umd/data-structure-typed.min.js +3 -3
  22. package/dist/umd/data-structure-typed.min.js.map +1 -1
  23. package/package.json +2 -2
  24. package/src/data-structures/binary-tree/avl-tree-counter.ts +1 -2
  25. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +9 -8
  26. package/src/data-structures/binary-tree/avl-tree.ts +4 -5
  27. package/src/data-structures/binary-tree/bst.ts +495 -85
  28. package/src/data-structures/binary-tree/red-black-tree.ts +1 -2
  29. package/src/data-structures/binary-tree/tree-counter.ts +5 -7
  30. package/src/data-structures/binary-tree/tree-multi-map.ts +7 -8
  31. package/src/types/data-structures/binary-tree/bst.ts +5 -5
  32. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +2 -2
  33. package/test/unit/data-structures/binary-tree/bst.test.ts +459 -8
  34. package/test/unit/data-structures/binary-tree/overall.test.ts +2 -2
  35. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +1 -1
  36. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +2 -2
@@ -8634,9 +8634,13 @@ var BST = class extends BinaryTree {
8634
8634
  constructor(keysNodesEntriesOrRaws = [], options) {
8635
8635
  super([], options);
8636
8636
  if (options) {
8637
- const { specifyComparable, isReverse } = options;
8638
- if (typeof specifyComparable === "function") this._specifyComparable = specifyComparable;
8639
- if (isReverse !== void 0) this._isReverse = isReverse;
8637
+ if ("comparator" in options && options.comparator !== void 0) {
8638
+ this._comparator = options.comparator;
8639
+ } else {
8640
+ this._comparator = this._createDefaultComparator();
8641
+ }
8642
+ } else {
8643
+ this._comparator = this._createDefaultComparator();
8640
8644
  }
8641
8645
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
8642
8646
  }
@@ -8650,40 +8654,12 @@ var BST = class extends BinaryTree {
8650
8654
  get root() {
8651
8655
  return this._root;
8652
8656
  }
8653
- _isReverse = false;
8654
- /**
8655
- * Gets whether the tree's comparison logic is reversed.
8656
- * @remarks Time O(1)
8657
- *
8658
- * @returns True if the tree is reversed (e.g., a max-heap logic).
8659
- */
8660
- get isReverse() {
8661
- return this._isReverse;
8662
- }
8663
8657
  /**
8664
- * The default comparator function.
8665
- * @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
8666
- */
8667
- _comparator = /* @__PURE__ */ __name((a, b) => {
8668
- if (isComparable(a) && isComparable(b)) {
8669
- if (a > b) return 1;
8670
- if (a < b) return -1;
8671
- return 0;
8672
- }
8673
- if (this._specifyComparable) {
8674
- const va = this._specifyComparable(a);
8675
- const vb = this._specifyComparable(b);
8676
- if (va > vb) return 1;
8677
- if (va < vb) return -1;
8678
- return 0;
8679
- }
8680
- if (typeof a === "object" || typeof b === "object") {
8681
- throw TypeError(
8682
- `When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
8683
- );
8684
- }
8685
- return 0;
8686
- }, "_comparator");
8658
+ * The comparator function used to determine the order of keys in the tree.
8659
+
8660
+ * @remarks Time O(1) Space O(1)
8661
+ */
8662
+ _comparator;
8687
8663
  /**
8688
8664
  * Gets the comparator function used by the tree.
8689
8665
  * @remarks Time O(1)
@@ -8693,16 +8669,6 @@ var BST = class extends BinaryTree {
8693
8669
  get comparator() {
8694
8670
  return this._comparator;
8695
8671
  }
8696
- _specifyComparable;
8697
- /**
8698
- * Gets the function used to extract a comparable value from a complex key.
8699
- * @remarks Time O(1)
8700
- *
8701
- * @returns The key-to-comparable conversion function.
8702
- */
8703
- get specifyComparable() {
8704
- return this._specifyComparable;
8705
- }
8706
8672
  /**
8707
8673
  * (Protected) Creates a new BST node.
8708
8674
  * @remarks Time O(1), Space O(1)
@@ -8743,7 +8709,7 @@ var BST = class extends BinaryTree {
8743
8709
  * @returns True if the key is valid, false otherwise.
8744
8710
  */
8745
8711
  isValidKey(key) {
8746
- return isComparable(key, this._specifyComparable !== void 0);
8712
+ return isComparable(key);
8747
8713
  }
8748
8714
  /**
8749
8715
  * Performs a Depth-First Search (DFS) traversal.
@@ -8832,8 +8798,8 @@ var BST = class extends BinaryTree {
8832
8798
  if (!this.isRealNode(cur.left)) return false;
8833
8799
  if (isRange) {
8834
8800
  const range = keyNodeEntryOrPredicate;
8835
- const leftS = this.isReverse ? range.high : range.low;
8836
- const leftI = this.isReverse ? range.includeHigh : range.includeLow;
8801
+ const leftS = range.low;
8802
+ const leftI = range.includeLow;
8837
8803
  return leftI && this._compare(cur.key, leftS) >= 0 || !leftI && this._compare(cur.key, leftS) > 0;
8838
8804
  }
8839
8805
  if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
@@ -8847,8 +8813,8 @@ var BST = class extends BinaryTree {
8847
8813
  if (!this.isRealNode(cur.right)) return false;
8848
8814
  if (isRange) {
8849
8815
  const range = keyNodeEntryOrPredicate;
8850
- const rightS = this.isReverse ? range.low : range.high;
8851
- const rightI = this.isReverse ? range.includeLow : range.includeHigh;
8816
+ const rightS = range.high;
8817
+ const rightI = range.includeHigh;
8852
8818
  return rightI && this._compare(cur.key, rightS) <= 0 || !rightI && this._compare(cur.key, rightS) < 0;
8853
8819
  }
8854
8820
  if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
@@ -9035,6 +9001,104 @@ var BST = class extends BinaryTree {
9035
9001
  upperBound(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
9036
9002
  return this._bound(keyNodeEntryOrPredicate, false, iterationType);
9037
9003
  }
9004
+ /**
9005
+ * Returns the first node with a key greater than or equal to the given key.
9006
+ * This is equivalent to Java TreeMap.ceilingEntry().
9007
+ * Supports RECURSIVE and ITERATIVE implementations.
9008
+ * @remarks Time Complexity: O(log n) on average, O(h) where h is tree height.
9009
+ * Space Complexity: O(h) for recursion, O(1) for iteration.
9010
+ *
9011
+ * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
9012
+ * @param [iterationType=this.iterationType] - The iteration type (RECURSIVE or ITERATIVE).
9013
+ * @returns The first node with key >= given key, or undefined if no such node exists.
9014
+ */
9015
+ ceilingEntry(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
9016
+ return this.lowerBound(keyNodeEntryOrPredicate, iterationType);
9017
+ }
9018
+ /**
9019
+ * Returns the first node with a key strictly greater than the given key.
9020
+ * This is equivalent to Java TreeMap.higherEntry().
9021
+ * Supports RECURSIVE and ITERATIVE implementations.
9022
+ * @remarks Time Complexity: O(log n) on average, O(h) where h is tree height.
9023
+ * Space Complexity: O(h) for recursion, O(1) for iteration.
9024
+ *
9025
+ * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
9026
+ * @param [iterationType=this.iterationType] - The iteration type (RECURSIVE or ITERATIVE).
9027
+ * @returns The first node with key > given key, or undefined if no such node exists.
9028
+ */
9029
+ higherEntry(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
9030
+ return this.upperBound(keyNodeEntryOrPredicate, iterationType);
9031
+ }
9032
+ /**
9033
+ * Returns the first node with a key less than or equal to the given key.
9034
+ * This is equivalent to Java TreeMap.floorEntry().
9035
+ * Supports RECURSIVE and ITERATIVE implementations.
9036
+ * @remarks Time Complexity: O(log n) on average, O(h) where h is tree height.
9037
+ * Space Complexity: O(h) for recursion, O(1) for iteration.
9038
+ *
9039
+ * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
9040
+ * @param [iterationType=this.iterationType] - The iteration type (RECURSIVE or ITERATIVE).
9041
+ * @returns The first node with key <= given key, or undefined if no such node exists.
9042
+ */
9043
+ floorEntry(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
9044
+ if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === void 0) {
9045
+ return void 0;
9046
+ }
9047
+ if (this._isPredicate(keyNodeEntryOrPredicate)) {
9048
+ return this._floorByPredicate(keyNodeEntryOrPredicate, iterationType);
9049
+ }
9050
+ let targetKey;
9051
+ if (this.isNode(keyNodeEntryOrPredicate)) {
9052
+ targetKey = keyNodeEntryOrPredicate.key;
9053
+ } else if (this.isEntry(keyNodeEntryOrPredicate)) {
9054
+ const key = keyNodeEntryOrPredicate[0];
9055
+ if (key === null || key === void 0) {
9056
+ return void 0;
9057
+ }
9058
+ targetKey = key;
9059
+ } else {
9060
+ targetKey = keyNodeEntryOrPredicate;
9061
+ }
9062
+ if (targetKey !== void 0) {
9063
+ return this._floorByKey(targetKey, iterationType);
9064
+ }
9065
+ return void 0;
9066
+ }
9067
+ /**
9068
+ * Returns the first node with a key strictly less than the given key.
9069
+ * This is equivalent to Java TreeMap.lowerEntry().
9070
+ * Supports RECURSIVE and ITERATIVE implementations.
9071
+ * @remarks Time Complexity: O(log n) on average, O(h) where h is tree height.
9072
+ * Space Complexity: O(h) for recursion, O(1) for iteration.
9073
+ *
9074
+ * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
9075
+ * @param [iterationType=this.iterationType] - The iteration type (RECURSIVE or ITERATIVE).
9076
+ * @returns The first node with key < given key, or undefined if no such node exists.
9077
+ */
9078
+ lowerEntry(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
9079
+ if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === void 0) {
9080
+ return void 0;
9081
+ }
9082
+ if (this._isPredicate(keyNodeEntryOrPredicate)) {
9083
+ return this._lowerByPredicate(keyNodeEntryOrPredicate, iterationType);
9084
+ }
9085
+ let targetKey;
9086
+ if (this.isNode(keyNodeEntryOrPredicate)) {
9087
+ targetKey = keyNodeEntryOrPredicate.key;
9088
+ } else if (this.isEntry(keyNodeEntryOrPredicate)) {
9089
+ const key = keyNodeEntryOrPredicate[0];
9090
+ if (key === null || key === void 0) {
9091
+ return void 0;
9092
+ }
9093
+ targetKey = key;
9094
+ } else {
9095
+ targetKey = keyNodeEntryOrPredicate;
9096
+ }
9097
+ if (targetKey !== void 0) {
9098
+ return this._lowerByKey(targetKey, iterationType);
9099
+ }
9100
+ return void 0;
9101
+ }
9038
9102
  /**
9039
9103
  * Traverses the tree and returns nodes that are lesser or greater than a target node.
9040
9104
  * @remarks Time O(N), as it performs a full traversal. Space O(log N) or O(N).
@@ -9169,31 +9233,234 @@ var BST = class extends BinaryTree {
9169
9233
  return out;
9170
9234
  }
9171
9235
  /**
9172
- * Deletes the first node found that satisfies the predicate.
9173
- * @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.
9236
+ * Deletes nodes that match a key, node, entry, predicate, or range.
9174
9237
  *
9175
- * @param predicate - A function to test each [key, value] pair.
9176
- * @returns True if a node was deleted, false otherwise.
9238
+ * @remarks
9239
+ * Time Complexity: O(N) for search + O(M log N) for M deletions, where N is tree size.
9240
+ * Space Complexity: O(M) for storing matched nodes and result map.
9241
+ *
9242
+ * @template K - The key type.
9243
+ * @template V - The value type.
9244
+ *
9245
+ * @param keyNodeEntryOrPredicate - The search criteria. Can be one of:
9246
+ * - A key (type K): searches for exact key match using the comparator.
9247
+ * - A BSTNode: searches for the matching node in the tree.
9248
+ * - An entry tuple: searches for the key-value pair.
9249
+ * - A NodePredicate function: tests each node and returns true for matches.
9250
+ * - A Range object: searches for nodes whose keys fall within the specified range (inclusive/exclusive based on range settings).
9251
+ * - null or undefined: treated as no match, returns empty results.
9252
+ *
9253
+ * @param onlyOne - If true, stops the search after finding the first match and only deletes that one node.
9254
+ * If false (default), searches for and deletes all matching nodes.
9255
+ *
9256
+ * @param startNode - The node to start the search from. Can be:
9257
+ * - A key, node, or entry: the method resolves it to a node and searches from that subtree.
9258
+ * - null or undefined: defaults to the root, searching the entire tree.
9259
+ * - Default value: this._root (the tree's root).
9260
+ *
9261
+ * @param iterationType - Controls the internal traversal implementation:
9262
+ * - 'RECURSIVE': uses recursive function calls for traversal.
9263
+ * - 'ITERATIVE': uses explicit stack-based iteration.
9264
+ * - Default: this.iterationType (the tree's default iteration mode).
9265
+ *
9266
+ * @returns A Map<K, boolean> containing the deletion results:
9267
+ * - Key: the matched node's key.
9268
+ * - Value: true if the deletion succeeded, false if it failed (e.g., key not found during deletion phase).
9269
+ * - If no nodes match the search criteria, the returned map is empty.
9270
+ */
9271
+ deleteWhere(keyNodeEntryOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
9272
+ const toDelete = this.search(keyNodeEntryOrPredicate, onlyOne, (node) => node, startNode, iterationType);
9273
+ let results = [];
9274
+ for (const node of toDelete) {
9275
+ const deleteInfo = this.delete(node);
9276
+ results = results.concat(deleteInfo);
9277
+ }
9278
+ return results;
9279
+ }
9280
+ /**
9281
+ * (Protected) Creates the default comparator function for keys that don't have a custom comparator.
9282
+ * @remarks Time O(1) Space O(1)
9283
+ * @returns The default comparator function.
9177
9284
  */
9178
- deleteWhere(predicate) {
9179
- const stack = [];
9180
- let cur = this._root;
9181
- let index = 0;
9182
- while (stack.length > 0 || cur !== void 0) {
9183
- while (cur !== void 0 && cur !== null) {
9184
- stack.push(cur);
9185
- cur = cur.left;
9285
+ _createDefaultComparator() {
9286
+ return (a, b) => {
9287
+ debugger;
9288
+ if (isComparable(a) && isComparable(b)) {
9289
+ if (a > b) return 1;
9290
+ if (a < b) return -1;
9291
+ return 0;
9292
+ }
9293
+ if (typeof a === "object" || typeof b === "object") {
9294
+ throw TypeError(
9295
+ `When comparing object type keys, a custom comparator must be provided in the constructor's options!`
9296
+ );
9297
+ }
9298
+ return 0;
9299
+ };
9300
+ }
9301
+ /**
9302
+ * (Protected) Binary search for floor by key with pruning optimization.
9303
+ * Performs standard BST binary search, choosing left or right subtree based on comparator result.
9304
+ * Finds first node where key <= target.
9305
+ * @remarks Time O(h) where h is tree height.
9306
+ *
9307
+ * @param key - The target key to search for.
9308
+ * @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
9309
+ * @returns The first node with key <= target, or undefined if none exists.
9310
+ */
9311
+ _floorByKey(key, iterationType) {
9312
+ if (iterationType === "RECURSIVE") {
9313
+ const dfs = /* @__PURE__ */ __name((cur) => {
9314
+ if (!this.isRealNode(cur)) return void 0;
9315
+ const cmp = this.comparator(cur.key, key);
9316
+ if (cmp <= 0) {
9317
+ const rightResult = dfs(cur.right);
9318
+ return rightResult ?? cur;
9319
+ } else {
9320
+ return dfs(cur.left);
9321
+ }
9322
+ }, "dfs");
9323
+ return dfs(this.root);
9324
+ } else {
9325
+ let current = this.root;
9326
+ let result = void 0;
9327
+ while (this.isRealNode(current)) {
9328
+ const cmp = this.comparator(current.key, key);
9329
+ if (cmp <= 0) {
9330
+ result = current;
9331
+ current = current.right ?? void 0;
9332
+ } else {
9333
+ current = current.left ?? void 0;
9334
+ }
9186
9335
  }
9187
- const node = stack.pop();
9188
- if (!node) break;
9189
- const key = node.key;
9190
- const val = node.value;
9191
- if (predicate(key, val, index++, this)) {
9192
- return this._deleteByKey(key);
9336
+ return result;
9337
+ }
9338
+ }
9339
+ /**
9340
+ * (Protected) In-order traversal search for floor by predicate.
9341
+ * Falls back to linear in-order traversal when predicate-based search is required.
9342
+ * Returns the last node that satisfies the predicate function.
9343
+ * @remarks Time Complexity: O(n) since it may visit every node.
9344
+ * Space Complexity: O(h) for recursion, O(h) for iterative stack.
9345
+ *
9346
+ * @param predicate - The predicate function to test nodes.
9347
+ * @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
9348
+ * @returns The last node satisfying predicate (highest key), or undefined if none found.
9349
+ */
9350
+ _floorByPredicate(predicate, iterationType) {
9351
+ if (iterationType === "RECURSIVE") {
9352
+ let result = void 0;
9353
+ const dfs = /* @__PURE__ */ __name((cur) => {
9354
+ if (!this.isRealNode(cur)) return;
9355
+ if (this.isRealNode(cur.left)) dfs(cur.left);
9356
+ if (predicate(cur)) {
9357
+ result = cur;
9358
+ }
9359
+ if (this.isRealNode(cur.right)) dfs(cur.right);
9360
+ }, "dfs");
9361
+ dfs(this.root);
9362
+ return result;
9363
+ } else {
9364
+ const stack = [];
9365
+ let current = this.root;
9366
+ let result = void 0;
9367
+ while (stack.length > 0 || this.isRealNode(current)) {
9368
+ if (this.isRealNode(current)) {
9369
+ stack.push(current);
9370
+ current = current.left;
9371
+ } else {
9372
+ const node = stack.pop();
9373
+ if (!this.isRealNode(node)) break;
9374
+ if (predicate(node)) {
9375
+ result = node;
9376
+ }
9377
+ current = node.right;
9378
+ }
9193
9379
  }
9194
- cur = node.right;
9380
+ return result;
9381
+ }
9382
+ }
9383
+ /**
9384
+ * (Protected) Binary search for lower by key with pruning optimization.
9385
+ * Performs standard BST binary search, choosing left or right subtree based on comparator result.
9386
+ * Finds first node where key < target.
9387
+ * @remarks Time O(h) where h is tree height.
9388
+ *
9389
+ * @param key - The target key to search for.
9390
+ * @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
9391
+ * @returns The first node with key < target, or undefined if none exists.
9392
+ */
9393
+ _lowerByKey(key, iterationType) {
9394
+ if (iterationType === "RECURSIVE") {
9395
+ const dfs = /* @__PURE__ */ __name((cur) => {
9396
+ if (!this.isRealNode(cur)) return void 0;
9397
+ const cmp = this.comparator(cur.key, key);
9398
+ if (cmp < 0) {
9399
+ const rightResult = dfs(cur.right);
9400
+ return rightResult ?? cur;
9401
+ } else {
9402
+ return dfs(cur.left);
9403
+ }
9404
+ }, "dfs");
9405
+ return dfs(this.root);
9406
+ } else {
9407
+ let current = this.root;
9408
+ let result = void 0;
9409
+ while (this.isRealNode(current)) {
9410
+ const cmp = this.comparator(current.key, key);
9411
+ if (cmp < 0) {
9412
+ result = current;
9413
+ current = current.right ?? void 0;
9414
+ } else {
9415
+ current = current.left ?? void 0;
9416
+ }
9417
+ }
9418
+ return result;
9419
+ }
9420
+ }
9421
+ /**
9422
+ * (Protected) In-order traversal search for lower by predicate.
9423
+ * Falls back to linear in-order traversal when predicate-based search is required.
9424
+ * Returns the node that satisfies the predicate and appears last in in-order traversal.
9425
+ * @remarks Time Complexity: O(n) since it may visit every node.
9426
+ * Space Complexity: O(h) for recursion, O(h) for iterative stack.
9427
+ *
9428
+ * @param predicate - The predicate function to test nodes.
9429
+ * @param iterationType - The iteration type (RECURSIVE or ITERATIVE).
9430
+ * @returns The last node satisfying predicate (highest key < target), or undefined if none found.
9431
+ */
9432
+ _lowerByPredicate(predicate, iterationType) {
9433
+ if (iterationType === "RECURSIVE") {
9434
+ let result = void 0;
9435
+ const dfs = /* @__PURE__ */ __name((cur) => {
9436
+ if (!this.isRealNode(cur)) return;
9437
+ if (this.isRealNode(cur.left)) dfs(cur.left);
9438
+ if (predicate(cur)) {
9439
+ result = cur;
9440
+ }
9441
+ if (this.isRealNode(cur.right)) dfs(cur.right);
9442
+ }, "dfs");
9443
+ dfs(this.root);
9444
+ return result;
9445
+ } else {
9446
+ const stack = [];
9447
+ let current = this.root;
9448
+ let result = void 0;
9449
+ while (stack.length > 0 || this.isRealNode(current)) {
9450
+ if (this.isRealNode(current)) {
9451
+ stack.push(current);
9452
+ current = current.left;
9453
+ } else {
9454
+ const node = stack.pop();
9455
+ if (!this.isRealNode(node)) break;
9456
+ if (predicate(node)) {
9457
+ result = node;
9458
+ }
9459
+ current = node.right;
9460
+ }
9461
+ }
9462
+ return result;
9195
9463
  }
9196
- return false;
9197
9464
  }
9198
9465
  /**
9199
9466
  * (Protected) Core bound search implementation supporting all parameter types.
@@ -9345,8 +9612,7 @@ var BST = class extends BinaryTree {
9345
9612
  _snapshotOptions() {
9346
9613
  return {
9347
9614
  ...super._snapshotOptions(),
9348
- specifyComparable: this.specifyComparable,
9349
- isReverse: this.isReverse
9615
+ comparator: this._comparator
9350
9616
  };
9351
9617
  }
9352
9618
  /**
@@ -9374,14 +9640,14 @@ var BST = class extends BinaryTree {
9374
9640
  }
9375
9641
  /**
9376
9642
  * (Protected) Compares two keys using the tree's comparator and reverse setting.
9377
- * @remarks Time O(1) (or O(C) if `specifyComparable` is used).
9643
+ * @remarks Time O(1) Space O(1)
9378
9644
  *
9379
9645
  * @param a - The first key.
9380
9646
  * @param b - The second key.
9381
9647
  * @returns A number (1, -1, or 0) representing the comparison.
9382
9648
  */
9383
9649
  _compare(a, b) {
9384
- return this._isReverse ? -this._comparator(a, b) : this._comparator(a, b);
9650
+ return this._comparator(a, b);
9385
9651
  }
9386
9652
  /**
9387
9653
  * (Private) Deletes a node by its key.