binary-tree-typed 2.1.2 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cjs/index.cjs +86 -86
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +2680 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -0
  5. package/dist/esm/index.mjs +86 -86
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +2675 -0
  8. package/dist/esm-legacy/index.mjs.map +1 -0
  9. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +57 -3
  10. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +65 -3
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +61 -5
  12. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  13. package/dist/types/data-structures/binary-tree/bst.d.ts +58 -3
  14. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +59 -4
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +66 -3
  17. package/dist/types/types/data-structures/base/base.d.ts +1 -1
  18. package/dist/umd/binary-tree-typed.js +6 -6
  19. package/dist/umd/binary-tree-typed.js.map +1 -1
  20. package/dist/umd/binary-tree-typed.min.js +1 -1
  21. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  22. package/package.json +20 -2
  23. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  24. package/src/data-structures/binary-tree/avl-tree-counter.ts +103 -12
  25. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
  26. package/src/data-structures/binary-tree/avl-tree.ts +109 -16
  27. package/src/data-structures/binary-tree/binary-tree.ts +3 -2
  28. package/src/data-structures/binary-tree/bst.ts +104 -12
  29. package/src/data-structures/binary-tree/red-black-tree.ts +110 -19
  30. package/src/data-structures/binary-tree/tree-counter.ts +102 -11
  31. package/src/data-structures/binary-tree/tree-multi-map.ts +124 -12
  32. package/src/data-structures/graph/abstract-graph.ts +8 -8
  33. package/src/data-structures/graph/directed-graph.ts +5 -5
  34. package/src/data-structures/graph/undirected-graph.ts +5 -5
  35. package/src/data-structures/hash/hash-map.ts +4 -4
  36. package/src/types/data-structures/base/base.ts +1 -1
  37. package/tsup.node.config.js +40 -6
@@ -1,9 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
5
 
8
6
  // src/utils/utils.ts
9
7
  function isPrimitiveComparable(value) {
@@ -62,7 +60,10 @@ function makeTrampoline(fn) {
62
60
  __name(makeTrampoline, "makeTrampoline");
63
61
 
64
62
  // src/data-structures/base/iterable-element-base.ts
65
- var _IterableElementBase = class _IterableElementBase {
63
+ var IterableElementBase = class {
64
+ static {
65
+ __name(this, "IterableElementBase");
66
+ }
66
67
  /**
67
68
  * Create a new iterable base.
68
69
  *
@@ -73,19 +74,19 @@ var _IterableElementBase = class _IterableElementBase {
73
74
  * Time O(1), Space O(1).
74
75
  */
75
76
  constructor(options) {
76
- /**
77
- * The converter used to transform a raw element (`R`) into a public element (`E`).
78
- *
79
- * @remarks
80
- * Time O(1), Space O(1).
81
- */
82
- __publicField(this, "_toElementFn");
83
77
  if (options) {
84
78
  const { toElementFn } = options;
85
79
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
86
80
  else if (toElementFn) throw new TypeError("toElementFn must be a function type");
87
81
  }
88
82
  }
83
+ /**
84
+ * The converter used to transform a raw element (`R`) into a public element (`E`).
85
+ *
86
+ * @remarks
87
+ * Time O(1), Space O(1).
88
+ */
89
+ _toElementFn;
89
90
  /**
90
91
  * Exposes the current `toElementFn`, if configured.
91
92
  *
@@ -280,11 +281,12 @@ var _IterableElementBase = class _IterableElementBase {
280
281
  console.log(this.toVisual());
281
282
  }
282
283
  };
283
- __name(_IterableElementBase, "IterableElementBase");
284
- var IterableElementBase = _IterableElementBase;
285
284
 
286
285
  // src/data-structures/base/linear-base.ts
287
- var _LinearBase = class _LinearBase extends IterableElementBase {
286
+ var LinearBase = class _LinearBase extends IterableElementBase {
287
+ static {
288
+ __name(this, "LinearBase");
289
+ }
288
290
  /**
289
291
  * Construct a linear container with runtime options.
290
292
  * @param options - `{ maxLen?, ... }` bounds/behavior options.
@@ -292,12 +294,12 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
292
294
  */
293
295
  constructor(options) {
294
296
  super(options);
295
- __publicField(this, "_maxLen", -1);
296
297
  if (options) {
297
298
  const { maxLen } = options;
298
299
  if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
299
300
  }
300
301
  }
302
+ _maxLen = -1;
301
303
  /**
302
304
  * Upper bound for length (if positive), or `-1` when unbounded.
303
305
  * @returns Maximum allowed length.
@@ -430,7 +432,7 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
430
432
  return array;
431
433
  }
432
434
  reduceRight(callbackfn, initialValue) {
433
- let accumulator = initialValue != null ? initialValue : 0;
435
+ let accumulator = initialValue ?? 0;
434
436
  for (let i = this.length - 1; i >= 0; i--) {
435
437
  accumulator = callbackfn(accumulator, this.at(i), i, this);
436
438
  }
@@ -472,11 +474,12 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
472
474
  return this;
473
475
  }
474
476
  };
475
- __name(_LinearBase, "LinearBase");
476
- var LinearBase = _LinearBase;
477
477
 
478
478
  // src/data-structures/queue/queue.ts
479
- var _Queue = class _Queue extends LinearBase {
479
+ var Queue = class _Queue extends LinearBase {
480
+ static {
481
+ __name(this, "Queue");
482
+ }
480
483
  /**
481
484
  * Create a Queue and optionally bulk-insert elements.
482
485
  * @remarks Time O(N), Space O(N)
@@ -486,15 +489,13 @@ var _Queue = class _Queue extends LinearBase {
486
489
  */
487
490
  constructor(elements = [], options) {
488
491
  super(options);
489
- __publicField(this, "_elements", []);
490
- __publicField(this, "_offset", 0);
491
- __publicField(this, "_autoCompactRatio", 0.5);
492
492
  if (options) {
493
493
  const { autoCompactRatio = 0.5 } = options;
494
494
  this._autoCompactRatio = autoCompactRatio;
495
495
  }
496
496
  this.pushMany(elements);
497
497
  }
498
+ _elements = [];
498
499
  /**
499
500
  * Get the underlying array buffer.
500
501
  * @remarks Time O(1), Space O(1)
@@ -503,6 +504,7 @@ var _Queue = class _Queue extends LinearBase {
503
504
  get elements() {
504
505
  return this._elements;
505
506
  }
507
+ _offset = 0;
506
508
  /**
507
509
  * Get the current start offset into the array.
508
510
  * @remarks Time O(1), Space O(1)
@@ -511,6 +513,7 @@ var _Queue = class _Queue extends LinearBase {
511
513
  get offset() {
512
514
  return this._offset;
513
515
  }
516
+ _autoCompactRatio = 0.5;
514
517
  /**
515
518
  * Get the compaction threshold (offset/size).
516
519
  * @remarks Time O(1), Space O(1)
@@ -755,11 +758,10 @@ var _Queue = class _Queue extends LinearBase {
755
758
  * @returns A new Queue with mapped elements.
756
759
  */
757
760
  map(callback, options, thisArg) {
758
- var _a, _b;
759
761
  const out = new this.constructor([], {
760
- toElementFn: options == null ? void 0 : options.toElementFn,
761
- maxLen: (_a = options == null ? void 0 : options.maxLen) != null ? _a : this._maxLen,
762
- autoCompactRatio: (_b = options == null ? void 0 : options.autoCompactRatio) != null ? _b : this._autoCompactRatio
762
+ toElementFn: options?.toElementFn,
763
+ maxLen: options?.maxLen ?? this._maxLen,
764
+ autoCompactRatio: options?.autoCompactRatio ?? this._autoCompactRatio
763
765
  });
764
766
  let index = 0;
765
767
  for (const v of this)
@@ -774,14 +776,13 @@ var _Queue = class _Queue extends LinearBase {
774
776
  * @returns A new queue with mapped elements (same element type).
775
777
  */
776
778
  mapSame(callback, thisArg) {
777
- var _a;
778
779
  const Ctor = this.constructor;
779
780
  const out = new Ctor([], {
780
781
  toElementFn: this.toElementFn,
781
782
  maxLen: this._maxLen,
782
783
  autoCompactRatio: this._autoCompactRatio
783
784
  });
784
- (_a = out._setAutoCompactRatio) == null ? void 0 : _a.call(out, this._autoCompactRatio);
785
+ out._setAutoCompactRatio?.(this._autoCompactRatio);
785
786
  let index = 0;
786
787
  for (const v of this) {
787
788
  const mv = thisArg === void 0 ? callback(v, index++, this) : callback.call(thisArg, v, index++, this);
@@ -841,11 +842,12 @@ var _Queue = class _Queue extends LinearBase {
841
842
  return new Ctor(elements, options);
842
843
  }
843
844
  };
844
- __name(_Queue, "Queue");
845
- var Queue = _Queue;
846
845
 
847
846
  // src/data-structures/base/iterable-entry-base.ts
848
- var _IterableEntryBase = class _IterableEntryBase {
847
+ var IterableEntryBase = class {
848
+ static {
849
+ __name(this, "IterableEntryBase");
850
+ }
849
851
  /**
850
852
  * Default iterator yielding `[key, value]` entries.
851
853
  * @returns Iterator of `[K, V]`.
@@ -894,7 +896,7 @@ var _IterableEntryBase = class _IterableEntryBase {
894
896
  every(predicate, thisArg) {
895
897
  let index = 0;
896
898
  for (const item of this) {
897
- if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
899
+ if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
898
900
  return false;
899
901
  }
900
902
  }
@@ -910,7 +912,7 @@ var _IterableEntryBase = class _IterableEntryBase {
910
912
  some(predicate, thisArg) {
911
913
  let index = 0;
912
914
  for (const item of this) {
913
- if (predicate.call(thisArg, item[0], item[1], index++, this)) {
915
+ if (predicate.call(thisArg, item[1], item[0], index++, this)) {
914
916
  return true;
915
917
  }
916
918
  }
@@ -926,7 +928,7 @@ var _IterableEntryBase = class _IterableEntryBase {
926
928
  let index = 0;
927
929
  for (const item of this) {
928
930
  const [key, value] = item;
929
- callbackfn.call(thisArg, key, value, index++, this);
931
+ callbackfn.call(thisArg, value, key, index++, this);
930
932
  }
931
933
  }
932
934
  /**
@@ -940,7 +942,7 @@ var _IterableEntryBase = class _IterableEntryBase {
940
942
  let index = 0;
941
943
  for (const item of this) {
942
944
  const [key, value] = item;
943
- if (callbackfn.call(thisArg, key, value, index++, this)) return item;
945
+ if (callbackfn.call(thisArg, value, key, index++, this)) return item;
944
946
  }
945
947
  return;
946
948
  }
@@ -1014,8 +1016,6 @@ var _IterableEntryBase = class _IterableEntryBase {
1014
1016
  console.log(this.toVisual());
1015
1017
  }
1016
1018
  };
1017
- __name(_IterableEntryBase, "IterableEntryBase");
1018
- var IterableEntryBase = _IterableEntryBase;
1019
1019
 
1020
1020
  // src/common/index.ts
1021
1021
  var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
@@ -1023,7 +1023,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1023
1023
  DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1024
1024
  return DFSOperation2;
1025
1025
  })(DFSOperation || {});
1026
- var _Range = class _Range {
1026
+ var Range = class {
1027
1027
  constructor(low, high, includeLow = true, includeHigh = true) {
1028
1028
  this.low = low;
1029
1029
  this.high = high;
@@ -1032,6 +1032,9 @@ var _Range = class _Range {
1032
1032
  if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
1033
1033
  if (low > high) throw new RangeError("low must be less than or equal to high");
1034
1034
  }
1035
+ static {
1036
+ __name(this, "Range");
1037
+ }
1035
1038
  // Determine whether a key is within the range
1036
1039
  isInRange(key, comparator) {
1037
1040
  const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
@@ -1039,11 +1042,15 @@ var _Range = class _Range {
1039
1042
  return lowCheck && highCheck;
1040
1043
  }
1041
1044
  };
1042
- __name(_Range, "Range");
1043
- var Range = _Range;
1044
1045
 
1045
1046
  // src/data-structures/binary-tree/binary-tree.ts
1046
- var _BinaryTreeNode = class _BinaryTreeNode {
1047
+ var BinaryTreeNode = class {
1048
+ static {
1049
+ __name(this, "BinaryTreeNode");
1050
+ }
1051
+ key;
1052
+ value;
1053
+ parent = void 0;
1047
1054
  /**
1048
1055
  * Creates an instance of BinaryTreeNode.
1049
1056
  * @remarks Time O(1), Space O(1)
@@ -1052,17 +1059,10 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1052
1059
  * @param [value] - The value associated with the key.
1053
1060
  */
1054
1061
  constructor(key, value) {
1055
- __publicField(this, "key");
1056
- __publicField(this, "value");
1057
- __publicField(this, "parent");
1058
- __publicField(this, "_left");
1059
- __publicField(this, "_right");
1060
- __publicField(this, "_height", 0);
1061
- __publicField(this, "_color", "BLACK");
1062
- __publicField(this, "_count", 1);
1063
1062
  this.key = key;
1064
1063
  this.value = value;
1065
1064
  }
1065
+ _left = void 0;
1066
1066
  /**
1067
1067
  * Gets the left child of the node.
1068
1068
  * @remarks Time O(1), Space O(1)
@@ -1084,6 +1084,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1084
1084
  }
1085
1085
  this._left = v;
1086
1086
  }
1087
+ _right = void 0;
1087
1088
  /**
1088
1089
  * Gets the right child of the node.
1089
1090
  * @remarks Time O(1), Space O(1)
@@ -1105,6 +1106,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1105
1106
  }
1106
1107
  this._right = v;
1107
1108
  }
1109
+ _height = 0;
1108
1110
  /**
1109
1111
  * Gets the height of the node (used in self-balancing trees).
1110
1112
  * @remarks Time O(1), Space O(1)
@@ -1123,6 +1125,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1123
1125
  set height(value) {
1124
1126
  this._height = value;
1125
1127
  }
1128
+ _color = "BLACK";
1126
1129
  /**
1127
1130
  * Gets the color of the node (used in Red-Black trees).
1128
1131
  * @remarks Time O(1), Space O(1)
@@ -1141,6 +1144,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1141
1144
  set color(value) {
1142
1145
  this._color = value;
1143
1146
  }
1147
+ _count = 1;
1144
1148
  /**
1145
1149
  * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
1146
1150
  * @remarks Time O(1), Space O(1)
@@ -1177,9 +1181,11 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1177
1181
  return "MAL_NODE";
1178
1182
  }
1179
1183
  };
1180
- __name(_BinaryTreeNode, "BinaryTreeNode");
1181
- var BinaryTreeNode = _BinaryTreeNode;
1182
- var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1184
+ var BinaryTree = class extends IterableEntryBase {
1185
+ static {
1186
+ __name(this, "BinaryTree");
1187
+ }
1188
+ iterationType = "ITERATIVE";
1183
1189
  /**
1184
1190
  * Creates an instance of BinaryTree.
1185
1191
  * @remarks Time O(N * M), where N is the number of items in `keysNodesEntriesOrRaws` and M is the tree size at insertion time (due to O(M) `add` operation). Space O(N) for storing the nodes.
@@ -1189,22 +1195,6 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1189
1195
  */
1190
1196
  constructor(keysNodesEntriesOrRaws = [], options) {
1191
1197
  super();
1192
- __publicField(this, "iterationType", "ITERATIVE");
1193
- __publicField(this, "_isMapMode", true);
1194
- __publicField(this, "_isDuplicate", false);
1195
- __publicField(this, "_store", /* @__PURE__ */ new Map());
1196
- __publicField(this, "_root");
1197
- __publicField(this, "_size", 0);
1198
- __publicField(this, "_NIL", new BinaryTreeNode(NaN));
1199
- __publicField(this, "_toEntryFn");
1200
- /**
1201
- * (Protected) Default callback function, returns the node's key.
1202
- * @remarks Time O(1)
1203
- *
1204
- * @param node - The node.
1205
- * @returns The node's key or undefined.
1206
- */
1207
- __publicField(this, "_DEFAULT_NODE_CALLBACK", /* @__PURE__ */ __name((node) => node ? node.key : void 0, "_DEFAULT_NODE_CALLBACK"));
1208
1198
  if (options) {
1209
1199
  const { iterationType, toEntryFn, isMapMode, isDuplicate } = options;
1210
1200
  if (iterationType) this.iterationType = iterationType;
@@ -1215,6 +1205,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1215
1205
  }
1216
1206
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
1217
1207
  }
1208
+ _isMapMode = true;
1218
1209
  /**
1219
1210
  * Gets whether the tree is in Map mode.
1220
1211
  * @remarks In Map mode (default), values are stored in an external Map, and nodes only hold keys. If false, values are stored directly on the nodes. Time O(1)
@@ -1224,6 +1215,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1224
1215
  get isMapMode() {
1225
1216
  return this._isMapMode;
1226
1217
  }
1218
+ _isDuplicate = false;
1227
1219
  /**
1228
1220
  * Gets whether the tree allows duplicate keys.
1229
1221
  * @remarks Time O(1)
@@ -1233,6 +1225,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1233
1225
  get isDuplicate() {
1234
1226
  return this._isDuplicate;
1235
1227
  }
1228
+ _store = /* @__PURE__ */ new Map();
1236
1229
  /**
1237
1230
  * Gets the external value store (used in Map mode).
1238
1231
  * @remarks Time O(1)
@@ -1242,6 +1235,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1242
1235
  get store() {
1243
1236
  return this._store;
1244
1237
  }
1238
+ _root;
1245
1239
  /**
1246
1240
  * Gets the root node of the tree.
1247
1241
  * @remarks Time O(1)
@@ -1251,6 +1245,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1251
1245
  get root() {
1252
1246
  return this._root;
1253
1247
  }
1248
+ _size = 0;
1254
1249
  /**
1255
1250
  * Gets the number of nodes in the tree.
1256
1251
  * @remarks Time O(1)
@@ -1260,6 +1255,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1260
1255
  get size() {
1261
1256
  return this._size;
1262
1257
  }
1258
+ _NIL = new BinaryTreeNode(NaN);
1263
1259
  /**
1264
1260
  * Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
1265
1261
  * @remarks Time O(1)
@@ -1269,6 +1265,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1269
1265
  get NIL() {
1270
1266
  return this._NIL;
1271
1267
  }
1268
+ _toEntryFn;
1272
1269
  /**
1273
1270
  * Gets the function used to convert raw data objects (R) into [key, value] entries.
1274
1271
  * @remarks Time O(1)
@@ -1428,7 +1425,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1428
1425
  if (newNode === void 0) return false;
1429
1426
  if (!this._root) {
1430
1427
  this._setRoot(newNode);
1431
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
1428
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
1432
1429
  this._size = 1;
1433
1430
  return true;
1434
1431
  }
@@ -1460,7 +1457,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1460
1457
  } else if (potentialParent.right === void 0) {
1461
1458
  potentialParent.right = newNode;
1462
1459
  }
1463
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
1460
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
1464
1461
  this._size++;
1465
1462
  return true;
1466
1463
  }
@@ -1525,7 +1522,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1525
1522
  if (!this._root) return deletedResult;
1526
1523
  const curr = this.getNode(keyNodeOrEntry);
1527
1524
  if (!curr) return deletedResult;
1528
- const parent = curr == null ? void 0 : curr.parent;
1525
+ const parent = curr?.parent;
1529
1526
  let needBalanced;
1530
1527
  let orgCurrent = curr;
1531
1528
  if (!curr.left && !curr.right && !parent) {
@@ -1630,13 +1627,12 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1630
1627
  * @returns The associated value, or undefined.
1631
1628
  */
1632
1629
  get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
1633
- var _a;
1634
1630
  if (this._isMapMode) {
1635
1631
  const key = this._extractKey(keyNodeEntryOrPredicate);
1636
1632
  if (key === null || key === void 0) return;
1637
1633
  return this._store.get(key);
1638
1634
  }
1639
- return (_a = this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)) == null ? void 0 : _a.value;
1635
+ return this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)?.value;
1640
1636
  }
1641
1637
  has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
1642
1638
  return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType).length > 0;
@@ -1724,7 +1720,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1724
1720
  let distEnsured = this.ensureNode(dist);
1725
1721
  const beginRootEnsured = this.ensureNode(startNode);
1726
1722
  let depth = 0;
1727
- while (distEnsured == null ? void 0 : distEnsured.parent) {
1723
+ while (distEnsured?.parent) {
1728
1724
  if (distEnsured === beginRootEnsured) {
1729
1725
  return depth;
1730
1726
  }
@@ -2197,7 +2193,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2197
2193
  filter(predicate, thisArg) {
2198
2194
  const out = this._createInstance();
2199
2195
  let i = 0;
2200
- for (const [k, v] of this) if (predicate.call(thisArg, k, v, i++, this)) out.add([k, v]);
2196
+ for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
2201
2197
  return out;
2202
2198
  }
2203
2199
  /**
@@ -2215,7 +2211,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2215
2211
  map(cb, options, thisArg) {
2216
2212
  const out = this._createLike([], options);
2217
2213
  let i = 0;
2218
- for (const [k, v] of this) out.add(cb.call(thisArg, k, v, i++, this));
2214
+ for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
2219
2215
  return out;
2220
2216
  }
2221
2217
  /**
@@ -2286,10 +2282,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2286
2282
  const dfs = /* @__PURE__ */ __name((node) => {
2287
2283
  if (!shouldVisitRoot(node)) return;
2288
2284
  const visitLeft = /* @__PURE__ */ __name(() => {
2289
- if (shouldVisitLeft(node) && (node == null ? void 0 : node.left) !== void 0) dfs(node == null ? void 0 : node.left);
2285
+ if (shouldVisitLeft(node) && node?.left !== void 0) dfs(node?.left);
2290
2286
  }, "visitLeft");
2291
2287
  const visitRight = /* @__PURE__ */ __name(() => {
2292
- if (shouldVisitRight(node) && (node == null ? void 0 : node.right) !== void 0) dfs(node == null ? void 0 : node.right);
2288
+ if (shouldVisitRight(node) && node?.right !== void 0) dfs(node?.right);
2293
2289
  }, "visitRight");
2294
2290
  switch (pattern) {
2295
2291
  case "IN":
@@ -2322,12 +2318,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2322
2318
  } else {
2323
2319
  const stack = [{ opt: 0 /* VISIT */, node: startNode }];
2324
2320
  const pushLeft = /* @__PURE__ */ __name((cur) => {
2325
- var _a;
2326
- if (shouldVisitLeft(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.left });
2321
+ if (shouldVisitLeft(cur.node)) stack.push({ opt: 0 /* VISIT */, node: cur.node?.left });
2327
2322
  }, "pushLeft");
2328
2323
  const pushRight = /* @__PURE__ */ __name((cur) => {
2329
- var _a;
2330
- if (shouldVisitRight(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.right });
2324
+ if (shouldVisitRight(cur.node)) stack.push({ opt: 0 /* VISIT */, node: cur.node?.right });
2331
2325
  }, "pushRight");
2332
2326
  const pushRoot = /* @__PURE__ */ __name((cur) => {
2333
2327
  if (shouldVisitRoot(cur.node)) stack.push({ opt: 1 /* PROCESS */, node: cur.node });
@@ -2399,6 +2393,14 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2399
2393
  }
2400
2394
  }
2401
2395
  }
2396
+ /**
2397
+ * (Protected) Default callback function, returns the node's key.
2398
+ * @remarks Time O(1)
2399
+ *
2400
+ * @param node - The node.
2401
+ * @returns The node's key or undefined.
2402
+ */
2403
+ _DEFAULT_NODE_CALLBACK = /* @__PURE__ */ __name((node) => node ? node.key : void 0, "_DEFAULT_NODE_CALLBACK");
2402
2404
  /**
2403
2405
  * (Protected) Snapshots the current tree's configuration options.
2404
2406
  * @remarks Time O(1)
@@ -2424,7 +2426,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2424
2426
  */
2425
2427
  _createInstance(options) {
2426
2428
  const Ctor = this.constructor;
2427
- return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
2429
+ return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
2428
2430
  }
2429
2431
  /**
2430
2432
  * (Protected) Creates a new instance of the same tree constructor, potentially with different generic types.
@@ -2437,7 +2439,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2437
2439
  */
2438
2440
  _createLike(iter = [], options) {
2439
2441
  const Ctor = this.constructor;
2440
- return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
2442
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
2441
2443
  }
2442
2444
  /**
2443
2445
  * (Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
@@ -2455,7 +2457,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2455
2457
  const [key, entryValue] = keyNodeOrEntry;
2456
2458
  if (key === void 0) return [void 0, void 0];
2457
2459
  else if (key === null) return [null, void 0];
2458
- const finalValue = value != null ? value : entryValue;
2460
+ const finalValue = value ?? entryValue;
2459
2461
  return [this.createNode(key, finalValue), finalValue];
2460
2462
  }
2461
2463
  return [this.createNode(keyNodeOrEntry, value), value];
@@ -2662,8 +2664,6 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2662
2664
  this._store.clear();
2663
2665
  }
2664
2666
  };
2665
- __name(_BinaryTree, "BinaryTree");
2666
- var BinaryTree = _BinaryTree;
2667
2667
  /**
2668
2668
  * data-structure-typed
2669
2669
  *