red-black-tree-typed 2.1.2 → 2.2.0

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 (31) hide show
  1. package/dist/cjs/index.cjs +321 -169
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +4019 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -0
  5. package/dist/esm/index.mjs +321 -169
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +4010 -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 +58 -4
  12. package/dist/types/data-structures/binary-tree/bst.d.ts +57 -3
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +58 -4
  14. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
  15. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +65 -3
  16. package/dist/umd/red-black-tree-typed.js +168 -14
  17. package/dist/umd/red-black-tree-typed.js.map +1 -1
  18. package/dist/umd/red-black-tree-typed.min.js +3 -3
  19. package/dist/umd/red-black-tree-typed.min.js.map +1 -1
  20. package/package.json +20 -2
  21. package/src/data-structures/binary-tree/avl-tree-counter.ts +102 -11
  22. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +115 -11
  23. package/src/data-structures/binary-tree/avl-tree.ts +105 -14
  24. package/src/data-structures/binary-tree/bst.ts +102 -11
  25. package/src/data-structures/binary-tree/red-black-tree.ts +108 -18
  26. package/src/data-structures/binary-tree/tree-counter.ts +101 -10
  27. package/src/data-structures/binary-tree/tree-multi-map.ts +122 -11
  28. package/src/data-structures/graph/abstract-graph.ts +5 -5
  29. package/src/data-structures/graph/directed-graph.ts +5 -5
  30. package/src/data-structures/graph/undirected-graph.ts +5 -5
  31. package/tsup.node.config.js +40 -6
@@ -1,7 +1,5 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
3
 
6
4
  // src/utils/utils.ts
7
5
  function isPrimitiveComparable(value) {
@@ -60,7 +58,10 @@ function makeTrampoline(fn) {
60
58
  __name(makeTrampoline, "makeTrampoline");
61
59
 
62
60
  // src/data-structures/base/iterable-element-base.ts
63
- var _IterableElementBase = class _IterableElementBase {
61
+ var IterableElementBase = class {
62
+ static {
63
+ __name(this, "IterableElementBase");
64
+ }
64
65
  /**
65
66
  * Create a new iterable base.
66
67
  *
@@ -71,19 +72,19 @@ var _IterableElementBase = class _IterableElementBase {
71
72
  * Time O(1), Space O(1).
72
73
  */
73
74
  constructor(options) {
74
- /**
75
- * The converter used to transform a raw element (`R`) into a public element (`E`).
76
- *
77
- * @remarks
78
- * Time O(1), Space O(1).
79
- */
80
- __publicField(this, "_toElementFn");
81
75
  if (options) {
82
76
  const { toElementFn } = options;
83
77
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
84
78
  else if (toElementFn) throw new TypeError("toElementFn must be a function type");
85
79
  }
86
80
  }
81
+ /**
82
+ * The converter used to transform a raw element (`R`) into a public element (`E`).
83
+ *
84
+ * @remarks
85
+ * Time O(1), Space O(1).
86
+ */
87
+ _toElementFn;
87
88
  /**
88
89
  * Exposes the current `toElementFn`, if configured.
89
90
  *
@@ -278,11 +279,12 @@ var _IterableElementBase = class _IterableElementBase {
278
279
  console.log(this.toVisual());
279
280
  }
280
281
  };
281
- __name(_IterableElementBase, "IterableElementBase");
282
- var IterableElementBase = _IterableElementBase;
283
282
 
284
283
  // src/data-structures/base/linear-base.ts
285
- var _LinearBase = class _LinearBase extends IterableElementBase {
284
+ var LinearBase = class _LinearBase extends IterableElementBase {
285
+ static {
286
+ __name(this, "LinearBase");
287
+ }
286
288
  /**
287
289
  * Construct a linear container with runtime options.
288
290
  * @param options - `{ maxLen?, ... }` bounds/behavior options.
@@ -290,12 +292,12 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
290
292
  */
291
293
  constructor(options) {
292
294
  super(options);
293
- __publicField(this, "_maxLen", -1);
294
295
  if (options) {
295
296
  const { maxLen } = options;
296
297
  if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
297
298
  }
298
299
  }
300
+ _maxLen = -1;
299
301
  /**
300
302
  * Upper bound for length (if positive), or `-1` when unbounded.
301
303
  * @returns Maximum allowed length.
@@ -428,7 +430,7 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
428
430
  return array;
429
431
  }
430
432
  reduceRight(callbackfn, initialValue) {
431
- let accumulator = initialValue != null ? initialValue : 0;
433
+ let accumulator = initialValue ?? 0;
432
434
  for (let i = this.length - 1; i >= 0; i--) {
433
435
  accumulator = callbackfn(accumulator, this.at(i), i, this);
434
436
  }
@@ -470,11 +472,12 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
470
472
  return this;
471
473
  }
472
474
  };
473
- __name(_LinearBase, "LinearBase");
474
- var LinearBase = _LinearBase;
475
475
 
476
476
  // src/data-structures/queue/queue.ts
477
- var _Queue = class _Queue extends LinearBase {
477
+ var Queue = class _Queue extends LinearBase {
478
+ static {
479
+ __name(this, "Queue");
480
+ }
478
481
  /**
479
482
  * Create a Queue and optionally bulk-insert elements.
480
483
  * @remarks Time O(N), Space O(N)
@@ -484,15 +487,13 @@ var _Queue = class _Queue extends LinearBase {
484
487
  */
485
488
  constructor(elements = [], options) {
486
489
  super(options);
487
- __publicField(this, "_elements", []);
488
- __publicField(this, "_offset", 0);
489
- __publicField(this, "_autoCompactRatio", 0.5);
490
490
  if (options) {
491
491
  const { autoCompactRatio = 0.5 } = options;
492
492
  this._autoCompactRatio = autoCompactRatio;
493
493
  }
494
494
  this.pushMany(elements);
495
495
  }
496
+ _elements = [];
496
497
  /**
497
498
  * Get the underlying array buffer.
498
499
  * @remarks Time O(1), Space O(1)
@@ -501,6 +502,7 @@ var _Queue = class _Queue extends LinearBase {
501
502
  get elements() {
502
503
  return this._elements;
503
504
  }
505
+ _offset = 0;
504
506
  /**
505
507
  * Get the current start offset into the array.
506
508
  * @remarks Time O(1), Space O(1)
@@ -509,6 +511,7 @@ var _Queue = class _Queue extends LinearBase {
509
511
  get offset() {
510
512
  return this._offset;
511
513
  }
514
+ _autoCompactRatio = 0.5;
512
515
  /**
513
516
  * Get the compaction threshold (offset/size).
514
517
  * @remarks Time O(1), Space O(1)
@@ -753,11 +756,10 @@ var _Queue = class _Queue extends LinearBase {
753
756
  * @returns A new Queue with mapped elements.
754
757
  */
755
758
  map(callback, options, thisArg) {
756
- var _a, _b;
757
759
  const out = new this.constructor([], {
758
- toElementFn: options == null ? void 0 : options.toElementFn,
759
- maxLen: (_a = options == null ? void 0 : options.maxLen) != null ? _a : this._maxLen,
760
- autoCompactRatio: (_b = options == null ? void 0 : options.autoCompactRatio) != null ? _b : this._autoCompactRatio
760
+ toElementFn: options?.toElementFn,
761
+ maxLen: options?.maxLen ?? this._maxLen,
762
+ autoCompactRatio: options?.autoCompactRatio ?? this._autoCompactRatio
761
763
  });
762
764
  let index = 0;
763
765
  for (const v of this)
@@ -772,14 +774,13 @@ var _Queue = class _Queue extends LinearBase {
772
774
  * @returns A new queue with mapped elements (same element type).
773
775
  */
774
776
  mapSame(callback, thisArg) {
775
- var _a;
776
777
  const Ctor = this.constructor;
777
778
  const out = new Ctor([], {
778
779
  toElementFn: this.toElementFn,
779
780
  maxLen: this._maxLen,
780
781
  autoCompactRatio: this._autoCompactRatio
781
782
  });
782
- (_a = out._setAutoCompactRatio) == null ? void 0 : _a.call(out, this._autoCompactRatio);
783
+ out._setAutoCompactRatio?.(this._autoCompactRatio);
783
784
  let index = 0;
784
785
  for (const v of this) {
785
786
  const mv = thisArg === void 0 ? callback(v, index++, this) : callback.call(thisArg, v, index++, this);
@@ -839,11 +840,12 @@ var _Queue = class _Queue extends LinearBase {
839
840
  return new Ctor(elements, options);
840
841
  }
841
842
  };
842
- __name(_Queue, "Queue");
843
- var Queue = _Queue;
844
843
 
845
844
  // src/data-structures/base/iterable-entry-base.ts
846
- var _IterableEntryBase = class _IterableEntryBase {
845
+ var IterableEntryBase = class {
846
+ static {
847
+ __name(this, "IterableEntryBase");
848
+ }
847
849
  /**
848
850
  * Default iterator yielding `[key, value]` entries.
849
851
  * @returns Iterator of `[K, V]`.
@@ -1012,8 +1014,6 @@ var _IterableEntryBase = class _IterableEntryBase {
1012
1014
  console.log(this.toVisual());
1013
1015
  }
1014
1016
  };
1015
- __name(_IterableEntryBase, "IterableEntryBase");
1016
- var IterableEntryBase = _IterableEntryBase;
1017
1017
 
1018
1018
  // src/common/index.ts
1019
1019
  var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
@@ -1021,7 +1021,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1021
1021
  DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1022
1022
  return DFSOperation2;
1023
1023
  })(DFSOperation || {});
1024
- var _Range = class _Range {
1024
+ var Range = class {
1025
1025
  constructor(low, high, includeLow = true, includeHigh = true) {
1026
1026
  this.low = low;
1027
1027
  this.high = high;
@@ -1030,6 +1030,9 @@ var _Range = class _Range {
1030
1030
  if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
1031
1031
  if (low > high) throw new RangeError("low must be less than or equal to high");
1032
1032
  }
1033
+ static {
1034
+ __name(this, "Range");
1035
+ }
1033
1036
  // Determine whether a key is within the range
1034
1037
  isInRange(key, comparator) {
1035
1038
  const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
@@ -1037,11 +1040,15 @@ var _Range = class _Range {
1037
1040
  return lowCheck && highCheck;
1038
1041
  }
1039
1042
  };
1040
- __name(_Range, "Range");
1041
- var Range = _Range;
1042
1043
 
1043
1044
  // src/data-structures/binary-tree/binary-tree.ts
1044
- var _BinaryTreeNode = class _BinaryTreeNode {
1045
+ var BinaryTreeNode = class {
1046
+ static {
1047
+ __name(this, "BinaryTreeNode");
1048
+ }
1049
+ key;
1050
+ value;
1051
+ parent = void 0;
1045
1052
  /**
1046
1053
  * Creates an instance of BinaryTreeNode.
1047
1054
  * @remarks Time O(1), Space O(1)
@@ -1050,17 +1057,10 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1050
1057
  * @param [value] - The value associated with the key.
1051
1058
  */
1052
1059
  constructor(key, value) {
1053
- __publicField(this, "key");
1054
- __publicField(this, "value");
1055
- __publicField(this, "parent");
1056
- __publicField(this, "_left");
1057
- __publicField(this, "_right");
1058
- __publicField(this, "_height", 0);
1059
- __publicField(this, "_color", "BLACK");
1060
- __publicField(this, "_count", 1);
1061
1060
  this.key = key;
1062
1061
  this.value = value;
1063
1062
  }
1063
+ _left = void 0;
1064
1064
  /**
1065
1065
  * Gets the left child of the node.
1066
1066
  * @remarks Time O(1), Space O(1)
@@ -1082,6 +1082,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1082
1082
  }
1083
1083
  this._left = v;
1084
1084
  }
1085
+ _right = void 0;
1085
1086
  /**
1086
1087
  * Gets the right child of the node.
1087
1088
  * @remarks Time O(1), Space O(1)
@@ -1103,6 +1104,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1103
1104
  }
1104
1105
  this._right = v;
1105
1106
  }
1107
+ _height = 0;
1106
1108
  /**
1107
1109
  * Gets the height of the node (used in self-balancing trees).
1108
1110
  * @remarks Time O(1), Space O(1)
@@ -1121,6 +1123,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1121
1123
  set height(value) {
1122
1124
  this._height = value;
1123
1125
  }
1126
+ _color = "BLACK";
1124
1127
  /**
1125
1128
  * Gets the color of the node (used in Red-Black trees).
1126
1129
  * @remarks Time O(1), Space O(1)
@@ -1139,6 +1142,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1139
1142
  set color(value) {
1140
1143
  this._color = value;
1141
1144
  }
1145
+ _count = 1;
1142
1146
  /**
1143
1147
  * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
1144
1148
  * @remarks Time O(1), Space O(1)
@@ -1175,9 +1179,11 @@ var _BinaryTreeNode = class _BinaryTreeNode {
1175
1179
  return "MAL_NODE";
1176
1180
  }
1177
1181
  };
1178
- __name(_BinaryTreeNode, "BinaryTreeNode");
1179
- var BinaryTreeNode = _BinaryTreeNode;
1180
- var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1182
+ var BinaryTree = class extends IterableEntryBase {
1183
+ static {
1184
+ __name(this, "BinaryTree");
1185
+ }
1186
+ iterationType = "ITERATIVE";
1181
1187
  /**
1182
1188
  * Creates an instance of BinaryTree.
1183
1189
  * @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.
@@ -1187,22 +1193,6 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1187
1193
  */
1188
1194
  constructor(keysNodesEntriesOrRaws = [], options) {
1189
1195
  super();
1190
- __publicField(this, "iterationType", "ITERATIVE");
1191
- __publicField(this, "_isMapMode", true);
1192
- __publicField(this, "_isDuplicate", false);
1193
- __publicField(this, "_store", /* @__PURE__ */ new Map());
1194
- __publicField(this, "_root");
1195
- __publicField(this, "_size", 0);
1196
- __publicField(this, "_NIL", new BinaryTreeNode(NaN));
1197
- __publicField(this, "_toEntryFn");
1198
- /**
1199
- * (Protected) Default callback function, returns the node's key.
1200
- * @remarks Time O(1)
1201
- *
1202
- * @param node - The node.
1203
- * @returns The node's key or undefined.
1204
- */
1205
- __publicField(this, "_DEFAULT_NODE_CALLBACK", /* @__PURE__ */ __name((node) => node ? node.key : void 0, "_DEFAULT_NODE_CALLBACK"));
1206
1196
  if (options) {
1207
1197
  const { iterationType, toEntryFn, isMapMode, isDuplicate } = options;
1208
1198
  if (iterationType) this.iterationType = iterationType;
@@ -1213,6 +1203,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1213
1203
  }
1214
1204
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
1215
1205
  }
1206
+ _isMapMode = true;
1216
1207
  /**
1217
1208
  * Gets whether the tree is in Map mode.
1218
1209
  * @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)
@@ -1222,6 +1213,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1222
1213
  get isMapMode() {
1223
1214
  return this._isMapMode;
1224
1215
  }
1216
+ _isDuplicate = false;
1225
1217
  /**
1226
1218
  * Gets whether the tree allows duplicate keys.
1227
1219
  * @remarks Time O(1)
@@ -1231,6 +1223,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1231
1223
  get isDuplicate() {
1232
1224
  return this._isDuplicate;
1233
1225
  }
1226
+ _store = /* @__PURE__ */ new Map();
1234
1227
  /**
1235
1228
  * Gets the external value store (used in Map mode).
1236
1229
  * @remarks Time O(1)
@@ -1240,6 +1233,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1240
1233
  get store() {
1241
1234
  return this._store;
1242
1235
  }
1236
+ _root;
1243
1237
  /**
1244
1238
  * Gets the root node of the tree.
1245
1239
  * @remarks Time O(1)
@@ -1249,6 +1243,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1249
1243
  get root() {
1250
1244
  return this._root;
1251
1245
  }
1246
+ _size = 0;
1252
1247
  /**
1253
1248
  * Gets the number of nodes in the tree.
1254
1249
  * @remarks Time O(1)
@@ -1258,6 +1253,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1258
1253
  get size() {
1259
1254
  return this._size;
1260
1255
  }
1256
+ _NIL = new BinaryTreeNode(NaN);
1261
1257
  /**
1262
1258
  * Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
1263
1259
  * @remarks Time O(1)
@@ -1267,6 +1263,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1267
1263
  get NIL() {
1268
1264
  return this._NIL;
1269
1265
  }
1266
+ _toEntryFn;
1270
1267
  /**
1271
1268
  * Gets the function used to convert raw data objects (R) into [key, value] entries.
1272
1269
  * @remarks Time O(1)
@@ -1426,7 +1423,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1426
1423
  if (newNode === void 0) return false;
1427
1424
  if (!this._root) {
1428
1425
  this._setRoot(newNode);
1429
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
1426
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
1430
1427
  this._size = 1;
1431
1428
  return true;
1432
1429
  }
@@ -1458,7 +1455,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1458
1455
  } else if (potentialParent.right === void 0) {
1459
1456
  potentialParent.right = newNode;
1460
1457
  }
1461
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
1458
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
1462
1459
  this._size++;
1463
1460
  return true;
1464
1461
  }
@@ -1523,7 +1520,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1523
1520
  if (!this._root) return deletedResult;
1524
1521
  const curr = this.getNode(keyNodeOrEntry);
1525
1522
  if (!curr) return deletedResult;
1526
- const parent = curr == null ? void 0 : curr.parent;
1523
+ const parent = curr?.parent;
1527
1524
  let needBalanced;
1528
1525
  let orgCurrent = curr;
1529
1526
  if (!curr.left && !curr.right && !parent) {
@@ -1628,13 +1625,12 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1628
1625
  * @returns The associated value, or undefined.
1629
1626
  */
1630
1627
  get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
1631
- var _a;
1632
1628
  if (this._isMapMode) {
1633
1629
  const key = this._extractKey(keyNodeEntryOrPredicate);
1634
1630
  if (key === null || key === void 0) return;
1635
1631
  return this._store.get(key);
1636
1632
  }
1637
- return (_a = this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)) == null ? void 0 : _a.value;
1633
+ return this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)?.value;
1638
1634
  }
1639
1635
  has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
1640
1636
  return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType).length > 0;
@@ -1722,7 +1718,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1722
1718
  let distEnsured = this.ensureNode(dist);
1723
1719
  const beginRootEnsured = this.ensureNode(startNode);
1724
1720
  let depth = 0;
1725
- while (distEnsured == null ? void 0 : distEnsured.parent) {
1721
+ while (distEnsured?.parent) {
1726
1722
  if (distEnsured === beginRootEnsured) {
1727
1723
  return depth;
1728
1724
  }
@@ -2284,10 +2280,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2284
2280
  const dfs = /* @__PURE__ */ __name((node) => {
2285
2281
  if (!shouldVisitRoot(node)) return;
2286
2282
  const visitLeft = /* @__PURE__ */ __name(() => {
2287
- if (shouldVisitLeft(node) && (node == null ? void 0 : node.left) !== void 0) dfs(node == null ? void 0 : node.left);
2283
+ if (shouldVisitLeft(node) && node?.left !== void 0) dfs(node?.left);
2288
2284
  }, "visitLeft");
2289
2285
  const visitRight = /* @__PURE__ */ __name(() => {
2290
- if (shouldVisitRight(node) && (node == null ? void 0 : node.right) !== void 0) dfs(node == null ? void 0 : node.right);
2286
+ if (shouldVisitRight(node) && node?.right !== void 0) dfs(node?.right);
2291
2287
  }, "visitRight");
2292
2288
  switch (pattern) {
2293
2289
  case "IN":
@@ -2320,12 +2316,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2320
2316
  } else {
2321
2317
  const stack = [{ opt: 0 /* VISIT */, node: startNode }];
2322
2318
  const pushLeft = /* @__PURE__ */ __name((cur) => {
2323
- var _a;
2324
- if (shouldVisitLeft(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.left });
2319
+ if (shouldVisitLeft(cur.node)) stack.push({ opt: 0 /* VISIT */, node: cur.node?.left });
2325
2320
  }, "pushLeft");
2326
2321
  const pushRight = /* @__PURE__ */ __name((cur) => {
2327
- var _a;
2328
- if (shouldVisitRight(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.right });
2322
+ if (shouldVisitRight(cur.node)) stack.push({ opt: 0 /* VISIT */, node: cur.node?.right });
2329
2323
  }, "pushRight");
2330
2324
  const pushRoot = /* @__PURE__ */ __name((cur) => {
2331
2325
  if (shouldVisitRoot(cur.node)) stack.push({ opt: 1 /* PROCESS */, node: cur.node });
@@ -2397,6 +2391,14 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2397
2391
  }
2398
2392
  }
2399
2393
  }
2394
+ /**
2395
+ * (Protected) Default callback function, returns the node's key.
2396
+ * @remarks Time O(1)
2397
+ *
2398
+ * @param node - The node.
2399
+ * @returns The node's key or undefined.
2400
+ */
2401
+ _DEFAULT_NODE_CALLBACK = /* @__PURE__ */ __name((node) => node ? node.key : void 0, "_DEFAULT_NODE_CALLBACK");
2400
2402
  /**
2401
2403
  * (Protected) Snapshots the current tree's configuration options.
2402
2404
  * @remarks Time O(1)
@@ -2422,7 +2424,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2422
2424
  */
2423
2425
  _createInstance(options) {
2424
2426
  const Ctor = this.constructor;
2425
- return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
2427
+ return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
2426
2428
  }
2427
2429
  /**
2428
2430
  * (Protected) Creates a new instance of the same tree constructor, potentially with different generic types.
@@ -2435,7 +2437,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2435
2437
  */
2436
2438
  _createLike(iter = [], options) {
2437
2439
  const Ctor = this.constructor;
2438
- return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
2440
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
2439
2441
  }
2440
2442
  /**
2441
2443
  * (Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
@@ -2453,7 +2455,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2453
2455
  const [key, entryValue] = keyNodeOrEntry;
2454
2456
  if (key === void 0) return [void 0, void 0];
2455
2457
  else if (key === null) return [null, void 0];
2456
- const finalValue = value != null ? value : entryValue;
2458
+ const finalValue = value ?? entryValue;
2457
2459
  return [this.createNode(key, finalValue), finalValue];
2458
2460
  }
2459
2461
  return [this.createNode(keyNodeOrEntry, value), value];
@@ -2660,11 +2662,15 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2660
2662
  this._store.clear();
2661
2663
  }
2662
2664
  };
2663
- __name(_BinaryTree, "BinaryTree");
2664
- var BinaryTree = _BinaryTree;
2665
2665
 
2666
2666
  // src/data-structures/binary-tree/bst.ts
2667
- var _BSTNode = class _BSTNode extends BinaryTreeNode {
2667
+ var BSTNode = class {
2668
+ static {
2669
+ __name(this, "BSTNode");
2670
+ }
2671
+ key;
2672
+ value;
2673
+ parent = void 0;
2668
2674
  /**
2669
2675
  * Creates an instance of BSTNode.
2670
2676
  * @remarks Time O(1), Space O(1)
@@ -2673,11 +2679,10 @@ var _BSTNode = class _BSTNode extends BinaryTreeNode {
2673
2679
  * @param [value] - The value associated with the key.
2674
2680
  */
2675
2681
  constructor(key, value) {
2676
- super(key, value);
2677
- __publicField(this, "parent");
2678
- __publicField(this, "_left");
2679
- __publicField(this, "_right");
2682
+ this.key = key;
2683
+ this.value = value;
2680
2684
  }
2685
+ _left = void 0;
2681
2686
  /**
2682
2687
  * Gets the left child of the node.
2683
2688
  * @remarks Time O(1), Space O(1)
@@ -2697,6 +2702,7 @@ var _BSTNode = class _BSTNode extends BinaryTreeNode {
2697
2702
  if (v) v.parent = this;
2698
2703
  this._left = v;
2699
2704
  }
2705
+ _right = void 0;
2700
2706
  /**
2701
2707
  * Gets the right child of the node.
2702
2708
  * @remarks Time O(1), Space O(1)
@@ -2716,10 +2722,85 @@ var _BSTNode = class _BSTNode extends BinaryTreeNode {
2716
2722
  if (v) v.parent = this;
2717
2723
  this._right = v;
2718
2724
  }
2725
+ _height = 0;
2726
+ /**
2727
+ * Gets the height of the node (used in self-balancing trees).
2728
+ * @remarks Time O(1), Space O(1)
2729
+ *
2730
+ * @returns The height.
2731
+ */
2732
+ get height() {
2733
+ return this._height;
2734
+ }
2735
+ /**
2736
+ * Sets the height of the node.
2737
+ * @remarks Time O(1), Space O(1)
2738
+ *
2739
+ * @param value - The new height.
2740
+ */
2741
+ set height(value) {
2742
+ this._height = value;
2743
+ }
2744
+ _color = "BLACK";
2745
+ /**
2746
+ * Gets the color of the node (used in Red-Black trees).
2747
+ * @remarks Time O(1), Space O(1)
2748
+ *
2749
+ * @returns The node's color.
2750
+ */
2751
+ get color() {
2752
+ return this._color;
2753
+ }
2754
+ /**
2755
+ * Sets the color of the node.
2756
+ * @remarks Time O(1), Space O(1)
2757
+ *
2758
+ * @param value - The new color.
2759
+ */
2760
+ set color(value) {
2761
+ this._color = value;
2762
+ }
2763
+ _count = 1;
2764
+ /**
2765
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
2766
+ * @remarks Time O(1), Space O(1)
2767
+ *
2768
+ * @returns The subtree node count.
2769
+ */
2770
+ get count() {
2771
+ return this._count;
2772
+ }
2773
+ /**
2774
+ * Sets the count of nodes in the subtree.
2775
+ * @remarks Time O(1), Space O(1)
2776
+ *
2777
+ * @param value - The new count.
2778
+ */
2779
+ set count(value) {
2780
+ this._count = value;
2781
+ }
2782
+ /**
2783
+ * Gets the position of the node relative to its parent.
2784
+ * @remarks Time O(1), Space O(1)
2785
+ *
2786
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
2787
+ */
2788
+ get familyPosition() {
2789
+ if (!this.parent) {
2790
+ return this.left || this.right ? "ROOT" : "ISOLATED";
2791
+ }
2792
+ if (this.parent.left === this) {
2793
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
2794
+ } else if (this.parent.right === this) {
2795
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
2796
+ }
2797
+ return "MAL_NODE";
2798
+ }
2719
2799
  };
2720
- __name(_BSTNode, "BSTNode");
2721
- var BSTNode = _BSTNode;
2722
- var _BST = class _BST extends BinaryTree {
2800
+ var BST = class extends BinaryTree {
2801
+ static {
2802
+ __name(this, "BST");
2803
+ }
2723
2804
  /**
2724
2805
  * Creates an instance of BST.
2725
2806
  * @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
@@ -2729,33 +2810,6 @@ var _BST = class _BST extends BinaryTree {
2729
2810
  */
2730
2811
  constructor(keysNodesEntriesOrRaws = [], options) {
2731
2812
  super([], options);
2732
- __publicField(this, "_root");
2733
- __publicField(this, "_isReverse", false);
2734
- /**
2735
- * The default comparator function.
2736
- * @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
2737
- */
2738
- __publicField(this, "_comparator", /* @__PURE__ */ __name((a, b) => {
2739
- if (isComparable(a) && isComparable(b)) {
2740
- if (a > b) return 1;
2741
- if (a < b) return -1;
2742
- return 0;
2743
- }
2744
- if (this._specifyComparable) {
2745
- const va = this._specifyComparable(a);
2746
- const vb = this._specifyComparable(b);
2747
- if (va > vb) return 1;
2748
- if (va < vb) return -1;
2749
- return 0;
2750
- }
2751
- if (typeof a === "object" || typeof b === "object") {
2752
- throw TypeError(
2753
- `When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
2754
- );
2755
- }
2756
- return 0;
2757
- }, "_comparator"));
2758
- __publicField(this, "_specifyComparable");
2759
2813
  if (options) {
2760
2814
  const { specifyComparable, isReverse } = options;
2761
2815
  if (typeof specifyComparable === "function") this._specifyComparable = specifyComparable;
@@ -2763,6 +2817,7 @@ var _BST = class _BST extends BinaryTree {
2763
2817
  }
2764
2818
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
2765
2819
  }
2820
+ _root = void 0;
2766
2821
  /**
2767
2822
  * Gets the root node of the tree.
2768
2823
  * @remarks Time O(1)
@@ -2772,6 +2827,7 @@ var _BST = class _BST extends BinaryTree {
2772
2827
  get root() {
2773
2828
  return this._root;
2774
2829
  }
2830
+ _isReverse = false;
2775
2831
  /**
2776
2832
  * Gets whether the tree's comparison logic is reversed.
2777
2833
  * @remarks Time O(1)
@@ -2781,6 +2837,30 @@ var _BST = class _BST extends BinaryTree {
2781
2837
  get isReverse() {
2782
2838
  return this._isReverse;
2783
2839
  }
2840
+ /**
2841
+ * The default comparator function.
2842
+ * @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
2843
+ */
2844
+ _comparator = /* @__PURE__ */ __name((a, b) => {
2845
+ if (isComparable(a) && isComparable(b)) {
2846
+ if (a > b) return 1;
2847
+ if (a < b) return -1;
2848
+ return 0;
2849
+ }
2850
+ if (this._specifyComparable) {
2851
+ const va = this._specifyComparable(a);
2852
+ const vb = this._specifyComparable(b);
2853
+ if (va > vb) return 1;
2854
+ if (va < vb) return -1;
2855
+ return 0;
2856
+ }
2857
+ if (typeof a === "object" || typeof b === "object") {
2858
+ throw TypeError(
2859
+ `When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
2860
+ );
2861
+ }
2862
+ return 0;
2863
+ }, "_comparator");
2784
2864
  /**
2785
2865
  * Gets the comparator function used by the tree.
2786
2866
  * @remarks Time O(1)
@@ -2790,6 +2870,7 @@ var _BST = class _BST extends BinaryTree {
2790
2870
  get comparator() {
2791
2871
  return this._comparator;
2792
2872
  }
2873
+ _specifyComparable;
2793
2874
  /**
2794
2875
  * Gets the function used to extract a comparable value from a complex key.
2795
2876
  * @remarks Time O(1)
@@ -2819,8 +2900,7 @@ var _BST = class _BST extends BinaryTree {
2819
2900
  * @returns The resolved node, or undefined if not found.
2820
2901
  */
2821
2902
  ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
2822
- var _a;
2823
- return (_a = super.ensureNode(keyNodeOrEntry, iterationType)) != null ? _a : void 0;
2903
+ return super.ensureNode(keyNodeOrEntry, iterationType) ?? void 0;
2824
2904
  }
2825
2905
  /**
2826
2906
  * Checks if the given item is a `BSTNode` instance.
@@ -2893,8 +2973,7 @@ var _BST = class _BST extends BinaryTree {
2893
2973
  * @returns The first matching node, or undefined if not found.
2894
2974
  */
2895
2975
  getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
2896
- var _a;
2897
- return (_a = this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0]) != null ? _a : void 0;
2976
+ return this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0] ?? void 0;
2898
2977
  }
2899
2978
  /**
2900
2979
  * Searches the tree for nodes matching a predicate, key, or range.
@@ -2999,7 +3078,7 @@ var _BST = class _BST extends BinaryTree {
2999
3078
  if (newNode === void 0) return false;
3000
3079
  if (this._root === void 0) {
3001
3080
  this._setRoot(newNode);
3002
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
3081
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
3003
3082
  this._size++;
3004
3083
  return true;
3005
3084
  }
@@ -3012,7 +3091,7 @@ var _BST = class _BST extends BinaryTree {
3012
3091
  } else if (this._compare(current.key, newNode.key) > 0) {
3013
3092
  if (current.left === void 0) {
3014
3093
  current.left = newNode;
3015
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
3094
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
3016
3095
  this._size++;
3017
3096
  return true;
3018
3097
  }
@@ -3020,7 +3099,7 @@ var _BST = class _BST extends BinaryTree {
3020
3099
  } else {
3021
3100
  if (current.right === void 0) {
3022
3101
  current.right = newNode;
3023
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
3102
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
3024
3103
  this._size++;
3025
3104
  return true;
3026
3105
  }
@@ -3043,10 +3122,10 @@ var _BST = class _BST extends BinaryTree {
3043
3122
  */
3044
3123
  addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
3045
3124
  const inserted = [];
3046
- const valuesIterator = values == null ? void 0 : values[Symbol.iterator]();
3125
+ const valuesIterator = values?.[Symbol.iterator]();
3047
3126
  if (!isBalanceAdd) {
3048
3127
  for (let kve of keysNodesEntriesOrRaws) {
3049
- const val = valuesIterator == null ? void 0 : valuesIterator.next().value;
3128
+ const val = valuesIterator?.next().value;
3050
3129
  if (this.isRaw(kve)) kve = this._toEntryFn(kve);
3051
3130
  inserted.push(this.add(kve, val));
3052
3131
  }
@@ -3055,7 +3134,7 @@ var _BST = class _BST extends BinaryTree {
3055
3134
  const realBTNExemplars = [];
3056
3135
  let i = 0;
3057
3136
  for (const kve of keysNodesEntriesOrRaws) {
3058
- realBTNExemplars.push({ key: kve, value: valuesIterator == null ? void 0 : valuesIterator.next().value, orgIndex: i++ });
3137
+ realBTNExemplars.push({ key: kve, value: valuesIterator?.next().value, orgIndex: i++ });
3059
3138
  }
3060
3139
  const sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
3061
3140
  let keyA, keyB;
@@ -3277,7 +3356,7 @@ var _BST = class _BST extends BinaryTree {
3277
3356
  */
3278
3357
  _createInstance(options) {
3279
3358
  const Ctor = this.constructor;
3280
- return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
3359
+ return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
3281
3360
  }
3282
3361
  /**
3283
3362
  * (Protected) Creates a new instance of the same BST constructor, potentially with different generic types.
@@ -3290,7 +3369,7 @@ var _BST = class _BST extends BinaryTree {
3290
3369
  */
3291
3370
  _createLike(iter = [], options) {
3292
3371
  const Ctor = this.constructor;
3293
- return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
3372
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
3294
3373
  }
3295
3374
  /**
3296
3375
  * (Protected) Snapshots the current BST's configuration options.
@@ -3317,7 +3396,7 @@ var _BST = class _BST extends BinaryTree {
3317
3396
  _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
3318
3397
  const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
3319
3398
  if (node === null) return [void 0, void 0];
3320
- return [node, value != null ? value : entryValue];
3399
+ return [node, value ?? entryValue];
3321
3400
  }
3322
3401
  /**
3323
3402
  * (Protected) Sets the root node and clears its parent reference.
@@ -3348,7 +3427,6 @@ var _BST = class _BST extends BinaryTree {
3348
3427
  * @returns True if the node was found and deleted, false otherwise.
3349
3428
  */
3350
3429
  _deleteByKey(key) {
3351
- var _a;
3352
3430
  let node = this._root;
3353
3431
  while (node) {
3354
3432
  const cmp = this._compare(node.key, key);
@@ -3357,7 +3435,7 @@ var _BST = class _BST extends BinaryTree {
3357
3435
  }
3358
3436
  if (!node) return false;
3359
3437
  const transplant = /* @__PURE__ */ __name((u, v) => {
3360
- const p = u == null ? void 0 : u.parent;
3438
+ const p = u?.parent;
3361
3439
  if (!p) {
3362
3440
  this._setRoot(v);
3363
3441
  } else if (p.left === u) {
@@ -3387,15 +3465,19 @@ var _BST = class _BST extends BinaryTree {
3387
3465
  succ.left = node.left;
3388
3466
  if (succ.left) succ.left.parent = succ;
3389
3467
  }
3390
- this._size = Math.max(0, ((_a = this._size) != null ? _a : 0) - 1);
3468
+ this._size = Math.max(0, (this._size ?? 0) - 1);
3391
3469
  return true;
3392
3470
  }
3393
3471
  };
3394
- __name(_BST, "BST");
3395
- var BST = _BST;
3396
3472
 
3397
3473
  // src/data-structures/binary-tree/red-black-tree.ts
3398
- var _RedBlackTreeNode = class _RedBlackTreeNode extends BSTNode {
3474
+ var RedBlackTreeNode = class {
3475
+ static {
3476
+ __name(this, "RedBlackTreeNode");
3477
+ }
3478
+ key;
3479
+ value;
3480
+ parent = void 0;
3399
3481
  /**
3400
3482
  * Create a Red-Black Tree and optionally bulk-insert items.
3401
3483
  * @remarks Time O(n log n), Space O(n)
@@ -3405,12 +3487,11 @@ var _RedBlackTreeNode = class _RedBlackTreeNode extends BSTNode {
3405
3487
  * @returns New RedBlackTree instance.
3406
3488
  */
3407
3489
  constructor(key, value, color = "BLACK") {
3408
- super(key, value);
3409
- __publicField(this, "parent");
3410
- __publicField(this, "_left");
3411
- __publicField(this, "_right");
3412
- this._color = color;
3490
+ this.key = key;
3491
+ this.value = value;
3492
+ this.color = color;
3413
3493
  }
3494
+ _left = void 0;
3414
3495
  /**
3415
3496
  * Get the left child pointer.
3416
3497
  * @remarks Time O(1), Space O(1)
@@ -3431,6 +3512,7 @@ var _RedBlackTreeNode = class _RedBlackTreeNode extends BSTNode {
3431
3512
  }
3432
3513
  this._left = v;
3433
3514
  }
3515
+ _right = void 0;
3434
3516
  /**
3435
3517
  * Get the right child pointer.
3436
3518
  * @remarks Time O(1), Space O(1)
@@ -3451,18 +3533,93 @@ var _RedBlackTreeNode = class _RedBlackTreeNode extends BSTNode {
3451
3533
  }
3452
3534
  this._right = v;
3453
3535
  }
3536
+ _height = 0;
3537
+ /**
3538
+ * Gets the height of the node (used in self-balancing trees).
3539
+ * @remarks Time O(1), Space O(1)
3540
+ *
3541
+ * @returns The height.
3542
+ */
3543
+ get height() {
3544
+ return this._height;
3545
+ }
3546
+ /**
3547
+ * Sets the height of the node.
3548
+ * @remarks Time O(1), Space O(1)
3549
+ *
3550
+ * @param value - The new height.
3551
+ */
3552
+ set height(value) {
3553
+ this._height = value;
3554
+ }
3555
+ _color = "BLACK";
3556
+ /**
3557
+ * Gets the color of the node (used in Red-Black trees).
3558
+ * @remarks Time O(1), Space O(1)
3559
+ *
3560
+ * @returns The node's color.
3561
+ */
3562
+ get color() {
3563
+ return this._color;
3564
+ }
3565
+ /**
3566
+ * Sets the color of the node.
3567
+ * @remarks Time O(1), Space O(1)
3568
+ *
3569
+ * @param value - The new color.
3570
+ */
3571
+ set color(value) {
3572
+ this._color = value;
3573
+ }
3574
+ _count = 1;
3575
+ /**
3576
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
3577
+ * @remarks Time O(1), Space O(1)
3578
+ *
3579
+ * @returns The subtree node count.
3580
+ */
3581
+ get count() {
3582
+ return this._count;
3583
+ }
3584
+ /**
3585
+ * Sets the count of nodes in the subtree.
3586
+ * @remarks Time O(1), Space O(1)
3587
+ *
3588
+ * @param value - The new count.
3589
+ */
3590
+ set count(value) {
3591
+ this._count = value;
3592
+ }
3593
+ /**
3594
+ * Gets the position of the node relative to its parent.
3595
+ * @remarks Time O(1), Space O(1)
3596
+ *
3597
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
3598
+ */
3599
+ get familyPosition() {
3600
+ if (!this.parent) {
3601
+ return this.left || this.right ? "ROOT" : "ISOLATED";
3602
+ }
3603
+ if (this.parent.left === this) {
3604
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
3605
+ } else if (this.parent.right === this) {
3606
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
3607
+ }
3608
+ return "MAL_NODE";
3609
+ }
3454
3610
  };
3455
- __name(_RedBlackTreeNode, "RedBlackTreeNode");
3456
- var RedBlackTreeNode = _RedBlackTreeNode;
3457
- var _RedBlackTree = class _RedBlackTree extends BST {
3611
+ var RedBlackTree = class extends BST {
3612
+ static {
3613
+ __name(this, "RedBlackTree");
3614
+ }
3458
3615
  constructor(keysNodesEntriesOrRaws = [], options) {
3459
3616
  super([], options);
3460
- __publicField(this, "_root");
3461
3617
  this._root = this.NIL;
3462
3618
  if (keysNodesEntriesOrRaws) {
3463
3619
  this.addMany(keysNodesEntriesOrRaws);
3464
3620
  }
3465
3621
  }
3622
+ _root;
3466
3623
  /**
3467
3624
  * Get the current root node.
3468
3625
  * @remarks Time O(1), Space O(1)
@@ -3607,11 +3764,11 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3607
3764
  }
3608
3765
  _createInstance(options) {
3609
3766
  const Ctor = this.constructor;
3610
- return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
3767
+ return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
3611
3768
  }
3612
3769
  _createLike(iter = [], options) {
3613
3770
  const Ctor = this.constructor;
3614
- return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
3771
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
3615
3772
  }
3616
3773
  _setRoot(v) {
3617
3774
  if (v) {
@@ -3630,16 +3787,15 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3630
3787
  * @returns Status string: 'CREATED' or 'UPDATED'.
3631
3788
  */
3632
3789
  _insert(node) {
3633
- var _a, _b;
3634
- let current = this.root;
3790
+ let current = this.root ?? this.NIL;
3635
3791
  let parent = void 0;
3636
- while (this.isRealNode(current)) {
3792
+ while (current !== this.NIL) {
3637
3793
  parent = current;
3638
3794
  const compared = this._compare(node.key, current.key);
3639
3795
  if (compared < 0) {
3640
- current = (_a = current.left) != null ? _a : this.NIL;
3796
+ current = current.left ?? this.NIL;
3641
3797
  } else if (compared > 0) {
3642
- current = (_b = current.right) != null ? _b : this.NIL;
3798
+ current = current.right ?? this.NIL;
3643
3799
  } else {
3644
3800
  this._replaceNode(current, node);
3645
3801
  return "UPDATED";
@@ -3685,11 +3841,10 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3685
3841
  * @returns void
3686
3842
  */
3687
3843
  _insertFixup(z) {
3688
- var _a, _b, _c, _d, _e;
3689
- while (((_a = z == null ? void 0 : z.parent) == null ? void 0 : _a.color) === "RED") {
3690
- if (z.parent === ((_b = z.parent.parent) == null ? void 0 : _b.left)) {
3844
+ while (z?.parent?.color === "RED") {
3845
+ if (z.parent === z.parent.parent?.left) {
3691
3846
  const y = z.parent.parent.right;
3692
- if ((y == null ? void 0 : y.color) === "RED") {
3847
+ if (y?.color === "RED") {
3693
3848
  z.parent.color = "BLACK";
3694
3849
  y.color = "BLACK";
3695
3850
  z.parent.parent.color = "RED";
@@ -3699,15 +3854,15 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3699
3854
  z = z.parent;
3700
3855
  this._leftRotate(z);
3701
3856
  }
3702
- if (z && this.isRealNode(z.parent) && this.isRealNode(z.parent.parent)) {
3857
+ if (z && z.parent && z.parent.parent) {
3703
3858
  z.parent.color = "BLACK";
3704
3859
  z.parent.parent.color = "RED";
3705
3860
  this._rightRotate(z.parent.parent);
3706
3861
  }
3707
3862
  }
3708
3863
  } else {
3709
- const y = (_e = (_d = (_c = z == null ? void 0 : z.parent) == null ? void 0 : _c.parent) == null ? void 0 : _d.left) != null ? _e : void 0;
3710
- if ((y == null ? void 0 : y.color) === "RED") {
3864
+ const y = z?.parent?.parent?.left ?? void 0;
3865
+ if (y?.color === "RED") {
3711
3866
  z.parent.color = "BLACK";
3712
3867
  y.color = "BLACK";
3713
3868
  z.parent.parent.color = "RED";
@@ -3717,7 +3872,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3717
3872
  z = z.parent;
3718
3873
  this._rightRotate(z);
3719
3874
  }
3720
- if (z && this.isRealNode(z.parent) && this.isRealNode(z.parent.parent)) {
3875
+ if (z && z.parent && z.parent.parent) {
3721
3876
  z.parent.color = "BLACK";
3722
3877
  z.parent.parent.color = "RED";
3723
3878
  this._leftRotate(z.parent.parent);
@@ -3734,7 +3889,6 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3734
3889
  * @returns void
3735
3890
  */
3736
3891
  _deleteFixup(node) {
3737
- var _a, _b, _c, _d;
3738
3892
  if (!node || node === this.root || node.color === "BLACK") {
3739
3893
  if (node) {
3740
3894
  node.color = "BLACK";
@@ -3748,17 +3902,17 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3748
3902
  }
3749
3903
  if (node === parent.left) {
3750
3904
  let sibling = parent.right;
3751
- if ((sibling == null ? void 0 : sibling.color) === "RED") {
3905
+ if (sibling?.color === "RED") {
3752
3906
  sibling.color = "BLACK";
3753
3907
  parent.color = "RED";
3754
3908
  this._leftRotate(parent);
3755
3909
  sibling = parent.right;
3756
3910
  }
3757
- if (((_b = (_a = sibling == null ? void 0 : sibling.left) == null ? void 0 : _a.color) != null ? _b : "BLACK") === "BLACK") {
3911
+ if ((sibling?.left?.color ?? "BLACK") === "BLACK") {
3758
3912
  if (sibling) sibling.color = "RED";
3759
3913
  node = parent;
3760
3914
  } else {
3761
- if (sibling == null ? void 0 : sibling.left) sibling.left.color = "BLACK";
3915
+ if (sibling?.left) sibling.left.color = "BLACK";
3762
3916
  if (sibling) sibling.color = parent.color;
3763
3917
  parent.color = "BLACK";
3764
3918
  this._rightRotate(parent);
@@ -3766,17 +3920,17 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3766
3920
  }
3767
3921
  } else {
3768
3922
  let sibling = parent.left;
3769
- if ((sibling == null ? void 0 : sibling.color) === "RED") {
3923
+ if (sibling?.color === "RED") {
3770
3924
  sibling.color = "BLACK";
3771
3925
  if (parent) parent.color = "RED";
3772
3926
  this._rightRotate(parent);
3773
3927
  if (parent) sibling = parent.left;
3774
3928
  }
3775
- if (((_d = (_c = sibling == null ? void 0 : sibling.right) == null ? void 0 : _c.color) != null ? _d : "BLACK") === "BLACK") {
3929
+ if ((sibling?.right?.color ?? "BLACK") === "BLACK") {
3776
3930
  if (sibling) sibling.color = "RED";
3777
3931
  node = parent;
3778
3932
  } else {
3779
- if (sibling == null ? void 0 : sibling.right) sibling.right.color = "BLACK";
3933
+ if (sibling?.right) sibling.right.color = "BLACK";
3780
3934
  if (sibling) sibling.color = parent.color;
3781
3935
  if (parent) parent.color = "BLACK";
3782
3936
  this._leftRotate(parent);
@@ -3800,7 +3954,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3800
3954
  }
3801
3955
  const y = x.right;
3802
3956
  x.right = y.left;
3803
- if (this.isRealNode(y.left)) {
3957
+ if (y.left && y.left !== this.NIL) {
3804
3958
  y.left.parent = x;
3805
3959
  }
3806
3960
  y.parent = x.parent;
@@ -3826,7 +3980,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3826
3980
  }
3827
3981
  const x = y.left;
3828
3982
  y.left = x.right;
3829
- if (this.isRealNode(x.right)) {
3983
+ if (x.right && x.right !== this.NIL) {
3830
3984
  x.right.parent = y;
3831
3985
  }
3832
3986
  x.parent = y.parent;
@@ -3841,8 +3995,6 @@ var _RedBlackTree = class _RedBlackTree extends BST {
3841
3995
  y.parent = x;
3842
3996
  }
3843
3997
  };
3844
- __name(_RedBlackTree, "RedBlackTree");
3845
- var RedBlackTree = _RedBlackTree;
3846
3998
  /**
3847
3999
  * data-structure-typed
3848
4000
  *