data-structure-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 (55) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/CONTRIBUTING.md +4 -0
  3. package/README.md +66 -21
  4. package/benchmark/report.html +1 -1
  5. package/benchmark/report.json +145 -169
  6. package/dist/cjs/index.cjs +1173 -583
  7. package/dist/cjs/index.cjs.map +1 -1
  8. package/dist/cjs-legacy/index.cjs +13623 -0
  9. package/dist/cjs-legacy/index.cjs.map +1 -0
  10. package/dist/esm/index.mjs +1173 -583
  11. package/dist/esm/index.mjs.map +1 -1
  12. package/dist/esm-legacy/index.mjs +13545 -0
  13. package/dist/esm-legacy/index.mjs.map +1 -0
  14. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +57 -3
  15. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +65 -3
  16. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +61 -5
  17. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  18. package/dist/types/data-structures/binary-tree/bst.d.ts +58 -3
  19. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +59 -4
  20. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +66 -3
  22. package/dist/types/types/data-structures/base/base.d.ts +1 -1
  23. package/dist/umd/data-structure-typed.js +614 -53
  24. package/dist/umd/data-structure-typed.js.map +1 -1
  25. package/dist/umd/data-structure-typed.min.js +3 -3
  26. package/dist/umd/data-structure-typed.min.js.map +1 -1
  27. package/package.json +20 -2
  28. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  29. package/src/data-structures/binary-tree/avl-tree-counter.ts +103 -12
  30. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
  31. package/src/data-structures/binary-tree/avl-tree.ts +109 -16
  32. package/src/data-structures/binary-tree/binary-tree.ts +3 -2
  33. package/src/data-structures/binary-tree/bst.ts +104 -12
  34. package/src/data-structures/binary-tree/red-black-tree.ts +110 -19
  35. package/src/data-structures/binary-tree/tree-counter.ts +102 -11
  36. package/src/data-structures/binary-tree/tree-multi-map.ts +124 -12
  37. package/src/data-structures/graph/abstract-graph.ts +8 -8
  38. package/src/data-structures/graph/directed-graph.ts +5 -5
  39. package/src/data-structures/graph/undirected-graph.ts +5 -5
  40. package/src/data-structures/hash/hash-map.ts +4 -4
  41. package/src/types/data-structures/base/base.ts +1 -1
  42. package/test/performance/data-structures/binary-tree/red-black-tree.test.ts +39 -36
  43. package/test/performance/runner-config.json +4 -4
  44. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +8 -7
  45. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +3 -3
  46. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +6 -6
  47. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +4 -4
  48. package/test/unit/data-structures/binary-tree/bst.test.ts +5 -5
  49. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +6 -6
  50. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +8 -7
  51. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +7 -7
  52. package/test/unit/data-structures/graph/directed-graph.test.ts +3 -3
  53. package/test/unit/data-structures/hash/hash-map.test.ts +14 -14
  54. package/tsup.node.config.js +40 -6
  55. package/test/performance/reportor.mjs +0 -505
@@ -1,10 +1,11 @@
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/data-structures/base/iterable-entry-base.ts
7
- var _IterableEntryBase = class _IterableEntryBase {
5
+ var IterableEntryBase = class {
6
+ static {
7
+ __name(this, "IterableEntryBase");
8
+ }
8
9
  /**
9
10
  * Default iterator yielding `[key, value]` entries.
10
11
  * @returns Iterator of `[K, V]`.
@@ -53,7 +54,7 @@ var _IterableEntryBase = class _IterableEntryBase {
53
54
  every(predicate, thisArg) {
54
55
  let index = 0;
55
56
  for (const item of this) {
56
- if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
57
+ if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
57
58
  return false;
58
59
  }
59
60
  }
@@ -69,7 +70,7 @@ var _IterableEntryBase = class _IterableEntryBase {
69
70
  some(predicate, thisArg) {
70
71
  let index = 0;
71
72
  for (const item of this) {
72
- if (predicate.call(thisArg, item[0], item[1], index++, this)) {
73
+ if (predicate.call(thisArg, item[1], item[0], index++, this)) {
73
74
  return true;
74
75
  }
75
76
  }
@@ -85,7 +86,7 @@ var _IterableEntryBase = class _IterableEntryBase {
85
86
  let index = 0;
86
87
  for (const item of this) {
87
88
  const [key, value] = item;
88
- callbackfn.call(thisArg, key, value, index++, this);
89
+ callbackfn.call(thisArg, value, key, index++, this);
89
90
  }
90
91
  }
91
92
  /**
@@ -99,7 +100,7 @@ var _IterableEntryBase = class _IterableEntryBase {
99
100
  let index = 0;
100
101
  for (const item of this) {
101
102
  const [key, value] = item;
102
- if (callbackfn.call(thisArg, key, value, index++, this)) return item;
103
+ if (callbackfn.call(thisArg, value, key, index++, this)) return item;
103
104
  }
104
105
  return;
105
106
  }
@@ -173,11 +174,12 @@ var _IterableEntryBase = class _IterableEntryBase {
173
174
  console.log(this.toVisual());
174
175
  }
175
176
  };
176
- __name(_IterableEntryBase, "IterableEntryBase");
177
- var IterableEntryBase = _IterableEntryBase;
178
177
 
179
178
  // src/data-structures/base/iterable-element-base.ts
180
- var _IterableElementBase = class _IterableElementBase {
179
+ var IterableElementBase = class {
180
+ static {
181
+ __name(this, "IterableElementBase");
182
+ }
181
183
  /**
182
184
  * Create a new iterable base.
183
185
  *
@@ -188,19 +190,19 @@ var _IterableElementBase = class _IterableElementBase {
188
190
  * Time O(1), Space O(1).
189
191
  */
190
192
  constructor(options) {
191
- /**
192
- * The converter used to transform a raw element (`R`) into a public element (`E`).
193
- *
194
- * @remarks
195
- * Time O(1), Space O(1).
196
- */
197
- __publicField(this, "_toElementFn");
198
193
  if (options) {
199
194
  const { toElementFn } = options;
200
195
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
201
196
  else if (toElementFn) throw new TypeError("toElementFn must be a function type");
202
197
  }
203
198
  }
199
+ /**
200
+ * The converter used to transform a raw element (`R`) into a public element (`E`).
201
+ *
202
+ * @remarks
203
+ * Time O(1), Space O(1).
204
+ */
205
+ _toElementFn;
204
206
  /**
205
207
  * Exposes the current `toElementFn`, if configured.
206
208
  *
@@ -395,8 +397,6 @@ var _IterableElementBase = class _IterableElementBase {
395
397
  console.log(this.toVisual());
396
398
  }
397
399
  };
398
- __name(_IterableElementBase, "IterableElementBase");
399
- var IterableElementBase = _IterableElementBase;
400
400
 
401
401
  // src/utils/utils.ts
402
402
  var uuidV4 = /* @__PURE__ */ __name(function() {
@@ -517,7 +517,10 @@ function toBinaryString(num, digit = 32) {
517
517
  __name(toBinaryString, "toBinaryString");
518
518
 
519
519
  // src/data-structures/hash/hash-map.ts
520
- var _HashMap = class _HashMap extends IterableEntryBase {
520
+ var HashMap = class extends IterableEntryBase {
521
+ static {
522
+ __name(this, "HashMap");
523
+ }
521
524
  /**
522
525
  * Create a HashMap and optionally bulk-insert entries.
523
526
  * @remarks Time O(N), Space O(N)
@@ -527,11 +530,6 @@ var _HashMap = class _HashMap extends IterableEntryBase {
527
530
  */
528
531
  constructor(entryOrRawElements = [], options) {
529
532
  super();
530
- __publicField(this, "_store", {});
531
- __publicField(this, "_objMap", /* @__PURE__ */ new Map());
532
- __publicField(this, "_toEntryFn");
533
- __publicField(this, "_size", 0);
534
- __publicField(this, "_hashFn", /* @__PURE__ */ __name((key) => String(key), "_hashFn"));
535
533
  if (options) {
536
534
  const { hashFn, toEntryFn } = options;
537
535
  if (hashFn) this._hashFn = hashFn;
@@ -539,6 +537,7 @@ var _HashMap = class _HashMap extends IterableEntryBase {
539
537
  }
540
538
  if (entryOrRawElements) this.setMany(entryOrRawElements);
541
539
  }
540
+ _store = {};
542
541
  /**
543
542
  * Get the internal store for non-object keys.
544
543
  * @remarks Time O(1), Space O(1)
@@ -547,6 +546,7 @@ var _HashMap = class _HashMap extends IterableEntryBase {
547
546
  get store() {
548
547
  return this._store;
549
548
  }
549
+ _objMap = /* @__PURE__ */ new Map();
550
550
  /**
551
551
  * Get the internal Map used for object/function keys.
552
552
  * @remarks Time O(1), Space O(1)
@@ -555,6 +555,7 @@ var _HashMap = class _HashMap extends IterableEntryBase {
555
555
  get objMap() {
556
556
  return this._objMap;
557
557
  }
558
+ _toEntryFn;
558
559
  /**
559
560
  * Get the raw→entry converter function if present.
560
561
  * @remarks Time O(1), Space O(1)
@@ -563,6 +564,7 @@ var _HashMap = class _HashMap extends IterableEntryBase {
563
564
  get toEntryFn() {
564
565
  return this._toEntryFn;
565
566
  }
567
+ _size = 0;
566
568
  /**
567
569
  * Get the number of distinct keys stored.
568
570
  * @remarks Time O(1), Space O(1)
@@ -571,6 +573,7 @@ var _HashMap = class _HashMap extends IterableEntryBase {
571
573
  get size() {
572
574
  return this._size;
573
575
  }
576
+ _hashFn = /* @__PURE__ */ __name((key) => String(key), "_hashFn");
574
577
  /**
575
578
  * Get the current hash function for non-object keys.
576
579
  * @remarks Time O(1), Space O(1)
@@ -646,10 +649,9 @@ var _HashMap = class _HashMap extends IterableEntryBase {
646
649
  * @returns Value or undefined.
647
650
  */
648
651
  get(key) {
649
- var _a;
650
652
  if (this._isObjKey(key)) return this.objMap.get(key);
651
653
  const strKey = this._getNoObjKey(key);
652
- return (_a = this._store[strKey]) == null ? void 0 : _a.value;
654
+ return this._store[strKey]?.value;
653
655
  }
654
656
  /**
655
657
  * Check if a key exists.
@@ -713,7 +715,7 @@ var _HashMap = class _HashMap extends IterableEntryBase {
713
715
  map(callbackfn, thisArg) {
714
716
  const out = this._createLike();
715
717
  let index = 0;
716
- for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, key, value, index++, this));
718
+ for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, value, key, index++, this));
717
719
  return out;
718
720
  }
719
721
  /**
@@ -726,7 +728,7 @@ var _HashMap = class _HashMap extends IterableEntryBase {
726
728
  filter(predicate, thisArg) {
727
729
  const out = this._createLike();
728
730
  let index = 0;
729
- for (const [key, value] of this) if (predicate.call(thisArg, key, value, index++, this)) out.set(key, value);
731
+ for (const [key, value] of this) if (predicate.call(thisArg, value, key, index++, this)) out.set(key, value);
730
732
  return out;
731
733
  }
732
734
  /**
@@ -774,9 +776,11 @@ var _HashMap = class _HashMap extends IterableEntryBase {
774
776
  return strKey;
775
777
  }
776
778
  };
777
- __name(_HashMap, "HashMap");
778
- var HashMap = _HashMap;
779
- var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
779
+ var LinkedHashMap = class extends IterableEntryBase {
780
+ static {
781
+ __name(this, "LinkedHashMap");
782
+ }
783
+ _sentinel;
780
784
  /**
781
785
  * Create a LinkedHashMap and optionally bulk-insert entries.
782
786
  * @remarks Time O(N), Space O(N)
@@ -786,22 +790,6 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
786
790
  */
787
791
  constructor(entryOrRawElements = [], options) {
788
792
  super();
789
- __publicField(this, "_sentinel");
790
- __publicField(this, "_hashFn", /* @__PURE__ */ __name((key) => String(key), "_hashFn"));
791
- __publicField(this, "_objHashFn", /* @__PURE__ */ __name((key) => key, "_objHashFn"));
792
- __publicField(this, "_noObjMap", {});
793
- __publicField(this, "_objMap", /* @__PURE__ */ new WeakMap());
794
- __publicField(this, "_head");
795
- __publicField(this, "_tail");
796
- __publicField(this, "_toEntryFn", /* @__PURE__ */ __name((rawElement) => {
797
- if (this.isEntry(rawElement)) {
798
- return rawElement;
799
- }
800
- throw new Error(
801
- "If `entryOrRawElements` does not adhere to [key,value], provide `options.toEntryFn` to transform raw records."
802
- );
803
- }, "_toEntryFn"));
804
- __publicField(this, "_size", 0);
805
793
  this._sentinel = {};
806
794
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
807
795
  if (options) {
@@ -812,9 +800,11 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
812
800
  }
813
801
  if (entryOrRawElements) this.setMany(entryOrRawElements);
814
802
  }
803
+ _hashFn = /* @__PURE__ */ __name((key) => String(key), "_hashFn");
815
804
  get hashFn() {
816
805
  return this._hashFn;
817
806
  }
807
+ _objHashFn = /* @__PURE__ */ __name((key) => key, "_objHashFn");
818
808
  /**
819
809
  * Get the hash function for object/weak keys.
820
810
  * @remarks Time O(1), Space O(1)
@@ -823,6 +813,7 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
823
813
  get objHashFn() {
824
814
  return this._objHashFn;
825
815
  }
816
+ _noObjMap = {};
826
817
  /**
827
818
  * Get the internal record for non-object keys.
828
819
  * @remarks Time O(1), Space O(1)
@@ -831,9 +822,11 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
831
822
  get noObjMap() {
832
823
  return this._noObjMap;
833
824
  }
825
+ _objMap = /* @__PURE__ */ new WeakMap();
834
826
  get objMap() {
835
827
  return this._objMap;
836
828
  }
829
+ _head;
837
830
  /**
838
831
  * Get the head node (first entry) sentinel link.
839
832
  * @remarks Time O(1), Space O(1)
@@ -842,6 +835,7 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
842
835
  get head() {
843
836
  return this._head;
844
837
  }
838
+ _tail;
845
839
  /**
846
840
  * Get the tail node (last entry) sentinel link.
847
841
  * @remarks Time O(1), Space O(1)
@@ -850,9 +844,18 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
850
844
  get tail() {
851
845
  return this._tail;
852
846
  }
847
+ _toEntryFn = /* @__PURE__ */ __name((rawElement) => {
848
+ if (this.isEntry(rawElement)) {
849
+ return rawElement;
850
+ }
851
+ throw new Error(
852
+ "If `entryOrRawElements` does not adhere to [key,value], provide `options.toEntryFn` to transform raw records."
853
+ );
854
+ }, "_toEntryFn");
853
855
  get toEntryFn() {
854
856
  return this._toEntryFn;
855
857
  }
858
+ _size = 0;
856
859
  get size() {
857
860
  return this._size;
858
861
  }
@@ -1050,7 +1053,7 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
1050
1053
  const out = this._createLike();
1051
1054
  let index = 0;
1052
1055
  for (const [key, value] of this) {
1053
- if (predicate.call(thisArg, key, value, index, this)) out.set(key, value);
1056
+ if (predicate.call(thisArg, value, key, index, this)) out.set(key, value);
1054
1057
  index++;
1055
1058
  }
1056
1059
  return out;
@@ -1068,7 +1071,7 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
1068
1071
  const out = this._createLike();
1069
1072
  let index = 0;
1070
1073
  for (const [key, value] of this) {
1071
- const [newKey, newValue] = callback.call(thisArg, key, value, index, this);
1074
+ const [newKey, newValue] = callback.call(thisArg, value, key, index, this);
1072
1075
  out.set(newKey, newValue);
1073
1076
  index++;
1074
1077
  }
@@ -1095,22 +1098,22 @@ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
1095
1098
  return new Ctor(entries, options);
1096
1099
  }
1097
1100
  };
1098
- __name(_LinkedHashMap, "LinkedHashMap");
1099
- var LinkedHashMap = _LinkedHashMap;
1100
1101
 
1101
1102
  // src/data-structures/base/linear-base.ts
1102
- var _LinkedListNode = class _LinkedListNode {
1103
+ var LinkedListNode = class {
1104
+ static {
1105
+ __name(this, "LinkedListNode");
1106
+ }
1103
1107
  /**
1104
1108
  * Initialize a node.
1105
1109
  * @param value - Element value.
1106
1110
  * @remarks Time O(1), Space O(1)
1107
1111
  */
1108
1112
  constructor(value) {
1109
- __publicField(this, "_value");
1110
- __publicField(this, "_next");
1111
1113
  this._value = value;
1112
1114
  this._next = void 0;
1113
1115
  }
1116
+ _value;
1114
1117
  /**
1115
1118
  * Element payload getter.
1116
1119
  * @returns Element value.
@@ -1127,6 +1130,7 @@ var _LinkedListNode = class _LinkedListNode {
1127
1130
  set value(value) {
1128
1131
  this._value = value;
1129
1132
  }
1133
+ _next;
1130
1134
  /**
1131
1135
  * Next node getter.
1132
1136
  * @returns Next node or `undefined`.
@@ -1144,9 +1148,10 @@ var _LinkedListNode = class _LinkedListNode {
1144
1148
  this._next = value;
1145
1149
  }
1146
1150
  };
1147
- __name(_LinkedListNode, "LinkedListNode");
1148
- var LinkedListNode = _LinkedListNode;
1149
- var _LinearBase = class _LinearBase extends IterableElementBase {
1151
+ var LinearBase = class _LinearBase extends IterableElementBase {
1152
+ static {
1153
+ __name(this, "LinearBase");
1154
+ }
1150
1155
  /**
1151
1156
  * Construct a linear container with runtime options.
1152
1157
  * @param options - `{ maxLen?, ... }` bounds/behavior options.
@@ -1154,12 +1159,12 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
1154
1159
  */
1155
1160
  constructor(options) {
1156
1161
  super(options);
1157
- __publicField(this, "_maxLen", -1);
1158
1162
  if (options) {
1159
1163
  const { maxLen } = options;
1160
1164
  if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
1161
1165
  }
1162
1166
  }
1167
+ _maxLen = -1;
1163
1168
  /**
1164
1169
  * Upper bound for length (if positive), or `-1` when unbounded.
1165
1170
  * @returns Maximum allowed length.
@@ -1292,7 +1297,7 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
1292
1297
  return array;
1293
1298
  }
1294
1299
  reduceRight(callbackfn, initialValue) {
1295
- let accumulator = initialValue != null ? initialValue : 0;
1300
+ let accumulator = initialValue ?? 0;
1296
1301
  for (let i = this.length - 1; i >= 0; i--) {
1297
1302
  accumulator = callbackfn(accumulator, this.at(i), i, this);
1298
1303
  }
@@ -1334,9 +1339,10 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
1334
1339
  return this;
1335
1340
  }
1336
1341
  };
1337
- __name(_LinearBase, "LinearBase");
1338
- var LinearBase = _LinearBase;
1339
- var _LinearLinkedBase = class _LinearLinkedBase extends LinearBase {
1342
+ var LinearLinkedBase = class extends LinearBase {
1343
+ static {
1344
+ __name(this, "LinearLinkedBase");
1345
+ }
1340
1346
  constructor(options) {
1341
1347
  super(options);
1342
1348
  if (options) {
@@ -1466,7 +1472,7 @@ var _LinearLinkedBase = class _LinearLinkedBase extends LinearBase {
1466
1472
  return removedList;
1467
1473
  }
1468
1474
  reduceRight(callbackfn, initialValue) {
1469
- let accumulator = initialValue != null ? initialValue : 0;
1475
+ let accumulator = initialValue ?? 0;
1470
1476
  let index = this.length - 1;
1471
1477
  for (const item of this._getReverseIterator()) {
1472
1478
  accumulator = callbackfn(accumulator, item, index--, this);
@@ -1474,11 +1480,12 @@ var _LinearLinkedBase = class _LinearLinkedBase extends LinearBase {
1474
1480
  return accumulator;
1475
1481
  }
1476
1482
  };
1477
- __name(_LinearLinkedBase, "LinearLinkedBase");
1478
- var LinearLinkedBase = _LinearLinkedBase;
1479
1483
 
1480
1484
  // src/data-structures/linked-list/singly-linked-list.ts
1481
- var _SinglyLinkedListNode = class _SinglyLinkedListNode extends LinkedListNode {
1485
+ var SinglyLinkedListNode = class extends LinkedListNode {
1486
+ static {
1487
+ __name(this, "SinglyLinkedListNode");
1488
+ }
1482
1489
  /**
1483
1490
  * Create a list node.
1484
1491
  * @remarks Time O(1), Space O(1)
@@ -1487,10 +1494,10 @@ var _SinglyLinkedListNode = class _SinglyLinkedListNode extends LinkedListNode {
1487
1494
  */
1488
1495
  constructor(value) {
1489
1496
  super(value);
1490
- __publicField(this, "_next");
1491
1497
  this._value = value;
1492
1498
  this._next = void 0;
1493
1499
  }
1500
+ _next;
1494
1501
  /**
1495
1502
  * Get the next node.
1496
1503
  * @remarks Time O(1), Space O(1)
@@ -1509,9 +1516,11 @@ var _SinglyLinkedListNode = class _SinglyLinkedListNode extends LinkedListNode {
1509
1516
  this._next = value;
1510
1517
  }
1511
1518
  };
1512
- __name(_SinglyLinkedListNode, "SinglyLinkedListNode");
1513
- var SinglyLinkedListNode = _SinglyLinkedListNode;
1514
- var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1519
+ var SinglyLinkedList = class extends LinearLinkedBase {
1520
+ static {
1521
+ __name(this, "SinglyLinkedList");
1522
+ }
1523
+ _equals = Object.is;
1515
1524
  /**
1516
1525
  * Create a SinglyLinkedList and optionally bulk-insert elements.
1517
1526
  * @remarks Time O(N), Space O(N)
@@ -1521,12 +1530,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1521
1530
  */
1522
1531
  constructor(elements = [], options) {
1523
1532
  super(options);
1524
- __publicField(this, "_equals", Object.is);
1525
- __publicField(this, "_head");
1526
- __publicField(this, "_tail");
1527
- __publicField(this, "_length", 0);
1528
1533
  this.pushMany(elements);
1529
1534
  }
1535
+ _head;
1530
1536
  /**
1531
1537
  * Get the head node.
1532
1538
  * @remarks Time O(1), Space O(1)
@@ -1535,6 +1541,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1535
1541
  get head() {
1536
1542
  return this._head;
1537
1543
  }
1544
+ _tail;
1538
1545
  /**
1539
1546
  * Get the tail node.
1540
1547
  * @remarks Time O(1), Space O(1)
@@ -1543,6 +1550,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1543
1550
  get tail() {
1544
1551
  return this._tail;
1545
1552
  }
1553
+ _length = 0;
1546
1554
  /**
1547
1555
  * Get the number of elements.
1548
1556
  * @remarks Time O(1), Space O(1)
@@ -1557,8 +1565,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1557
1565
  * @returns First element or undefined.
1558
1566
  */
1559
1567
  get first() {
1560
- var _a;
1561
- return (_a = this.head) == null ? void 0 : _a.value;
1568
+ return this.head?.value;
1562
1569
  }
1563
1570
  /**
1564
1571
  * Get the last element value.
@@ -1566,8 +1573,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1566
1573
  * @returns Last element or undefined.
1567
1574
  */
1568
1575
  get last() {
1569
- var _a;
1570
- return (_a = this.tail) == null ? void 0 : _a.value;
1576
+ return this.tail?.value;
1571
1577
  }
1572
1578
  /**
1573
1579
  * Create a new list from an iterable of elements.
@@ -2046,7 +2052,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
2046
2052
  * @returns A new SinglyLinkedList with mapped values.
2047
2053
  */
2048
2054
  map(callback, options, thisArg) {
2049
- const out = this._createLike([], { ...options != null ? options : {}, maxLen: this._maxLen });
2055
+ const out = this._createLike([], { ...options ?? {}, maxLen: this._maxLen });
2050
2056
  let index = 0;
2051
2057
  for (const value of this) out.push(callback.call(thisArg, value, index++, this));
2052
2058
  return out;
@@ -2171,8 +2177,6 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
2171
2177
  return this._createLike([], options);
2172
2178
  }
2173
2179
  };
2174
- __name(_SinglyLinkedList, "SinglyLinkedList");
2175
- var SinglyLinkedList = _SinglyLinkedList;
2176
2180
  function elementOrPredicate(input, equals) {
2177
2181
  if (input instanceof SinglyLinkedListNode) return (node) => node === input;
2178
2182
  if (typeof input === "function") return input;
@@ -2182,7 +2186,10 @@ function elementOrPredicate(input, equals) {
2182
2186
  __name(elementOrPredicate, "elementOrPredicate");
2183
2187
 
2184
2188
  // src/data-structures/linked-list/doubly-linked-list.ts
2185
- var _DoublyLinkedListNode = class _DoublyLinkedListNode extends LinkedListNode {
2189
+ var DoublyLinkedListNode = class extends LinkedListNode {
2190
+ static {
2191
+ __name(this, "DoublyLinkedListNode");
2192
+ }
2186
2193
  /**
2187
2194
  * Create a node.
2188
2195
  * @remarks Time O(1), Space O(1)
@@ -2191,12 +2198,11 @@ var _DoublyLinkedListNode = class _DoublyLinkedListNode extends LinkedListNode {
2191
2198
  */
2192
2199
  constructor(value) {
2193
2200
  super(value);
2194
- __publicField(this, "_next");
2195
- __publicField(this, "_prev");
2196
2201
  this._value = value;
2197
2202
  this._next = void 0;
2198
2203
  this._prev = void 0;
2199
2204
  }
2205
+ _next;
2200
2206
  /**
2201
2207
  * Get the next node link.
2202
2208
  * @remarks Time O(1), Space O(1)
@@ -2214,6 +2220,7 @@ var _DoublyLinkedListNode = class _DoublyLinkedListNode extends LinkedListNode {
2214
2220
  set next(value) {
2215
2221
  this._next = value;
2216
2222
  }
2223
+ _prev;
2217
2224
  /**
2218
2225
  * Get the previous node link.
2219
2226
  * @remarks Time O(1), Space O(1)
@@ -2232,9 +2239,11 @@ var _DoublyLinkedListNode = class _DoublyLinkedListNode extends LinkedListNode {
2232
2239
  this._prev = value;
2233
2240
  }
2234
2241
  };
2235
- __name(_DoublyLinkedListNode, "DoublyLinkedListNode");
2236
- var DoublyLinkedListNode = _DoublyLinkedListNode;
2237
- var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2242
+ var DoublyLinkedList = class extends LinearLinkedBase {
2243
+ static {
2244
+ __name(this, "DoublyLinkedList");
2245
+ }
2246
+ _equals = Object.is;
2238
2247
  /**
2239
2248
  * Create a DoublyLinkedList and optionally bulk-insert elements.
2240
2249
  * @remarks Time O(N), Space O(N)
@@ -2244,18 +2253,15 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2244
2253
  */
2245
2254
  constructor(elements = [], options) {
2246
2255
  super(options);
2247
- __publicField(this, "_equals", Object.is);
2248
- __publicField(this, "_head");
2249
- __publicField(this, "_tail");
2250
- __publicField(this, "_length", 0);
2251
2256
  this._head = void 0;
2252
2257
  this._tail = void 0;
2253
2258
  this._length = 0;
2254
- if ((options == null ? void 0 : options.maxLen) && Number.isInteger(options.maxLen) && options.maxLen > 0) {
2259
+ if (options?.maxLen && Number.isInteger(options.maxLen) && options.maxLen > 0) {
2255
2260
  this._maxLen = options.maxLen;
2256
2261
  }
2257
2262
  this.pushMany(elements);
2258
2263
  }
2264
+ _head;
2259
2265
  /**
2260
2266
  * Get the head node.
2261
2267
  * @remarks Time O(1), Space O(1)
@@ -2264,6 +2270,7 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2264
2270
  get head() {
2265
2271
  return this._head;
2266
2272
  }
2273
+ _tail;
2267
2274
  /**
2268
2275
  * Get the tail node.
2269
2276
  * @remarks Time O(1), Space O(1)
@@ -2272,6 +2279,7 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2272
2279
  get tail() {
2273
2280
  return this._tail;
2274
2281
  }
2282
+ _length = 0;
2275
2283
  /**
2276
2284
  * Get the number of elements.
2277
2285
  * @remarks Time O(1), Space O(1)
@@ -2286,8 +2294,7 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2286
2294
  * @returns First element or undefined.
2287
2295
  */
2288
2296
  get first() {
2289
- var _a;
2290
- return (_a = this.head) == null ? void 0 : _a.value;
2297
+ return this.head?.value;
2291
2298
  }
2292
2299
  /**
2293
2300
  * Get the last element value.
@@ -2295,8 +2302,7 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2295
2302
  * @returns Last element or undefined.
2296
2303
  */
2297
2304
  get last() {
2298
- var _a;
2299
- return (_a = this.tail) == null ? void 0 : _a.value;
2305
+ return this.tail?.value;
2300
2306
  }
2301
2307
  /**
2302
2308
  * Create a new list from an array of elements.
@@ -2711,7 +2717,7 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2711
2717
  * @returns A new DoublyLinkedList with mapped values.
2712
2718
  */
2713
2719
  map(callback, options, thisArg) {
2714
- const out = this._createLike([], { ...options != null ? options : {}, maxLen: this._maxLen });
2720
+ const out = this._createLike([], { ...options ?? {}, maxLen: this._maxLen });
2715
2721
  let index = 0;
2716
2722
  for (const v of this) out.push(callback.call(thisArg, v, index++, this));
2717
2723
  return out;
@@ -2797,28 +2803,26 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2797
2803
  }
2798
2804
  }
2799
2805
  };
2800
- __name(_DoublyLinkedList, "DoublyLinkedList");
2801
- var DoublyLinkedList = _DoublyLinkedList;
2802
2806
 
2803
2807
  // src/data-structures/linked-list/skip-linked-list.ts
2804
- var _SkipListNode = class _SkipListNode {
2808
+ var SkipListNode = class {
2809
+ static {
2810
+ __name(this, "SkipListNode");
2811
+ }
2812
+ key;
2813
+ value;
2814
+ forward;
2805
2815
  constructor(key, value, level) {
2806
- __publicField(this, "key");
2807
- __publicField(this, "value");
2808
- __publicField(this, "forward");
2809
2816
  this.key = key;
2810
2817
  this.value = value;
2811
2818
  this.forward = new Array(level);
2812
2819
  }
2813
2820
  };
2814
- __name(_SkipListNode, "SkipListNode");
2815
- var SkipListNode = _SkipListNode;
2816
- var _SkipList = class _SkipList {
2821
+ var SkipList = class {
2822
+ static {
2823
+ __name(this, "SkipList");
2824
+ }
2817
2825
  constructor(elements = [], options) {
2818
- __publicField(this, "_head", new SkipListNode(void 0, void 0, this.maxLevel));
2819
- __publicField(this, "_level", 0);
2820
- __publicField(this, "_maxLevel", 16);
2821
- __publicField(this, "_probability", 0.5);
2822
2826
  if (options) {
2823
2827
  const { maxLevel, probability } = options;
2824
2828
  if (typeof maxLevel === "number") this._maxLevel = maxLevel;
@@ -2828,15 +2832,19 @@ var _SkipList = class _SkipList {
2828
2832
  for (const [key, value] of elements) this.add(key, value);
2829
2833
  }
2830
2834
  }
2835
+ _head = new SkipListNode(void 0, void 0, this.maxLevel);
2831
2836
  get head() {
2832
2837
  return this._head;
2833
2838
  }
2839
+ _level = 0;
2834
2840
  get level() {
2835
2841
  return this._level;
2836
2842
  }
2843
+ _maxLevel = 16;
2837
2844
  get maxLevel() {
2838
2845
  return this._maxLevel;
2839
2846
  }
2847
+ _probability = 0.5;
2840
2848
  get probability() {
2841
2849
  return this._probability;
2842
2850
  }
@@ -2942,11 +2950,13 @@ var _SkipList = class _SkipList {
2942
2950
  return level;
2943
2951
  }
2944
2952
  };
2945
- __name(_SkipList, "SkipList");
2946
- var SkipList = _SkipList;
2947
2953
 
2948
2954
  // src/data-structures/stack/stack.ts
2949
- var _Stack = class _Stack extends IterableElementBase {
2955
+ var Stack = class extends IterableElementBase {
2956
+ static {
2957
+ __name(this, "Stack");
2958
+ }
2959
+ _equals = Object.is;
2950
2960
  /**
2951
2961
  * Create a Stack and optionally bulk-push elements.
2952
2962
  * @remarks Time O(N), Space O(N)
@@ -2956,10 +2966,9 @@ var _Stack = class _Stack extends IterableElementBase {
2956
2966
  */
2957
2967
  constructor(elements = [], options) {
2958
2968
  super(options);
2959
- __publicField(this, "_equals", Object.is);
2960
- __publicField(this, "_elements", []);
2961
2969
  this.pushMany(elements);
2962
2970
  }
2971
+ _elements = [];
2963
2972
  /**
2964
2973
  * Get the backing array of elements.
2965
2974
  * @remarks Time O(1), Space O(1)
@@ -3134,7 +3143,7 @@ var _Stack = class _Stack extends IterableElementBase {
3134
3143
  * @returns A new Stack with mapped elements.
3135
3144
  */
3136
3145
  map(callback, options, thisArg) {
3137
- const out = this._createLike([], { ...options != null ? options : {} });
3146
+ const out = this._createLike([], { ...options ?? {} });
3138
3147
  let index = 0;
3139
3148
  for (const v of this) {
3140
3149
  out.push(thisArg === void 0 ? callback(v, index, this) : callback.call(thisArg, v, index, this));
@@ -3194,11 +3203,12 @@ var _Stack = class _Stack extends IterableElementBase {
3194
3203
  for (let i = 0; i < this.elements.length; i++) yield this.elements[i];
3195
3204
  }
3196
3205
  };
3197
- __name(_Stack, "Stack");
3198
- var Stack = _Stack;
3199
3206
 
3200
3207
  // src/data-structures/queue/queue.ts
3201
- var _Queue = class _Queue extends LinearBase {
3208
+ var Queue = class _Queue extends LinearBase {
3209
+ static {
3210
+ __name(this, "Queue");
3211
+ }
3202
3212
  /**
3203
3213
  * Create a Queue and optionally bulk-insert elements.
3204
3214
  * @remarks Time O(N), Space O(N)
@@ -3208,15 +3218,13 @@ var _Queue = class _Queue extends LinearBase {
3208
3218
  */
3209
3219
  constructor(elements = [], options) {
3210
3220
  super(options);
3211
- __publicField(this, "_elements", []);
3212
- __publicField(this, "_offset", 0);
3213
- __publicField(this, "_autoCompactRatio", 0.5);
3214
3221
  if (options) {
3215
3222
  const { autoCompactRatio = 0.5 } = options;
3216
3223
  this._autoCompactRatio = autoCompactRatio;
3217
3224
  }
3218
3225
  this.pushMany(elements);
3219
3226
  }
3227
+ _elements = [];
3220
3228
  /**
3221
3229
  * Get the underlying array buffer.
3222
3230
  * @remarks Time O(1), Space O(1)
@@ -3225,6 +3233,7 @@ var _Queue = class _Queue extends LinearBase {
3225
3233
  get elements() {
3226
3234
  return this._elements;
3227
3235
  }
3236
+ _offset = 0;
3228
3237
  /**
3229
3238
  * Get the current start offset into the array.
3230
3239
  * @remarks Time O(1), Space O(1)
@@ -3233,6 +3242,7 @@ var _Queue = class _Queue extends LinearBase {
3233
3242
  get offset() {
3234
3243
  return this._offset;
3235
3244
  }
3245
+ _autoCompactRatio = 0.5;
3236
3246
  /**
3237
3247
  * Get the compaction threshold (offset/size).
3238
3248
  * @remarks Time O(1), Space O(1)
@@ -3477,11 +3487,10 @@ var _Queue = class _Queue extends LinearBase {
3477
3487
  * @returns A new Queue with mapped elements.
3478
3488
  */
3479
3489
  map(callback, options, thisArg) {
3480
- var _a, _b;
3481
3490
  const out = new this.constructor([], {
3482
- toElementFn: options == null ? void 0 : options.toElementFn,
3483
- maxLen: (_a = options == null ? void 0 : options.maxLen) != null ? _a : this._maxLen,
3484
- autoCompactRatio: (_b = options == null ? void 0 : options.autoCompactRatio) != null ? _b : this._autoCompactRatio
3491
+ toElementFn: options?.toElementFn,
3492
+ maxLen: options?.maxLen ?? this._maxLen,
3493
+ autoCompactRatio: options?.autoCompactRatio ?? this._autoCompactRatio
3485
3494
  });
3486
3495
  let index = 0;
3487
3496
  for (const v of this)
@@ -3496,14 +3505,13 @@ var _Queue = class _Queue extends LinearBase {
3496
3505
  * @returns A new queue with mapped elements (same element type).
3497
3506
  */
3498
3507
  mapSame(callback, thisArg) {
3499
- var _a;
3500
3508
  const Ctor = this.constructor;
3501
3509
  const out = new Ctor([], {
3502
3510
  toElementFn: this.toElementFn,
3503
3511
  maxLen: this._maxLen,
3504
3512
  autoCompactRatio: this._autoCompactRatio
3505
3513
  });
3506
- (_a = out._setAutoCompactRatio) == null ? void 0 : _a.call(out, this._autoCompactRatio);
3514
+ out._setAutoCompactRatio?.(this._autoCompactRatio);
3507
3515
  let index = 0;
3508
3516
  for (const v of this) {
3509
3517
  const mv = thisArg === void 0 ? callback(v, index++, this) : callback.call(thisArg, v, index++, this);
@@ -3563,9 +3571,10 @@ var _Queue = class _Queue extends LinearBase {
3563
3571
  return new Ctor(elements, options);
3564
3572
  }
3565
3573
  };
3566
- __name(_Queue, "Queue");
3567
- var Queue = _Queue;
3568
- var _LinkedListQueue = class _LinkedListQueue extends SinglyLinkedList {
3574
+ var LinkedListQueue = class extends SinglyLinkedList {
3575
+ static {
3576
+ __name(this, "LinkedListQueue");
3577
+ }
3569
3578
  /**
3570
3579
  * Deep clone this linked-list-based queue.
3571
3580
  * @remarks Time O(N), Space O(N)
@@ -3577,11 +3586,13 @@ var _LinkedListQueue = class _LinkedListQueue extends SinglyLinkedList {
3577
3586
  return out;
3578
3587
  }
3579
3588
  };
3580
- __name(_LinkedListQueue, "LinkedListQueue");
3581
- var LinkedListQueue = _LinkedListQueue;
3582
3589
 
3583
3590
  // src/data-structures/queue/deque.ts
3584
- var _Deque = class _Deque extends LinearBase {
3591
+ var Deque = class extends LinearBase {
3592
+ static {
3593
+ __name(this, "Deque");
3594
+ }
3595
+ _equals = Object.is;
3585
3596
  /**
3586
3597
  * Create a Deque and optionally bulk-insert elements.
3587
3598
  * @remarks Time O(N), Space O(N)
@@ -3591,15 +3602,6 @@ var _Deque = class _Deque extends LinearBase {
3591
3602
  */
3592
3603
  constructor(elements = [], options) {
3593
3604
  super(options);
3594
- __publicField(this, "_equals", Object.is);
3595
- __publicField(this, "_bucketSize", 1 << 12);
3596
- __publicField(this, "_bucketFirst", 0);
3597
- __publicField(this, "_firstInBucket", 0);
3598
- __publicField(this, "_bucketLast", 0);
3599
- __publicField(this, "_lastInBucket", 0);
3600
- __publicField(this, "_bucketCount", 0);
3601
- __publicField(this, "_buckets", []);
3602
- __publicField(this, "_length", 0);
3603
3605
  if (options) {
3604
3606
  const { bucketSize } = options;
3605
3607
  if (typeof bucketSize === "number") this._bucketSize = bucketSize;
@@ -3619,6 +3621,7 @@ var _Deque = class _Deque extends LinearBase {
3619
3621
  this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
3620
3622
  this.pushMany(elements);
3621
3623
  }
3624
+ _bucketSize = 1 << 12;
3622
3625
  /**
3623
3626
  * Get the current bucket size.
3624
3627
  * @remarks Time O(1), Space O(1)
@@ -3627,6 +3630,7 @@ var _Deque = class _Deque extends LinearBase {
3627
3630
  get bucketSize() {
3628
3631
  return this._bucketSize;
3629
3632
  }
3633
+ _bucketFirst = 0;
3630
3634
  /**
3631
3635
  * Get the index of the first bucket in use.
3632
3636
  * @remarks Time O(1), Space O(1)
@@ -3635,6 +3639,7 @@ var _Deque = class _Deque extends LinearBase {
3635
3639
  get bucketFirst() {
3636
3640
  return this._bucketFirst;
3637
3641
  }
3642
+ _firstInBucket = 0;
3638
3643
  /**
3639
3644
  * Get the index inside the first bucket.
3640
3645
  * @remarks Time O(1), Space O(1)
@@ -3643,6 +3648,7 @@ var _Deque = class _Deque extends LinearBase {
3643
3648
  get firstInBucket() {
3644
3649
  return this._firstInBucket;
3645
3650
  }
3651
+ _bucketLast = 0;
3646
3652
  /**
3647
3653
  * Get the index of the last bucket in use.
3648
3654
  * @remarks Time O(1), Space O(1)
@@ -3651,6 +3657,7 @@ var _Deque = class _Deque extends LinearBase {
3651
3657
  get bucketLast() {
3652
3658
  return this._bucketLast;
3653
3659
  }
3660
+ _lastInBucket = 0;
3654
3661
  /**
3655
3662
  * Get the index inside the last bucket.
3656
3663
  * @remarks Time O(1), Space O(1)
@@ -3659,6 +3666,7 @@ var _Deque = class _Deque extends LinearBase {
3659
3666
  get lastInBucket() {
3660
3667
  return this._lastInBucket;
3661
3668
  }
3669
+ _bucketCount = 0;
3662
3670
  /**
3663
3671
  * Get the number of buckets allocated.
3664
3672
  * @remarks Time O(1), Space O(1)
@@ -3667,6 +3675,7 @@ var _Deque = class _Deque extends LinearBase {
3667
3675
  get bucketCount() {
3668
3676
  return this._bucketCount;
3669
3677
  }
3678
+ _buckets = [];
3670
3679
  /**
3671
3680
  * Get the internal buckets array.
3672
3681
  * @remarks Time O(1), Space O(1)
@@ -3675,6 +3684,7 @@ var _Deque = class _Deque extends LinearBase {
3675
3684
  get buckets() {
3676
3685
  return this._buckets;
3677
3686
  }
3687
+ _length = 0;
3678
3688
  /**
3679
3689
  * Get the number of elements in the deque.
3680
3690
  * @remarks Time O(1), Space O(1)
@@ -4190,7 +4200,7 @@ var _Deque = class _Deque extends LinearBase {
4190
4200
  */
4191
4201
  map(callback, options, thisArg) {
4192
4202
  const out = this._createLike([], {
4193
- ...options != null ? options : {},
4203
+ ...options ?? {},
4194
4204
  bucketSize: this._bucketSize,
4195
4205
  maxLen: this._maxLen
4196
4206
  });
@@ -4304,11 +4314,13 @@ var _Deque = class _Deque extends LinearBase {
4304
4314
  }
4305
4315
  }
4306
4316
  };
4307
- __name(_Deque, "Deque");
4308
- var Deque = _Deque;
4309
4317
 
4310
4318
  // src/data-structures/heap/heap.ts
4311
- var _Heap = class _Heap extends IterableElementBase {
4319
+ var Heap = class _Heap extends IterableElementBase {
4320
+ static {
4321
+ __name(this, "Heap");
4322
+ }
4323
+ _equals = Object.is;
4312
4324
  /**
4313
4325
  * Create a Heap and optionally bulk-insert elements.
4314
4326
  * @remarks Time O(N), Space O(N)
@@ -4318,23 +4330,13 @@ var _Heap = class _Heap extends IterableElementBase {
4318
4330
  */
4319
4331
  constructor(elements = [], options) {
4320
4332
  super(options);
4321
- __publicField(this, "_equals", Object.is);
4322
- __publicField(this, "_elements", []);
4323
- __publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
4324
- if (typeof a === "object" || typeof b === "object") {
4325
- throw TypeError("When comparing object types, define a custom comparator in options.");
4326
- }
4327
- if (a > b) return 1;
4328
- if (a < b) return -1;
4329
- return 0;
4330
- }, "_DEFAULT_COMPARATOR"));
4331
- __publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
4332
4333
  if (options) {
4333
4334
  const { comparator } = options;
4334
4335
  if (comparator) this._comparator = comparator;
4335
4336
  }
4336
4337
  this.addMany(elements);
4337
4338
  }
4339
+ _elements = [];
4338
4340
  /**
4339
4341
  * Get the backing array of the heap.
4340
4342
  * @remarks Time O(1), Space O(1)
@@ -4357,8 +4359,7 @@ var _Heap = class _Heap extends IterableElementBase {
4357
4359
  * @returns Last element or undefined.
4358
4360
  */
4359
4361
  get leaf() {
4360
- var _a;
4361
- return (_a = this.elements[this.size - 1]) != null ? _a : void 0;
4362
+ return this.elements[this.size - 1] ?? void 0;
4362
4363
  }
4363
4364
  /**
4364
4365
  * Create a heap of the same class from an iterable.
@@ -4631,7 +4632,7 @@ var _Heap = class _Heap extends IterableElementBase {
4631
4632
  * @returns A new heap with mapped elements.
4632
4633
  */
4633
4634
  map(callback, options, thisArg) {
4634
- const { comparator, toElementFn, ...rest } = options != null ? options : {};
4635
+ const { comparator, toElementFn, ...rest } = options ?? {};
4635
4636
  if (!comparator) throw new TypeError("Heap.map requires options.comparator for EM");
4636
4637
  const out = this._createLike([], { ...rest, comparator, toElementFn });
4637
4638
  let i = 0;
@@ -4657,6 +4658,15 @@ var _Heap = class _Heap extends IterableElementBase {
4657
4658
  }
4658
4659
  return out;
4659
4660
  }
4661
+ _DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
4662
+ if (typeof a === "object" || typeof b === "object") {
4663
+ throw TypeError("When comparing object types, define a custom comparator in options.");
4664
+ }
4665
+ if (a > b) return 1;
4666
+ if (a < b) return -1;
4667
+ return 0;
4668
+ }, "_DEFAULT_COMPARATOR");
4669
+ _comparator = this._DEFAULT_COMPARATOR;
4660
4670
  /**
4661
4671
  * Get the comparator used to order elements.
4662
4672
  * @remarks Time O(1), Space O(1)
@@ -4710,7 +4720,7 @@ var _Heap = class _Heap extends IterableElementBase {
4710
4720
  */
4711
4721
  _createInstance(options) {
4712
4722
  const Ctor = this.constructor;
4713
- const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
4723
+ const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options ?? {} });
4714
4724
  return next;
4715
4725
  }
4716
4726
  /**
@@ -4738,25 +4748,27 @@ var _Heap = class _Heap extends IterableElementBase {
4738
4748
  return this._createLike([], options);
4739
4749
  }
4740
4750
  };
4741
- __name(_Heap, "Heap");
4742
- var Heap = _Heap;
4743
- var _FibonacciHeapNode = class _FibonacciHeapNode {
4751
+ var FibonacciHeapNode = class {
4752
+ static {
4753
+ __name(this, "FibonacciHeapNode");
4754
+ }
4755
+ element;
4756
+ degree;
4757
+ left;
4758
+ right;
4759
+ child;
4760
+ parent;
4761
+ marked;
4744
4762
  constructor(element, degree = 0) {
4745
- __publicField(this, "element");
4746
- __publicField(this, "degree");
4747
- __publicField(this, "left");
4748
- __publicField(this, "right");
4749
- __publicField(this, "child");
4750
- __publicField(this, "parent");
4751
- __publicField(this, "marked");
4752
4763
  this.element = element;
4753
4764
  this.degree = degree;
4754
4765
  this.marked = false;
4755
4766
  }
4756
4767
  };
4757
- __name(_FibonacciHeapNode, "FibonacciHeapNode");
4758
- var FibonacciHeapNode = _FibonacciHeapNode;
4759
- var _FibonacciHeap = class _FibonacciHeap {
4768
+ var FibonacciHeap = class {
4769
+ static {
4770
+ __name(this, "FibonacciHeap");
4771
+ }
4760
4772
  /**
4761
4773
  * Create a FibonacciHeap.
4762
4774
  * @remarks Time O(1), Space O(1)
@@ -4764,14 +4776,11 @@ var _FibonacciHeap = class _FibonacciHeap {
4764
4776
  * @returns New FibonacciHeap instance.
4765
4777
  */
4766
4778
  constructor(comparator) {
4767
- __publicField(this, "_root");
4768
- __publicField(this, "_size", 0);
4769
- __publicField(this, "_min");
4770
- __publicField(this, "_comparator");
4771
4779
  this.clear();
4772
4780
  this._comparator = comparator || this._defaultComparator;
4773
4781
  if (typeof this.comparator !== "function") throw new Error("FibonacciHeap: comparator must be a function.");
4774
4782
  }
4783
+ _root;
4775
4784
  /**
4776
4785
  * Get the circular root list head.
4777
4786
  * @remarks Time O(1), Space O(1)
@@ -4780,9 +4789,11 @@ var _FibonacciHeap = class _FibonacciHeap {
4780
4789
  get root() {
4781
4790
  return this._root;
4782
4791
  }
4792
+ _size = 0;
4783
4793
  get size() {
4784
4794
  return this._size;
4785
4795
  }
4796
+ _min;
4786
4797
  /**
4787
4798
  * Get the current minimum node.
4788
4799
  * @remarks Time O(1), Space O(1)
@@ -4791,6 +4802,7 @@ var _FibonacciHeap = class _FibonacciHeap {
4791
4802
  get min() {
4792
4803
  return this._min;
4793
4804
  }
4805
+ _comparator;
4794
4806
  get comparator() {
4795
4807
  return this._comparator;
4796
4808
  }
@@ -4967,11 +4979,12 @@ var _FibonacciHeap = class _FibonacciHeap {
4967
4979
  }
4968
4980
  }
4969
4981
  };
4970
- __name(_FibonacciHeap, "FibonacciHeap");
4971
- var FibonacciHeap = _FibonacciHeap;
4972
4982
 
4973
4983
  // src/data-structures/heap/max-heap.ts
4974
- var _MaxHeap = class _MaxHeap extends Heap {
4984
+ var MaxHeap = class extends Heap {
4985
+ static {
4986
+ __name(this, "MaxHeap");
4987
+ }
4975
4988
  /**
4976
4989
  * Create a max-heap. For objects, supply a custom comparator.
4977
4990
  * @param elements Optional initial elements.
@@ -4993,11 +5006,12 @@ var _MaxHeap = class _MaxHeap extends Heap {
4993
5006
  });
4994
5007
  }
4995
5008
  };
4996
- __name(_MaxHeap, "MaxHeap");
4997
- var MaxHeap = _MaxHeap;
4998
5009
 
4999
5010
  // src/data-structures/heap/min-heap.ts
5000
- var _MinHeap = class _MinHeap extends Heap {
5011
+ var MinHeap = class extends Heap {
5012
+ static {
5013
+ __name(this, "MinHeap");
5014
+ }
5001
5015
  /**
5002
5016
  * Create a min-heap.
5003
5017
  * @param elements Optional initial elements.
@@ -5007,36 +5021,39 @@ var _MinHeap = class _MinHeap extends Heap {
5007
5021
  super(elements, options);
5008
5022
  }
5009
5023
  };
5010
- __name(_MinHeap, "MinHeap");
5011
- var MinHeap = _MinHeap;
5012
5024
 
5013
5025
  // src/data-structures/graph/abstract-graph.ts
5014
- var _AbstractVertex = class _AbstractVertex {
5026
+ var AbstractVertex = class {
5027
+ static {
5028
+ __name(this, "AbstractVertex");
5029
+ }
5030
+ key;
5031
+ value;
5015
5032
  constructor(key, value) {
5016
- __publicField(this, "key");
5017
- __publicField(this, "value");
5018
5033
  this.key = key;
5019
5034
  this.value = value;
5020
5035
  }
5021
5036
  };
5022
- __name(_AbstractVertex, "AbstractVertex");
5023
- var AbstractVertex = _AbstractVertex;
5024
- var _AbstractEdge = class _AbstractEdge {
5037
+ var AbstractEdge = class {
5038
+ static {
5039
+ __name(this, "AbstractEdge");
5040
+ }
5041
+ value;
5042
+ weight;
5025
5043
  constructor(weight, value) {
5026
- __publicField(this, "value");
5027
- __publicField(this, "weight");
5028
- __publicField(this, "_hashCode");
5029
5044
  this.weight = weight !== void 0 ? weight : 1;
5030
5045
  this.value = value;
5031
5046
  this._hashCode = uuidV4();
5032
5047
  }
5048
+ _hashCode;
5033
5049
  get hashCode() {
5034
5050
  return this._hashCode;
5035
5051
  }
5036
5052
  };
5037
- __name(_AbstractEdge, "AbstractEdge");
5038
- var AbstractEdge = _AbstractEdge;
5039
- var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5053
+ var AbstractGraph = class extends IterableEntryBase {
5054
+ static {
5055
+ __name(this, "AbstractGraph");
5056
+ }
5040
5057
  /**
5041
5058
  * Construct a graph with runtime defaults.
5042
5059
  * @param options - `GraphOptions<V>` in `options.graph` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
@@ -5044,14 +5061,14 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5044
5061
  */
5045
5062
  constructor(options) {
5046
5063
  super();
5047
- __publicField(this, "_options", { defaultEdgeWeight: 1 });
5048
- __publicField(this, "_vertexMap", /* @__PURE__ */ new Map());
5049
- const graph = options == null ? void 0 : options.graph;
5050
- this._options = { defaultEdgeWeight: 1, ...graph != null ? graph : {} };
5064
+ const graph = options?.graph;
5065
+ this._options = { defaultEdgeWeight: 1, ...graph ?? {} };
5051
5066
  }
5067
+ _options = { defaultEdgeWeight: 1 };
5052
5068
  get options() {
5053
5069
  return this._options;
5054
5070
  }
5071
+ _vertexMap = /* @__PURE__ */ new Map();
5055
5072
  get vertexMap() {
5056
5073
  return this._vertexMap;
5057
5074
  }
@@ -5209,10 +5226,9 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5209
5226
  * @remarks Time O(L), Space O(1) where L is path length
5210
5227
  */
5211
5228
  getPathSumWeight(path) {
5212
- var _a;
5213
5229
  let sum = 0;
5214
5230
  for (let i = 0; i < path.length; i++) {
5215
- sum += ((_a = this.getEdge(path[i], path[i + 1])) == null ? void 0 : _a.weight) || 0;
5231
+ sum += this.getEdge(path[i], path[i + 1])?.weight || 0;
5216
5232
  }
5217
5233
  return sum;
5218
5234
  }
@@ -5274,7 +5290,6 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5274
5290
  * @remarks Time O((V + E) log V) weighted / O(V + E) unweighted, Space O(V + E)
5275
5291
  */
5276
5292
  getMinPathBetween(v1, v2, isWeight, isDFS = false) {
5277
- var _a, _b;
5278
5293
  if (isWeight === void 0) isWeight = false;
5279
5294
  if (isWeight) {
5280
5295
  if (isDFS) {
@@ -5292,7 +5307,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5292
5307
  }
5293
5308
  return allPaths[minIndex] || void 0;
5294
5309
  } else {
5295
- return (_b = (_a = this.dijkstra(v1, v2, true, true)) == null ? void 0 : _a.minPath) != null ? _b : [];
5310
+ return this.dijkstra(v1, v2, true, true)?.minPath ?? [];
5296
5311
  }
5297
5312
  } else {
5298
5313
  let minPath = [];
@@ -5421,7 +5436,6 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5421
5436
  return { distMap, preMap, seen, paths, minDist, minPath };
5422
5437
  }
5423
5438
  dijkstra(src, dest = void 0, getMinDist = false, genPaths = false) {
5424
- var _a;
5425
5439
  let minDist = Number.MAX_SAFE_INTEGER;
5426
5440
  let minDest = void 0;
5427
5441
  let minPath = [];
@@ -5459,8 +5473,8 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5459
5473
  }, "getPaths");
5460
5474
  while (heap.size > 0) {
5461
5475
  const curHeapNode = heap.poll();
5462
- const dist = curHeapNode == null ? void 0 : curHeapNode.key;
5463
- const cur = curHeapNode == null ? void 0 : curHeapNode.value;
5476
+ const dist = curHeapNode?.key;
5477
+ const cur = curHeapNode?.value;
5464
5478
  if (dist !== void 0) {
5465
5479
  if (cur) {
5466
5480
  seen.add(cur);
@@ -5476,7 +5490,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5476
5490
  const neighbors = this.getNeighbors(cur);
5477
5491
  for (const neighbor of neighbors) {
5478
5492
  if (!seen.has(neighbor)) {
5479
- const weight = (_a = this.getEdge(cur, neighbor)) == null ? void 0 : _a.weight;
5493
+ const weight = this.getEdge(cur, neighbor)?.weight;
5480
5494
  if (typeof weight === "number") {
5481
5495
  const distSrcToNeighbor = distMap.get(neighbor);
5482
5496
  if (distSrcToNeighbor !== void 0) {
@@ -5599,7 +5613,6 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5599
5613
  * @remarks Time O(V^3), Space O(V^2)
5600
5614
  */
5601
5615
  floydWarshall() {
5602
- var _a;
5603
5616
  const idAndVertices = [...this._vertexMap];
5604
5617
  const n = idAndVertices.length;
5605
5618
  const costs = [];
@@ -5613,7 +5626,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5613
5626
  }
5614
5627
  for (let i = 0; i < n; i++) {
5615
5628
  for (let j = 0; j < n; j++) {
5616
- costs[i][j] = ((_a = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])) == null ? void 0 : _a.weight) || Number.MAX_SAFE_INTEGER;
5629
+ costs[i][j] = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])?.weight || Number.MAX_SAFE_INTEGER;
5617
5630
  }
5618
5631
  }
5619
5632
  for (let k = 0; k < n; k++) {
@@ -5677,7 +5690,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5677
5690
  const filtered = [];
5678
5691
  let index = 0;
5679
5692
  for (const [key, value] of this) {
5680
- if (predicate.call(thisArg, key, value, index, this)) {
5693
+ if (predicate.call(thisArg, value, key, index, this)) {
5681
5694
  filtered.push([key, value]);
5682
5695
  }
5683
5696
  index++;
@@ -5692,7 +5705,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5692
5705
  const filtered = [];
5693
5706
  let index = 0;
5694
5707
  for (const [key, value] of this) {
5695
- if (predicate.call(thisArg, key, value, index, this)) {
5708
+ if (predicate.call(thisArg, value, key, index, this)) {
5696
5709
  filtered.push([key, value]);
5697
5710
  }
5698
5711
  index++;
@@ -5703,7 +5716,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5703
5716
  const mapped = [];
5704
5717
  let index = 0;
5705
5718
  for (const [key, value] of this) {
5706
- mapped.push(callback.call(thisArg, key, value, index, this));
5719
+ mapped.push(callback.call(thisArg, value, key, index, this));
5707
5720
  index++;
5708
5721
  }
5709
5722
  return mapped;
@@ -5756,7 +5769,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5756
5769
  _createInstance(_options) {
5757
5770
  const Ctor = this.constructor;
5758
5771
  const instance = new Ctor();
5759
- const graph = _options == null ? void 0 : _options.graph;
5772
+ const graph = _options?.graph;
5760
5773
  if (graph) instance._options = { ...instance._options, ...graph };
5761
5774
  else instance._options = { ...instance._options, ...this._options };
5762
5775
  return instance;
@@ -5835,29 +5848,32 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5835
5848
  return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
5836
5849
  }
5837
5850
  };
5838
- __name(_AbstractGraph, "AbstractGraph");
5839
- var AbstractGraph = _AbstractGraph;
5840
5851
 
5841
5852
  // src/data-structures/graph/directed-graph.ts
5842
- var _DirectedVertex = class _DirectedVertex extends AbstractVertex {
5853
+ var DirectedVertex = class extends AbstractVertex {
5854
+ static {
5855
+ __name(this, "DirectedVertex");
5856
+ }
5843
5857
  constructor(key, value) {
5844
5858
  super(key, value);
5845
5859
  }
5846
5860
  };
5847
- __name(_DirectedVertex, "DirectedVertex");
5848
- var DirectedVertex = _DirectedVertex;
5849
- var _DirectedEdge = class _DirectedEdge extends AbstractEdge {
5861
+ var DirectedEdge = class extends AbstractEdge {
5862
+ static {
5863
+ __name(this, "DirectedEdge");
5864
+ }
5865
+ src;
5866
+ dest;
5850
5867
  constructor(src, dest, weight, value) {
5851
5868
  super(weight, value);
5852
- __publicField(this, "src");
5853
- __publicField(this, "dest");
5854
5869
  this.src = src;
5855
5870
  this.dest = dest;
5856
5871
  }
5857
5872
  };
5858
- __name(_DirectedEdge, "DirectedEdge");
5859
- var DirectedEdge = _DirectedEdge;
5860
- var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
5873
+ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
5874
+ static {
5875
+ __name(this, "DirectedGraph");
5876
+ }
5861
5877
  /**
5862
5878
  * Construct a directed graph with runtime defaults.
5863
5879
  * @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
@@ -5865,15 +5881,15 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
5865
5881
  */
5866
5882
  constructor(options) {
5867
5883
  super(options);
5868
- __publicField(this, "_outEdgeMap", /* @__PURE__ */ new Map());
5869
- __publicField(this, "_inEdgeMap", /* @__PURE__ */ new Map());
5870
5884
  }
5885
+ _outEdgeMap = /* @__PURE__ */ new Map();
5871
5886
  get outEdgeMap() {
5872
5887
  return this._outEdgeMap;
5873
5888
  }
5874
5889
  set outEdgeMap(v) {
5875
5890
  this._outEdgeMap = v;
5876
5891
  }
5892
+ _inEdgeMap = /* @__PURE__ */ new Map();
5877
5893
  get inEdgeMap() {
5878
5894
  return this._inEdgeMap;
5879
5895
  }
@@ -5926,8 +5942,7 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
5926
5942
  * @remarks Time O(1), Space O(1)
5927
5943
  */
5928
5944
  createEdge(src, dest, weight, value) {
5929
- var _a;
5930
- return new DirectedEdge(src, dest, (_a = weight != null ? weight : this.options.defaultEdgeWeight) != null ? _a : 1, value);
5945
+ return new DirectedEdge(src, dest, weight ?? this.options.defaultEdgeWeight ?? 1, value);
5931
5946
  }
5932
5947
  /**
5933
5948
  * Get the unique edge from `src` to `dest`, if present.
@@ -5998,7 +6013,7 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
5998
6013
  if (src && dest) {
5999
6014
  const srcOutEdges = this._outEdgeMap.get(src);
6000
6015
  if (srcOutEdges && srcOutEdges.length > 0) {
6001
- arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === (dest == null ? void 0 : dest.key));
6016
+ arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === dest?.key);
6002
6017
  }
6003
6018
  const destInEdges = this._inEdgeMap.get(dest);
6004
6019
  if (destInEdges && destInEdges.length > 0) {
@@ -6120,7 +6135,7 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
6120
6135
  * @remarks Time O(V + E), Space O(V)
6121
6136
  */
6122
6137
  topologicalSort(propertyName) {
6123
- propertyName = propertyName != null ? propertyName : "key";
6138
+ propertyName = propertyName ?? "key";
6124
6139
  const statusMap = /* @__PURE__ */ new Map();
6125
6140
  for (const entry of this.vertexMap) {
6126
6141
  statusMap.set(entry[1], 0);
@@ -6313,27 +6328,30 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
6313
6328
  }
6314
6329
  }
6315
6330
  };
6316
- __name(_DirectedGraph, "DirectedGraph");
6317
- var DirectedGraph = _DirectedGraph;
6318
6331
 
6319
6332
  // src/data-structures/graph/undirected-graph.ts
6320
- var _UndirectedVertex = class _UndirectedVertex extends AbstractVertex {
6333
+ var UndirectedVertex = class extends AbstractVertex {
6334
+ static {
6335
+ __name(this, "UndirectedVertex");
6336
+ }
6321
6337
  constructor(key, value) {
6322
6338
  super(key, value);
6323
6339
  }
6324
6340
  };
6325
- __name(_UndirectedVertex, "UndirectedVertex");
6326
- var UndirectedVertex = _UndirectedVertex;
6327
- var _UndirectedEdge = class _UndirectedEdge extends AbstractEdge {
6341
+ var UndirectedEdge = class extends AbstractEdge {
6342
+ static {
6343
+ __name(this, "UndirectedEdge");
6344
+ }
6345
+ endpoints;
6328
6346
  constructor(v1, v2, weight, value) {
6329
6347
  super(weight, value);
6330
- __publicField(this, "endpoints");
6331
6348
  this.endpoints = [v1, v2];
6332
6349
  }
6333
6350
  };
6334
- __name(_UndirectedEdge, "UndirectedEdge");
6335
- var UndirectedEdge = _UndirectedEdge;
6336
- var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6351
+ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6352
+ static {
6353
+ __name(this, "UndirectedGraph");
6354
+ }
6337
6355
  /**
6338
6356
  * Construct an undirected graph with runtime defaults.
6339
6357
  * @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
@@ -6341,9 +6359,9 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6341
6359
  */
6342
6360
  constructor(options) {
6343
6361
  super(options);
6344
- __publicField(this, "_edgeMap");
6345
6362
  this._edgeMap = /* @__PURE__ */ new Map();
6346
6363
  }
6364
+ _edgeMap;
6347
6365
  get edgeMap() {
6348
6366
  return this._edgeMap;
6349
6367
  }
@@ -6396,8 +6414,7 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6396
6414
  * @remarks Time O(1), Space O(1)
6397
6415
  */
6398
6416
  createEdge(v1, v2, weight, value) {
6399
- var _a;
6400
- return new UndirectedEdge(v1, v2, (_a = weight != null ? weight : this.options.defaultEdgeWeight) != null ? _a : 1, value);
6417
+ return new UndirectedEdge(v1, v2, weight ?? this.options.defaultEdgeWeight ?? 1, value);
6401
6418
  }
6402
6419
  /**
6403
6420
  * Get an undirected edge between two vertices, if present.
@@ -6407,13 +6424,12 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6407
6424
  * @remarks Time O(1) avg, Space O(1)
6408
6425
  */
6409
6426
  getEdge(v1, v2) {
6410
- var _a;
6411
6427
  let edgeMap = [];
6412
6428
  if (v1 !== void 0 && v2 !== void 0) {
6413
6429
  const vertex1 = this._getVertex(v1);
6414
6430
  const vertex2 = this._getVertex(v2);
6415
6431
  if (vertex1 && vertex2) {
6416
- edgeMap = (_a = this._edgeMap.get(vertex1)) == null ? void 0 : _a.filter((e) => e.endpoints.includes(vertex2.key));
6432
+ edgeMap = this._edgeMap.get(vertex1)?.filter((e) => e.endpoints.includes(vertex2.key));
6417
6433
  }
6418
6434
  }
6419
6435
  return edgeMap ? edgeMap[0] || void 0 : void 0;
@@ -6506,10 +6522,9 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6506
6522
  * @remarks Time O(1) avg, Space O(1)
6507
6523
  */
6508
6524
  degreeOf(vertexOrKey) {
6509
- var _a;
6510
6525
  const vertex = this._getVertex(vertexOrKey);
6511
6526
  if (vertex) {
6512
- return ((_a = this._edgeMap.get(vertex)) == null ? void 0 : _a.length) || 0;
6527
+ return this._edgeMap.get(vertex)?.length || 0;
6513
6528
  } else {
6514
6529
  return 0;
6515
6530
  }
@@ -6702,29 +6717,32 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6702
6717
  return true;
6703
6718
  }
6704
6719
  };
6705
- __name(_UndirectedGraph, "UndirectedGraph");
6706
- var UndirectedGraph = _UndirectedGraph;
6707
6720
 
6708
6721
  // src/data-structures/graph/map-graph.ts
6709
- var _MapVertex = class _MapVertex extends DirectedVertex {
6722
+ var MapVertex = class extends DirectedVertex {
6723
+ static {
6724
+ __name(this, "MapVertex");
6725
+ }
6726
+ lat;
6727
+ long;
6710
6728
  constructor(key, value, lat, long) {
6711
6729
  super(key, value);
6712
- __publicField(this, "lat");
6713
- __publicField(this, "long");
6714
6730
  this.lat = lat;
6715
6731
  this.long = long;
6716
6732
  }
6717
6733
  };
6718
- __name(_MapVertex, "MapVertex");
6719
- var MapVertex = _MapVertex;
6720
- var _MapEdge = class _MapEdge extends DirectedEdge {
6734
+ var MapEdge = class extends DirectedEdge {
6735
+ static {
6736
+ __name(this, "MapEdge");
6737
+ }
6721
6738
  constructor(src, dest, weight, value) {
6722
6739
  super(src, dest, weight, value);
6723
6740
  }
6724
6741
  };
6725
- __name(_MapEdge, "MapEdge");
6726
- var MapEdge = _MapEdge;
6727
- var _MapGraph = class _MapGraph extends DirectedGraph {
6742
+ var MapGraph = class _MapGraph extends DirectedGraph {
6743
+ static {
6744
+ __name(this, "MapGraph");
6745
+ }
6728
6746
  /**
6729
6747
  * Construct a MapGraph.
6730
6748
  * @param originCoord - Origin coordinate `[lat, long]` used as default.
@@ -6733,14 +6751,14 @@ var _MapGraph = class _MapGraph extends DirectedGraph {
6733
6751
  */
6734
6752
  constructor(originCoord, bottomRight) {
6735
6753
  super();
6736
- __publicField(this, "_originCoord", [0, 0]);
6737
- __publicField(this, "_bottomRight");
6738
6754
  this._originCoord = originCoord;
6739
6755
  this._bottomRight = bottomRight;
6740
6756
  }
6757
+ _originCoord = [0, 0];
6741
6758
  get originCoord() {
6742
6759
  return this._originCoord;
6743
6760
  }
6761
+ _bottomRight;
6744
6762
  get bottomRight() {
6745
6763
  return this._bottomRight;
6746
6764
  }
@@ -6792,13 +6810,11 @@ var _MapGraph = class _MapGraph extends DirectedGraph {
6792
6810
  */
6793
6811
  _createInstance(options) {
6794
6812
  const { originCoord, bottomRight } = options || {};
6795
- const oc = originCoord != null ? originCoord : this.originCoord;
6796
- const br = bottomRight != null ? bottomRight : this.bottomRight;
6813
+ const oc = originCoord ?? this.originCoord;
6814
+ const br = bottomRight ?? this.bottomRight;
6797
6815
  return new _MapGraph(oc, br);
6798
6816
  }
6799
6817
  };
6800
- __name(_MapGraph, "MapGraph");
6801
- var MapGraph = _MapGraph;
6802
6818
 
6803
6819
  // src/common/index.ts
6804
6820
  var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
@@ -6806,7 +6822,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
6806
6822
  DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
6807
6823
  return DFSOperation2;
6808
6824
  })(DFSOperation || {});
6809
- var _Range = class _Range {
6825
+ var Range = class {
6810
6826
  constructor(low, high, includeLow = true, includeHigh = true) {
6811
6827
  this.low = low;
6812
6828
  this.high = high;
@@ -6815,6 +6831,9 @@ var _Range = class _Range {
6815
6831
  if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
6816
6832
  if (low > high) throw new RangeError("low must be less than or equal to high");
6817
6833
  }
6834
+ static {
6835
+ __name(this, "Range");
6836
+ }
6818
6837
  // Determine whether a key is within the range
6819
6838
  isInRange(key, comparator) {
6820
6839
  const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
@@ -6822,11 +6841,15 @@ var _Range = class _Range {
6822
6841
  return lowCheck && highCheck;
6823
6842
  }
6824
6843
  };
6825
- __name(_Range, "Range");
6826
- var Range = _Range;
6827
6844
 
6828
6845
  // src/data-structures/binary-tree/binary-tree.ts
6829
- var _BinaryTreeNode = class _BinaryTreeNode {
6846
+ var BinaryTreeNode = class {
6847
+ static {
6848
+ __name(this, "BinaryTreeNode");
6849
+ }
6850
+ key;
6851
+ value;
6852
+ parent = void 0;
6830
6853
  /**
6831
6854
  * Creates an instance of BinaryTreeNode.
6832
6855
  * @remarks Time O(1), Space O(1)
@@ -6835,17 +6858,10 @@ var _BinaryTreeNode = class _BinaryTreeNode {
6835
6858
  * @param [value] - The value associated with the key.
6836
6859
  */
6837
6860
  constructor(key, value) {
6838
- __publicField(this, "key");
6839
- __publicField(this, "value");
6840
- __publicField(this, "parent");
6841
- __publicField(this, "_left");
6842
- __publicField(this, "_right");
6843
- __publicField(this, "_height", 0);
6844
- __publicField(this, "_color", "BLACK");
6845
- __publicField(this, "_count", 1);
6846
6861
  this.key = key;
6847
6862
  this.value = value;
6848
6863
  }
6864
+ _left = void 0;
6849
6865
  /**
6850
6866
  * Gets the left child of the node.
6851
6867
  * @remarks Time O(1), Space O(1)
@@ -6867,6 +6883,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
6867
6883
  }
6868
6884
  this._left = v;
6869
6885
  }
6886
+ _right = void 0;
6870
6887
  /**
6871
6888
  * Gets the right child of the node.
6872
6889
  * @remarks Time O(1), Space O(1)
@@ -6888,6 +6905,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
6888
6905
  }
6889
6906
  this._right = v;
6890
6907
  }
6908
+ _height = 0;
6891
6909
  /**
6892
6910
  * Gets the height of the node (used in self-balancing trees).
6893
6911
  * @remarks Time O(1), Space O(1)
@@ -6906,6 +6924,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
6906
6924
  set height(value) {
6907
6925
  this._height = value;
6908
6926
  }
6927
+ _color = "BLACK";
6909
6928
  /**
6910
6929
  * Gets the color of the node (used in Red-Black trees).
6911
6930
  * @remarks Time O(1), Space O(1)
@@ -6924,6 +6943,7 @@ var _BinaryTreeNode = class _BinaryTreeNode {
6924
6943
  set color(value) {
6925
6944
  this._color = value;
6926
6945
  }
6946
+ _count = 1;
6927
6947
  /**
6928
6948
  * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
6929
6949
  * @remarks Time O(1), Space O(1)
@@ -6960,9 +6980,11 @@ var _BinaryTreeNode = class _BinaryTreeNode {
6960
6980
  return "MAL_NODE";
6961
6981
  }
6962
6982
  };
6963
- __name(_BinaryTreeNode, "BinaryTreeNode");
6964
- var BinaryTreeNode = _BinaryTreeNode;
6965
- var _BinaryTree = class _BinaryTree extends IterableEntryBase {
6983
+ var BinaryTree = class extends IterableEntryBase {
6984
+ static {
6985
+ __name(this, "BinaryTree");
6986
+ }
6987
+ iterationType = "ITERATIVE";
6966
6988
  /**
6967
6989
  * Creates an instance of BinaryTree.
6968
6990
  * @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.
@@ -6972,22 +6994,6 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
6972
6994
  */
6973
6995
  constructor(keysNodesEntriesOrRaws = [], options) {
6974
6996
  super();
6975
- __publicField(this, "iterationType", "ITERATIVE");
6976
- __publicField(this, "_isMapMode", true);
6977
- __publicField(this, "_isDuplicate", false);
6978
- __publicField(this, "_store", /* @__PURE__ */ new Map());
6979
- __publicField(this, "_root");
6980
- __publicField(this, "_size", 0);
6981
- __publicField(this, "_NIL", new BinaryTreeNode(NaN));
6982
- __publicField(this, "_toEntryFn");
6983
- /**
6984
- * (Protected) Default callback function, returns the node's key.
6985
- * @remarks Time O(1)
6986
- *
6987
- * @param node - The node.
6988
- * @returns The node's key or undefined.
6989
- */
6990
- __publicField(this, "_DEFAULT_NODE_CALLBACK", /* @__PURE__ */ __name((node) => node ? node.key : void 0, "_DEFAULT_NODE_CALLBACK"));
6991
6997
  if (options) {
6992
6998
  const { iterationType, toEntryFn, isMapMode, isDuplicate } = options;
6993
6999
  if (iterationType) this.iterationType = iterationType;
@@ -6998,6 +7004,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
6998
7004
  }
6999
7005
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
7000
7006
  }
7007
+ _isMapMode = true;
7001
7008
  /**
7002
7009
  * Gets whether the tree is in Map mode.
7003
7010
  * @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)
@@ -7007,6 +7014,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7007
7014
  get isMapMode() {
7008
7015
  return this._isMapMode;
7009
7016
  }
7017
+ _isDuplicate = false;
7010
7018
  /**
7011
7019
  * Gets whether the tree allows duplicate keys.
7012
7020
  * @remarks Time O(1)
@@ -7016,6 +7024,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7016
7024
  get isDuplicate() {
7017
7025
  return this._isDuplicate;
7018
7026
  }
7027
+ _store = /* @__PURE__ */ new Map();
7019
7028
  /**
7020
7029
  * Gets the external value store (used in Map mode).
7021
7030
  * @remarks Time O(1)
@@ -7025,6 +7034,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7025
7034
  get store() {
7026
7035
  return this._store;
7027
7036
  }
7037
+ _root;
7028
7038
  /**
7029
7039
  * Gets the root node of the tree.
7030
7040
  * @remarks Time O(1)
@@ -7034,6 +7044,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7034
7044
  get root() {
7035
7045
  return this._root;
7036
7046
  }
7047
+ _size = 0;
7037
7048
  /**
7038
7049
  * Gets the number of nodes in the tree.
7039
7050
  * @remarks Time O(1)
@@ -7043,6 +7054,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7043
7054
  get size() {
7044
7055
  return this._size;
7045
7056
  }
7057
+ _NIL = new BinaryTreeNode(NaN);
7046
7058
  /**
7047
7059
  * Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
7048
7060
  * @remarks Time O(1)
@@ -7052,6 +7064,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7052
7064
  get NIL() {
7053
7065
  return this._NIL;
7054
7066
  }
7067
+ _toEntryFn;
7055
7068
  /**
7056
7069
  * Gets the function used to convert raw data objects (R) into [key, value] entries.
7057
7070
  * @remarks Time O(1)
@@ -7211,7 +7224,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7211
7224
  if (newNode === void 0) return false;
7212
7225
  if (!this._root) {
7213
7226
  this._setRoot(newNode);
7214
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
7227
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
7215
7228
  this._size = 1;
7216
7229
  return true;
7217
7230
  }
@@ -7243,7 +7256,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7243
7256
  } else if (potentialParent.right === void 0) {
7244
7257
  potentialParent.right = newNode;
7245
7258
  }
7246
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
7259
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
7247
7260
  this._size++;
7248
7261
  return true;
7249
7262
  }
@@ -7308,7 +7321,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7308
7321
  if (!this._root) return deletedResult;
7309
7322
  const curr = this.getNode(keyNodeOrEntry);
7310
7323
  if (!curr) return deletedResult;
7311
- const parent = curr == null ? void 0 : curr.parent;
7324
+ const parent = curr?.parent;
7312
7325
  let needBalanced;
7313
7326
  let orgCurrent = curr;
7314
7327
  if (!curr.left && !curr.right && !parent) {
@@ -7413,13 +7426,12 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7413
7426
  * @returns The associated value, or undefined.
7414
7427
  */
7415
7428
  get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
7416
- var _a;
7417
7429
  if (this._isMapMode) {
7418
7430
  const key = this._extractKey(keyNodeEntryOrPredicate);
7419
7431
  if (key === null || key === void 0) return;
7420
7432
  return this._store.get(key);
7421
7433
  }
7422
- return (_a = this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)) == null ? void 0 : _a.value;
7434
+ return this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)?.value;
7423
7435
  }
7424
7436
  has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
7425
7437
  return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType).length > 0;
@@ -7507,7 +7519,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7507
7519
  let distEnsured = this.ensureNode(dist);
7508
7520
  const beginRootEnsured = this.ensureNode(startNode);
7509
7521
  let depth = 0;
7510
- while (distEnsured == null ? void 0 : distEnsured.parent) {
7522
+ while (distEnsured?.parent) {
7511
7523
  if (distEnsured === beginRootEnsured) {
7512
7524
  return depth;
7513
7525
  }
@@ -7980,7 +7992,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7980
7992
  filter(predicate, thisArg) {
7981
7993
  const out = this._createInstance();
7982
7994
  let i = 0;
7983
- for (const [k, v] of this) if (predicate.call(thisArg, k, v, i++, this)) out.add([k, v]);
7995
+ for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
7984
7996
  return out;
7985
7997
  }
7986
7998
  /**
@@ -7998,7 +8010,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7998
8010
  map(cb, options, thisArg) {
7999
8011
  const out = this._createLike([], options);
8000
8012
  let i = 0;
8001
- for (const [k, v] of this) out.add(cb.call(thisArg, k, v, i++, this));
8013
+ for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
8002
8014
  return out;
8003
8015
  }
8004
8016
  /**
@@ -8069,10 +8081,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8069
8081
  const dfs = /* @__PURE__ */ __name((node) => {
8070
8082
  if (!shouldVisitRoot(node)) return;
8071
8083
  const visitLeft = /* @__PURE__ */ __name(() => {
8072
- if (shouldVisitLeft(node) && (node == null ? void 0 : node.left) !== void 0) dfs(node == null ? void 0 : node.left);
8084
+ if (shouldVisitLeft(node) && node?.left !== void 0) dfs(node?.left);
8073
8085
  }, "visitLeft");
8074
8086
  const visitRight = /* @__PURE__ */ __name(() => {
8075
- if (shouldVisitRight(node) && (node == null ? void 0 : node.right) !== void 0) dfs(node == null ? void 0 : node.right);
8087
+ if (shouldVisitRight(node) && node?.right !== void 0) dfs(node?.right);
8076
8088
  }, "visitRight");
8077
8089
  switch (pattern) {
8078
8090
  case "IN":
@@ -8105,12 +8117,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8105
8117
  } else {
8106
8118
  const stack = [{ opt: 0 /* VISIT */, node: startNode }];
8107
8119
  const pushLeft = /* @__PURE__ */ __name((cur) => {
8108
- var _a;
8109
- if (shouldVisitLeft(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.left });
8120
+ if (shouldVisitLeft(cur.node)) stack.push({ opt: 0 /* VISIT */, node: cur.node?.left });
8110
8121
  }, "pushLeft");
8111
8122
  const pushRight = /* @__PURE__ */ __name((cur) => {
8112
- var _a;
8113
- if (shouldVisitRight(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.right });
8123
+ if (shouldVisitRight(cur.node)) stack.push({ opt: 0 /* VISIT */, node: cur.node?.right });
8114
8124
  }, "pushRight");
8115
8125
  const pushRoot = /* @__PURE__ */ __name((cur) => {
8116
8126
  if (shouldVisitRoot(cur.node)) stack.push({ opt: 1 /* PROCESS */, node: cur.node });
@@ -8182,6 +8192,14 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8182
8192
  }
8183
8193
  }
8184
8194
  }
8195
+ /**
8196
+ * (Protected) Default callback function, returns the node's key.
8197
+ * @remarks Time O(1)
8198
+ *
8199
+ * @param node - The node.
8200
+ * @returns The node's key or undefined.
8201
+ */
8202
+ _DEFAULT_NODE_CALLBACK = /* @__PURE__ */ __name((node) => node ? node.key : void 0, "_DEFAULT_NODE_CALLBACK");
8185
8203
  /**
8186
8204
  * (Protected) Snapshots the current tree's configuration options.
8187
8205
  * @remarks Time O(1)
@@ -8207,7 +8225,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8207
8225
  */
8208
8226
  _createInstance(options) {
8209
8227
  const Ctor = this.constructor;
8210
- return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
8228
+ return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
8211
8229
  }
8212
8230
  /**
8213
8231
  * (Protected) Creates a new instance of the same tree constructor, potentially with different generic types.
@@ -8220,7 +8238,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8220
8238
  */
8221
8239
  _createLike(iter = [], options) {
8222
8240
  const Ctor = this.constructor;
8223
- return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
8241
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
8224
8242
  }
8225
8243
  /**
8226
8244
  * (Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
@@ -8238,7 +8256,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8238
8256
  const [key, entryValue] = keyNodeOrEntry;
8239
8257
  if (key === void 0) return [void 0, void 0];
8240
8258
  else if (key === null) return [null, void 0];
8241
- const finalValue = value != null ? value : entryValue;
8259
+ const finalValue = value ?? entryValue;
8242
8260
  return [this.createNode(key, finalValue), finalValue];
8243
8261
  }
8244
8262
  return [this.createNode(keyNodeOrEntry, value), value];
@@ -8445,11 +8463,15 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8445
8463
  this._store.clear();
8446
8464
  }
8447
8465
  };
8448
- __name(_BinaryTree, "BinaryTree");
8449
- var BinaryTree = _BinaryTree;
8450
8466
 
8451
8467
  // src/data-structures/binary-tree/bst.ts
8452
- var _BSTNode = class _BSTNode extends BinaryTreeNode {
8468
+ var BSTNode = class {
8469
+ static {
8470
+ __name(this, "BSTNode");
8471
+ }
8472
+ key;
8473
+ value;
8474
+ parent = void 0;
8453
8475
  /**
8454
8476
  * Creates an instance of BSTNode.
8455
8477
  * @remarks Time O(1), Space O(1)
@@ -8458,11 +8480,10 @@ var _BSTNode = class _BSTNode extends BinaryTreeNode {
8458
8480
  * @param [value] - The value associated with the key.
8459
8481
  */
8460
8482
  constructor(key, value) {
8461
- super(key, value);
8462
- __publicField(this, "parent");
8463
- __publicField(this, "_left");
8464
- __publicField(this, "_right");
8483
+ this.key = key;
8484
+ this.value = value;
8465
8485
  }
8486
+ _left = void 0;
8466
8487
  /**
8467
8488
  * Gets the left child of the node.
8468
8489
  * @remarks Time O(1), Space O(1)
@@ -8482,6 +8503,7 @@ var _BSTNode = class _BSTNode extends BinaryTreeNode {
8482
8503
  if (v) v.parent = this;
8483
8504
  this._left = v;
8484
8505
  }
8506
+ _right = void 0;
8485
8507
  /**
8486
8508
  * Gets the right child of the node.
8487
8509
  * @remarks Time O(1), Space O(1)
@@ -8501,10 +8523,85 @@ var _BSTNode = class _BSTNode extends BinaryTreeNode {
8501
8523
  if (v) v.parent = this;
8502
8524
  this._right = v;
8503
8525
  }
8526
+ _height = 0;
8527
+ /**
8528
+ * Gets the height of the node (used in self-balancing trees).
8529
+ * @remarks Time O(1), Space O(1)
8530
+ *
8531
+ * @returns The height.
8532
+ */
8533
+ get height() {
8534
+ return this._height;
8535
+ }
8536
+ /**
8537
+ * Sets the height of the node.
8538
+ * @remarks Time O(1), Space O(1)
8539
+ *
8540
+ * @param value - The new height.
8541
+ */
8542
+ set height(value) {
8543
+ this._height = value;
8544
+ }
8545
+ _color = "BLACK";
8546
+ /**
8547
+ * Gets the color of the node (used in Red-Black trees).
8548
+ * @remarks Time O(1), Space O(1)
8549
+ *
8550
+ * @returns The node's color.
8551
+ */
8552
+ get color() {
8553
+ return this._color;
8554
+ }
8555
+ /**
8556
+ * Sets the color of the node.
8557
+ * @remarks Time O(1), Space O(1)
8558
+ *
8559
+ * @param value - The new color.
8560
+ */
8561
+ set color(value) {
8562
+ this._color = value;
8563
+ }
8564
+ _count = 1;
8565
+ /**
8566
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
8567
+ * @remarks Time O(1), Space O(1)
8568
+ *
8569
+ * @returns The subtree node count.
8570
+ */
8571
+ get count() {
8572
+ return this._count;
8573
+ }
8574
+ /**
8575
+ * Sets the count of nodes in the subtree.
8576
+ * @remarks Time O(1), Space O(1)
8577
+ *
8578
+ * @param value - The new count.
8579
+ */
8580
+ set count(value) {
8581
+ this._count = value;
8582
+ }
8583
+ /**
8584
+ * Gets the position of the node relative to its parent.
8585
+ * @remarks Time O(1), Space O(1)
8586
+ *
8587
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
8588
+ */
8589
+ get familyPosition() {
8590
+ if (!this.parent) {
8591
+ return this.left || this.right ? "ROOT" : "ISOLATED";
8592
+ }
8593
+ if (this.parent.left === this) {
8594
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
8595
+ } else if (this.parent.right === this) {
8596
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
8597
+ }
8598
+ return "MAL_NODE";
8599
+ }
8504
8600
  };
8505
- __name(_BSTNode, "BSTNode");
8506
- var BSTNode = _BSTNode;
8507
- var _BST = class _BST extends BinaryTree {
8601
+ var BST = class extends BinaryTree {
8602
+ static {
8603
+ __name(this, "BST");
8604
+ }
8508
8605
  /**
8509
8606
  * Creates an instance of BST.
8510
8607
  * @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
@@ -8514,33 +8611,6 @@ var _BST = class _BST extends BinaryTree {
8514
8611
  */
8515
8612
  constructor(keysNodesEntriesOrRaws = [], options) {
8516
8613
  super([], options);
8517
- __publicField(this, "_root");
8518
- __publicField(this, "_isReverse", false);
8519
- /**
8520
- * The default comparator function.
8521
- * @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
8522
- */
8523
- __publicField(this, "_comparator", /* @__PURE__ */ __name((a, b) => {
8524
- if (isComparable(a) && isComparable(b)) {
8525
- if (a > b) return 1;
8526
- if (a < b) return -1;
8527
- return 0;
8528
- }
8529
- if (this._specifyComparable) {
8530
- const va = this._specifyComparable(a);
8531
- const vb = this._specifyComparable(b);
8532
- if (va > vb) return 1;
8533
- if (va < vb) return -1;
8534
- return 0;
8535
- }
8536
- if (typeof a === "object" || typeof b === "object") {
8537
- throw TypeError(
8538
- `When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
8539
- );
8540
- }
8541
- return 0;
8542
- }, "_comparator"));
8543
- __publicField(this, "_specifyComparable");
8544
8614
  if (options) {
8545
8615
  const { specifyComparable, isReverse } = options;
8546
8616
  if (typeof specifyComparable === "function") this._specifyComparable = specifyComparable;
@@ -8548,6 +8618,7 @@ var _BST = class _BST extends BinaryTree {
8548
8618
  }
8549
8619
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
8550
8620
  }
8621
+ _root = void 0;
8551
8622
  /**
8552
8623
  * Gets the root node of the tree.
8553
8624
  * @remarks Time O(1)
@@ -8557,6 +8628,7 @@ var _BST = class _BST extends BinaryTree {
8557
8628
  get root() {
8558
8629
  return this._root;
8559
8630
  }
8631
+ _isReverse = false;
8560
8632
  /**
8561
8633
  * Gets whether the tree's comparison logic is reversed.
8562
8634
  * @remarks Time O(1)
@@ -8566,6 +8638,30 @@ var _BST = class _BST extends BinaryTree {
8566
8638
  get isReverse() {
8567
8639
  return this._isReverse;
8568
8640
  }
8641
+ /**
8642
+ * The default comparator function.
8643
+ * @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
8644
+ */
8645
+ _comparator = /* @__PURE__ */ __name((a, b) => {
8646
+ if (isComparable(a) && isComparable(b)) {
8647
+ if (a > b) return 1;
8648
+ if (a < b) return -1;
8649
+ return 0;
8650
+ }
8651
+ if (this._specifyComparable) {
8652
+ const va = this._specifyComparable(a);
8653
+ const vb = this._specifyComparable(b);
8654
+ if (va > vb) return 1;
8655
+ if (va < vb) return -1;
8656
+ return 0;
8657
+ }
8658
+ if (typeof a === "object" || typeof b === "object") {
8659
+ throw TypeError(
8660
+ `When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
8661
+ );
8662
+ }
8663
+ return 0;
8664
+ }, "_comparator");
8569
8665
  /**
8570
8666
  * Gets the comparator function used by the tree.
8571
8667
  * @remarks Time O(1)
@@ -8575,6 +8671,7 @@ var _BST = class _BST extends BinaryTree {
8575
8671
  get comparator() {
8576
8672
  return this._comparator;
8577
8673
  }
8674
+ _specifyComparable;
8578
8675
  /**
8579
8676
  * Gets the function used to extract a comparable value from a complex key.
8580
8677
  * @remarks Time O(1)
@@ -8604,8 +8701,7 @@ var _BST = class _BST extends BinaryTree {
8604
8701
  * @returns The resolved node, or undefined if not found.
8605
8702
  */
8606
8703
  ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
8607
- var _a;
8608
- return (_a = super.ensureNode(keyNodeOrEntry, iterationType)) != null ? _a : void 0;
8704
+ return super.ensureNode(keyNodeOrEntry, iterationType) ?? void 0;
8609
8705
  }
8610
8706
  /**
8611
8707
  * Checks if the given item is a `BSTNode` instance.
@@ -8678,8 +8774,7 @@ var _BST = class _BST extends BinaryTree {
8678
8774
  * @returns The first matching node, or undefined if not found.
8679
8775
  */
8680
8776
  getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
8681
- var _a;
8682
- return (_a = this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0]) != null ? _a : void 0;
8777
+ return this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0] ?? void 0;
8683
8778
  }
8684
8779
  /**
8685
8780
  * Searches the tree for nodes matching a predicate, key, or range.
@@ -8784,7 +8879,7 @@ var _BST = class _BST extends BinaryTree {
8784
8879
  if (newNode === void 0) return false;
8785
8880
  if (this._root === void 0) {
8786
8881
  this._setRoot(newNode);
8787
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
8882
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
8788
8883
  this._size++;
8789
8884
  return true;
8790
8885
  }
@@ -8797,7 +8892,7 @@ var _BST = class _BST extends BinaryTree {
8797
8892
  } else if (this._compare(current.key, newNode.key) > 0) {
8798
8893
  if (current.left === void 0) {
8799
8894
  current.left = newNode;
8800
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
8895
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
8801
8896
  this._size++;
8802
8897
  return true;
8803
8898
  }
@@ -8805,7 +8900,7 @@ var _BST = class _BST extends BinaryTree {
8805
8900
  } else {
8806
8901
  if (current.right === void 0) {
8807
8902
  current.right = newNode;
8808
- if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
8903
+ if (this._isMapMode) this._setValue(newNode?.key, newValue);
8809
8904
  this._size++;
8810
8905
  return true;
8811
8906
  }
@@ -8828,10 +8923,10 @@ var _BST = class _BST extends BinaryTree {
8828
8923
  */
8829
8924
  addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8830
8925
  const inserted = [];
8831
- const valuesIterator = values == null ? void 0 : values[Symbol.iterator]();
8926
+ const valuesIterator = values?.[Symbol.iterator]();
8832
8927
  if (!isBalanceAdd) {
8833
8928
  for (let kve of keysNodesEntriesOrRaws) {
8834
- const val = valuesIterator == null ? void 0 : valuesIterator.next().value;
8929
+ const val = valuesIterator?.next().value;
8835
8930
  if (this.isRaw(kve)) kve = this._toEntryFn(kve);
8836
8931
  inserted.push(this.add(kve, val));
8837
8932
  }
@@ -8840,7 +8935,7 @@ var _BST = class _BST extends BinaryTree {
8840
8935
  const realBTNExemplars = [];
8841
8936
  let i = 0;
8842
8937
  for (const kve of keysNodesEntriesOrRaws) {
8843
- realBTNExemplars.push({ key: kve, value: valuesIterator == null ? void 0 : valuesIterator.next().value, orgIndex: i++ });
8938
+ realBTNExemplars.push({ key: kve, value: valuesIterator?.next().value, orgIndex: i++ });
8844
8939
  }
8845
8940
  const sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
8846
8941
  let keyA, keyB;
@@ -9021,7 +9116,7 @@ var _BST = class _BST extends BinaryTree {
9021
9116
  const out = this._createLike([], options);
9022
9117
  let index = 0;
9023
9118
  for (const [key, value] of this) {
9024
- out.add(callback.call(thisArg, key, value, index++, this));
9119
+ out.add(callback.call(thisArg, value, key, index++, this));
9025
9120
  }
9026
9121
  return out;
9027
9122
  }
@@ -9062,7 +9157,7 @@ var _BST = class _BST extends BinaryTree {
9062
9157
  */
9063
9158
  _createInstance(options) {
9064
9159
  const Ctor = this.constructor;
9065
- return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
9160
+ return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
9066
9161
  }
9067
9162
  /**
9068
9163
  * (Protected) Creates a new instance of the same BST constructor, potentially with different generic types.
@@ -9075,7 +9170,7 @@ var _BST = class _BST extends BinaryTree {
9075
9170
  */
9076
9171
  _createLike(iter = [], options) {
9077
9172
  const Ctor = this.constructor;
9078
- return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
9173
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
9079
9174
  }
9080
9175
  /**
9081
9176
  * (Protected) Snapshots the current BST's configuration options.
@@ -9102,7 +9197,7 @@ var _BST = class _BST extends BinaryTree {
9102
9197
  _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
9103
9198
  const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
9104
9199
  if (node === null) return [void 0, void 0];
9105
- return [node, value != null ? value : entryValue];
9200
+ return [node, value ?? entryValue];
9106
9201
  }
9107
9202
  /**
9108
9203
  * (Protected) Sets the root node and clears its parent reference.
@@ -9133,7 +9228,6 @@ var _BST = class _BST extends BinaryTree {
9133
9228
  * @returns True if the node was found and deleted, false otherwise.
9134
9229
  */
9135
9230
  _deleteByKey(key) {
9136
- var _a;
9137
9231
  let node = this._root;
9138
9232
  while (node) {
9139
9233
  const cmp = this._compare(node.key, key);
@@ -9142,7 +9236,7 @@ var _BST = class _BST extends BinaryTree {
9142
9236
  }
9143
9237
  if (!node) return false;
9144
9238
  const transplant = /* @__PURE__ */ __name((u, v) => {
9145
- const p = u == null ? void 0 : u.parent;
9239
+ const p = u?.parent;
9146
9240
  if (!p) {
9147
9241
  this._setRoot(v);
9148
9242
  } else if (p.left === u) {
@@ -9172,15 +9266,18 @@ var _BST = class _BST extends BinaryTree {
9172
9266
  succ.left = node.left;
9173
9267
  if (succ.left) succ.left.parent = succ;
9174
9268
  }
9175
- this._size = Math.max(0, ((_a = this._size) != null ? _a : 0) - 1);
9269
+ this._size = Math.max(0, (this._size ?? 0) - 1);
9176
9270
  return true;
9177
9271
  }
9178
9272
  };
9179
- __name(_BST, "BST");
9180
- var BST = _BST;
9181
9273
 
9182
9274
  // src/data-structures/binary-tree/binary-indexed-tree.ts
9183
- var _BinaryIndexedTree = class _BinaryIndexedTree {
9275
+ var BinaryIndexedTree = class {
9276
+ static {
9277
+ __name(this, "BinaryIndexedTree");
9278
+ }
9279
+ _freq;
9280
+ _max;
9184
9281
  /**
9185
9282
  * The constructor initializes the properties of an object, including default frequency, maximum
9186
9283
  * value, a freqMap data structure, the most significant bit, and the count of negative frequencies.
@@ -9188,17 +9285,13 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
9188
9285
  * value of 0.
9189
9286
  */
9190
9287
  constructor({ frequency = 0, max }) {
9191
- __publicField(this, "_freq");
9192
- __publicField(this, "_max");
9193
- __publicField(this, "_freqMap");
9194
- __publicField(this, "_msb");
9195
- __publicField(this, "_negativeCount");
9196
9288
  this._freq = frequency;
9197
9289
  this._max = max;
9198
9290
  this._freqMap = { 0: 0 };
9199
9291
  this._msb = getMSB(max);
9200
9292
  this._negativeCount = frequency < 0 ? max : 0;
9201
9293
  }
9294
+ _freqMap;
9202
9295
  /**
9203
9296
  * The function returns the frequency map of numbers.
9204
9297
  * @returns The `_freqMap` property, which is a record with number keys and number values, is being
@@ -9207,6 +9300,7 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
9207
9300
  get freqMap() {
9208
9301
  return this._freqMap;
9209
9302
  }
9303
+ _msb;
9210
9304
  /**
9211
9305
  * The function returns the value of the _msb property.
9212
9306
  * @returns The `_msb` property of the object.
@@ -9214,6 +9308,7 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
9214
9308
  get msb() {
9215
9309
  return this._msb;
9216
9310
  }
9311
+ _negativeCount;
9217
9312
  /**
9218
9313
  * The function returns the value of the _negativeCount property.
9219
9314
  * @returns The method is returning the value of the variable `_negativeCount`, which is of type
@@ -9462,11 +9557,12 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
9462
9557
  return left;
9463
9558
  }
9464
9559
  };
9465
- __name(_BinaryIndexedTree, "BinaryIndexedTree");
9466
- var BinaryIndexedTree = _BinaryIndexedTree;
9467
9560
 
9468
9561
  // src/data-structures/binary-tree/segment-tree.ts
9469
- var _SegmentTreeNode = class _SegmentTreeNode {
9562
+ var SegmentTreeNode = class {
9563
+ static {
9564
+ __name(this, "SegmentTreeNode");
9565
+ }
9470
9566
  /**
9471
9567
  * The constructor initializes the properties of a SegmentTreeNode object.
9472
9568
  * @param {number} start - The `start` parameter represents the starting index of the segment covered
@@ -9479,17 +9575,12 @@ var _SegmentTreeNode = class _SegmentTreeNode {
9479
9575
  * of type `SegmentTreeNodeVal`. It represents the value associated with the segment tree node.
9480
9576
  */
9481
9577
  constructor(start, end, sum, value) {
9482
- __publicField(this, "_start", 0);
9483
- __publicField(this, "_end", 0);
9484
- __publicField(this, "_value");
9485
- __publicField(this, "_sum", 0);
9486
- __publicField(this, "_left");
9487
- __publicField(this, "_right");
9488
9578
  this._start = start;
9489
9579
  this._end = end;
9490
9580
  this._sum = sum;
9491
9581
  this._value = value || void 0;
9492
9582
  }
9583
+ _start = 0;
9493
9584
  /**
9494
9585
  * The function returns the value of the protected variable _start.
9495
9586
  * @returns The start value, which is of type number.
@@ -9504,6 +9595,7 @@ var _SegmentTreeNode = class _SegmentTreeNode {
9504
9595
  set start(value) {
9505
9596
  this._start = value;
9506
9597
  }
9598
+ _end = 0;
9507
9599
  /**
9508
9600
  * The function returns the value of the protected variable `_end`.
9509
9601
  * @returns The value of the protected property `_end`.
@@ -9519,6 +9611,7 @@ var _SegmentTreeNode = class _SegmentTreeNode {
9519
9611
  set end(value) {
9520
9612
  this._end = value;
9521
9613
  }
9614
+ _value = void 0;
9522
9615
  /**
9523
9616
  * The function returns the value of a segment tree node.
9524
9617
  * @returns The value being returned is either a `SegmentTreeNodeVal` object or `undefined`.
@@ -9534,6 +9627,7 @@ var _SegmentTreeNode = class _SegmentTreeNode {
9534
9627
  set value(value) {
9535
9628
  this._value = value;
9536
9629
  }
9630
+ _sum = 0;
9537
9631
  /**
9538
9632
  * The function returns the value of the sum property.
9539
9633
  * @returns The method is returning the value of the variable `_sum`.
@@ -9548,6 +9642,7 @@ var _SegmentTreeNode = class _SegmentTreeNode {
9548
9642
  set sum(value) {
9549
9643
  this._sum = value;
9550
9644
  }
9645
+ _left = void 0;
9551
9646
  /**
9552
9647
  * The function returns the left child of a segment tree node.
9553
9648
  * @returns The `left` property of the `SegmentTreeNode` object is being returned. It is of type
@@ -9564,6 +9659,7 @@ var _SegmentTreeNode = class _SegmentTreeNode {
9564
9659
  set left(value) {
9565
9660
  this._left = value;
9566
9661
  }
9662
+ _right = void 0;
9567
9663
  /**
9568
9664
  * The function returns the right child of a segment tree node.
9569
9665
  * @returns The `getRight()` method is returning a value of type `SegmentTreeNode` or `undefined`.
@@ -9581,9 +9677,10 @@ var _SegmentTreeNode = class _SegmentTreeNode {
9581
9677
  this._right = value;
9582
9678
  }
9583
9679
  };
9584
- __name(_SegmentTreeNode, "SegmentTreeNode");
9585
- var SegmentTreeNode = _SegmentTreeNode;
9586
- var _SegmentTree = class _SegmentTree {
9680
+ var SegmentTree = class {
9681
+ static {
9682
+ __name(this, "SegmentTree");
9683
+ }
9587
9684
  /**
9588
9685
  * The constructor initializes the values, start, end, and root properties of an object.
9589
9686
  * @param {number[]} values - An array of numbers that will be used to build a binary search tree.
@@ -9594,10 +9691,6 @@ var _SegmentTree = class _SegmentTree {
9594
9691
  * included in the range. If not provided, it defaults to the index of the last element in the "values" array.
9595
9692
  */
9596
9693
  constructor(values, start, end) {
9597
- __publicField(this, "_values", []);
9598
- __publicField(this, "_start", 0);
9599
- __publicField(this, "_end");
9600
- __publicField(this, "_root");
9601
9694
  start = start || 0;
9602
9695
  end = end || values.length - 1;
9603
9696
  this._values = values;
@@ -9610,6 +9703,7 @@ var _SegmentTree = class _SegmentTree {
9610
9703
  this._values = [];
9611
9704
  }
9612
9705
  }
9706
+ _values = [];
9613
9707
  /**
9614
9708
  * The function returns an array of numbers.
9615
9709
  * @returns An array of numbers is being returned.
@@ -9617,6 +9711,7 @@ var _SegmentTree = class _SegmentTree {
9617
9711
  get values() {
9618
9712
  return this._values;
9619
9713
  }
9714
+ _start = 0;
9620
9715
  /**
9621
9716
  * The function returns the value of the protected variable _start.
9622
9717
  * @returns The start value, which is of type number.
@@ -9624,6 +9719,7 @@ var _SegmentTree = class _SegmentTree {
9624
9719
  get start() {
9625
9720
  return this._start;
9626
9721
  }
9722
+ _end;
9627
9723
  /**
9628
9724
  * The function returns the value of the protected variable `_end`.
9629
9725
  * @returns The value of the protected property `_end`.
@@ -9631,6 +9727,7 @@ var _SegmentTree = class _SegmentTree {
9631
9727
  get end() {
9632
9728
  return this._end;
9633
9729
  }
9730
+ _root;
9634
9731
  /**
9635
9732
  * The function returns the root node of a segment tree.
9636
9733
  * @returns The `root` property of the class `SegmentTreeNode` or `undefined` if it is not defined.
@@ -9745,11 +9842,15 @@ var _SegmentTree = class _SegmentTree {
9745
9842
  return dfs(root, indexA, indexB);
9746
9843
  }
9747
9844
  };
9748
- __name(_SegmentTree, "SegmentTree");
9749
- var SegmentTree = _SegmentTree;
9750
9845
 
9751
9846
  // src/data-structures/binary-tree/avl-tree.ts
9752
- var _AVLTreeNode = class _AVLTreeNode extends BSTNode {
9847
+ var AVLTreeNode = class {
9848
+ static {
9849
+ __name(this, "AVLTreeNode");
9850
+ }
9851
+ key;
9852
+ value;
9853
+ parent = void 0;
9753
9854
  /**
9754
9855
  * Creates an instance of AVLTreeNode.
9755
9856
  * @remarks Time O(1), Space O(1)
@@ -9758,11 +9859,10 @@ var _AVLTreeNode = class _AVLTreeNode extends BSTNode {
9758
9859
  * @param [value] - The value associated with the key.
9759
9860
  */
9760
9861
  constructor(key, value) {
9761
- super(key, value);
9762
- __publicField(this, "parent");
9763
- __publicField(this, "_left");
9764
- __publicField(this, "_right");
9862
+ this.key = key;
9863
+ this.value = value;
9765
9864
  }
9865
+ _left = void 0;
9766
9866
  /**
9767
9867
  * Gets the left child of the node.
9768
9868
  * @remarks Time O(1), Space O(1)
@@ -9784,6 +9884,7 @@ var _AVLTreeNode = class _AVLTreeNode extends BSTNode {
9784
9884
  }
9785
9885
  this._left = v;
9786
9886
  }
9887
+ _right = void 0;
9787
9888
  /**
9788
9889
  * Gets the right child of the node.
9789
9890
  * @remarks Time O(1), Space O(1)
@@ -9805,10 +9906,85 @@ var _AVLTreeNode = class _AVLTreeNode extends BSTNode {
9805
9906
  }
9806
9907
  this._right = v;
9807
9908
  }
9909
+ _height = 0;
9910
+ /**
9911
+ * Gets the height of the node (used in self-balancing trees).
9912
+ * @remarks Time O(1), Space O(1)
9913
+ *
9914
+ * @returns The height.
9915
+ */
9916
+ get height() {
9917
+ return this._height;
9918
+ }
9919
+ /**
9920
+ * Sets the height of the node.
9921
+ * @remarks Time O(1), Space O(1)
9922
+ *
9923
+ * @param value - The new height.
9924
+ */
9925
+ set height(value) {
9926
+ this._height = value;
9927
+ }
9928
+ _color = "BLACK";
9929
+ /**
9930
+ * Gets the color of the node (used in Red-Black trees).
9931
+ * @remarks Time O(1), Space O(1)
9932
+ *
9933
+ * @returns The node's color.
9934
+ */
9935
+ get color() {
9936
+ return this._color;
9937
+ }
9938
+ /**
9939
+ * Sets the color of the node.
9940
+ * @remarks Time O(1), Space O(1)
9941
+ *
9942
+ * @param value - The new color.
9943
+ */
9944
+ set color(value) {
9945
+ this._color = value;
9946
+ }
9947
+ _count = 1;
9948
+ /**
9949
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
9950
+ * @remarks Time O(1), Space O(1)
9951
+ *
9952
+ * @returns The subtree node count.
9953
+ */
9954
+ get count() {
9955
+ return this._count;
9956
+ }
9957
+ /**
9958
+ * Sets the count of nodes in the subtree.
9959
+ * @remarks Time O(1), Space O(1)
9960
+ *
9961
+ * @param value - The new count.
9962
+ */
9963
+ set count(value) {
9964
+ this._count = value;
9965
+ }
9966
+ /**
9967
+ * Gets the position of the node relative to its parent.
9968
+ * @remarks Time O(1), Space O(1)
9969
+ *
9970
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
9971
+ */
9972
+ get familyPosition() {
9973
+ if (!this.parent) {
9974
+ return this.left || this.right ? "ROOT" : "ISOLATED";
9975
+ }
9976
+ if (this.parent.left === this) {
9977
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
9978
+ } else if (this.parent.right === this) {
9979
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
9980
+ }
9981
+ return "MAL_NODE";
9982
+ }
9808
9983
  };
9809
- __name(_AVLTreeNode, "AVLTreeNode");
9810
- var AVLTreeNode = _AVLTreeNode;
9811
- var _AVLTree = class _AVLTree extends BST {
9984
+ var AVLTree = class extends BST {
9985
+ static {
9986
+ __name(this, "AVLTree");
9987
+ }
9812
9988
  /**
9813
9989
  * Creates an instance of AVLTree.
9814
9990
  * @remarks Time O(N log N) (from `addMany` with balanced add). Space O(N).
@@ -9917,7 +10093,7 @@ var _AVLTree = class _AVLTree extends BST {
9917
10093
  const out = this._createLike([], options);
9918
10094
  let index = 0;
9919
10095
  for (const [key, value] of this) {
9920
- out.add(callback.call(thisArg, key, value, index++, this));
10096
+ out.add(callback.call(thisArg, value, key, index++, this));
9921
10097
  }
9922
10098
  return out;
9923
10099
  }
@@ -9931,7 +10107,7 @@ var _AVLTree = class _AVLTree extends BST {
9931
10107
  */
9932
10108
  _createInstance(options) {
9933
10109
  const Ctor = this.constructor;
9934
- return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
10110
+ return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
9935
10111
  }
9936
10112
  /**
9937
10113
  * (Protected) Creates a new instance of the same AVLTree constructor, potentially with different generic types.
@@ -9944,7 +10120,7 @@ var _AVLTree = class _AVLTree extends BST {
9944
10120
  */
9945
10121
  _createLike(iter = [], options) {
9946
10122
  const Ctor = this.constructor;
9947
- return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
10123
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
9948
10124
  }
9949
10125
  /**
9950
10126
  * (Protected) Swaps properties of two nodes, including height.
@@ -10013,7 +10189,7 @@ var _AVLTree = class _AVLTree extends BST {
10013
10189
  if (A === this.root) {
10014
10190
  if (B) this._setRoot(B);
10015
10191
  } else {
10016
- if ((parentOfA == null ? void 0 : parentOfA.left) === A) {
10192
+ if (parentOfA?.left === A) {
10017
10193
  parentOfA.left = B;
10018
10194
  } else {
10019
10195
  if (parentOfA) parentOfA.right = B;
@@ -10196,11 +10372,15 @@ var _AVLTree = class _AVLTree extends BST {
10196
10372
  return super._replaceNode(oldNode, newNode);
10197
10373
  }
10198
10374
  };
10199
- __name(_AVLTree, "AVLTree");
10200
- var AVLTree = _AVLTree;
10201
10375
 
10202
10376
  // src/data-structures/binary-tree/red-black-tree.ts
10203
- var _RedBlackTreeNode = class _RedBlackTreeNode extends BSTNode {
10377
+ var RedBlackTreeNode = class {
10378
+ static {
10379
+ __name(this, "RedBlackTreeNode");
10380
+ }
10381
+ key;
10382
+ value;
10383
+ parent = void 0;
10204
10384
  /**
10205
10385
  * Create a Red-Black Tree and optionally bulk-insert items.
10206
10386
  * @remarks Time O(n log n), Space O(n)
@@ -10210,12 +10390,11 @@ var _RedBlackTreeNode = class _RedBlackTreeNode extends BSTNode {
10210
10390
  * @returns New RedBlackTree instance.
10211
10391
  */
10212
10392
  constructor(key, value, color = "BLACK") {
10213
- super(key, value);
10214
- __publicField(this, "parent");
10215
- __publicField(this, "_left");
10216
- __publicField(this, "_right");
10217
- this._color = color;
10393
+ this.key = key;
10394
+ this.value = value;
10395
+ this.color = color;
10218
10396
  }
10397
+ _left = void 0;
10219
10398
  /**
10220
10399
  * Get the left child pointer.
10221
10400
  * @remarks Time O(1), Space O(1)
@@ -10236,6 +10415,7 @@ var _RedBlackTreeNode = class _RedBlackTreeNode extends BSTNode {
10236
10415
  }
10237
10416
  this._left = v;
10238
10417
  }
10418
+ _right = void 0;
10239
10419
  /**
10240
10420
  * Get the right child pointer.
10241
10421
  * @remarks Time O(1), Space O(1)
@@ -10256,32 +10436,107 @@ var _RedBlackTreeNode = class _RedBlackTreeNode extends BSTNode {
10256
10436
  }
10257
10437
  this._right = v;
10258
10438
  }
10259
- };
10260
- __name(_RedBlackTreeNode, "RedBlackTreeNode");
10261
- var RedBlackTreeNode = _RedBlackTreeNode;
10262
- var _RedBlackTree = class _RedBlackTree extends BST {
10263
- constructor(keysNodesEntriesOrRaws = [], options) {
10264
- super([], options);
10265
- __publicField(this, "_root");
10266
- this._root = this.NIL;
10267
- if (keysNodesEntriesOrRaws) {
10268
- this.addMany(keysNodesEntriesOrRaws);
10269
- }
10270
- }
10439
+ _height = 0;
10271
10440
  /**
10272
- * Get the current root node.
10441
+ * Gets the height of the node (used in self-balancing trees).
10273
10442
  * @remarks Time O(1), Space O(1)
10274
- * @returns Root node, or undefined.
10443
+ *
10444
+ * @returns The height.
10275
10445
  */
10276
- get root() {
10277
- return this._root;
10446
+ get height() {
10447
+ return this._height;
10278
10448
  }
10279
10449
  /**
10280
- * Create a red-black node for the given key/value (value ignored in map mode).
10450
+ * Sets the height of the node.
10281
10451
  * @remarks Time O(1), Space O(1)
10282
- * @param key - See parameter type for details.
10283
- * @param [value] - See parameter type for details.
10284
- * @param color - See parameter type for details.
10452
+ *
10453
+ * @param value - The new height.
10454
+ */
10455
+ set height(value) {
10456
+ this._height = value;
10457
+ }
10458
+ _color = "BLACK";
10459
+ /**
10460
+ * Gets the color of the node (used in Red-Black trees).
10461
+ * @remarks Time O(1), Space O(1)
10462
+ *
10463
+ * @returns The node's color.
10464
+ */
10465
+ get color() {
10466
+ return this._color;
10467
+ }
10468
+ /**
10469
+ * Sets the color of the node.
10470
+ * @remarks Time O(1), Space O(1)
10471
+ *
10472
+ * @param value - The new color.
10473
+ */
10474
+ set color(value) {
10475
+ this._color = value;
10476
+ }
10477
+ _count = 1;
10478
+ /**
10479
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
10480
+ * @remarks Time O(1), Space O(1)
10481
+ *
10482
+ * @returns The subtree node count.
10483
+ */
10484
+ get count() {
10485
+ return this._count;
10486
+ }
10487
+ /**
10488
+ * Sets the count of nodes in the subtree.
10489
+ * @remarks Time O(1), Space O(1)
10490
+ *
10491
+ * @param value - The new count.
10492
+ */
10493
+ set count(value) {
10494
+ this._count = value;
10495
+ }
10496
+ /**
10497
+ * Gets the position of the node relative to its parent.
10498
+ * @remarks Time O(1), Space O(1)
10499
+ *
10500
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
10501
+ */
10502
+ get familyPosition() {
10503
+ if (!this.parent) {
10504
+ return this.left || this.right ? "ROOT" : "ISOLATED";
10505
+ }
10506
+ if (this.parent.left === this) {
10507
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
10508
+ } else if (this.parent.right === this) {
10509
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
10510
+ }
10511
+ return "MAL_NODE";
10512
+ }
10513
+ };
10514
+ var RedBlackTree = class extends BST {
10515
+ static {
10516
+ __name(this, "RedBlackTree");
10517
+ }
10518
+ constructor(keysNodesEntriesOrRaws = [], options) {
10519
+ super([], options);
10520
+ this._root = this.NIL;
10521
+ if (keysNodesEntriesOrRaws) {
10522
+ this.addMany(keysNodesEntriesOrRaws);
10523
+ }
10524
+ }
10525
+ _root;
10526
+ /**
10527
+ * Get the current root node.
10528
+ * @remarks Time O(1), Space O(1)
10529
+ * @returns Root node, or undefined.
10530
+ */
10531
+ get root() {
10532
+ return this._root;
10533
+ }
10534
+ /**
10535
+ * Create a red-black node for the given key/value (value ignored in map mode).
10536
+ * @remarks Time O(1), Space O(1)
10537
+ * @param key - See parameter type for details.
10538
+ * @param [value] - See parameter type for details.
10539
+ * @param color - See parameter type for details.
10285
10540
  * @returns A new RedBlackTreeNode instance.
10286
10541
  */
10287
10542
  createNode(key, value, color = "BLACK") {
@@ -10406,17 +10661,17 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10406
10661
  const out = this._createLike([], options);
10407
10662
  let index = 0;
10408
10663
  for (const [key, value] of this) {
10409
- out.add(callback.call(thisArg, key, value, index++, this));
10664
+ out.add(callback.call(thisArg, value, key, index++, this));
10410
10665
  }
10411
10666
  return out;
10412
10667
  }
10413
10668
  _createInstance(options) {
10414
10669
  const Ctor = this.constructor;
10415
- return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
10670
+ return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
10416
10671
  }
10417
10672
  _createLike(iter = [], options) {
10418
10673
  const Ctor = this.constructor;
10419
- return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
10674
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
10420
10675
  }
10421
10676
  _setRoot(v) {
10422
10677
  if (v) {
@@ -10435,16 +10690,15 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10435
10690
  * @returns Status string: 'CREATED' or 'UPDATED'.
10436
10691
  */
10437
10692
  _insert(node) {
10438
- var _a, _b;
10439
- let current = this.root;
10693
+ let current = this.root ?? this.NIL;
10440
10694
  let parent = void 0;
10441
- while (this.isRealNode(current)) {
10695
+ while (current !== this.NIL) {
10442
10696
  parent = current;
10443
10697
  const compared = this._compare(node.key, current.key);
10444
10698
  if (compared < 0) {
10445
- current = (_a = current.left) != null ? _a : this.NIL;
10699
+ current = current.left ?? this.NIL;
10446
10700
  } else if (compared > 0) {
10447
- current = (_b = current.right) != null ? _b : this.NIL;
10701
+ current = current.right ?? this.NIL;
10448
10702
  } else {
10449
10703
  this._replaceNode(current, node);
10450
10704
  return "UPDATED";
@@ -10490,11 +10744,10 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10490
10744
  * @returns void
10491
10745
  */
10492
10746
  _insertFixup(z) {
10493
- var _a, _b, _c, _d, _e;
10494
- while (((_a = z == null ? void 0 : z.parent) == null ? void 0 : _a.color) === "RED") {
10495
- if (z.parent === ((_b = z.parent.parent) == null ? void 0 : _b.left)) {
10747
+ while (z?.parent?.color === "RED") {
10748
+ if (z.parent === z.parent.parent?.left) {
10496
10749
  const y = z.parent.parent.right;
10497
- if ((y == null ? void 0 : y.color) === "RED") {
10750
+ if (y?.color === "RED") {
10498
10751
  z.parent.color = "BLACK";
10499
10752
  y.color = "BLACK";
10500
10753
  z.parent.parent.color = "RED";
@@ -10504,15 +10757,15 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10504
10757
  z = z.parent;
10505
10758
  this._leftRotate(z);
10506
10759
  }
10507
- if (z && this.isRealNode(z.parent) && this.isRealNode(z.parent.parent)) {
10760
+ if (z && z.parent && z.parent.parent) {
10508
10761
  z.parent.color = "BLACK";
10509
10762
  z.parent.parent.color = "RED";
10510
10763
  this._rightRotate(z.parent.parent);
10511
10764
  }
10512
10765
  }
10513
10766
  } else {
10514
- 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;
10515
- if ((y == null ? void 0 : y.color) === "RED") {
10767
+ const y = z?.parent?.parent?.left ?? void 0;
10768
+ if (y?.color === "RED") {
10516
10769
  z.parent.color = "BLACK";
10517
10770
  y.color = "BLACK";
10518
10771
  z.parent.parent.color = "RED";
@@ -10522,7 +10775,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10522
10775
  z = z.parent;
10523
10776
  this._rightRotate(z);
10524
10777
  }
10525
- if (z && this.isRealNode(z.parent) && this.isRealNode(z.parent.parent)) {
10778
+ if (z && z.parent && z.parent.parent) {
10526
10779
  z.parent.color = "BLACK";
10527
10780
  z.parent.parent.color = "RED";
10528
10781
  this._leftRotate(z.parent.parent);
@@ -10539,7 +10792,6 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10539
10792
  * @returns void
10540
10793
  */
10541
10794
  _deleteFixup(node) {
10542
- var _a, _b, _c, _d;
10543
10795
  if (!node || node === this.root || node.color === "BLACK") {
10544
10796
  if (node) {
10545
10797
  node.color = "BLACK";
@@ -10553,17 +10805,17 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10553
10805
  }
10554
10806
  if (node === parent.left) {
10555
10807
  let sibling = parent.right;
10556
- if ((sibling == null ? void 0 : sibling.color) === "RED") {
10808
+ if (sibling?.color === "RED") {
10557
10809
  sibling.color = "BLACK";
10558
10810
  parent.color = "RED";
10559
10811
  this._leftRotate(parent);
10560
10812
  sibling = parent.right;
10561
10813
  }
10562
- if (((_b = (_a = sibling == null ? void 0 : sibling.left) == null ? void 0 : _a.color) != null ? _b : "BLACK") === "BLACK") {
10814
+ if ((sibling?.left?.color ?? "BLACK") === "BLACK") {
10563
10815
  if (sibling) sibling.color = "RED";
10564
10816
  node = parent;
10565
10817
  } else {
10566
- if (sibling == null ? void 0 : sibling.left) sibling.left.color = "BLACK";
10818
+ if (sibling?.left) sibling.left.color = "BLACK";
10567
10819
  if (sibling) sibling.color = parent.color;
10568
10820
  parent.color = "BLACK";
10569
10821
  this._rightRotate(parent);
@@ -10571,17 +10823,17 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10571
10823
  }
10572
10824
  } else {
10573
10825
  let sibling = parent.left;
10574
- if ((sibling == null ? void 0 : sibling.color) === "RED") {
10826
+ if (sibling?.color === "RED") {
10575
10827
  sibling.color = "BLACK";
10576
10828
  if (parent) parent.color = "RED";
10577
10829
  this._rightRotate(parent);
10578
10830
  if (parent) sibling = parent.left;
10579
10831
  }
10580
- if (((_d = (_c = sibling == null ? void 0 : sibling.right) == null ? void 0 : _c.color) != null ? _d : "BLACK") === "BLACK") {
10832
+ if ((sibling?.right?.color ?? "BLACK") === "BLACK") {
10581
10833
  if (sibling) sibling.color = "RED";
10582
10834
  node = parent;
10583
10835
  } else {
10584
- if (sibling == null ? void 0 : sibling.right) sibling.right.color = "BLACK";
10836
+ if (sibling?.right) sibling.right.color = "BLACK";
10585
10837
  if (sibling) sibling.color = parent.color;
10586
10838
  if (parent) parent.color = "BLACK";
10587
10839
  this._leftRotate(parent);
@@ -10605,7 +10857,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10605
10857
  }
10606
10858
  const y = x.right;
10607
10859
  x.right = y.left;
10608
- if (this.isRealNode(y.left)) {
10860
+ if (y.left && y.left !== this.NIL) {
10609
10861
  y.left.parent = x;
10610
10862
  }
10611
10863
  y.parent = x.parent;
@@ -10631,7 +10883,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10631
10883
  }
10632
10884
  const x = y.left;
10633
10885
  y.left = x.right;
10634
- if (this.isRealNode(x.right)) {
10886
+ if (x.right && x.right !== this.NIL) {
10635
10887
  x.right.parent = y;
10636
10888
  }
10637
10889
  x.parent = y.parent;
@@ -10646,11 +10898,15 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10646
10898
  y.parent = x;
10647
10899
  }
10648
10900
  };
10649
- __name(_RedBlackTree, "RedBlackTree");
10650
- var RedBlackTree = _RedBlackTree;
10651
10901
 
10652
10902
  // src/data-structures/binary-tree/avl-tree-multi-map.ts
10653
- var _AVLTreeMultiMapNode = class _AVLTreeMultiMapNode extends AVLTreeNode {
10903
+ var AVLTreeMultiMapNode = class {
10904
+ static {
10905
+ __name(this, "AVLTreeMultiMapNode");
10906
+ }
10907
+ key;
10908
+ value;
10909
+ parent = void 0;
10654
10910
  /**
10655
10911
  * Create an AVLTreeMultiMap node with a value bucket.
10656
10912
  * @remarks Time O(1), Space O(1)
@@ -10658,12 +10914,11 @@ var _AVLTreeMultiMapNode = class _AVLTreeMultiMapNode extends AVLTreeNode {
10658
10914
  * @param value - Initial array of values.
10659
10915
  * @returns New AVLTreeMultiMapNode instance.
10660
10916
  */
10661
- constructor(key, value) {
10662
- super(key, value);
10663
- __publicField(this, "parent");
10664
- __publicField(this, "_left");
10665
- __publicField(this, "_right");
10917
+ constructor(key, value = []) {
10918
+ this.key = key;
10919
+ this.value = value;
10666
10920
  }
10921
+ _left = void 0;
10667
10922
  /**
10668
10923
  * Get the left child pointer.
10669
10924
  * @remarks Time O(1), Space O(1)
@@ -10684,6 +10939,7 @@ var _AVLTreeMultiMapNode = class _AVLTreeMultiMapNode extends AVLTreeNode {
10684
10939
  }
10685
10940
  this._left = v;
10686
10941
  }
10942
+ _right = void 0;
10687
10943
  /**
10688
10944
  * Get the right child pointer.
10689
10945
  * @remarks Time O(1), Space O(1)
@@ -10704,10 +10960,85 @@ var _AVLTreeMultiMapNode = class _AVLTreeMultiMapNode extends AVLTreeNode {
10704
10960
  }
10705
10961
  this._right = v;
10706
10962
  }
10963
+ _height = 0;
10964
+ /**
10965
+ * Gets the height of the node (used in self-balancing trees).
10966
+ * @remarks Time O(1), Space O(1)
10967
+ *
10968
+ * @returns The height.
10969
+ */
10970
+ get height() {
10971
+ return this._height;
10972
+ }
10973
+ /**
10974
+ * Sets the height of the node.
10975
+ * @remarks Time O(1), Space O(1)
10976
+ *
10977
+ * @param value - The new height.
10978
+ */
10979
+ set height(value) {
10980
+ this._height = value;
10981
+ }
10982
+ _color = "BLACK";
10983
+ /**
10984
+ * Gets the color of the node (used in Red-Black trees).
10985
+ * @remarks Time O(1), Space O(1)
10986
+ *
10987
+ * @returns The node's color.
10988
+ */
10989
+ get color() {
10990
+ return this._color;
10991
+ }
10992
+ /**
10993
+ * Sets the color of the node.
10994
+ * @remarks Time O(1), Space O(1)
10995
+ *
10996
+ * @param value - The new color.
10997
+ */
10998
+ set color(value) {
10999
+ this._color = value;
11000
+ }
11001
+ _count = 1;
11002
+ /**
11003
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
11004
+ * @remarks Time O(1), Space O(1)
11005
+ *
11006
+ * @returns The subtree node count.
11007
+ */
11008
+ get count() {
11009
+ return this._count;
11010
+ }
11011
+ /**
11012
+ * Sets the count of nodes in the subtree.
11013
+ * @remarks Time O(1), Space O(1)
11014
+ *
11015
+ * @param value - The new count.
11016
+ */
11017
+ set count(value) {
11018
+ this._count = value;
11019
+ }
11020
+ /**
11021
+ * Gets the position of the node relative to its parent.
11022
+ * @remarks Time O(1), Space O(1)
11023
+ *
11024
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
11025
+ */
11026
+ get familyPosition() {
11027
+ if (!this.parent) {
11028
+ return this.left || this.right ? "ROOT" : "ISOLATED";
11029
+ }
11030
+ if (this.parent.left === this) {
11031
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
11032
+ } else if (this.parent.right === this) {
11033
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
11034
+ }
11035
+ return "MAL_NODE";
11036
+ }
10707
11037
  };
10708
- __name(_AVLTreeMultiMapNode, "AVLTreeMultiMapNode");
10709
- var AVLTreeMultiMapNode = _AVLTreeMultiMapNode;
10710
- var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11038
+ var AVLTreeMultiMap = class extends AVLTree {
11039
+ static {
11040
+ __name(this, "AVLTreeMultiMap");
11041
+ }
10711
11042
  /**
10712
11043
  * Create an AVLTreeMultiMap and optionally bulk-insert items.
10713
11044
  * @remarks Time O(N log N), Space O(N)
@@ -10724,6 +11055,16 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
10724
11055
  createNode(key, value = []) {
10725
11056
  return new AVLTreeMultiMapNode(key, this._isMapMode ? [] : value);
10726
11057
  }
11058
+ /**
11059
+ * Checks if the given item is a `AVLTreeMultiMapNode` instance.
11060
+ * @remarks Time O(1), Space O(1)
11061
+ *
11062
+ * @param keyNodeOrEntry - The item to check.
11063
+ * @returns True if it's a AVLTreeMultiMapNode, false otherwise.
11064
+ */
11065
+ isNode(keyNodeOrEntry) {
11066
+ return keyNodeOrEntry instanceof AVLTreeMultiMapNode;
11067
+ }
10727
11068
  /**
10728
11069
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
10729
11070
  * @remarks Time O(log N + M), Space O(1)
@@ -10832,7 +11173,7 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
10832
11173
  map(callback, options, thisArg) {
10833
11174
  const out = this._createLike([], options);
10834
11175
  let i = 0;
10835
- for (const [k, v] of this) out.add(callback.call(thisArg, k, v, i++, this));
11176
+ for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
10836
11177
  return out;
10837
11178
  }
10838
11179
  /**
@@ -10845,9 +11186,8 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
10845
11186
  * @returns An empty like-kind instance.
10846
11187
  */
10847
11188
  _createInstance(options) {
10848
- var _a, _b;
10849
11189
  const Ctor = this.constructor;
10850
- return new Ctor([], { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
11190
+ return new Ctor([], { ...this._snapshotOptions?.() ?? {}, ...options ?? {} });
10851
11191
  }
10852
11192
  /**
10853
11193
  * (Protected) Create a like-kind instance and seed it from an iterable.
@@ -10860,16 +11200,19 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
10860
11200
  * @returns A like-kind AVLTree built from the iterable.
10861
11201
  */
10862
11202
  _createLike(iter = [], options) {
10863
- var _a, _b;
10864
11203
  const Ctor = this.constructor;
10865
- return new Ctor(iter, { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
11204
+ return new Ctor(iter, { ...this._snapshotOptions?.() ?? {}, ...options ?? {} });
10866
11205
  }
10867
11206
  };
10868
- __name(_AVLTreeMultiMap, "AVLTreeMultiMap");
10869
- var AVLTreeMultiMap = _AVLTreeMultiMap;
10870
11207
 
10871
11208
  // src/data-structures/binary-tree/tree-multi-map.ts
10872
- var _TreeMultiMapNode = class _TreeMultiMapNode extends RedBlackTreeNode {
11209
+ var TreeMultiMapNode = class {
11210
+ static {
11211
+ __name(this, "TreeMultiMapNode");
11212
+ }
11213
+ key;
11214
+ value;
11215
+ parent = void 0;
10873
11216
  /**
10874
11217
  * Create a TreeMultiMap node with an optional value bucket.
10875
11218
  * @remarks Time O(1), Space O(1)
@@ -10877,12 +11220,12 @@ var _TreeMultiMapNode = class _TreeMultiMapNode extends RedBlackTreeNode {
10877
11220
  * @param [value] - Initial array of values.
10878
11221
  * @returns New TreeMultiMapNode instance.
10879
11222
  */
10880
- constructor(key, value) {
10881
- super(key, value);
10882
- __publicField(this, "parent");
10883
- __publicField(this, "_left");
10884
- __publicField(this, "_right");
11223
+ constructor(key, value = [], color = "BLACK") {
11224
+ this.key = key;
11225
+ this.value = value;
11226
+ this.color = color;
10885
11227
  }
11228
+ _left = void 0;
10886
11229
  /**
10887
11230
  * Get the left child pointer.
10888
11231
  * @remarks Time O(1), Space O(1)
@@ -10903,6 +11246,7 @@ var _TreeMultiMapNode = class _TreeMultiMapNode extends RedBlackTreeNode {
10903
11246
  }
10904
11247
  this._left = v;
10905
11248
  }
11249
+ _right = void 0;
10906
11250
  /**
10907
11251
  * Get the right child pointer.
10908
11252
  * @remarks Time O(1), Space O(1)
@@ -10923,10 +11267,85 @@ var _TreeMultiMapNode = class _TreeMultiMapNode extends RedBlackTreeNode {
10923
11267
  }
10924
11268
  this._right = v;
10925
11269
  }
11270
+ _height = 0;
11271
+ /**
11272
+ * Gets the height of the node (used in self-balancing trees).
11273
+ * @remarks Time O(1), Space O(1)
11274
+ *
11275
+ * @returns The height.
11276
+ */
11277
+ get height() {
11278
+ return this._height;
11279
+ }
11280
+ /**
11281
+ * Sets the height of the node.
11282
+ * @remarks Time O(1), Space O(1)
11283
+ *
11284
+ * @param value - The new height.
11285
+ */
11286
+ set height(value) {
11287
+ this._height = value;
11288
+ }
11289
+ _color = "BLACK";
11290
+ /**
11291
+ * Gets the color of the node (used in Red-Black trees).
11292
+ * @remarks Time O(1), Space O(1)
11293
+ *
11294
+ * @returns The node's color.
11295
+ */
11296
+ get color() {
11297
+ return this._color;
11298
+ }
11299
+ /**
11300
+ * Sets the color of the node.
11301
+ * @remarks Time O(1), Space O(1)
11302
+ *
11303
+ * @param value - The new color.
11304
+ */
11305
+ set color(value) {
11306
+ this._color = value;
11307
+ }
11308
+ _count = 1;
11309
+ /**
11310
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
11311
+ * @remarks Time O(1), Space O(1)
11312
+ *
11313
+ * @returns The subtree node count.
11314
+ */
11315
+ get count() {
11316
+ return this._count;
11317
+ }
11318
+ /**
11319
+ * Sets the count of nodes in the subtree.
11320
+ * @remarks Time O(1), Space O(1)
11321
+ *
11322
+ * @param value - The new count.
11323
+ */
11324
+ set count(value) {
11325
+ this._count = value;
11326
+ }
11327
+ /**
11328
+ * Gets the position of the node relative to its parent.
11329
+ * @remarks Time O(1), Space O(1)
11330
+ *
11331
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
11332
+ */
11333
+ get familyPosition() {
11334
+ if (!this.parent) {
11335
+ return this.left || this.right ? "ROOT" : "ISOLATED";
11336
+ }
11337
+ if (this.parent.left === this) {
11338
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
11339
+ } else if (this.parent.right === this) {
11340
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
11341
+ }
11342
+ return "MAL_NODE";
11343
+ }
10926
11344
  };
10927
- __name(_TreeMultiMapNode, "TreeMultiMapNode");
10928
- var TreeMultiMapNode = _TreeMultiMapNode;
10929
- var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11345
+ var TreeMultiMap = class extends RedBlackTree {
11346
+ static {
11347
+ __name(this, "TreeMultiMap");
11348
+ }
10930
11349
  /**
10931
11350
  * Create a TreeMultiMap and optionally bulk-insert items.
10932
11351
  * @remarks Time O(N log N), Space O(N)
@@ -10943,6 +11362,16 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
10943
11362
  createNode(key, value = []) {
10944
11363
  return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
10945
11364
  }
11365
+ /**
11366
+ * Checks if the given item is a `TreeMultiMapNode` instance.
11367
+ * @remarks Time O(1), Space O(1)
11368
+ *
11369
+ * @param keyNodeOrEntry - The item to check.
11370
+ * @returns True if it's a TreeMultiMapNode, false otherwise.
11371
+ */
11372
+ isNode(keyNodeOrEntry) {
11373
+ return keyNodeOrEntry instanceof TreeMultiMapNode;
11374
+ }
10946
11375
  /**
10947
11376
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
10948
11377
  * @remarks Time O(log N + M), Space O(1)
@@ -11023,7 +11452,7 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11023
11452
  map(callback, options, thisArg) {
11024
11453
  const out = this._createLike([], options);
11025
11454
  let i = 0;
11026
- for (const [k, v] of this) out.add(callback.call(thisArg, k, v, i++, this));
11455
+ for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
11027
11456
  return out;
11028
11457
  }
11029
11458
  /**
@@ -11036,9 +11465,8 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11036
11465
  * @returns An empty like-kind instance.
11037
11466
  */
11038
11467
  _createInstance(options) {
11039
- var _a, _b;
11040
11468
  const Ctor = this.constructor;
11041
- return new Ctor([], { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
11469
+ return new Ctor([], { ...this._snapshotOptions?.() ?? {}, ...options ?? {} });
11042
11470
  }
11043
11471
  /**
11044
11472
  * (Protected) Create a like-kind instance and seed it from an iterable.
@@ -11051,16 +11479,19 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11051
11479
  * @returns A like-kind RedBlackTree built from the iterable.
11052
11480
  */
11053
11481
  _createLike(iter = [], options) {
11054
- var _a, _b;
11055
11482
  const Ctor = this.constructor;
11056
- return new Ctor(iter, { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
11483
+ return new Ctor(iter, { ...this._snapshotOptions?.() ?? {}, ...options ?? {} });
11057
11484
  }
11058
11485
  };
11059
- __name(_TreeMultiMap, "TreeMultiMap");
11060
- var TreeMultiMap = _TreeMultiMap;
11061
11486
 
11062
11487
  // src/data-structures/binary-tree/tree-counter.ts
11063
- var _TreeCounterNode = class _TreeCounterNode extends RedBlackTreeNode {
11488
+ var TreeCounterNode = class {
11489
+ static {
11490
+ __name(this, "TreeCounterNode");
11491
+ }
11492
+ key;
11493
+ value;
11494
+ parent = void 0;
11064
11495
  /**
11065
11496
  * Create a tree counter node.
11066
11497
  * @remarks Time O(1), Space O(1)
@@ -11071,12 +11502,12 @@ var _TreeCounterNode = class _TreeCounterNode extends RedBlackTreeNode {
11071
11502
  * @returns New TreeCounterNode instance.
11072
11503
  */
11073
11504
  constructor(key, value, count = 1, color = "BLACK") {
11074
- super(key, value, color);
11075
- __publicField(this, "parent");
11076
- __publicField(this, "_left");
11077
- __publicField(this, "_right");
11505
+ this.key = key;
11506
+ this.value = value;
11507
+ this.color = color;
11078
11508
  this.count = count;
11079
11509
  }
11510
+ _left = void 0;
11080
11511
  /**
11081
11512
  * Get the left child pointer.
11082
11513
  * @remarks Time O(1), Space O(1)
@@ -11097,6 +11528,7 @@ var _TreeCounterNode = class _TreeCounterNode extends RedBlackTreeNode {
11097
11528
  }
11098
11529
  this._left = v;
11099
11530
  }
11531
+ _right = void 0;
11100
11532
  /**
11101
11533
  * Get the right child pointer.
11102
11534
  * @remarks Time O(1), Space O(1)
@@ -11117,10 +11549,85 @@ var _TreeCounterNode = class _TreeCounterNode extends RedBlackTreeNode {
11117
11549
  }
11118
11550
  this._right = v;
11119
11551
  }
11552
+ _height = 0;
11553
+ /**
11554
+ * Gets the height of the node (used in self-balancing trees).
11555
+ * @remarks Time O(1), Space O(1)
11556
+ *
11557
+ * @returns The height.
11558
+ */
11559
+ get height() {
11560
+ return this._height;
11561
+ }
11562
+ /**
11563
+ * Sets the height of the node.
11564
+ * @remarks Time O(1), Space O(1)
11565
+ *
11566
+ * @param value - The new height.
11567
+ */
11568
+ set height(value) {
11569
+ this._height = value;
11570
+ }
11571
+ _color = "BLACK";
11572
+ /**
11573
+ * Gets the color of the node (used in Red-Black trees).
11574
+ * @remarks Time O(1), Space O(1)
11575
+ *
11576
+ * @returns The node's color.
11577
+ */
11578
+ get color() {
11579
+ return this._color;
11580
+ }
11581
+ /**
11582
+ * Sets the color of the node.
11583
+ * @remarks Time O(1), Space O(1)
11584
+ *
11585
+ * @param value - The new color.
11586
+ */
11587
+ set color(value) {
11588
+ this._color = value;
11589
+ }
11590
+ _count = 1;
11591
+ /**
11592
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
11593
+ * @remarks Time O(1), Space O(1)
11594
+ *
11595
+ * @returns The subtree node count.
11596
+ */
11597
+ get count() {
11598
+ return this._count;
11599
+ }
11600
+ /**
11601
+ * Sets the count of nodes in the subtree.
11602
+ * @remarks Time O(1), Space O(1)
11603
+ *
11604
+ * @param value - The new count.
11605
+ */
11606
+ set count(value) {
11607
+ this._count = value;
11608
+ }
11609
+ /**
11610
+ * Gets the position of the node relative to its parent.
11611
+ * @remarks Time O(1), Space O(1)
11612
+ *
11613
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
11614
+ */
11615
+ get familyPosition() {
11616
+ if (!this.parent) {
11617
+ return this.left || this.right ? "ROOT" : "ISOLATED";
11618
+ }
11619
+ if (this.parent.left === this) {
11620
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
11621
+ } else if (this.parent.right === this) {
11622
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
11623
+ }
11624
+ return "MAL_NODE";
11625
+ }
11120
11626
  };
11121
- __name(_TreeCounterNode, "TreeCounterNode");
11122
- var TreeCounterNode = _TreeCounterNode;
11123
- var _TreeCounter = class _TreeCounter extends RedBlackTree {
11627
+ var TreeCounter = class extends RedBlackTree {
11628
+ static {
11629
+ __name(this, "TreeCounter");
11630
+ }
11124
11631
  /**
11125
11632
  * Create a TreeCounter and optionally bulk-insert items.
11126
11633
  * @remarks Time O(N log N), Space O(N)
@@ -11130,9 +11637,9 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11130
11637
  */
11131
11638
  constructor(keysNodesEntriesOrRaws = [], options) {
11132
11639
  super([], options);
11133
- __publicField(this, "_count", 0);
11134
11640
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
11135
11641
  }
11642
+ _count = 0;
11136
11643
  /**
11137
11644
  * Get the total aggregate count across all nodes.
11138
11645
  * @remarks Time O(1), Space O(1)
@@ -11172,7 +11679,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11172
11679
  */
11173
11680
  add(keyNodeOrEntry, value, count = 1) {
11174
11681
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
11175
- const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
11682
+ const orgCount = newNode?.count || 0;
11176
11683
  const isSuccessAdded = super.add(newNode, newValue);
11177
11684
  if (isSuccessAdded) {
11178
11685
  this._count += orgCount;
@@ -11326,7 +11833,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11326
11833
  const out = this._createLike([], options);
11327
11834
  let index = 0;
11328
11835
  for (const [key, value] of this) {
11329
- out.add(callback.call(thisArg, key, value, index++, this));
11836
+ out.add(callback.call(thisArg, value, key, index++, this));
11330
11837
  }
11331
11838
  return out;
11332
11839
  }
@@ -11352,7 +11859,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11352
11859
  */
11353
11860
  _createInstance(options) {
11354
11861
  const Ctor = this.constructor;
11355
- return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
11862
+ return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
11356
11863
  }
11357
11864
  /**
11358
11865
  * (Protected) Create a like-kind instance and seed it from an iterable.
@@ -11368,7 +11875,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11368
11875
  const Ctor = this.constructor;
11369
11876
  return new Ctor(iter, {
11370
11877
  ...this._snapshotOptions(),
11371
- ...options != null ? options : {}
11878
+ ...options ?? {}
11372
11879
  });
11373
11880
  }
11374
11881
  /**
@@ -11385,7 +11892,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11385
11892
  if (this.isEntry(keyNodeOrEntry)) {
11386
11893
  const [key, entryValue] = keyNodeOrEntry;
11387
11894
  if (key === void 0 || key === null) return [void 0, void 0];
11388
- const finalValue = value != null ? value : entryValue;
11895
+ const finalValue = value ?? entryValue;
11389
11896
  return [this.createNode(key, finalValue, "BLACK", count), finalValue];
11390
11897
  }
11391
11898
  return [this.createNode(keyNodeOrEntry, value, "BLACK", count), value];
@@ -11430,11 +11937,15 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11430
11937
  return super._replaceNode(oldNode, newNode);
11431
11938
  }
11432
11939
  };
11433
- __name(_TreeCounter, "TreeCounter");
11434
- var TreeCounter = _TreeCounter;
11435
11940
 
11436
11941
  // src/data-structures/binary-tree/avl-tree-counter.ts
11437
- var _AVLTreeCounterNode = class _AVLTreeCounterNode extends AVLTreeNode {
11942
+ var AVLTreeCounterNode = class {
11943
+ static {
11944
+ __name(this, "AVLTreeCounterNode");
11945
+ }
11946
+ key;
11947
+ value;
11948
+ parent = void 0;
11438
11949
  /**
11439
11950
  * Create an AVL counter node.
11440
11951
  * @remarks Time O(1), Space O(1)
@@ -11444,12 +11955,11 @@ var _AVLTreeCounterNode = class _AVLTreeCounterNode extends AVLTreeNode {
11444
11955
  * @returns New AVLTreeCounterNode instance.
11445
11956
  */
11446
11957
  constructor(key, value, count = 1) {
11447
- super(key, value);
11448
- __publicField(this, "parent");
11449
- __publicField(this, "_left");
11450
- __publicField(this, "_right");
11958
+ this.key = key;
11959
+ this.value = value;
11451
11960
  this.count = count;
11452
11961
  }
11962
+ _left = void 0;
11453
11963
  /**
11454
11964
  * Get the left child pointer.
11455
11965
  * @remarks Time O(1), Space O(1)
@@ -11470,6 +11980,7 @@ var _AVLTreeCounterNode = class _AVLTreeCounterNode extends AVLTreeNode {
11470
11980
  }
11471
11981
  this._left = v;
11472
11982
  }
11983
+ _right = void 0;
11473
11984
  /**
11474
11985
  * Get the right child pointer.
11475
11986
  * @remarks Time O(1), Space O(1)
@@ -11490,10 +12001,85 @@ var _AVLTreeCounterNode = class _AVLTreeCounterNode extends AVLTreeNode {
11490
12001
  }
11491
12002
  this._right = v;
11492
12003
  }
12004
+ _height = 0;
12005
+ /**
12006
+ * Gets the height of the node (used in self-balancing trees).
12007
+ * @remarks Time O(1), Space O(1)
12008
+ *
12009
+ * @returns The height.
12010
+ */
12011
+ get height() {
12012
+ return this._height;
12013
+ }
12014
+ /**
12015
+ * Sets the height of the node.
12016
+ * @remarks Time O(1), Space O(1)
12017
+ *
12018
+ * @param value - The new height.
12019
+ */
12020
+ set height(value) {
12021
+ this._height = value;
12022
+ }
12023
+ _color = "BLACK";
12024
+ /**
12025
+ * Gets the color of the node (used in Red-Black trees).
12026
+ * @remarks Time O(1), Space O(1)
12027
+ *
12028
+ * @returns The node's color.
12029
+ */
12030
+ get color() {
12031
+ return this._color;
12032
+ }
12033
+ /**
12034
+ * Sets the color of the node.
12035
+ * @remarks Time O(1), Space O(1)
12036
+ *
12037
+ * @param value - The new color.
12038
+ */
12039
+ set color(value) {
12040
+ this._color = value;
12041
+ }
12042
+ _count = 1;
12043
+ /**
12044
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
12045
+ * @remarks Time O(1), Space O(1)
12046
+ *
12047
+ * @returns The subtree node count.
12048
+ */
12049
+ get count() {
12050
+ return this._count;
12051
+ }
12052
+ /**
12053
+ * Sets the count of nodes in the subtree.
12054
+ * @remarks Time O(1), Space O(1)
12055
+ *
12056
+ * @param value - The new count.
12057
+ */
12058
+ set count(value) {
12059
+ this._count = value;
12060
+ }
12061
+ /**
12062
+ * Gets the position of the node relative to its parent.
12063
+ * @remarks Time O(1), Space O(1)
12064
+ *
12065
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
12066
+ */
12067
+ get familyPosition() {
12068
+ if (!this.parent) {
12069
+ return this.left || this.right ? "ROOT" : "ISOLATED";
12070
+ }
12071
+ if (this.parent.left === this) {
12072
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
12073
+ } else if (this.parent.right === this) {
12074
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
12075
+ }
12076
+ return "MAL_NODE";
12077
+ }
11493
12078
  };
11494
- __name(_AVLTreeCounterNode, "AVLTreeCounterNode");
11495
- var AVLTreeCounterNode = _AVLTreeCounterNode;
11496
- var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
12079
+ var AVLTreeCounter = class extends AVLTree {
12080
+ static {
12081
+ __name(this, "AVLTreeCounter");
12082
+ }
11497
12083
  /**
11498
12084
  * Create a AVLTreeCounter instance
11499
12085
  * @remarks Time O(n), Space O(n)
@@ -11503,9 +12089,9 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11503
12089
  */
11504
12090
  constructor(keysNodesEntriesOrRaws = [], options) {
11505
12091
  super([], options);
11506
- __publicField(this, "_count", 0);
11507
12092
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
11508
12093
  }
12094
+ _count = 0;
11509
12095
  get count() {
11510
12096
  return this._count;
11511
12097
  }
@@ -11541,7 +12127,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11541
12127
  add(keyNodeOrEntry, value, count = 1) {
11542
12128
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
11543
12129
  if (newNode === void 0) return false;
11544
- const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
12130
+ const orgNodeCount = newNode?.count || 0;
11545
12131
  const inserted = super.add(newNode, newValue);
11546
12132
  if (inserted) {
11547
12133
  this._count += orgNodeCount;
@@ -11556,12 +12142,11 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11556
12142
  * @returns Array of deletion results including deleted node and a rebalance hint when present.
11557
12143
  */
11558
12144
  delete(keyNodeOrEntry, ignoreCount = false) {
11559
- var _a;
11560
12145
  const deletedResult = [];
11561
12146
  if (!this.root) return deletedResult;
11562
- const curr = (_a = this.getNode(keyNodeOrEntry)) != null ? _a : void 0;
12147
+ const curr = this.getNode(keyNodeOrEntry) ?? void 0;
11563
12148
  if (!curr) return deletedResult;
11564
- const parent = (curr == null ? void 0 : curr.parent) ? curr.parent : void 0;
12149
+ const parent = curr?.parent ? curr.parent : void 0;
11565
12150
  let needBalanced = void 0, orgCurrent = curr;
11566
12151
  if (curr.count > 1 && !ignoreCount) {
11567
12152
  curr.count--;
@@ -11673,7 +12258,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11673
12258
  const out = this._createLike([], options);
11674
12259
  let index = 0;
11675
12260
  for (const [key, value] of this) {
11676
- out.add(callback.call(thisArg, key, value, index++, this));
12261
+ out.add(callback.call(thisArg, value, key, index++, this));
11677
12262
  }
11678
12263
  return out;
11679
12264
  }
@@ -11688,7 +12273,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11688
12273
  */
11689
12274
  _createInstance(options) {
11690
12275
  const Ctor = this.constructor;
11691
- return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
12276
+ return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
11692
12277
  }
11693
12278
  /**
11694
12279
  * (Protected) Create a like-kind instance and seed it from an iterable.
@@ -11702,7 +12287,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11702
12287
  */
11703
12288
  _createLike(iter = [], options) {
11704
12289
  const Ctor = this.constructor;
11705
- return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
12290
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
11706
12291
  }
11707
12292
  /**
11708
12293
  * (Protected) Normalize input into a node plus its effective value and count.
@@ -11718,7 +12303,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11718
12303
  if (this.isEntry(keyNodeOrEntry)) {
11719
12304
  const [key, entryValue] = keyNodeOrEntry;
11720
12305
  if (key === void 0 || key === null) return [void 0, void 0];
11721
- const finalValue = value != null ? value : entryValue;
12306
+ const finalValue = value ?? entryValue;
11722
12307
  return [this.createNode(key, finalValue, count), finalValue];
11723
12308
  }
11724
12309
  return [this.createNode(keyNodeOrEntry, value, count), value];
@@ -11763,20 +12348,22 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11763
12348
  return super._replaceNode(oldNode, newNode);
11764
12349
  }
11765
12350
  };
11766
- __name(_AVLTreeCounter, "AVLTreeCounter");
11767
- var AVLTreeCounter = _AVLTreeCounter;
11768
12351
 
11769
12352
  // src/data-structures/priority-queue/priority-queue.ts
11770
- var _PriorityQueue = class _PriorityQueue extends Heap {
12353
+ var PriorityQueue = class extends Heap {
12354
+ static {
12355
+ __name(this, "PriorityQueue");
12356
+ }
11771
12357
  constructor(elements = [], options) {
11772
12358
  super(elements, options);
11773
12359
  }
11774
12360
  };
11775
- __name(_PriorityQueue, "PriorityQueue");
11776
- var PriorityQueue = _PriorityQueue;
11777
12361
 
11778
12362
  // src/data-structures/priority-queue/min-priority-queue.ts
11779
- var _MinPriorityQueue = class _MinPriorityQueue extends PriorityQueue {
12363
+ var MinPriorityQueue = class extends PriorityQueue {
12364
+ static {
12365
+ __name(this, "MinPriorityQueue");
12366
+ }
11780
12367
  /**
11781
12368
  * Creates a min-priority queue.
11782
12369
  * @param elements Optional initial elements to insert.
@@ -11787,11 +12374,12 @@ var _MinPriorityQueue = class _MinPriorityQueue extends PriorityQueue {
11787
12374
  super(elements, options);
11788
12375
  }
11789
12376
  };
11790
- __name(_MinPriorityQueue, "MinPriorityQueue");
11791
- var MinPriorityQueue = _MinPriorityQueue;
11792
12377
 
11793
12378
  // src/data-structures/priority-queue/max-priority-queue.ts
11794
- var _MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
12379
+ var MaxPriorityQueue = class extends PriorityQueue {
12380
+ static {
12381
+ __name(this, "MaxPriorityQueue");
12382
+ }
11795
12383
  /**
11796
12384
  * Creates a max-priority queue.
11797
12385
  * @param elements Optional initial elements to insert.
@@ -11815,11 +12403,12 @@ var _MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
11815
12403
  });
11816
12404
  }
11817
12405
  };
11818
- __name(_MaxPriorityQueue, "MaxPriorityQueue");
11819
- var MaxPriorityQueue = _MaxPriorityQueue;
11820
12406
 
11821
12407
  // src/data-structures/matrix/matrix.ts
11822
- var _Matrix = class _Matrix {
12408
+ var Matrix = class _Matrix {
12409
+ static {
12410
+ __name(this, "Matrix");
12411
+ }
11823
12412
  /**
11824
12413
  * The constructor function initializes a matrix object with the provided data and options, or with
11825
12414
  * default values if no options are provided.
@@ -11828,22 +12417,18 @@ var _Matrix = class _Matrix {
11828
12417
  * properties:
11829
12418
  */
11830
12419
  constructor(data, options) {
11831
- __publicField(this, "_rows", 0);
11832
- __publicField(this, "_cols", 0);
11833
- __publicField(this, "_data");
11834
- var _a, _b, _c;
11835
12420
  if (options) {
11836
12421
  const { rows, cols, addFn, subtractFn, multiplyFn } = options;
11837
12422
  if (typeof rows === "number" && rows > 0) this._rows = rows;
11838
12423
  else this._rows = data.length;
11839
12424
  if (typeof cols === "number" && cols > 0) this._cols = cols;
11840
- else this._cols = ((_a = data[0]) == null ? void 0 : _a.length) || 0;
12425
+ else this._cols = data[0]?.length || 0;
11841
12426
  if (addFn) this._addFn = addFn;
11842
12427
  if (subtractFn) this._subtractFn = subtractFn;
11843
12428
  if (multiplyFn) this._multiplyFn = multiplyFn;
11844
12429
  } else {
11845
12430
  this._rows = data.length;
11846
- this._cols = (_c = (_b = data[0]) == null ? void 0 : _b.length) != null ? _c : 0;
12431
+ this._cols = data[0]?.length ?? 0;
11847
12432
  }
11848
12433
  if (data.length > 0) {
11849
12434
  this._data = data;
@@ -11854,6 +12439,7 @@ var _Matrix = class _Matrix {
11854
12439
  }
11855
12440
  }
11856
12441
  }
12442
+ _rows = 0;
11857
12443
  /**
11858
12444
  * The function returns the number of rows.
11859
12445
  * @returns The number of rows.
@@ -11861,6 +12447,7 @@ var _Matrix = class _Matrix {
11861
12447
  get rows() {
11862
12448
  return this._rows;
11863
12449
  }
12450
+ _cols = 0;
11864
12451
  /**
11865
12452
  * The function returns the value of the protected variable _cols.
11866
12453
  * @returns The number of columns.
@@ -11868,6 +12455,7 @@ var _Matrix = class _Matrix {
11868
12455
  get cols() {
11869
12456
  return this._cols;
11870
12457
  }
12458
+ _data;
11871
12459
  /**
11872
12460
  * The function returns a two-dimensional array of numbers.
11873
12461
  * @returns The data property, which is a two-dimensional array of numbers.
@@ -12066,7 +12654,6 @@ var _Matrix = class _Matrix {
12066
12654
  * @returns a Matrix object, which represents the inverse of the original matrix.
12067
12655
  */
12068
12656
  inverse() {
12069
- var _a;
12070
12657
  if (this.rows !== this.cols) {
12071
12658
  throw new Error("Matrix must be square for inversion.");
12072
12659
  }
@@ -12093,7 +12680,7 @@ var _Matrix = class _Matrix {
12093
12680
  throw new Error("Matrix is singular, and its inverse does not exist.");
12094
12681
  }
12095
12682
  augmentedMatrix._swapRows(i, pivotRow);
12096
- const pivotElement = (_a = augmentedMatrix.get(i, i)) != null ? _a : 1;
12683
+ const pivotElement = augmentedMatrix.get(i, i) ?? 1;
12097
12684
  if (pivotElement === 0) {
12098
12685
  throw new Error("Matrix is singular, and its inverse does not exist (division by zero).");
12099
12686
  }
@@ -12236,11 +12823,14 @@ var _Matrix = class _Matrix {
12236
12823
  }
12237
12824
  }
12238
12825
  };
12239
- __name(_Matrix, "Matrix");
12240
- var Matrix = _Matrix;
12241
12826
 
12242
12827
  // src/data-structures/matrix/navigator.ts
12243
- var _Character = class _Character {
12828
+ var Character = class _Character {
12829
+ static {
12830
+ __name(this, "Character");
12831
+ }
12832
+ direction;
12833
+ turn;
12244
12834
  /**
12245
12835
  * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
12246
12836
  * Character class.
@@ -12250,26 +12840,25 @@ var _Character = class _Character {
12250
12840
  * turning direction. It is used to determine the new direction when the character turns.
12251
12841
  */
12252
12842
  constructor(direction, turning) {
12253
- __publicField(this, "direction");
12254
- __publicField(this, "turn");
12255
12843
  this.direction = direction;
12256
12844
  this.turn = () => new _Character(turning[direction], turning);
12257
12845
  }
12258
12846
  };
12259
- __name(_Character, "Character");
12260
- var Character = _Character;
12261
- var _Navigator = class _Navigator {
12847
+ var Navigator = class {
12848
+ static {
12849
+ __name(this, "Navigator");
12850
+ }
12851
+ onMove;
12852
+ _matrix;
12853
+ _cur;
12854
+ _character;
12855
+ _VISITED;
12262
12856
  /**
12263
12857
  * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
12264
12858
  * in the matrix.
12265
12859
  * @param - - `matrix`: a 2D array representing the grid or map
12266
12860
  */
12267
12861
  constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }) {
12268
- __publicField(this, "onMove");
12269
- __publicField(this, "_matrix");
12270
- __publicField(this, "_cur");
12271
- __publicField(this, "_character");
12272
- __publicField(this, "_VISITED");
12273
12862
  this._matrix = matrix;
12274
12863
  this._cur = cur;
12275
12864
  this._character = new Character(charDir, turning);
@@ -12347,24 +12936,23 @@ var _Navigator = class _Navigator {
12347
12936
  if (this.onMove) this.onMove(this._cur);
12348
12937
  }
12349
12938
  };
12350
- __name(_Navigator, "Navigator");
12351
- var Navigator = _Navigator;
12352
12939
 
12353
12940
  // src/data-structures/trie/trie.ts
12354
- var _TrieNode = class _TrieNode {
12941
+ var TrieNode = class {
12942
+ static {
12943
+ __name(this, "TrieNode");
12944
+ }
12355
12945
  /**
12356
12946
  * Create a Trie node with a character key.
12357
12947
  * @remarks Time O(1), Space O(1)
12358
12948
  * @returns New TrieNode instance.
12359
12949
  */
12360
12950
  constructor(key) {
12361
- __publicField(this, "_key");
12362
- __publicField(this, "_children");
12363
- __publicField(this, "_isEnd");
12364
12951
  this._key = key;
12365
12952
  this._isEnd = false;
12366
12953
  this._children = /* @__PURE__ */ new Map();
12367
12954
  }
12955
+ _key;
12368
12956
  /**
12369
12957
  * Get the character key of this node.
12370
12958
  * @remarks Time O(1), Space O(1)
@@ -12382,6 +12970,7 @@ var _TrieNode = class _TrieNode {
12382
12970
  set key(value) {
12383
12971
  this._key = value;
12384
12972
  }
12973
+ _children;
12385
12974
  /**
12386
12975
  * Get the child map of this node.
12387
12976
  * @remarks Time O(1), Space O(1)
@@ -12399,6 +12988,7 @@ var _TrieNode = class _TrieNode {
12399
12988
  set children(value) {
12400
12989
  this._children = value;
12401
12990
  }
12991
+ _isEnd;
12402
12992
  /**
12403
12993
  * Check whether this node marks the end of a word.
12404
12994
  * @remarks Time O(1), Space O(1)
@@ -12417,9 +13007,10 @@ var _TrieNode = class _TrieNode {
12417
13007
  this._isEnd = value;
12418
13008
  }
12419
13009
  };
12420
- __name(_TrieNode, "TrieNode");
12421
- var TrieNode = _TrieNode;
12422
- var _Trie = class _Trie extends IterableElementBase {
13010
+ var Trie = class extends IterableElementBase {
13011
+ static {
13012
+ __name(this, "Trie");
13013
+ }
12423
13014
  /**
12424
13015
  * Create a Trie and optionally bulk-insert words.
12425
13016
  * @remarks Time O(totalChars), Space O(totalChars)
@@ -12429,9 +13020,6 @@ var _Trie = class _Trie extends IterableElementBase {
12429
13020
  */
12430
13021
  constructor(words = [], options) {
12431
13022
  super(options);
12432
- __publicField(this, "_size", 0);
12433
- __publicField(this, "_caseSensitive", true);
12434
- __publicField(this, "_root", new TrieNode(""));
12435
13023
  if (options) {
12436
13024
  const { caseSensitive } = options;
12437
13025
  if (caseSensitive !== void 0) this._caseSensitive = caseSensitive;
@@ -12440,6 +13028,7 @@ var _Trie = class _Trie extends IterableElementBase {
12440
13028
  this.addMany(words);
12441
13029
  }
12442
13030
  }
13031
+ _size = 0;
12443
13032
  /**
12444
13033
  * Get the number of stored words.
12445
13034
  * @remarks Time O(1), Space O(1)
@@ -12448,6 +13037,7 @@ var _Trie = class _Trie extends IterableElementBase {
12448
13037
  get size() {
12449
13038
  return this._size;
12450
13039
  }
13040
+ _caseSensitive = true;
12451
13041
  /**
12452
13042
  * Get whether comparisons are case-sensitive.
12453
13043
  * @remarks Time O(1), Space O(1)
@@ -12456,6 +13046,7 @@ var _Trie = class _Trie extends IterableElementBase {
12456
13046
  get caseSensitive() {
12457
13047
  return this._caseSensitive;
12458
13048
  }
13049
+ _root = new TrieNode("");
12459
13050
  /**
12460
13051
  * Get the root node.
12461
13052
  * @remarks Time O(1), Space O(1)
@@ -12785,7 +13376,7 @@ var _Trie = class _Trie extends IterableElementBase {
12785
13376
  const next = new Ctor([], {
12786
13377
  toElementFn: this.toElementFn,
12787
13378
  caseSensitive: this.caseSensitive,
12788
- ...options != null ? options : {}
13379
+ ...options ?? {}
12789
13380
  });
12790
13381
  return next;
12791
13382
  }
@@ -12841,11 +13432,12 @@ var _Trie = class _Trie extends IterableElementBase {
12841
13432
  return str;
12842
13433
  }
12843
13434
  };
12844
- __name(_Trie, "Trie");
12845
- var Trie = _Trie;
12846
13435
 
12847
13436
  // src/data-structures/tree/tree.ts
12848
- var _TreeNode = class _TreeNode {
13437
+ var TreeNode = class _TreeNode {
13438
+ static {
13439
+ __name(this, "TreeNode");
13440
+ }
12849
13441
  /**
12850
13442
  * The constructor function initializes a TreeNode object with a key, optional value, and optional
12851
13443
  * children.
@@ -12857,13 +13449,11 @@ var _TreeNode = class _TreeNode {
12857
13449
  * default value is an empty array.
12858
13450
  */
12859
13451
  constructor(key, value, children) {
12860
- __publicField(this, "_key");
12861
- __publicField(this, "_value");
12862
- __publicField(this, "_children");
12863
13452
  this._key = key;
12864
13453
  this._value = value || void 0;
12865
13454
  if (children) this._children = children;
12866
13455
  }
13456
+ _key;
12867
13457
  /**
12868
13458
  * The function returns the value of the protected variable _key.
12869
13459
  * @returns The value of the `_key` property, which is a string.
@@ -12879,6 +13469,7 @@ var _TreeNode = class _TreeNode {
12879
13469
  set key(value) {
12880
13470
  this._key = value;
12881
13471
  }
13472
+ _value;
12882
13473
  /**
12883
13474
  * The function returns the value stored in a variable, or undefined if the variable is empty.
12884
13475
  * @returns The value of the variable `_value` is being returned.
@@ -12894,6 +13485,7 @@ var _TreeNode = class _TreeNode {
12894
13485
  set value(value) {
12895
13486
  this._value = value;
12896
13487
  }
13488
+ _children;
12897
13489
  /**
12898
13490
  * The function returns an array of TreeNode objects or undefined.
12899
13491
  * @returns The `children` property is being returned. It is of type `TreeNode<V>[] | undefined`,
@@ -12949,8 +13541,6 @@ var _TreeNode = class _TreeNode {
12949
13541
  return maxDepth;
12950
13542
  }
12951
13543
  };
12952
- __name(_TreeNode, "TreeNode");
12953
- var TreeNode = _TreeNode;
12954
13544
  /**
12955
13545
  * data-structure-typed
12956
13546
  *