data-structure-typed 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/CONTRIBUTING.md +4 -0
  3. package/README.md +19 -7
  4. package/dist/cjs/index.cjs +1175 -585
  5. package/dist/cjs/index.cjs.map +1 -1
  6. package/dist/{index.cjs → cjs-legacy/index.cjs} +1145 -613
  7. package/dist/cjs-legacy/index.cjs.map +1 -0
  8. package/dist/esm/index.mjs +1175 -585
  9. package/dist/esm/index.mjs.map +1 -1
  10. package/dist/{index.js → esm-legacy/index.mjs} +1147 -615
  11. package/dist/esm-legacy/index.mjs.map +1 -0
  12. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +58 -4
  13. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +66 -4
  14. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +59 -5
  15. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  16. package/dist/types/data-structures/binary-tree/bst.d.ts +58 -4
  17. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +60 -6
  18. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +58 -4
  19. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +66 -4
  20. package/dist/types/data-structures/heap/heap.d.ts +4 -4
  21. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  22. package/dist/types/interfaces/binary-tree.d.ts +1 -1
  23. package/dist/umd/data-structure-typed.js +711 -228
  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/jest.integration.config.js +7 -3
  28. package/package.json +29 -7
  29. package/src/data-structures/binary-tree/avl-tree-counter.ts +106 -15
  30. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
  31. package/src/data-structures/binary-tree/avl-tree.ts +107 -16
  32. package/src/data-structures/binary-tree/binary-tree.ts +4 -4
  33. package/src/data-structures/binary-tree/bst.ts +103 -12
  34. package/src/data-structures/binary-tree/red-black-tree.ts +110 -20
  35. package/src/data-structures/binary-tree/tree-counter.ts +105 -14
  36. package/src/data-structures/binary-tree/tree-multi-map.ts +123 -12
  37. package/src/data-structures/graph/abstract-graph.ts +5 -5
  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/heap/heap.ts +5 -5
  41. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  42. package/src/interfaces/binary-tree.ts +1 -1
  43. package/test/integration/compile.test.mjs +159 -0
  44. package/test/integration/compile.test.ts +176 -0
  45. package/test/integration/heap.test.js +1 -1
  46. package/test/integration/index.html +1 -1
  47. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +5 -4
  48. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
  49. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -3
  50. package/test/unit/data-structures/binary-tree/bst.test.ts +2 -2
  51. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +3 -3
  52. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +5 -4
  53. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +4 -4
  54. package/{tsconfig-base.json → tsconfig.base.json} +0 -1
  55. package/tsconfig.test.json +1 -0
  56. package/{tsconfig-types.json → tsconfig.types.json} +1 -3
  57. package/tsup.config.js +2 -3
  58. package/tsup.node.config.js +71 -0
  59. package/dist/index.cjs.map +0 -1
  60. package/dist/index.js.map +0 -1
  61. package/test/integration/compile.js +0 -144
  62. package/test/integration/compile.mjs +0 -135
  63. package/test/integration/compile.ts +0 -171
  64. package/tsup.node.config.ts +0 -37
@@ -1,13 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
7
 
6
8
  // src/data-structures/base/iterable-entry-base.ts
7
- var IterableEntryBase = class {
8
- static {
9
- __name(this, "IterableEntryBase");
10
- }
9
+ var _IterableEntryBase = class _IterableEntryBase {
11
10
  /**
12
11
  * Default iterator yielding `[key, value]` entries.
13
12
  * @returns Iterator of `[K, V]`.
@@ -176,12 +175,11 @@ var IterableEntryBase = class {
176
175
  console.log(this.toVisual());
177
176
  }
178
177
  };
178
+ __name(_IterableEntryBase, "IterableEntryBase");
179
+ var IterableEntryBase = _IterableEntryBase;
179
180
 
180
181
  // src/data-structures/base/iterable-element-base.ts
181
- var IterableElementBase = class {
182
- static {
183
- __name(this, "IterableElementBase");
184
- }
182
+ var _IterableElementBase = class _IterableElementBase {
185
183
  /**
186
184
  * Create a new iterable base.
187
185
  *
@@ -192,19 +190,19 @@ var IterableElementBase = class {
192
190
  * Time O(1), Space O(1).
193
191
  */
194
192
  constructor(options) {
193
+ /**
194
+ * The converter used to transform a raw element (`R`) into a public element (`E`).
195
+ *
196
+ * @remarks
197
+ * Time O(1), Space O(1).
198
+ */
199
+ __publicField(this, "_toElementFn");
195
200
  if (options) {
196
201
  const { toElementFn } = options;
197
202
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
198
203
  else if (toElementFn) throw new TypeError("toElementFn must be a function type");
199
204
  }
200
205
  }
201
- /**
202
- * The converter used to transform a raw element (`R`) into a public element (`E`).
203
- *
204
- * @remarks
205
- * Time O(1), Space O(1).
206
- */
207
- _toElementFn;
208
206
  /**
209
207
  * Exposes the current `toElementFn`, if configured.
210
208
  *
@@ -399,6 +397,8 @@ var IterableElementBase = class {
399
397
  console.log(this.toVisual());
400
398
  }
401
399
  };
400
+ __name(_IterableElementBase, "IterableElementBase");
401
+ var IterableElementBase = _IterableElementBase;
402
402
 
403
403
  // src/utils/utils.ts
404
404
  var uuidV4 = /* @__PURE__ */ __name(function() {
@@ -519,10 +519,7 @@ function toBinaryString(num, digit = 32) {
519
519
  __name(toBinaryString, "toBinaryString");
520
520
 
521
521
  // src/data-structures/hash/hash-map.ts
522
- var HashMap = class extends IterableEntryBase {
523
- static {
524
- __name(this, "HashMap");
525
- }
522
+ var _HashMap = class _HashMap extends IterableEntryBase {
526
523
  /**
527
524
  * Create a HashMap and optionally bulk-insert entries.
528
525
  * @remarks Time O(N), Space O(N)
@@ -532,6 +529,11 @@ var HashMap = class extends IterableEntryBase {
532
529
  */
533
530
  constructor(entryOrRawElements = [], options) {
534
531
  super();
532
+ __publicField(this, "_store", {});
533
+ __publicField(this, "_objMap", /* @__PURE__ */ new Map());
534
+ __publicField(this, "_toEntryFn");
535
+ __publicField(this, "_size", 0);
536
+ __publicField(this, "_hashFn", /* @__PURE__ */ __name((key) => String(key), "_hashFn"));
535
537
  if (options) {
536
538
  const { hashFn, toEntryFn } = options;
537
539
  if (hashFn) this._hashFn = hashFn;
@@ -539,7 +541,6 @@ var HashMap = class extends IterableEntryBase {
539
541
  }
540
542
  if (entryOrRawElements) this.setMany(entryOrRawElements);
541
543
  }
542
- _store = {};
543
544
  /**
544
545
  * Get the internal store for non-object keys.
545
546
  * @remarks Time O(1), Space O(1)
@@ -548,7 +549,6 @@ var HashMap = class extends IterableEntryBase {
548
549
  get store() {
549
550
  return this._store;
550
551
  }
551
- _objMap = /* @__PURE__ */ new Map();
552
552
  /**
553
553
  * Get the internal Map used for object/function keys.
554
554
  * @remarks Time O(1), Space O(1)
@@ -557,7 +557,6 @@ var HashMap = class extends IterableEntryBase {
557
557
  get objMap() {
558
558
  return this._objMap;
559
559
  }
560
- _toEntryFn;
561
560
  /**
562
561
  * Get the raw→entry converter function if present.
563
562
  * @remarks Time O(1), Space O(1)
@@ -566,7 +565,6 @@ var HashMap = class extends IterableEntryBase {
566
565
  get toEntryFn() {
567
566
  return this._toEntryFn;
568
567
  }
569
- _size = 0;
570
568
  /**
571
569
  * Get the number of distinct keys stored.
572
570
  * @remarks Time O(1), Space O(1)
@@ -575,7 +573,6 @@ var HashMap = class extends IterableEntryBase {
575
573
  get size() {
576
574
  return this._size;
577
575
  }
578
- _hashFn = /* @__PURE__ */ __name((key) => String(key), "_hashFn");
579
576
  /**
580
577
  * Get the current hash function for non-object keys.
581
578
  * @remarks Time O(1), Space O(1)
@@ -651,9 +648,10 @@ var HashMap = class extends IterableEntryBase {
651
648
  * @returns Value or undefined.
652
649
  */
653
650
  get(key) {
651
+ var _a;
654
652
  if (this._isObjKey(key)) return this.objMap.get(key);
655
653
  const strKey = this._getNoObjKey(key);
656
- return this._store[strKey]?.value;
654
+ return (_a = this._store[strKey]) == null ? void 0 : _a.value;
657
655
  }
658
656
  /**
659
657
  * Check if a key exists.
@@ -778,11 +776,9 @@ var HashMap = class extends IterableEntryBase {
778
776
  return strKey;
779
777
  }
780
778
  };
781
- var LinkedHashMap = class extends IterableEntryBase {
782
- static {
783
- __name(this, "LinkedHashMap");
784
- }
785
- _sentinel;
779
+ __name(_HashMap, "HashMap");
780
+ var HashMap = _HashMap;
781
+ var _LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
786
782
  /**
787
783
  * Create a LinkedHashMap and optionally bulk-insert entries.
788
784
  * @remarks Time O(N), Space O(N)
@@ -792,6 +788,22 @@ var LinkedHashMap = class extends IterableEntryBase {
792
788
  */
793
789
  constructor(entryOrRawElements = [], options) {
794
790
  super();
791
+ __publicField(this, "_sentinel");
792
+ __publicField(this, "_hashFn", /* @__PURE__ */ __name((key) => String(key), "_hashFn"));
793
+ __publicField(this, "_objHashFn", /* @__PURE__ */ __name((key) => key, "_objHashFn"));
794
+ __publicField(this, "_noObjMap", {});
795
+ __publicField(this, "_objMap", /* @__PURE__ */ new WeakMap());
796
+ __publicField(this, "_head");
797
+ __publicField(this, "_tail");
798
+ __publicField(this, "_toEntryFn", /* @__PURE__ */ __name((rawElement) => {
799
+ if (this.isEntry(rawElement)) {
800
+ return rawElement;
801
+ }
802
+ throw new Error(
803
+ "If `entryOrRawElements` does not adhere to [key,value], provide `options.toEntryFn` to transform raw records."
804
+ );
805
+ }, "_toEntryFn"));
806
+ __publicField(this, "_size", 0);
795
807
  this._sentinel = {};
796
808
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
797
809
  if (options) {
@@ -802,11 +814,9 @@ var LinkedHashMap = class extends IterableEntryBase {
802
814
  }
803
815
  if (entryOrRawElements) this.setMany(entryOrRawElements);
804
816
  }
805
- _hashFn = /* @__PURE__ */ __name((key) => String(key), "_hashFn");
806
817
  get hashFn() {
807
818
  return this._hashFn;
808
819
  }
809
- _objHashFn = /* @__PURE__ */ __name((key) => key, "_objHashFn");
810
820
  /**
811
821
  * Get the hash function for object/weak keys.
812
822
  * @remarks Time O(1), Space O(1)
@@ -815,7 +825,6 @@ var LinkedHashMap = class extends IterableEntryBase {
815
825
  get objHashFn() {
816
826
  return this._objHashFn;
817
827
  }
818
- _noObjMap = {};
819
828
  /**
820
829
  * Get the internal record for non-object keys.
821
830
  * @remarks Time O(1), Space O(1)
@@ -824,11 +833,9 @@ var LinkedHashMap = class extends IterableEntryBase {
824
833
  get noObjMap() {
825
834
  return this._noObjMap;
826
835
  }
827
- _objMap = /* @__PURE__ */ new WeakMap();
828
836
  get objMap() {
829
837
  return this._objMap;
830
838
  }
831
- _head;
832
839
  /**
833
840
  * Get the head node (first entry) sentinel link.
834
841
  * @remarks Time O(1), Space O(1)
@@ -837,7 +844,6 @@ var LinkedHashMap = class extends IterableEntryBase {
837
844
  get head() {
838
845
  return this._head;
839
846
  }
840
- _tail;
841
847
  /**
842
848
  * Get the tail node (last entry) sentinel link.
843
849
  * @remarks Time O(1), Space O(1)
@@ -846,18 +852,9 @@ var LinkedHashMap = class extends IterableEntryBase {
846
852
  get tail() {
847
853
  return this._tail;
848
854
  }
849
- _toEntryFn = /* @__PURE__ */ __name((rawElement) => {
850
- if (this.isEntry(rawElement)) {
851
- return rawElement;
852
- }
853
- throw new Error(
854
- "If `entryOrRawElements` does not adhere to [key,value], provide `options.toEntryFn` to transform raw records."
855
- );
856
- }, "_toEntryFn");
857
855
  get toEntryFn() {
858
856
  return this._toEntryFn;
859
857
  }
860
- _size = 0;
861
858
  get size() {
862
859
  return this._size;
863
860
  }
@@ -1100,22 +1097,22 @@ var LinkedHashMap = class extends IterableEntryBase {
1100
1097
  return new Ctor(entries, options);
1101
1098
  }
1102
1099
  };
1100
+ __name(_LinkedHashMap, "LinkedHashMap");
1101
+ var LinkedHashMap = _LinkedHashMap;
1103
1102
 
1104
1103
  // src/data-structures/base/linear-base.ts
1105
- var LinkedListNode = class {
1106
- static {
1107
- __name(this, "LinkedListNode");
1108
- }
1104
+ var _LinkedListNode = class _LinkedListNode {
1109
1105
  /**
1110
1106
  * Initialize a node.
1111
1107
  * @param value - Element value.
1112
1108
  * @remarks Time O(1), Space O(1)
1113
1109
  */
1114
1110
  constructor(value) {
1111
+ __publicField(this, "_value");
1112
+ __publicField(this, "_next");
1115
1113
  this._value = value;
1116
1114
  this._next = void 0;
1117
1115
  }
1118
- _value;
1119
1116
  /**
1120
1117
  * Element payload getter.
1121
1118
  * @returns Element value.
@@ -1132,7 +1129,6 @@ var LinkedListNode = class {
1132
1129
  set value(value) {
1133
1130
  this._value = value;
1134
1131
  }
1135
- _next;
1136
1132
  /**
1137
1133
  * Next node getter.
1138
1134
  * @returns Next node or `undefined`.
@@ -1150,10 +1146,9 @@ var LinkedListNode = class {
1150
1146
  this._next = value;
1151
1147
  }
1152
1148
  };
1153
- var LinearBase = class _LinearBase extends IterableElementBase {
1154
- static {
1155
- __name(this, "LinearBase");
1156
- }
1149
+ __name(_LinkedListNode, "LinkedListNode");
1150
+ var LinkedListNode = _LinkedListNode;
1151
+ var _LinearBase = class _LinearBase extends IterableElementBase {
1157
1152
  /**
1158
1153
  * Construct a linear container with runtime options.
1159
1154
  * @param options - `{ maxLen?, ... }` bounds/behavior options.
@@ -1161,12 +1156,12 @@ var LinearBase = class _LinearBase extends IterableElementBase {
1161
1156
  */
1162
1157
  constructor(options) {
1163
1158
  super(options);
1159
+ __publicField(this, "_maxLen", -1);
1164
1160
  if (options) {
1165
1161
  const { maxLen } = options;
1166
1162
  if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
1167
1163
  }
1168
1164
  }
1169
- _maxLen = -1;
1170
1165
  /**
1171
1166
  * Upper bound for length (if positive), or `-1` when unbounded.
1172
1167
  * @returns Maximum allowed length.
@@ -1299,7 +1294,7 @@ var LinearBase = class _LinearBase extends IterableElementBase {
1299
1294
  return array;
1300
1295
  }
1301
1296
  reduceRight(callbackfn, initialValue) {
1302
- let accumulator = initialValue ?? 0;
1297
+ let accumulator = initialValue != null ? initialValue : 0;
1303
1298
  for (let i = this.length - 1; i >= 0; i--) {
1304
1299
  accumulator = callbackfn(accumulator, this.at(i), i, this);
1305
1300
  }
@@ -1341,10 +1336,9 @@ var LinearBase = class _LinearBase extends IterableElementBase {
1341
1336
  return this;
1342
1337
  }
1343
1338
  };
1344
- var LinearLinkedBase = class extends LinearBase {
1345
- static {
1346
- __name(this, "LinearLinkedBase");
1347
- }
1339
+ __name(_LinearBase, "LinearBase");
1340
+ var LinearBase = _LinearBase;
1341
+ var _LinearLinkedBase = class _LinearLinkedBase extends LinearBase {
1348
1342
  constructor(options) {
1349
1343
  super(options);
1350
1344
  if (options) {
@@ -1474,7 +1468,7 @@ var LinearLinkedBase = class extends LinearBase {
1474
1468
  return removedList;
1475
1469
  }
1476
1470
  reduceRight(callbackfn, initialValue) {
1477
- let accumulator = initialValue ?? 0;
1471
+ let accumulator = initialValue != null ? initialValue : 0;
1478
1472
  let index = this.length - 1;
1479
1473
  for (const item of this._getReverseIterator()) {
1480
1474
  accumulator = callbackfn(accumulator, item, index--, this);
@@ -1482,12 +1476,11 @@ var LinearLinkedBase = class extends LinearBase {
1482
1476
  return accumulator;
1483
1477
  }
1484
1478
  };
1479
+ __name(_LinearLinkedBase, "LinearLinkedBase");
1480
+ var LinearLinkedBase = _LinearLinkedBase;
1485
1481
 
1486
1482
  // src/data-structures/linked-list/singly-linked-list.ts
1487
- var SinglyLinkedListNode = class extends LinkedListNode {
1488
- static {
1489
- __name(this, "SinglyLinkedListNode");
1490
- }
1483
+ var _SinglyLinkedListNode = class _SinglyLinkedListNode extends LinkedListNode {
1491
1484
  /**
1492
1485
  * Create a list node.
1493
1486
  * @remarks Time O(1), Space O(1)
@@ -1496,10 +1489,10 @@ var SinglyLinkedListNode = class extends LinkedListNode {
1496
1489
  */
1497
1490
  constructor(value) {
1498
1491
  super(value);
1492
+ __publicField(this, "_next");
1499
1493
  this._value = value;
1500
1494
  this._next = void 0;
1501
1495
  }
1502
- _next;
1503
1496
  /**
1504
1497
  * Get the next node.
1505
1498
  * @remarks Time O(1), Space O(1)
@@ -1518,11 +1511,9 @@ var SinglyLinkedListNode = class extends LinkedListNode {
1518
1511
  this._next = value;
1519
1512
  }
1520
1513
  };
1521
- var SinglyLinkedList = class extends LinearLinkedBase {
1522
- static {
1523
- __name(this, "SinglyLinkedList");
1524
- }
1525
- _equals = Object.is;
1514
+ __name(_SinglyLinkedListNode, "SinglyLinkedListNode");
1515
+ var SinglyLinkedListNode = _SinglyLinkedListNode;
1516
+ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1526
1517
  /**
1527
1518
  * Create a SinglyLinkedList and optionally bulk-insert elements.
1528
1519
  * @remarks Time O(N), Space O(N)
@@ -1532,9 +1523,12 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1532
1523
  */
1533
1524
  constructor(elements = [], options) {
1534
1525
  super(options);
1526
+ __publicField(this, "_equals", Object.is);
1527
+ __publicField(this, "_head");
1528
+ __publicField(this, "_tail");
1529
+ __publicField(this, "_length", 0);
1535
1530
  this.pushMany(elements);
1536
1531
  }
1537
- _head;
1538
1532
  /**
1539
1533
  * Get the head node.
1540
1534
  * @remarks Time O(1), Space O(1)
@@ -1543,7 +1537,6 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1543
1537
  get head() {
1544
1538
  return this._head;
1545
1539
  }
1546
- _tail;
1547
1540
  /**
1548
1541
  * Get the tail node.
1549
1542
  * @remarks Time O(1), Space O(1)
@@ -1552,7 +1545,6 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1552
1545
  get tail() {
1553
1546
  return this._tail;
1554
1547
  }
1555
- _length = 0;
1556
1548
  /**
1557
1549
  * Get the number of elements.
1558
1550
  * @remarks Time O(1), Space O(1)
@@ -1567,7 +1559,8 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1567
1559
  * @returns First element or undefined.
1568
1560
  */
1569
1561
  get first() {
1570
- return this.head?.value;
1562
+ var _a;
1563
+ return (_a = this.head) == null ? void 0 : _a.value;
1571
1564
  }
1572
1565
  /**
1573
1566
  * Get the last element value.
@@ -1575,7 +1568,8 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1575
1568
  * @returns Last element or undefined.
1576
1569
  */
1577
1570
  get last() {
1578
- return this.tail?.value;
1571
+ var _a;
1572
+ return (_a = this.tail) == null ? void 0 : _a.value;
1579
1573
  }
1580
1574
  /**
1581
1575
  * Create a new list from an iterable of elements.
@@ -2054,7 +2048,7 @@ var SinglyLinkedList = class extends LinearLinkedBase {
2054
2048
  * @returns A new SinglyLinkedList with mapped values.
2055
2049
  */
2056
2050
  map(callback, options, thisArg) {
2057
- const out = this._createLike([], { ...options ?? {}, maxLen: this._maxLen });
2051
+ const out = this._createLike([], { ...options != null ? options : {}, maxLen: this._maxLen });
2058
2052
  let index = 0;
2059
2053
  for (const value of this) out.push(callback.call(thisArg, value, index++, this));
2060
2054
  return out;
@@ -2065,7 +2059,7 @@ var SinglyLinkedList = class extends LinearLinkedBase {
2065
2059
  * @param value - Value to wrap in a node.
2066
2060
  * @returns A new SinglyLinkedListNode instance.
2067
2061
  */
2068
- _createNode(value) {
2062
+ createNode(value) {
2069
2063
  return new SinglyLinkedListNode(value);
2070
2064
  }
2071
2065
  /**
@@ -2085,7 +2079,7 @@ var SinglyLinkedList = class extends LinearLinkedBase {
2085
2079
  */
2086
2080
  _ensureNode(elementOrNode) {
2087
2081
  if (this.isNode(elementOrNode)) return elementOrNode;
2088
- return this._createNode(elementOrNode);
2082
+ return this.createNode(elementOrNode);
2089
2083
  }
2090
2084
  /**
2091
2085
  * (Protected) Normalize input into a node predicate.
@@ -2179,6 +2173,8 @@ var SinglyLinkedList = class extends LinearLinkedBase {
2179
2173
  return this._createLike([], options);
2180
2174
  }
2181
2175
  };
2176
+ __name(_SinglyLinkedList, "SinglyLinkedList");
2177
+ var SinglyLinkedList = _SinglyLinkedList;
2182
2178
  function elementOrPredicate(input, equals) {
2183
2179
  if (input instanceof SinglyLinkedListNode) return (node) => node === input;
2184
2180
  if (typeof input === "function") return input;
@@ -2188,10 +2184,7 @@ function elementOrPredicate(input, equals) {
2188
2184
  __name(elementOrPredicate, "elementOrPredicate");
2189
2185
 
2190
2186
  // src/data-structures/linked-list/doubly-linked-list.ts
2191
- var DoublyLinkedListNode = class extends LinkedListNode {
2192
- static {
2193
- __name(this, "DoublyLinkedListNode");
2194
- }
2187
+ var _DoublyLinkedListNode = class _DoublyLinkedListNode extends LinkedListNode {
2195
2188
  /**
2196
2189
  * Create a node.
2197
2190
  * @remarks Time O(1), Space O(1)
@@ -2200,11 +2193,12 @@ var DoublyLinkedListNode = class extends LinkedListNode {
2200
2193
  */
2201
2194
  constructor(value) {
2202
2195
  super(value);
2196
+ __publicField(this, "_next");
2197
+ __publicField(this, "_prev");
2203
2198
  this._value = value;
2204
2199
  this._next = void 0;
2205
2200
  this._prev = void 0;
2206
2201
  }
2207
- _next;
2208
2202
  /**
2209
2203
  * Get the next node link.
2210
2204
  * @remarks Time O(1), Space O(1)
@@ -2222,7 +2216,6 @@ var DoublyLinkedListNode = class extends LinkedListNode {
2222
2216
  set next(value) {
2223
2217
  this._next = value;
2224
2218
  }
2225
- _prev;
2226
2219
  /**
2227
2220
  * Get the previous node link.
2228
2221
  * @remarks Time O(1), Space O(1)
@@ -2241,11 +2234,9 @@ var DoublyLinkedListNode = class extends LinkedListNode {
2241
2234
  this._prev = value;
2242
2235
  }
2243
2236
  };
2244
- var DoublyLinkedList = class extends LinearLinkedBase {
2245
- static {
2246
- __name(this, "DoublyLinkedList");
2247
- }
2248
- _equals = Object.is;
2237
+ __name(_DoublyLinkedListNode, "DoublyLinkedListNode");
2238
+ var DoublyLinkedListNode = _DoublyLinkedListNode;
2239
+ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2249
2240
  /**
2250
2241
  * Create a DoublyLinkedList and optionally bulk-insert elements.
2251
2242
  * @remarks Time O(N), Space O(N)
@@ -2255,15 +2246,18 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2255
2246
  */
2256
2247
  constructor(elements = [], options) {
2257
2248
  super(options);
2249
+ __publicField(this, "_equals", Object.is);
2250
+ __publicField(this, "_head");
2251
+ __publicField(this, "_tail");
2252
+ __publicField(this, "_length", 0);
2258
2253
  this._head = void 0;
2259
2254
  this._tail = void 0;
2260
2255
  this._length = 0;
2261
- if (options?.maxLen && Number.isInteger(options.maxLen) && options.maxLen > 0) {
2256
+ if ((options == null ? void 0 : options.maxLen) && Number.isInteger(options.maxLen) && options.maxLen > 0) {
2262
2257
  this._maxLen = options.maxLen;
2263
2258
  }
2264
2259
  this.pushMany(elements);
2265
2260
  }
2266
- _head;
2267
2261
  /**
2268
2262
  * Get the head node.
2269
2263
  * @remarks Time O(1), Space O(1)
@@ -2272,7 +2266,6 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2272
2266
  get head() {
2273
2267
  return this._head;
2274
2268
  }
2275
- _tail;
2276
2269
  /**
2277
2270
  * Get the tail node.
2278
2271
  * @remarks Time O(1), Space O(1)
@@ -2281,7 +2274,6 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2281
2274
  get tail() {
2282
2275
  return this._tail;
2283
2276
  }
2284
- _length = 0;
2285
2277
  /**
2286
2278
  * Get the number of elements.
2287
2279
  * @remarks Time O(1), Space O(1)
@@ -2296,7 +2288,8 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2296
2288
  * @returns First element or undefined.
2297
2289
  */
2298
2290
  get first() {
2299
- return this.head?.value;
2291
+ var _a;
2292
+ return (_a = this.head) == null ? void 0 : _a.value;
2300
2293
  }
2301
2294
  /**
2302
2295
  * Get the last element value.
@@ -2304,7 +2297,8 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2304
2297
  * @returns Last element or undefined.
2305
2298
  */
2306
2299
  get last() {
2307
- return this.tail?.value;
2300
+ var _a;
2301
+ return (_a = this.tail) == null ? void 0 : _a.value;
2308
2302
  }
2309
2303
  /**
2310
2304
  * Create a new list from an array of elements.
@@ -2719,7 +2713,7 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2719
2713
  * @returns A new DoublyLinkedList with mapped values.
2720
2714
  */
2721
2715
  map(callback, options, thisArg) {
2722
- const out = this._createLike([], { ...options ?? {}, maxLen: this._maxLen });
2716
+ const out = this._createLike([], { ...options != null ? options : {}, maxLen: this._maxLen });
2723
2717
  let index = 0;
2724
2718
  for (const v of this) out.push(callback.call(thisArg, v, index++, this));
2725
2719
  return out;
@@ -2805,26 +2799,28 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2805
2799
  }
2806
2800
  }
2807
2801
  };
2802
+ __name(_DoublyLinkedList, "DoublyLinkedList");
2803
+ var DoublyLinkedList = _DoublyLinkedList;
2808
2804
 
2809
2805
  // src/data-structures/linked-list/skip-linked-list.ts
2810
- var SkipListNode = class {
2811
- static {
2812
- __name(this, "SkipListNode");
2813
- }
2814
- key;
2815
- value;
2816
- forward;
2806
+ var _SkipListNode = class _SkipListNode {
2817
2807
  constructor(key, value, level) {
2808
+ __publicField(this, "key");
2809
+ __publicField(this, "value");
2810
+ __publicField(this, "forward");
2818
2811
  this.key = key;
2819
2812
  this.value = value;
2820
2813
  this.forward = new Array(level);
2821
2814
  }
2822
2815
  };
2823
- var SkipList = class {
2824
- static {
2825
- __name(this, "SkipList");
2826
- }
2816
+ __name(_SkipListNode, "SkipListNode");
2817
+ var SkipListNode = _SkipListNode;
2818
+ var _SkipList = class _SkipList {
2827
2819
  constructor(elements = [], options) {
2820
+ __publicField(this, "_head", new SkipListNode(void 0, void 0, this.maxLevel));
2821
+ __publicField(this, "_level", 0);
2822
+ __publicField(this, "_maxLevel", 16);
2823
+ __publicField(this, "_probability", 0.5);
2828
2824
  if (options) {
2829
2825
  const { maxLevel, probability } = options;
2830
2826
  if (typeof maxLevel === "number") this._maxLevel = maxLevel;
@@ -2834,19 +2830,15 @@ var SkipList = class {
2834
2830
  for (const [key, value] of elements) this.add(key, value);
2835
2831
  }
2836
2832
  }
2837
- _head = new SkipListNode(void 0, void 0, this.maxLevel);
2838
2833
  get head() {
2839
2834
  return this._head;
2840
2835
  }
2841
- _level = 0;
2842
2836
  get level() {
2843
2837
  return this._level;
2844
2838
  }
2845
- _maxLevel = 16;
2846
2839
  get maxLevel() {
2847
2840
  return this._maxLevel;
2848
2841
  }
2849
- _probability = 0.5;
2850
2842
  get probability() {
2851
2843
  return this._probability;
2852
2844
  }
@@ -2952,13 +2944,11 @@ var SkipList = class {
2952
2944
  return level;
2953
2945
  }
2954
2946
  };
2947
+ __name(_SkipList, "SkipList");
2948
+ var SkipList = _SkipList;
2955
2949
 
2956
2950
  // src/data-structures/stack/stack.ts
2957
- var Stack = class extends IterableElementBase {
2958
- static {
2959
- __name(this, "Stack");
2960
- }
2961
- _equals = Object.is;
2951
+ var _Stack = class _Stack extends IterableElementBase {
2962
2952
  /**
2963
2953
  * Create a Stack and optionally bulk-push elements.
2964
2954
  * @remarks Time O(N), Space O(N)
@@ -2968,9 +2958,10 @@ var Stack = class extends IterableElementBase {
2968
2958
  */
2969
2959
  constructor(elements = [], options) {
2970
2960
  super(options);
2961
+ __publicField(this, "_equals", Object.is);
2962
+ __publicField(this, "_elements", []);
2971
2963
  this.pushMany(elements);
2972
2964
  }
2973
- _elements = [];
2974
2965
  /**
2975
2966
  * Get the backing array of elements.
2976
2967
  * @remarks Time O(1), Space O(1)
@@ -3145,7 +3136,7 @@ var Stack = class extends IterableElementBase {
3145
3136
  * @returns A new Stack with mapped elements.
3146
3137
  */
3147
3138
  map(callback, options, thisArg) {
3148
- const out = this._createLike([], { ...options ?? {} });
3139
+ const out = this._createLike([], { ...options != null ? options : {} });
3149
3140
  let index = 0;
3150
3141
  for (const v of this) {
3151
3142
  out.push(thisArg === void 0 ? callback(v, index, this) : callback.call(thisArg, v, index, this));
@@ -3205,12 +3196,11 @@ var Stack = class extends IterableElementBase {
3205
3196
  for (let i = 0; i < this.elements.length; i++) yield this.elements[i];
3206
3197
  }
3207
3198
  };
3199
+ __name(_Stack, "Stack");
3200
+ var Stack = _Stack;
3208
3201
 
3209
3202
  // src/data-structures/queue/queue.ts
3210
- var Queue = class _Queue extends LinearBase {
3211
- static {
3212
- __name(this, "Queue");
3213
- }
3203
+ var _Queue = class _Queue extends LinearBase {
3214
3204
  /**
3215
3205
  * Create a Queue and optionally bulk-insert elements.
3216
3206
  * @remarks Time O(N), Space O(N)
@@ -3220,13 +3210,15 @@ var Queue = class _Queue extends LinearBase {
3220
3210
  */
3221
3211
  constructor(elements = [], options) {
3222
3212
  super(options);
3213
+ __publicField(this, "_elements", []);
3214
+ __publicField(this, "_offset", 0);
3215
+ __publicField(this, "_autoCompactRatio", 0.5);
3223
3216
  if (options) {
3224
3217
  const { autoCompactRatio = 0.5 } = options;
3225
3218
  this._autoCompactRatio = autoCompactRatio;
3226
3219
  }
3227
3220
  this.pushMany(elements);
3228
3221
  }
3229
- _elements = [];
3230
3222
  /**
3231
3223
  * Get the underlying array buffer.
3232
3224
  * @remarks Time O(1), Space O(1)
@@ -3235,7 +3227,6 @@ var Queue = class _Queue extends LinearBase {
3235
3227
  get elements() {
3236
3228
  return this._elements;
3237
3229
  }
3238
- _offset = 0;
3239
3230
  /**
3240
3231
  * Get the current start offset into the array.
3241
3232
  * @remarks Time O(1), Space O(1)
@@ -3244,7 +3235,6 @@ var Queue = class _Queue extends LinearBase {
3244
3235
  get offset() {
3245
3236
  return this._offset;
3246
3237
  }
3247
- _autoCompactRatio = 0.5;
3248
3238
  /**
3249
3239
  * Get the compaction threshold (offset/size).
3250
3240
  * @remarks Time O(1), Space O(1)
@@ -3489,10 +3479,11 @@ var Queue = class _Queue extends LinearBase {
3489
3479
  * @returns A new Queue with mapped elements.
3490
3480
  */
3491
3481
  map(callback, options, thisArg) {
3482
+ var _a, _b;
3492
3483
  const out = new this.constructor([], {
3493
- toElementFn: options?.toElementFn,
3494
- maxLen: options?.maxLen ?? this._maxLen,
3495
- autoCompactRatio: options?.autoCompactRatio ?? this._autoCompactRatio
3484
+ toElementFn: options == null ? void 0 : options.toElementFn,
3485
+ maxLen: (_a = options == null ? void 0 : options.maxLen) != null ? _a : this._maxLen,
3486
+ autoCompactRatio: (_b = options == null ? void 0 : options.autoCompactRatio) != null ? _b : this._autoCompactRatio
3496
3487
  });
3497
3488
  let index = 0;
3498
3489
  for (const v of this)
@@ -3507,13 +3498,14 @@ var Queue = class _Queue extends LinearBase {
3507
3498
  * @returns A new queue with mapped elements (same element type).
3508
3499
  */
3509
3500
  mapSame(callback, thisArg) {
3501
+ var _a;
3510
3502
  const Ctor = this.constructor;
3511
3503
  const out = new Ctor([], {
3512
3504
  toElementFn: this.toElementFn,
3513
3505
  maxLen: this._maxLen,
3514
3506
  autoCompactRatio: this._autoCompactRatio
3515
3507
  });
3516
- out._setAutoCompactRatio?.(this._autoCompactRatio);
3508
+ (_a = out._setAutoCompactRatio) == null ? void 0 : _a.call(out, this._autoCompactRatio);
3517
3509
  let index = 0;
3518
3510
  for (const v of this) {
3519
3511
  const mv = thisArg === void 0 ? callback(v, index++, this) : callback.call(thisArg, v, index++, this);
@@ -3573,10 +3565,9 @@ var Queue = class _Queue extends LinearBase {
3573
3565
  return new Ctor(elements, options);
3574
3566
  }
3575
3567
  };
3576
- var LinkedListQueue = class extends SinglyLinkedList {
3577
- static {
3578
- __name(this, "LinkedListQueue");
3579
- }
3568
+ __name(_Queue, "Queue");
3569
+ var Queue = _Queue;
3570
+ var _LinkedListQueue = class _LinkedListQueue extends SinglyLinkedList {
3580
3571
  /**
3581
3572
  * Deep clone this linked-list-based queue.
3582
3573
  * @remarks Time O(N), Space O(N)
@@ -3588,13 +3579,11 @@ var LinkedListQueue = class extends SinglyLinkedList {
3588
3579
  return out;
3589
3580
  }
3590
3581
  };
3582
+ __name(_LinkedListQueue, "LinkedListQueue");
3583
+ var LinkedListQueue = _LinkedListQueue;
3591
3584
 
3592
3585
  // src/data-structures/queue/deque.ts
3593
- var Deque = class extends LinearBase {
3594
- static {
3595
- __name(this, "Deque");
3596
- }
3597
- _equals = Object.is;
3586
+ var _Deque = class _Deque extends LinearBase {
3598
3587
  /**
3599
3588
  * Create a Deque and optionally bulk-insert elements.
3600
3589
  * @remarks Time O(N), Space O(N)
@@ -3604,6 +3593,15 @@ var Deque = class extends LinearBase {
3604
3593
  */
3605
3594
  constructor(elements = [], options) {
3606
3595
  super(options);
3596
+ __publicField(this, "_equals", Object.is);
3597
+ __publicField(this, "_bucketSize", 1 << 12);
3598
+ __publicField(this, "_bucketFirst", 0);
3599
+ __publicField(this, "_firstInBucket", 0);
3600
+ __publicField(this, "_bucketLast", 0);
3601
+ __publicField(this, "_lastInBucket", 0);
3602
+ __publicField(this, "_bucketCount", 0);
3603
+ __publicField(this, "_buckets", []);
3604
+ __publicField(this, "_length", 0);
3607
3605
  if (options) {
3608
3606
  const { bucketSize } = options;
3609
3607
  if (typeof bucketSize === "number") this._bucketSize = bucketSize;
@@ -3623,7 +3621,6 @@ var Deque = class extends LinearBase {
3623
3621
  this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
3624
3622
  this.pushMany(elements);
3625
3623
  }
3626
- _bucketSize = 1 << 12;
3627
3624
  /**
3628
3625
  * Get the current bucket size.
3629
3626
  * @remarks Time O(1), Space O(1)
@@ -3632,7 +3629,6 @@ var Deque = class extends LinearBase {
3632
3629
  get bucketSize() {
3633
3630
  return this._bucketSize;
3634
3631
  }
3635
- _bucketFirst = 0;
3636
3632
  /**
3637
3633
  * Get the index of the first bucket in use.
3638
3634
  * @remarks Time O(1), Space O(1)
@@ -3641,7 +3637,6 @@ var Deque = class extends LinearBase {
3641
3637
  get bucketFirst() {
3642
3638
  return this._bucketFirst;
3643
3639
  }
3644
- _firstInBucket = 0;
3645
3640
  /**
3646
3641
  * Get the index inside the first bucket.
3647
3642
  * @remarks Time O(1), Space O(1)
@@ -3650,7 +3645,6 @@ var Deque = class extends LinearBase {
3650
3645
  get firstInBucket() {
3651
3646
  return this._firstInBucket;
3652
3647
  }
3653
- _bucketLast = 0;
3654
3648
  /**
3655
3649
  * Get the index of the last bucket in use.
3656
3650
  * @remarks Time O(1), Space O(1)
@@ -3659,7 +3653,6 @@ var Deque = class extends LinearBase {
3659
3653
  get bucketLast() {
3660
3654
  return this._bucketLast;
3661
3655
  }
3662
- _lastInBucket = 0;
3663
3656
  /**
3664
3657
  * Get the index inside the last bucket.
3665
3658
  * @remarks Time O(1), Space O(1)
@@ -3668,7 +3661,6 @@ var Deque = class extends LinearBase {
3668
3661
  get lastInBucket() {
3669
3662
  return this._lastInBucket;
3670
3663
  }
3671
- _bucketCount = 0;
3672
3664
  /**
3673
3665
  * Get the number of buckets allocated.
3674
3666
  * @remarks Time O(1), Space O(1)
@@ -3677,7 +3669,6 @@ var Deque = class extends LinearBase {
3677
3669
  get bucketCount() {
3678
3670
  return this._bucketCount;
3679
3671
  }
3680
- _buckets = [];
3681
3672
  /**
3682
3673
  * Get the internal buckets array.
3683
3674
  * @remarks Time O(1), Space O(1)
@@ -3686,7 +3677,6 @@ var Deque = class extends LinearBase {
3686
3677
  get buckets() {
3687
3678
  return this._buckets;
3688
3679
  }
3689
- _length = 0;
3690
3680
  /**
3691
3681
  * Get the number of elements in the deque.
3692
3682
  * @remarks Time O(1), Space O(1)
@@ -4202,7 +4192,7 @@ var Deque = class extends LinearBase {
4202
4192
  */
4203
4193
  map(callback, options, thisArg) {
4204
4194
  const out = this._createLike([], {
4205
- ...options ?? {},
4195
+ ...options != null ? options : {},
4206
4196
  bucketSize: this._bucketSize,
4207
4197
  maxLen: this._maxLen
4208
4198
  });
@@ -4316,13 +4306,11 @@ var Deque = class extends LinearBase {
4316
4306
  }
4317
4307
  }
4318
4308
  };
4309
+ __name(_Deque, "Deque");
4310
+ var Deque = _Deque;
4319
4311
 
4320
4312
  // src/data-structures/heap/heap.ts
4321
- var Heap = class _Heap extends IterableElementBase {
4322
- static {
4323
- __name(this, "Heap");
4324
- }
4325
- _equals = Object.is;
4313
+ var _Heap = class _Heap extends IterableElementBase {
4326
4314
  /**
4327
4315
  * Create a Heap and optionally bulk-insert elements.
4328
4316
  * @remarks Time O(N), Space O(N)
@@ -4332,13 +4320,23 @@ var Heap = class _Heap extends IterableElementBase {
4332
4320
  */
4333
4321
  constructor(elements = [], options) {
4334
4322
  super(options);
4323
+ __publicField(this, "_equals", Object.is);
4324
+ __publicField(this, "_elements", []);
4325
+ __publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
4326
+ if (typeof a === "object" || typeof b === "object") {
4327
+ throw TypeError("When comparing object types, define a custom comparator in options.");
4328
+ }
4329
+ if (a > b) return 1;
4330
+ if (a < b) return -1;
4331
+ return 0;
4332
+ }, "_DEFAULT_COMPARATOR"));
4333
+ __publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
4335
4334
  if (options) {
4336
4335
  const { comparator } = options;
4337
4336
  if (comparator) this._comparator = comparator;
4338
4337
  }
4339
4338
  this.addMany(elements);
4340
4339
  }
4341
- _elements = [];
4342
4340
  /**
4343
4341
  * Get the backing array of the heap.
4344
4342
  * @remarks Time O(1), Space O(1)
@@ -4361,7 +4359,8 @@ var Heap = class _Heap extends IterableElementBase {
4361
4359
  * @returns Last element or undefined.
4362
4360
  */
4363
4361
  get leaf() {
4364
- return this.elements[this.size - 1] ?? void 0;
4362
+ var _a;
4363
+ return (_a = this.elements[this.size - 1]) != null ? _a : void 0;
4365
4364
  }
4366
4365
  /**
4367
4366
  * Create a heap of the same class from an iterable.
@@ -4634,7 +4633,7 @@ var Heap = class _Heap extends IterableElementBase {
4634
4633
  * @returns A new heap with mapped elements.
4635
4634
  */
4636
4635
  map(callback, options, thisArg) {
4637
- const { comparator, toElementFn, ...rest } = options ?? {};
4636
+ const { comparator, toElementFn, ...rest } = options != null ? options : {};
4638
4637
  if (!comparator) throw new TypeError("Heap.map requires options.comparator for EM");
4639
4638
  const out = this._createLike([], { ...rest, comparator, toElementFn });
4640
4639
  let i = 0;
@@ -4660,15 +4659,6 @@ var Heap = class _Heap extends IterableElementBase {
4660
4659
  }
4661
4660
  return out;
4662
4661
  }
4663
- _DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
4664
- if (typeof a === "object" || typeof b === "object") {
4665
- throw TypeError("When comparing object types, define a custom comparator in options.");
4666
- }
4667
- if (a > b) return 1;
4668
- if (a < b) return -1;
4669
- return 0;
4670
- }, "_DEFAULT_COMPARATOR");
4671
- _comparator = this._DEFAULT_COMPARATOR;
4672
4662
  /**
4673
4663
  * Get the comparator used to order elements.
4674
4664
  * @remarks Time O(1), Space O(1)
@@ -4722,7 +4712,7 @@ var Heap = class _Heap extends IterableElementBase {
4722
4712
  */
4723
4713
  _createInstance(options) {
4724
4714
  const Ctor = this.constructor;
4725
- const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options ?? {} });
4715
+ const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
4726
4716
  return next;
4727
4717
  }
4728
4718
  /**
@@ -4750,27 +4740,25 @@ var Heap = class _Heap extends IterableElementBase {
4750
4740
  return this._createLike([], options);
4751
4741
  }
4752
4742
  };
4753
- var FibonacciHeapNode = class {
4754
- static {
4755
- __name(this, "FibonacciHeapNode");
4756
- }
4757
- element;
4758
- degree;
4759
- left;
4760
- right;
4761
- child;
4762
- parent;
4763
- marked;
4743
+ __name(_Heap, "Heap");
4744
+ var Heap = _Heap;
4745
+ var _FibonacciHeapNode = class _FibonacciHeapNode {
4764
4746
  constructor(element, degree = 0) {
4747
+ __publicField(this, "element");
4748
+ __publicField(this, "degree");
4749
+ __publicField(this, "left");
4750
+ __publicField(this, "right");
4751
+ __publicField(this, "child");
4752
+ __publicField(this, "parent");
4753
+ __publicField(this, "marked");
4765
4754
  this.element = element;
4766
4755
  this.degree = degree;
4767
4756
  this.marked = false;
4768
4757
  }
4769
4758
  };
4770
- var FibonacciHeap = class {
4771
- static {
4772
- __name(this, "FibonacciHeap");
4773
- }
4759
+ __name(_FibonacciHeapNode, "FibonacciHeapNode");
4760
+ var FibonacciHeapNode = _FibonacciHeapNode;
4761
+ var _FibonacciHeap = class _FibonacciHeap {
4774
4762
  /**
4775
4763
  * Create a FibonacciHeap.
4776
4764
  * @remarks Time O(1), Space O(1)
@@ -4778,11 +4766,14 @@ var FibonacciHeap = class {
4778
4766
  * @returns New FibonacciHeap instance.
4779
4767
  */
4780
4768
  constructor(comparator) {
4769
+ __publicField(this, "_root");
4770
+ __publicField(this, "_size", 0);
4771
+ __publicField(this, "_min");
4772
+ __publicField(this, "_comparator");
4781
4773
  this.clear();
4782
4774
  this._comparator = comparator || this._defaultComparator;
4783
4775
  if (typeof this.comparator !== "function") throw new Error("FibonacciHeap: comparator must be a function.");
4784
4776
  }
4785
- _root;
4786
4777
  /**
4787
4778
  * Get the circular root list head.
4788
4779
  * @remarks Time O(1), Space O(1)
@@ -4791,11 +4782,9 @@ var FibonacciHeap = class {
4791
4782
  get root() {
4792
4783
  return this._root;
4793
4784
  }
4794
- _size = 0;
4795
4785
  get size() {
4796
4786
  return this._size;
4797
4787
  }
4798
- _min;
4799
4788
  /**
4800
4789
  * Get the current minimum node.
4801
4790
  * @remarks Time O(1), Space O(1)
@@ -4804,7 +4793,6 @@ var FibonacciHeap = class {
4804
4793
  get min() {
4805
4794
  return this._min;
4806
4795
  }
4807
- _comparator;
4808
4796
  get comparator() {
4809
4797
  return this._comparator;
4810
4798
  }
@@ -4824,7 +4812,7 @@ var FibonacciHeap = class {
4824
4812
  * @returns This heap.
4825
4813
  */
4826
4814
  push(element) {
4827
- const node = this._createNode(element);
4815
+ const node = this.createNode(element);
4828
4816
  node.left = node;
4829
4817
  node.right = node;
4830
4818
  this.mergeWithRoot(node);
@@ -4923,7 +4911,7 @@ var FibonacciHeap = class {
4923
4911
  this._size += heapToMerge.size;
4924
4912
  heapToMerge.clear();
4925
4913
  }
4926
- _createNode(element) {
4914
+ createNode(element) {
4927
4915
  return new FibonacciHeapNode(element);
4928
4916
  }
4929
4917
  isEmpty() {
@@ -4981,12 +4969,11 @@ var FibonacciHeap = class {
4981
4969
  }
4982
4970
  }
4983
4971
  };
4972
+ __name(_FibonacciHeap, "FibonacciHeap");
4973
+ var FibonacciHeap = _FibonacciHeap;
4984
4974
 
4985
4975
  // src/data-structures/heap/max-heap.ts
4986
- var MaxHeap = class extends Heap {
4987
- static {
4988
- __name(this, "MaxHeap");
4989
- }
4976
+ var _MaxHeap = class _MaxHeap extends Heap {
4990
4977
  /**
4991
4978
  * Create a max-heap. For objects, supply a custom comparator.
4992
4979
  * @param elements Optional initial elements.
@@ -5008,12 +4995,11 @@ var MaxHeap = class extends Heap {
5008
4995
  });
5009
4996
  }
5010
4997
  };
4998
+ __name(_MaxHeap, "MaxHeap");
4999
+ var MaxHeap = _MaxHeap;
5011
5000
 
5012
5001
  // src/data-structures/heap/min-heap.ts
5013
- var MinHeap = class extends Heap {
5014
- static {
5015
- __name(this, "MinHeap");
5016
- }
5002
+ var _MinHeap = class _MinHeap extends Heap {
5017
5003
  /**
5018
5004
  * Create a min-heap.
5019
5005
  * @param elements Optional initial elements.
@@ -5023,39 +5009,36 @@ var MinHeap = class extends Heap {
5023
5009
  super(elements, options);
5024
5010
  }
5025
5011
  };
5012
+ __name(_MinHeap, "MinHeap");
5013
+ var MinHeap = _MinHeap;
5026
5014
 
5027
5015
  // src/data-structures/graph/abstract-graph.ts
5028
- var AbstractVertex = class {
5029
- static {
5030
- __name(this, "AbstractVertex");
5031
- }
5032
- key;
5033
- value;
5016
+ var _AbstractVertex = class _AbstractVertex {
5034
5017
  constructor(key, value) {
5018
+ __publicField(this, "key");
5019
+ __publicField(this, "value");
5035
5020
  this.key = key;
5036
5021
  this.value = value;
5037
5022
  }
5038
5023
  };
5039
- var AbstractEdge = class {
5040
- static {
5041
- __name(this, "AbstractEdge");
5042
- }
5043
- value;
5044
- weight;
5024
+ __name(_AbstractVertex, "AbstractVertex");
5025
+ var AbstractVertex = _AbstractVertex;
5026
+ var _AbstractEdge = class _AbstractEdge {
5045
5027
  constructor(weight, value) {
5028
+ __publicField(this, "value");
5029
+ __publicField(this, "weight");
5030
+ __publicField(this, "_hashCode");
5046
5031
  this.weight = weight !== void 0 ? weight : 1;
5047
5032
  this.value = value;
5048
5033
  this._hashCode = uuidV4();
5049
5034
  }
5050
- _hashCode;
5051
5035
  get hashCode() {
5052
5036
  return this._hashCode;
5053
5037
  }
5054
5038
  };
5055
- var AbstractGraph = class extends IterableEntryBase {
5056
- static {
5057
- __name(this, "AbstractGraph");
5058
- }
5039
+ __name(_AbstractEdge, "AbstractEdge");
5040
+ var AbstractEdge = _AbstractEdge;
5041
+ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
5059
5042
  /**
5060
5043
  * Construct a graph with runtime defaults.
5061
5044
  * @param options - `GraphOptions<V>` in `options.graph` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
@@ -5063,14 +5046,14 @@ var AbstractGraph = class extends IterableEntryBase {
5063
5046
  */
5064
5047
  constructor(options) {
5065
5048
  super();
5066
- const graph = options?.graph;
5067
- this._options = { defaultEdgeWeight: 1, ...graph ?? {} };
5049
+ __publicField(this, "_options", { defaultEdgeWeight: 1 });
5050
+ __publicField(this, "_vertexMap", /* @__PURE__ */ new Map());
5051
+ const graph = options == null ? void 0 : options.graph;
5052
+ this._options = { defaultEdgeWeight: 1, ...graph != null ? graph : {} };
5068
5053
  }
5069
- _options = { defaultEdgeWeight: 1 };
5070
5054
  get options() {
5071
5055
  return this._options;
5072
5056
  }
5073
- _vertexMap = /* @__PURE__ */ new Map();
5074
5057
  get vertexMap() {
5075
5058
  return this._vertexMap;
5076
5059
  }
@@ -5228,9 +5211,10 @@ var AbstractGraph = class extends IterableEntryBase {
5228
5211
  * @remarks Time O(L), Space O(1) where L is path length
5229
5212
  */
5230
5213
  getPathSumWeight(path) {
5214
+ var _a;
5231
5215
  let sum = 0;
5232
5216
  for (let i = 0; i < path.length; i++) {
5233
- sum += this.getEdge(path[i], path[i + 1])?.weight || 0;
5217
+ sum += ((_a = this.getEdge(path[i], path[i + 1])) == null ? void 0 : _a.weight) || 0;
5234
5218
  }
5235
5219
  return sum;
5236
5220
  }
@@ -5292,6 +5276,7 @@ var AbstractGraph = class extends IterableEntryBase {
5292
5276
  * @remarks Time O((V + E) log V) weighted / O(V + E) unweighted, Space O(V + E)
5293
5277
  */
5294
5278
  getMinPathBetween(v1, v2, isWeight, isDFS = false) {
5279
+ var _a, _b;
5295
5280
  if (isWeight === void 0) isWeight = false;
5296
5281
  if (isWeight) {
5297
5282
  if (isDFS) {
@@ -5309,7 +5294,7 @@ var AbstractGraph = class extends IterableEntryBase {
5309
5294
  }
5310
5295
  return allPaths[minIndex] || void 0;
5311
5296
  } else {
5312
- return this.dijkstra(v1, v2, true, true)?.minPath ?? [];
5297
+ return (_b = (_a = this.dijkstra(v1, v2, true, true)) == null ? void 0 : _a.minPath) != null ? _b : [];
5313
5298
  }
5314
5299
  } else {
5315
5300
  let minPath = [];
@@ -5438,6 +5423,7 @@ var AbstractGraph = class extends IterableEntryBase {
5438
5423
  return { distMap, preMap, seen, paths, minDist, minPath };
5439
5424
  }
5440
5425
  dijkstra(src, dest = void 0, getMinDist = false, genPaths = false) {
5426
+ var _a;
5441
5427
  let minDist = Number.MAX_SAFE_INTEGER;
5442
5428
  let minDest = void 0;
5443
5429
  let minPath = [];
@@ -5475,8 +5461,8 @@ var AbstractGraph = class extends IterableEntryBase {
5475
5461
  }, "getPaths");
5476
5462
  while (heap.size > 0) {
5477
5463
  const curHeapNode = heap.poll();
5478
- const dist = curHeapNode?.key;
5479
- const cur = curHeapNode?.value;
5464
+ const dist = curHeapNode == null ? void 0 : curHeapNode.key;
5465
+ const cur = curHeapNode == null ? void 0 : curHeapNode.value;
5480
5466
  if (dist !== void 0) {
5481
5467
  if (cur) {
5482
5468
  seen.add(cur);
@@ -5492,7 +5478,7 @@ var AbstractGraph = class extends IterableEntryBase {
5492
5478
  const neighbors = this.getNeighbors(cur);
5493
5479
  for (const neighbor of neighbors) {
5494
5480
  if (!seen.has(neighbor)) {
5495
- const weight = this.getEdge(cur, neighbor)?.weight;
5481
+ const weight = (_a = this.getEdge(cur, neighbor)) == null ? void 0 : _a.weight;
5496
5482
  if (typeof weight === "number") {
5497
5483
  const distSrcToNeighbor = distMap.get(neighbor);
5498
5484
  if (distSrcToNeighbor !== void 0) {
@@ -5615,6 +5601,7 @@ var AbstractGraph = class extends IterableEntryBase {
5615
5601
  * @remarks Time O(V^3), Space O(V^2)
5616
5602
  */
5617
5603
  floydWarshall() {
5604
+ var _a;
5618
5605
  const idAndVertices = [...this._vertexMap];
5619
5606
  const n = idAndVertices.length;
5620
5607
  const costs = [];
@@ -5628,7 +5615,7 @@ var AbstractGraph = class extends IterableEntryBase {
5628
5615
  }
5629
5616
  for (let i = 0; i < n; i++) {
5630
5617
  for (let j = 0; j < n; j++) {
5631
- costs[i][j] = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])?.weight || Number.MAX_SAFE_INTEGER;
5618
+ costs[i][j] = ((_a = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])) == null ? void 0 : _a.weight) || Number.MAX_SAFE_INTEGER;
5632
5619
  }
5633
5620
  }
5634
5621
  for (let k = 0; k < n; k++) {
@@ -5771,7 +5758,7 @@ var AbstractGraph = class extends IterableEntryBase {
5771
5758
  _createInstance(_options) {
5772
5759
  const Ctor = this.constructor;
5773
5760
  const instance = new Ctor();
5774
- const graph = _options?.graph;
5761
+ const graph = _options == null ? void 0 : _options.graph;
5775
5762
  if (graph) instance._options = { ...instance._options, ...graph };
5776
5763
  else instance._options = { ...instance._options, ...this._options };
5777
5764
  return instance;
@@ -5850,32 +5837,29 @@ var AbstractGraph = class extends IterableEntryBase {
5850
5837
  return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
5851
5838
  }
5852
5839
  };
5840
+ __name(_AbstractGraph, "AbstractGraph");
5841
+ var AbstractGraph = _AbstractGraph;
5853
5842
 
5854
5843
  // src/data-structures/graph/directed-graph.ts
5855
- var DirectedVertex = class extends AbstractVertex {
5856
- static {
5857
- __name(this, "DirectedVertex");
5858
- }
5844
+ var _DirectedVertex = class _DirectedVertex extends AbstractVertex {
5859
5845
  constructor(key, value) {
5860
5846
  super(key, value);
5861
5847
  }
5862
5848
  };
5863
- var DirectedEdge = class extends AbstractEdge {
5864
- static {
5865
- __name(this, "DirectedEdge");
5866
- }
5867
- src;
5868
- dest;
5849
+ __name(_DirectedVertex, "DirectedVertex");
5850
+ var DirectedVertex = _DirectedVertex;
5851
+ var _DirectedEdge = class _DirectedEdge extends AbstractEdge {
5869
5852
  constructor(src, dest, weight, value) {
5870
5853
  super(weight, value);
5854
+ __publicField(this, "src");
5855
+ __publicField(this, "dest");
5871
5856
  this.src = src;
5872
5857
  this.dest = dest;
5873
5858
  }
5874
5859
  };
5875
- var DirectedGraph = class _DirectedGraph extends AbstractGraph {
5876
- static {
5877
- __name(this, "DirectedGraph");
5878
- }
5860
+ __name(_DirectedEdge, "DirectedEdge");
5861
+ var DirectedEdge = _DirectedEdge;
5862
+ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
5879
5863
  /**
5880
5864
  * Construct a directed graph with runtime defaults.
5881
5865
  * @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
@@ -5883,15 +5867,15 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
5883
5867
  */
5884
5868
  constructor(options) {
5885
5869
  super(options);
5870
+ __publicField(this, "_outEdgeMap", /* @__PURE__ */ new Map());
5871
+ __publicField(this, "_inEdgeMap", /* @__PURE__ */ new Map());
5886
5872
  }
5887
- _outEdgeMap = /* @__PURE__ */ new Map();
5888
5873
  get outEdgeMap() {
5889
5874
  return this._outEdgeMap;
5890
5875
  }
5891
5876
  set outEdgeMap(v) {
5892
5877
  this._outEdgeMap = v;
5893
5878
  }
5894
- _inEdgeMap = /* @__PURE__ */ new Map();
5895
5879
  get inEdgeMap() {
5896
5880
  return this._inEdgeMap;
5897
5881
  }
@@ -5944,7 +5928,8 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
5944
5928
  * @remarks Time O(1), Space O(1)
5945
5929
  */
5946
5930
  createEdge(src, dest, weight, value) {
5947
- return new DirectedEdge(src, dest, weight ?? this.options.defaultEdgeWeight ?? 1, value);
5931
+ var _a;
5932
+ return new DirectedEdge(src, dest, (_a = weight != null ? weight : this.options.defaultEdgeWeight) != null ? _a : 1, value);
5948
5933
  }
5949
5934
  /**
5950
5935
  * Get the unique edge from `src` to `dest`, if present.
@@ -6015,7 +6000,7 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
6015
6000
  if (src && dest) {
6016
6001
  const srcOutEdges = this._outEdgeMap.get(src);
6017
6002
  if (srcOutEdges && srcOutEdges.length > 0) {
6018
- arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === dest?.key);
6003
+ arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === (dest == null ? void 0 : dest.key));
6019
6004
  }
6020
6005
  const destInEdges = this._inEdgeMap.get(dest);
6021
6006
  if (destInEdges && destInEdges.length > 0) {
@@ -6137,7 +6122,7 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
6137
6122
  * @remarks Time O(V + E), Space O(V)
6138
6123
  */
6139
6124
  topologicalSort(propertyName) {
6140
- propertyName = propertyName ?? "key";
6125
+ propertyName = propertyName != null ? propertyName : "key";
6141
6126
  const statusMap = /* @__PURE__ */ new Map();
6142
6127
  for (const entry of this.vertexMap) {
6143
6128
  statusMap.set(entry[1], 0);
@@ -6330,30 +6315,27 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
6330
6315
  }
6331
6316
  }
6332
6317
  };
6318
+ __name(_DirectedGraph, "DirectedGraph");
6319
+ var DirectedGraph = _DirectedGraph;
6333
6320
 
6334
6321
  // src/data-structures/graph/undirected-graph.ts
6335
- var UndirectedVertex = class extends AbstractVertex {
6336
- static {
6337
- __name(this, "UndirectedVertex");
6338
- }
6322
+ var _UndirectedVertex = class _UndirectedVertex extends AbstractVertex {
6339
6323
  constructor(key, value) {
6340
6324
  super(key, value);
6341
6325
  }
6342
6326
  };
6343
- var UndirectedEdge = class extends AbstractEdge {
6344
- static {
6345
- __name(this, "UndirectedEdge");
6346
- }
6347
- endpoints;
6327
+ __name(_UndirectedVertex, "UndirectedVertex");
6328
+ var UndirectedVertex = _UndirectedVertex;
6329
+ var _UndirectedEdge = class _UndirectedEdge extends AbstractEdge {
6348
6330
  constructor(v1, v2, weight, value) {
6349
6331
  super(weight, value);
6332
+ __publicField(this, "endpoints");
6350
6333
  this.endpoints = [v1, v2];
6351
6334
  }
6352
6335
  };
6353
- var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6354
- static {
6355
- __name(this, "UndirectedGraph");
6356
- }
6336
+ __name(_UndirectedEdge, "UndirectedEdge");
6337
+ var UndirectedEdge = _UndirectedEdge;
6338
+ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6357
6339
  /**
6358
6340
  * Construct an undirected graph with runtime defaults.
6359
6341
  * @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
@@ -6361,9 +6343,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6361
6343
  */
6362
6344
  constructor(options) {
6363
6345
  super(options);
6346
+ __publicField(this, "_edgeMap");
6364
6347
  this._edgeMap = /* @__PURE__ */ new Map();
6365
6348
  }
6366
- _edgeMap;
6367
6349
  get edgeMap() {
6368
6350
  return this._edgeMap;
6369
6351
  }
@@ -6416,7 +6398,8 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6416
6398
  * @remarks Time O(1), Space O(1)
6417
6399
  */
6418
6400
  createEdge(v1, v2, weight, value) {
6419
- return new UndirectedEdge(v1, v2, weight ?? this.options.defaultEdgeWeight ?? 1, value);
6401
+ var _a;
6402
+ return new UndirectedEdge(v1, v2, (_a = weight != null ? weight : this.options.defaultEdgeWeight) != null ? _a : 1, value);
6420
6403
  }
6421
6404
  /**
6422
6405
  * Get an undirected edge between two vertices, if present.
@@ -6426,12 +6409,13 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6426
6409
  * @remarks Time O(1) avg, Space O(1)
6427
6410
  */
6428
6411
  getEdge(v1, v2) {
6412
+ var _a;
6429
6413
  let edgeMap = [];
6430
6414
  if (v1 !== void 0 && v2 !== void 0) {
6431
6415
  const vertex1 = this._getVertex(v1);
6432
6416
  const vertex2 = this._getVertex(v2);
6433
6417
  if (vertex1 && vertex2) {
6434
- edgeMap = this._edgeMap.get(vertex1)?.filter((e) => e.endpoints.includes(vertex2.key));
6418
+ edgeMap = (_a = this._edgeMap.get(vertex1)) == null ? void 0 : _a.filter((e) => e.endpoints.includes(vertex2.key));
6435
6419
  }
6436
6420
  }
6437
6421
  return edgeMap ? edgeMap[0] || void 0 : void 0;
@@ -6524,9 +6508,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6524
6508
  * @remarks Time O(1) avg, Space O(1)
6525
6509
  */
6526
6510
  degreeOf(vertexOrKey) {
6511
+ var _a;
6527
6512
  const vertex = this._getVertex(vertexOrKey);
6528
6513
  if (vertex) {
6529
- return this._edgeMap.get(vertex)?.length || 0;
6514
+ return ((_a = this._edgeMap.get(vertex)) == null ? void 0 : _a.length) || 0;
6530
6515
  } else {
6531
6516
  return 0;
6532
6517
  }
@@ -6719,32 +6704,29 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
6719
6704
  return true;
6720
6705
  }
6721
6706
  };
6707
+ __name(_UndirectedGraph, "UndirectedGraph");
6708
+ var UndirectedGraph = _UndirectedGraph;
6722
6709
 
6723
6710
  // src/data-structures/graph/map-graph.ts
6724
- var MapVertex = class extends DirectedVertex {
6725
- static {
6726
- __name(this, "MapVertex");
6727
- }
6728
- lat;
6729
- long;
6711
+ var _MapVertex = class _MapVertex extends DirectedVertex {
6730
6712
  constructor(key, value, lat, long) {
6731
6713
  super(key, value);
6714
+ __publicField(this, "lat");
6715
+ __publicField(this, "long");
6732
6716
  this.lat = lat;
6733
6717
  this.long = long;
6734
6718
  }
6735
6719
  };
6736
- var MapEdge = class extends DirectedEdge {
6737
- static {
6738
- __name(this, "MapEdge");
6739
- }
6720
+ __name(_MapVertex, "MapVertex");
6721
+ var MapVertex = _MapVertex;
6722
+ var _MapEdge = class _MapEdge extends DirectedEdge {
6740
6723
  constructor(src, dest, weight, value) {
6741
6724
  super(src, dest, weight, value);
6742
6725
  }
6743
6726
  };
6744
- var MapGraph = class _MapGraph extends DirectedGraph {
6745
- static {
6746
- __name(this, "MapGraph");
6747
- }
6727
+ __name(_MapEdge, "MapEdge");
6728
+ var MapEdge = _MapEdge;
6729
+ var _MapGraph = class _MapGraph extends DirectedGraph {
6748
6730
  /**
6749
6731
  * Construct a MapGraph.
6750
6732
  * @param originCoord - Origin coordinate `[lat, long]` used as default.
@@ -6753,14 +6735,14 @@ var MapGraph = class _MapGraph extends DirectedGraph {
6753
6735
  */
6754
6736
  constructor(originCoord, bottomRight) {
6755
6737
  super();
6738
+ __publicField(this, "_originCoord", [0, 0]);
6739
+ __publicField(this, "_bottomRight");
6756
6740
  this._originCoord = originCoord;
6757
6741
  this._bottomRight = bottomRight;
6758
6742
  }
6759
- _originCoord = [0, 0];
6760
6743
  get originCoord() {
6761
6744
  return this._originCoord;
6762
6745
  }
6763
- _bottomRight;
6764
6746
  get bottomRight() {
6765
6747
  return this._bottomRight;
6766
6748
  }
@@ -6812,11 +6794,13 @@ var MapGraph = class _MapGraph extends DirectedGraph {
6812
6794
  */
6813
6795
  _createInstance(options) {
6814
6796
  const { originCoord, bottomRight } = options || {};
6815
- const oc = originCoord ?? this.originCoord;
6816
- const br = bottomRight ?? this.bottomRight;
6797
+ const oc = originCoord != null ? originCoord : this.originCoord;
6798
+ const br = bottomRight != null ? bottomRight : this.bottomRight;
6817
6799
  return new _MapGraph(oc, br);
6818
6800
  }
6819
6801
  };
6802
+ __name(_MapGraph, "MapGraph");
6803
+ var MapGraph = _MapGraph;
6820
6804
 
6821
6805
  // src/common/index.ts
6822
6806
  var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
@@ -6824,7 +6808,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
6824
6808
  DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
6825
6809
  return DFSOperation2;
6826
6810
  })(DFSOperation || {});
6827
- var Range = class {
6811
+ var _Range = class _Range {
6828
6812
  constructor(low, high, includeLow = true, includeHigh = true) {
6829
6813
  this.low = low;
6830
6814
  this.high = high;
@@ -6833,9 +6817,6 @@ var Range = class {
6833
6817
  if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
6834
6818
  if (low > high) throw new RangeError("low must be less than or equal to high");
6835
6819
  }
6836
- static {
6837
- __name(this, "Range");
6838
- }
6839
6820
  // Determine whether a key is within the range
6840
6821
  isInRange(key, comparator) {
6841
6822
  const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
@@ -6843,15 +6824,11 @@ var Range = class {
6843
6824
  return lowCheck && highCheck;
6844
6825
  }
6845
6826
  };
6827
+ __name(_Range, "Range");
6828
+ var Range = _Range;
6846
6829
 
6847
6830
  // src/data-structures/binary-tree/binary-tree.ts
6848
- var BinaryTreeNode = class {
6849
- static {
6850
- __name(this, "BinaryTreeNode");
6851
- }
6852
- key;
6853
- value;
6854
- parent = void 0;
6831
+ var _BinaryTreeNode = class _BinaryTreeNode {
6855
6832
  /**
6856
6833
  * Creates an instance of BinaryTreeNode.
6857
6834
  * @remarks Time O(1), Space O(1)
@@ -6860,10 +6837,17 @@ var BinaryTreeNode = class {
6860
6837
  * @param [value] - The value associated with the key.
6861
6838
  */
6862
6839
  constructor(key, value) {
6840
+ __publicField(this, "key");
6841
+ __publicField(this, "value");
6842
+ __publicField(this, "parent");
6843
+ __publicField(this, "_left");
6844
+ __publicField(this, "_right");
6845
+ __publicField(this, "_height", 0);
6846
+ __publicField(this, "_color", "BLACK");
6847
+ __publicField(this, "_count", 1);
6863
6848
  this.key = key;
6864
6849
  this.value = value;
6865
6850
  }
6866
- _left = void 0;
6867
6851
  /**
6868
6852
  * Gets the left child of the node.
6869
6853
  * @remarks Time O(1), Space O(1)
@@ -6885,7 +6869,6 @@ var BinaryTreeNode = class {
6885
6869
  }
6886
6870
  this._left = v;
6887
6871
  }
6888
- _right = void 0;
6889
6872
  /**
6890
6873
  * Gets the right child of the node.
6891
6874
  * @remarks Time O(1), Space O(1)
@@ -6907,7 +6890,6 @@ var BinaryTreeNode = class {
6907
6890
  }
6908
6891
  this._right = v;
6909
6892
  }
6910
- _height = 0;
6911
6893
  /**
6912
6894
  * Gets the height of the node (used in self-balancing trees).
6913
6895
  * @remarks Time O(1), Space O(1)
@@ -6926,7 +6908,6 @@ var BinaryTreeNode = class {
6926
6908
  set height(value) {
6927
6909
  this._height = value;
6928
6910
  }
6929
- _color = "BLACK";
6930
6911
  /**
6931
6912
  * Gets the color of the node (used in Red-Black trees).
6932
6913
  * @remarks Time O(1), Space O(1)
@@ -6945,7 +6926,6 @@ var BinaryTreeNode = class {
6945
6926
  set color(value) {
6946
6927
  this._color = value;
6947
6928
  }
6948
- _count = 1;
6949
6929
  /**
6950
6930
  * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
6951
6931
  * @remarks Time O(1), Space O(1)
@@ -6982,11 +6962,9 @@ var BinaryTreeNode = class {
6982
6962
  return "MAL_NODE";
6983
6963
  }
6984
6964
  };
6985
- var BinaryTree = class extends IterableEntryBase {
6986
- static {
6987
- __name(this, "BinaryTree");
6988
- }
6989
- iterationType = "ITERATIVE";
6965
+ __name(_BinaryTreeNode, "BinaryTreeNode");
6966
+ var BinaryTreeNode = _BinaryTreeNode;
6967
+ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
6990
6968
  /**
6991
6969
  * Creates an instance of BinaryTree.
6992
6970
  * @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.
@@ -6996,6 +6974,22 @@ var BinaryTree = class extends IterableEntryBase {
6996
6974
  */
6997
6975
  constructor(keysNodesEntriesOrRaws = [], options) {
6998
6976
  super();
6977
+ __publicField(this, "iterationType", "ITERATIVE");
6978
+ __publicField(this, "_isMapMode", true);
6979
+ __publicField(this, "_isDuplicate", false);
6980
+ __publicField(this, "_store", /* @__PURE__ */ new Map());
6981
+ __publicField(this, "_root");
6982
+ __publicField(this, "_size", 0);
6983
+ __publicField(this, "_NIL", new BinaryTreeNode(NaN));
6984
+ __publicField(this, "_toEntryFn");
6985
+ /**
6986
+ * (Protected) Default callback function, returns the node's key.
6987
+ * @remarks Time O(1)
6988
+ *
6989
+ * @param node - The node.
6990
+ * @returns The node's key or undefined.
6991
+ */
6992
+ __publicField(this, "_DEFAULT_NODE_CALLBACK", /* @__PURE__ */ __name((node) => node ? node.key : void 0, "_DEFAULT_NODE_CALLBACK"));
6999
6993
  if (options) {
7000
6994
  const { iterationType, toEntryFn, isMapMode, isDuplicate } = options;
7001
6995
  if (iterationType) this.iterationType = iterationType;
@@ -7006,7 +7000,6 @@ var BinaryTree = class extends IterableEntryBase {
7006
7000
  }
7007
7001
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
7008
7002
  }
7009
- _isMapMode = true;
7010
7003
  /**
7011
7004
  * Gets whether the tree is in Map mode.
7012
7005
  * @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)
@@ -7016,7 +7009,6 @@ var BinaryTree = class extends IterableEntryBase {
7016
7009
  get isMapMode() {
7017
7010
  return this._isMapMode;
7018
7011
  }
7019
- _isDuplicate = false;
7020
7012
  /**
7021
7013
  * Gets whether the tree allows duplicate keys.
7022
7014
  * @remarks Time O(1)
@@ -7026,7 +7018,6 @@ var BinaryTree = class extends IterableEntryBase {
7026
7018
  get isDuplicate() {
7027
7019
  return this._isDuplicate;
7028
7020
  }
7029
- _store = /* @__PURE__ */ new Map();
7030
7021
  /**
7031
7022
  * Gets the external value store (used in Map mode).
7032
7023
  * @remarks Time O(1)
@@ -7036,7 +7027,6 @@ var BinaryTree = class extends IterableEntryBase {
7036
7027
  get store() {
7037
7028
  return this._store;
7038
7029
  }
7039
- _root;
7040
7030
  /**
7041
7031
  * Gets the root node of the tree.
7042
7032
  * @remarks Time O(1)
@@ -7046,7 +7036,6 @@ var BinaryTree = class extends IterableEntryBase {
7046
7036
  get root() {
7047
7037
  return this._root;
7048
7038
  }
7049
- _size = 0;
7050
7039
  /**
7051
7040
  * Gets the number of nodes in the tree.
7052
7041
  * @remarks Time O(1)
@@ -7056,7 +7045,6 @@ var BinaryTree = class extends IterableEntryBase {
7056
7045
  get size() {
7057
7046
  return this._size;
7058
7047
  }
7059
- _NIL = new BinaryTreeNode(NaN);
7060
7048
  /**
7061
7049
  * Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
7062
7050
  * @remarks Time O(1)
@@ -7066,7 +7054,6 @@ var BinaryTree = class extends IterableEntryBase {
7066
7054
  get NIL() {
7067
7055
  return this._NIL;
7068
7056
  }
7069
- _toEntryFn;
7070
7057
  /**
7071
7058
  * Gets the function used to convert raw data objects (R) into [key, value] entries.
7072
7059
  * @remarks Time O(1)
@@ -7084,7 +7071,7 @@ var BinaryTree = class extends IterableEntryBase {
7084
7071
  * @param [value] - The value for the new node (used if not in Map mode).
7085
7072
  * @returns The newly created node.
7086
7073
  */
7087
- _createNode(key, value) {
7074
+ createNode(key, value) {
7088
7075
  return new BinaryTreeNode(key, this._isMapMode ? void 0 : value);
7089
7076
  }
7090
7077
  /**
@@ -7226,7 +7213,7 @@ var BinaryTree = class extends IterableEntryBase {
7226
7213
  if (newNode === void 0) return false;
7227
7214
  if (!this._root) {
7228
7215
  this._setRoot(newNode);
7229
- if (this._isMapMode) this._setValue(newNode?.key, newValue);
7216
+ if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
7230
7217
  this._size = 1;
7231
7218
  return true;
7232
7219
  }
@@ -7258,7 +7245,7 @@ var BinaryTree = class extends IterableEntryBase {
7258
7245
  } else if (potentialParent.right === void 0) {
7259
7246
  potentialParent.right = newNode;
7260
7247
  }
7261
- if (this._isMapMode) this._setValue(newNode?.key, newValue);
7248
+ if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
7262
7249
  this._size++;
7263
7250
  return true;
7264
7251
  }
@@ -7323,7 +7310,7 @@ var BinaryTree = class extends IterableEntryBase {
7323
7310
  if (!this._root) return deletedResult;
7324
7311
  const curr = this.getNode(keyNodeOrEntry);
7325
7312
  if (!curr) return deletedResult;
7326
- const parent = curr?.parent;
7313
+ const parent = curr == null ? void 0 : curr.parent;
7327
7314
  let needBalanced;
7328
7315
  let orgCurrent = curr;
7329
7316
  if (!curr.left && !curr.right && !parent) {
@@ -7428,12 +7415,13 @@ var BinaryTree = class extends IterableEntryBase {
7428
7415
  * @returns The associated value, or undefined.
7429
7416
  */
7430
7417
  get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
7418
+ var _a;
7431
7419
  if (this._isMapMode) {
7432
7420
  const key = this._extractKey(keyNodeEntryOrPredicate);
7433
7421
  if (key === null || key === void 0) return;
7434
7422
  return this._store.get(key);
7435
7423
  }
7436
- return this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)?.value;
7424
+ return (_a = this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)) == null ? void 0 : _a.value;
7437
7425
  }
7438
7426
  has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
7439
7427
  return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType).length > 0;
@@ -7521,7 +7509,7 @@ var BinaryTree = class extends IterableEntryBase {
7521
7509
  let distEnsured = this.ensureNode(dist);
7522
7510
  const beginRootEnsured = this.ensureNode(startNode);
7523
7511
  let depth = 0;
7524
- while (distEnsured?.parent) {
7512
+ while (distEnsured == null ? void 0 : distEnsured.parent) {
7525
7513
  if (distEnsured === beginRootEnsured) {
7526
7514
  return depth;
7527
7515
  }
@@ -8083,10 +8071,10 @@ var BinaryTree = class extends IterableEntryBase {
8083
8071
  const dfs = /* @__PURE__ */ __name((node) => {
8084
8072
  if (!shouldVisitRoot(node)) return;
8085
8073
  const visitLeft = /* @__PURE__ */ __name(() => {
8086
- if (shouldVisitLeft(node) && node?.left !== void 0) dfs(node?.left);
8074
+ if (shouldVisitLeft(node) && (node == null ? void 0 : node.left) !== void 0) dfs(node == null ? void 0 : node.left);
8087
8075
  }, "visitLeft");
8088
8076
  const visitRight = /* @__PURE__ */ __name(() => {
8089
- if (shouldVisitRight(node) && node?.right !== void 0) dfs(node?.right);
8077
+ if (shouldVisitRight(node) && (node == null ? void 0 : node.right) !== void 0) dfs(node == null ? void 0 : node.right);
8090
8078
  }, "visitRight");
8091
8079
  switch (pattern) {
8092
8080
  case "IN":
@@ -8119,10 +8107,12 @@ var BinaryTree = class extends IterableEntryBase {
8119
8107
  } else {
8120
8108
  const stack = [{ opt: 0 /* VISIT */, node: startNode }];
8121
8109
  const pushLeft = /* @__PURE__ */ __name((cur) => {
8122
- if (shouldVisitLeft(cur.node)) stack.push({ opt: 0 /* VISIT */, node: cur.node?.left });
8110
+ var _a;
8111
+ if (shouldVisitLeft(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.left });
8123
8112
  }, "pushLeft");
8124
8113
  const pushRight = /* @__PURE__ */ __name((cur) => {
8125
- if (shouldVisitRight(cur.node)) stack.push({ opt: 0 /* VISIT */, node: cur.node?.right });
8114
+ var _a;
8115
+ if (shouldVisitRight(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.right });
8126
8116
  }, "pushRight");
8127
8117
  const pushRoot = /* @__PURE__ */ __name((cur) => {
8128
8118
  if (shouldVisitRoot(cur.node)) stack.push({ opt: 1 /* PROCESS */, node: cur.node });
@@ -8194,14 +8184,6 @@ var BinaryTree = class extends IterableEntryBase {
8194
8184
  }
8195
8185
  }
8196
8186
  }
8197
- /**
8198
- * (Protected) Default callback function, returns the node's key.
8199
- * @remarks Time O(1)
8200
- *
8201
- * @param node - The node.
8202
- * @returns The node's key or undefined.
8203
- */
8204
- _DEFAULT_NODE_CALLBACK = /* @__PURE__ */ __name((node) => node ? node.key : void 0, "_DEFAULT_NODE_CALLBACK");
8205
8187
  /**
8206
8188
  * (Protected) Snapshots the current tree's configuration options.
8207
8189
  * @remarks Time O(1)
@@ -8227,7 +8209,7 @@ var BinaryTree = class extends IterableEntryBase {
8227
8209
  */
8228
8210
  _createInstance(options) {
8229
8211
  const Ctor = this.constructor;
8230
- return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
8212
+ return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
8231
8213
  }
8232
8214
  /**
8233
8215
  * (Protected) Creates a new instance of the same tree constructor, potentially with different generic types.
@@ -8240,7 +8222,7 @@ var BinaryTree = class extends IterableEntryBase {
8240
8222
  */
8241
8223
  _createLike(iter = [], options) {
8242
8224
  const Ctor = this.constructor;
8243
- return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
8225
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
8244
8226
  }
8245
8227
  /**
8246
8228
  * (Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
@@ -8258,10 +8240,10 @@ var BinaryTree = class extends IterableEntryBase {
8258
8240
  const [key, entryValue] = keyNodeOrEntry;
8259
8241
  if (key === void 0) return [void 0, void 0];
8260
8242
  else if (key === null) return [null, void 0];
8261
- const finalValue = value ?? entryValue;
8262
- return [this._createNode(key, finalValue), finalValue];
8243
+ const finalValue = value != null ? value : entryValue;
8244
+ return [this.createNode(key, finalValue), finalValue];
8263
8245
  }
8264
- return [this._createNode(keyNodeOrEntry, value), value];
8246
+ return [this.createNode(keyNodeOrEntry, value), value];
8265
8247
  }
8266
8248
  /**
8267
8249
  * (Protected) Helper for cloning. Performs a BFS and adds all nodes to the new tree.
@@ -8346,7 +8328,7 @@ var BinaryTree = class extends IterableEntryBase {
8346
8328
  destNode = this.ensureNode(destNode);
8347
8329
  if (srcNode && destNode) {
8348
8330
  const { key, value } = destNode;
8349
- const tempNode = this._createNode(key, value);
8331
+ const tempNode = this.createNode(key, value);
8350
8332
  if (tempNode) {
8351
8333
  destNode.key = srcNode.key;
8352
8334
  if (!this._isMapMode) destNode.value = srcNode.value;
@@ -8465,13 +8447,11 @@ var BinaryTree = class extends IterableEntryBase {
8465
8447
  this._store.clear();
8466
8448
  }
8467
8449
  };
8450
+ __name(_BinaryTree, "BinaryTree");
8451
+ var BinaryTree = _BinaryTree;
8468
8452
 
8469
8453
  // src/data-structures/binary-tree/bst.ts
8470
- var BSTNode = class extends BinaryTreeNode {
8471
- static {
8472
- __name(this, "BSTNode");
8473
- }
8474
- parent = void 0;
8454
+ var _BSTNode = class _BSTNode {
8475
8455
  /**
8476
8456
  * Creates an instance of BSTNode.
8477
8457
  * @remarks Time O(1), Space O(1)
@@ -8480,9 +8460,17 @@ var BSTNode = class extends BinaryTreeNode {
8480
8460
  * @param [value] - The value associated with the key.
8481
8461
  */
8482
8462
  constructor(key, value) {
8483
- super(key, value);
8463
+ __publicField(this, "key");
8464
+ __publicField(this, "value");
8465
+ __publicField(this, "parent");
8466
+ __publicField(this, "_left");
8467
+ __publicField(this, "_right");
8468
+ __publicField(this, "_height", 0);
8469
+ __publicField(this, "_color", "BLACK");
8470
+ __publicField(this, "_count", 1);
8471
+ this.key = key;
8472
+ this.value = value;
8484
8473
  }
8485
- _left = void 0;
8486
8474
  /**
8487
8475
  * Gets the left child of the node.
8488
8476
  * @remarks Time O(1), Space O(1)
@@ -8502,7 +8490,6 @@ var BSTNode = class extends BinaryTreeNode {
8502
8490
  if (v) v.parent = this;
8503
8491
  this._left = v;
8504
8492
  }
8505
- _right = void 0;
8506
8493
  /**
8507
8494
  * Gets the right child of the node.
8508
8495
  * @remarks Time O(1), Space O(1)
@@ -8522,11 +8509,81 @@ var BSTNode = class extends BinaryTreeNode {
8522
8509
  if (v) v.parent = this;
8523
8510
  this._right = v;
8524
8511
  }
8525
- };
8526
- var BST = class extends BinaryTree {
8527
- static {
8528
- __name(this, "BST");
8512
+ /**
8513
+ * Gets the height of the node (used in self-balancing trees).
8514
+ * @remarks Time O(1), Space O(1)
8515
+ *
8516
+ * @returns The height.
8517
+ */
8518
+ get height() {
8519
+ return this._height;
8520
+ }
8521
+ /**
8522
+ * Sets the height of the node.
8523
+ * @remarks Time O(1), Space O(1)
8524
+ *
8525
+ * @param value - The new height.
8526
+ */
8527
+ set height(value) {
8528
+ this._height = value;
8529
+ }
8530
+ /**
8531
+ * Gets the color of the node (used in Red-Black trees).
8532
+ * @remarks Time O(1), Space O(1)
8533
+ *
8534
+ * @returns The node's color.
8535
+ */
8536
+ get color() {
8537
+ return this._color;
8538
+ }
8539
+ /**
8540
+ * Sets the color of the node.
8541
+ * @remarks Time O(1), Space O(1)
8542
+ *
8543
+ * @param value - The new color.
8544
+ */
8545
+ set color(value) {
8546
+ this._color = value;
8547
+ }
8548
+ /**
8549
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
8550
+ * @remarks Time O(1), Space O(1)
8551
+ *
8552
+ * @returns The subtree node count.
8553
+ */
8554
+ get count() {
8555
+ return this._count;
8556
+ }
8557
+ /**
8558
+ * Sets the count of nodes in the subtree.
8559
+ * @remarks Time O(1), Space O(1)
8560
+ *
8561
+ * @param value - The new count.
8562
+ */
8563
+ set count(value) {
8564
+ this._count = value;
8565
+ }
8566
+ /**
8567
+ * Gets the position of the node relative to its parent.
8568
+ * @remarks Time O(1), Space O(1)
8569
+ *
8570
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
8571
+ */
8572
+ get familyPosition() {
8573
+ if (!this.parent) {
8574
+ return this.left || this.right ? "ROOT" : "ISOLATED";
8575
+ }
8576
+ if (this.parent.left === this) {
8577
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
8578
+ } else if (this.parent.right === this) {
8579
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
8580
+ }
8581
+ return "MAL_NODE";
8529
8582
  }
8583
+ };
8584
+ __name(_BSTNode, "BSTNode");
8585
+ var BSTNode = _BSTNode;
8586
+ var _BST = class _BST extends BinaryTree {
8530
8587
  /**
8531
8588
  * Creates an instance of BST.
8532
8589
  * @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
@@ -8536,6 +8593,33 @@ var BST = class extends BinaryTree {
8536
8593
  */
8537
8594
  constructor(keysNodesEntriesOrRaws = [], options) {
8538
8595
  super([], options);
8596
+ __publicField(this, "_root");
8597
+ __publicField(this, "_isReverse", false);
8598
+ /**
8599
+ * The default comparator function.
8600
+ * @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
8601
+ */
8602
+ __publicField(this, "_comparator", /* @__PURE__ */ __name((a, b) => {
8603
+ if (isComparable(a) && isComparable(b)) {
8604
+ if (a > b) return 1;
8605
+ if (a < b) return -1;
8606
+ return 0;
8607
+ }
8608
+ if (this._specifyComparable) {
8609
+ const va = this._specifyComparable(a);
8610
+ const vb = this._specifyComparable(b);
8611
+ if (va > vb) return 1;
8612
+ if (va < vb) return -1;
8613
+ return 0;
8614
+ }
8615
+ if (typeof a === "object" || typeof b === "object") {
8616
+ throw TypeError(
8617
+ `When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
8618
+ );
8619
+ }
8620
+ return 0;
8621
+ }, "_comparator"));
8622
+ __publicField(this, "_specifyComparable");
8539
8623
  if (options) {
8540
8624
  const { specifyComparable, isReverse } = options;
8541
8625
  if (typeof specifyComparable === "function") this._specifyComparable = specifyComparable;
@@ -8543,7 +8627,6 @@ var BST = class extends BinaryTree {
8543
8627
  }
8544
8628
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
8545
8629
  }
8546
- _root = void 0;
8547
8630
  /**
8548
8631
  * Gets the root node of the tree.
8549
8632
  * @remarks Time O(1)
@@ -8553,7 +8636,6 @@ var BST = class extends BinaryTree {
8553
8636
  get root() {
8554
8637
  return this._root;
8555
8638
  }
8556
- _isReverse = false;
8557
8639
  /**
8558
8640
  * Gets whether the tree's comparison logic is reversed.
8559
8641
  * @remarks Time O(1)
@@ -8563,30 +8645,6 @@ var BST = class extends BinaryTree {
8563
8645
  get isReverse() {
8564
8646
  return this._isReverse;
8565
8647
  }
8566
- /**
8567
- * The default comparator function.
8568
- * @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
8569
- */
8570
- _comparator = /* @__PURE__ */ __name((a, b) => {
8571
- if (isComparable(a) && isComparable(b)) {
8572
- if (a > b) return 1;
8573
- if (a < b) return -1;
8574
- return 0;
8575
- }
8576
- if (this._specifyComparable) {
8577
- const va = this._specifyComparable(a);
8578
- const vb = this._specifyComparable(b);
8579
- if (va > vb) return 1;
8580
- if (va < vb) return -1;
8581
- return 0;
8582
- }
8583
- if (typeof a === "object" || typeof b === "object") {
8584
- throw TypeError(
8585
- `When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
8586
- );
8587
- }
8588
- return 0;
8589
- }, "_comparator");
8590
8648
  /**
8591
8649
  * Gets the comparator function used by the tree.
8592
8650
  * @remarks Time O(1)
@@ -8596,7 +8654,6 @@ var BST = class extends BinaryTree {
8596
8654
  get comparator() {
8597
8655
  return this._comparator;
8598
8656
  }
8599
- _specifyComparable;
8600
8657
  /**
8601
8658
  * Gets the function used to extract a comparable value from a complex key.
8602
8659
  * @remarks Time O(1)
@@ -8614,7 +8671,7 @@ var BST = class extends BinaryTree {
8614
8671
  * @param [value] - The value for the new node (used if not in Map mode).
8615
8672
  * @returns The newly created BSTNode.
8616
8673
  */
8617
- _createNode(key, value) {
8674
+ createNode(key, value) {
8618
8675
  return new BSTNode(key, this._isMapMode ? void 0 : value);
8619
8676
  }
8620
8677
  /**
@@ -8626,7 +8683,8 @@ var BST = class extends BinaryTree {
8626
8683
  * @returns The resolved node, or undefined if not found.
8627
8684
  */
8628
8685
  ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
8629
- return super.ensureNode(keyNodeOrEntry, iterationType) ?? void 0;
8686
+ var _a;
8687
+ return (_a = super.ensureNode(keyNodeOrEntry, iterationType)) != null ? _a : void 0;
8630
8688
  }
8631
8689
  /**
8632
8690
  * Checks if the given item is a `BSTNode` instance.
@@ -8699,7 +8757,8 @@ var BST = class extends BinaryTree {
8699
8757
  * @returns The first matching node, or undefined if not found.
8700
8758
  */
8701
8759
  getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
8702
- return this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0] ?? void 0;
8760
+ var _a;
8761
+ return (_a = this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0]) != null ? _a : void 0;
8703
8762
  }
8704
8763
  /**
8705
8764
  * Searches the tree for nodes matching a predicate, key, or range.
@@ -8804,7 +8863,7 @@ var BST = class extends BinaryTree {
8804
8863
  if (newNode === void 0) return false;
8805
8864
  if (this._root === void 0) {
8806
8865
  this._setRoot(newNode);
8807
- if (this._isMapMode) this._setValue(newNode?.key, newValue);
8866
+ if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
8808
8867
  this._size++;
8809
8868
  return true;
8810
8869
  }
@@ -8817,7 +8876,7 @@ var BST = class extends BinaryTree {
8817
8876
  } else if (this._compare(current.key, newNode.key) > 0) {
8818
8877
  if (current.left === void 0) {
8819
8878
  current.left = newNode;
8820
- if (this._isMapMode) this._setValue(newNode?.key, newValue);
8879
+ if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
8821
8880
  this._size++;
8822
8881
  return true;
8823
8882
  }
@@ -8825,7 +8884,7 @@ var BST = class extends BinaryTree {
8825
8884
  } else {
8826
8885
  if (current.right === void 0) {
8827
8886
  current.right = newNode;
8828
- if (this._isMapMode) this._setValue(newNode?.key, newValue);
8887
+ if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
8829
8888
  this._size++;
8830
8889
  return true;
8831
8890
  }
@@ -8848,10 +8907,10 @@ var BST = class extends BinaryTree {
8848
8907
  */
8849
8908
  addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8850
8909
  const inserted = [];
8851
- const valuesIterator = values?.[Symbol.iterator]();
8910
+ const valuesIterator = values == null ? void 0 : values[Symbol.iterator]();
8852
8911
  if (!isBalanceAdd) {
8853
8912
  for (let kve of keysNodesEntriesOrRaws) {
8854
- const val = valuesIterator?.next().value;
8913
+ const val = valuesIterator == null ? void 0 : valuesIterator.next().value;
8855
8914
  if (this.isRaw(kve)) kve = this._toEntryFn(kve);
8856
8915
  inserted.push(this.add(kve, val));
8857
8916
  }
@@ -8860,7 +8919,7 @@ var BST = class extends BinaryTree {
8860
8919
  const realBTNExemplars = [];
8861
8920
  let i = 0;
8862
8921
  for (const kve of keysNodesEntriesOrRaws) {
8863
- realBTNExemplars.push({ key: kve, value: valuesIterator?.next().value, orgIndex: i++ });
8922
+ realBTNExemplars.push({ key: kve, value: valuesIterator == null ? void 0 : valuesIterator.next().value, orgIndex: i++ });
8864
8923
  }
8865
8924
  const sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
8866
8925
  let keyA, keyB;
@@ -9082,7 +9141,7 @@ var BST = class extends BinaryTree {
9082
9141
  */
9083
9142
  _createInstance(options) {
9084
9143
  const Ctor = this.constructor;
9085
- return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
9144
+ return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
9086
9145
  }
9087
9146
  /**
9088
9147
  * (Protected) Creates a new instance of the same BST constructor, potentially with different generic types.
@@ -9095,7 +9154,7 @@ var BST = class extends BinaryTree {
9095
9154
  */
9096
9155
  _createLike(iter = [], options) {
9097
9156
  const Ctor = this.constructor;
9098
- return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
9157
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
9099
9158
  }
9100
9159
  /**
9101
9160
  * (Protected) Snapshots the current BST's configuration options.
@@ -9122,7 +9181,7 @@ var BST = class extends BinaryTree {
9122
9181
  _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
9123
9182
  const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
9124
9183
  if (node === null) return [void 0, void 0];
9125
- return [node, value ?? entryValue];
9184
+ return [node, value != null ? value : entryValue];
9126
9185
  }
9127
9186
  /**
9128
9187
  * (Protected) Sets the root node and clears its parent reference.
@@ -9153,6 +9212,7 @@ var BST = class extends BinaryTree {
9153
9212
  * @returns True if the node was found and deleted, false otherwise.
9154
9213
  */
9155
9214
  _deleteByKey(key) {
9215
+ var _a;
9156
9216
  let node = this._root;
9157
9217
  while (node) {
9158
9218
  const cmp = this._compare(node.key, key);
@@ -9161,7 +9221,7 @@ var BST = class extends BinaryTree {
9161
9221
  }
9162
9222
  if (!node) return false;
9163
9223
  const transplant = /* @__PURE__ */ __name((u, v) => {
9164
- const p = u?.parent;
9224
+ const p = u == null ? void 0 : u.parent;
9165
9225
  if (!p) {
9166
9226
  this._setRoot(v);
9167
9227
  } else if (p.left === u) {
@@ -9191,18 +9251,15 @@ var BST = class extends BinaryTree {
9191
9251
  succ.left = node.left;
9192
9252
  if (succ.left) succ.left.parent = succ;
9193
9253
  }
9194
- this._size = Math.max(0, (this._size ?? 0) - 1);
9254
+ this._size = Math.max(0, ((_a = this._size) != null ? _a : 0) - 1);
9195
9255
  return true;
9196
9256
  }
9197
9257
  };
9258
+ __name(_BST, "BST");
9259
+ var BST = _BST;
9198
9260
 
9199
9261
  // src/data-structures/binary-tree/binary-indexed-tree.ts
9200
- var BinaryIndexedTree = class {
9201
- static {
9202
- __name(this, "BinaryIndexedTree");
9203
- }
9204
- _freq;
9205
- _max;
9262
+ var _BinaryIndexedTree = class _BinaryIndexedTree {
9206
9263
  /**
9207
9264
  * The constructor initializes the properties of an object, including default frequency, maximum
9208
9265
  * value, a freqMap data structure, the most significant bit, and the count of negative frequencies.
@@ -9210,13 +9267,17 @@ var BinaryIndexedTree = class {
9210
9267
  * value of 0.
9211
9268
  */
9212
9269
  constructor({ frequency = 0, max }) {
9270
+ __publicField(this, "_freq");
9271
+ __publicField(this, "_max");
9272
+ __publicField(this, "_freqMap");
9273
+ __publicField(this, "_msb");
9274
+ __publicField(this, "_negativeCount");
9213
9275
  this._freq = frequency;
9214
9276
  this._max = max;
9215
9277
  this._freqMap = { 0: 0 };
9216
9278
  this._msb = getMSB(max);
9217
9279
  this._negativeCount = frequency < 0 ? max : 0;
9218
9280
  }
9219
- _freqMap;
9220
9281
  /**
9221
9282
  * The function returns the frequency map of numbers.
9222
9283
  * @returns The `_freqMap` property, which is a record with number keys and number values, is being
@@ -9225,7 +9286,6 @@ var BinaryIndexedTree = class {
9225
9286
  get freqMap() {
9226
9287
  return this._freqMap;
9227
9288
  }
9228
- _msb;
9229
9289
  /**
9230
9290
  * The function returns the value of the _msb property.
9231
9291
  * @returns The `_msb` property of the object.
@@ -9233,7 +9293,6 @@ var BinaryIndexedTree = class {
9233
9293
  get msb() {
9234
9294
  return this._msb;
9235
9295
  }
9236
- _negativeCount;
9237
9296
  /**
9238
9297
  * The function returns the value of the _negativeCount property.
9239
9298
  * @returns The method is returning the value of the variable `_negativeCount`, which is of type
@@ -9482,12 +9541,11 @@ var BinaryIndexedTree = class {
9482
9541
  return left;
9483
9542
  }
9484
9543
  };
9544
+ __name(_BinaryIndexedTree, "BinaryIndexedTree");
9545
+ var BinaryIndexedTree = _BinaryIndexedTree;
9485
9546
 
9486
9547
  // src/data-structures/binary-tree/segment-tree.ts
9487
- var SegmentTreeNode = class {
9488
- static {
9489
- __name(this, "SegmentTreeNode");
9490
- }
9548
+ var _SegmentTreeNode = class _SegmentTreeNode {
9491
9549
  /**
9492
9550
  * The constructor initializes the properties of a SegmentTreeNode object.
9493
9551
  * @param {number} start - The `start` parameter represents the starting index of the segment covered
@@ -9500,12 +9558,17 @@ var SegmentTreeNode = class {
9500
9558
  * of type `SegmentTreeNodeVal`. It represents the value associated with the segment tree node.
9501
9559
  */
9502
9560
  constructor(start, end, sum, value) {
9561
+ __publicField(this, "_start", 0);
9562
+ __publicField(this, "_end", 0);
9563
+ __publicField(this, "_value");
9564
+ __publicField(this, "_sum", 0);
9565
+ __publicField(this, "_left");
9566
+ __publicField(this, "_right");
9503
9567
  this._start = start;
9504
9568
  this._end = end;
9505
9569
  this._sum = sum;
9506
9570
  this._value = value || void 0;
9507
9571
  }
9508
- _start = 0;
9509
9572
  /**
9510
9573
  * The function returns the value of the protected variable _start.
9511
9574
  * @returns The start value, which is of type number.
@@ -9520,7 +9583,6 @@ var SegmentTreeNode = class {
9520
9583
  set start(value) {
9521
9584
  this._start = value;
9522
9585
  }
9523
- _end = 0;
9524
9586
  /**
9525
9587
  * The function returns the value of the protected variable `_end`.
9526
9588
  * @returns The value of the protected property `_end`.
@@ -9536,7 +9598,6 @@ var SegmentTreeNode = class {
9536
9598
  set end(value) {
9537
9599
  this._end = value;
9538
9600
  }
9539
- _value = void 0;
9540
9601
  /**
9541
9602
  * The function returns the value of a segment tree node.
9542
9603
  * @returns The value being returned is either a `SegmentTreeNodeVal` object or `undefined`.
@@ -9552,7 +9613,6 @@ var SegmentTreeNode = class {
9552
9613
  set value(value) {
9553
9614
  this._value = value;
9554
9615
  }
9555
- _sum = 0;
9556
9616
  /**
9557
9617
  * The function returns the value of the sum property.
9558
9618
  * @returns The method is returning the value of the variable `_sum`.
@@ -9567,7 +9627,6 @@ var SegmentTreeNode = class {
9567
9627
  set sum(value) {
9568
9628
  this._sum = value;
9569
9629
  }
9570
- _left = void 0;
9571
9630
  /**
9572
9631
  * The function returns the left child of a segment tree node.
9573
9632
  * @returns The `left` property of the `SegmentTreeNode` object is being returned. It is of type
@@ -9584,7 +9643,6 @@ var SegmentTreeNode = class {
9584
9643
  set left(value) {
9585
9644
  this._left = value;
9586
9645
  }
9587
- _right = void 0;
9588
9646
  /**
9589
9647
  * The function returns the right child of a segment tree node.
9590
9648
  * @returns The `getRight()` method is returning a value of type `SegmentTreeNode` or `undefined`.
@@ -9602,10 +9660,9 @@ var SegmentTreeNode = class {
9602
9660
  this._right = value;
9603
9661
  }
9604
9662
  };
9605
- var SegmentTree = class {
9606
- static {
9607
- __name(this, "SegmentTree");
9608
- }
9663
+ __name(_SegmentTreeNode, "SegmentTreeNode");
9664
+ var SegmentTreeNode = _SegmentTreeNode;
9665
+ var _SegmentTree = class _SegmentTree {
9609
9666
  /**
9610
9667
  * The constructor initializes the values, start, end, and root properties of an object.
9611
9668
  * @param {number[]} values - An array of numbers that will be used to build a binary search tree.
@@ -9616,6 +9673,10 @@ var SegmentTree = class {
9616
9673
  * included in the range. If not provided, it defaults to the index of the last element in the "values" array.
9617
9674
  */
9618
9675
  constructor(values, start, end) {
9676
+ __publicField(this, "_values", []);
9677
+ __publicField(this, "_start", 0);
9678
+ __publicField(this, "_end");
9679
+ __publicField(this, "_root");
9619
9680
  start = start || 0;
9620
9681
  end = end || values.length - 1;
9621
9682
  this._values = values;
@@ -9628,7 +9689,6 @@ var SegmentTree = class {
9628
9689
  this._values = [];
9629
9690
  }
9630
9691
  }
9631
- _values = [];
9632
9692
  /**
9633
9693
  * The function returns an array of numbers.
9634
9694
  * @returns An array of numbers is being returned.
@@ -9636,7 +9696,6 @@ var SegmentTree = class {
9636
9696
  get values() {
9637
9697
  return this._values;
9638
9698
  }
9639
- _start = 0;
9640
9699
  /**
9641
9700
  * The function returns the value of the protected variable _start.
9642
9701
  * @returns The start value, which is of type number.
@@ -9644,7 +9703,6 @@ var SegmentTree = class {
9644
9703
  get start() {
9645
9704
  return this._start;
9646
9705
  }
9647
- _end;
9648
9706
  /**
9649
9707
  * The function returns the value of the protected variable `_end`.
9650
9708
  * @returns The value of the protected property `_end`.
@@ -9652,7 +9710,6 @@ var SegmentTree = class {
9652
9710
  get end() {
9653
9711
  return this._end;
9654
9712
  }
9655
- _root;
9656
9713
  /**
9657
9714
  * The function returns the root node of a segment tree.
9658
9715
  * @returns The `root` property of the class `SegmentTreeNode` or `undefined` if it is not defined.
@@ -9767,13 +9824,11 @@ var SegmentTree = class {
9767
9824
  return dfs(root, indexA, indexB);
9768
9825
  }
9769
9826
  };
9827
+ __name(_SegmentTree, "SegmentTree");
9828
+ var SegmentTree = _SegmentTree;
9770
9829
 
9771
9830
  // src/data-structures/binary-tree/avl-tree.ts
9772
- var AVLTreeNode = class extends BSTNode {
9773
- static {
9774
- __name(this, "AVLTreeNode");
9775
- }
9776
- parent = void 0;
9831
+ var _AVLTreeNode = class _AVLTreeNode {
9777
9832
  /**
9778
9833
  * Creates an instance of AVLTreeNode.
9779
9834
  * @remarks Time O(1), Space O(1)
@@ -9782,9 +9837,17 @@ var AVLTreeNode = class extends BSTNode {
9782
9837
  * @param [value] - The value associated with the key.
9783
9838
  */
9784
9839
  constructor(key, value) {
9785
- super(key, value);
9840
+ __publicField(this, "key");
9841
+ __publicField(this, "value");
9842
+ __publicField(this, "parent");
9843
+ __publicField(this, "_left");
9844
+ __publicField(this, "_right");
9845
+ __publicField(this, "_height", 0);
9846
+ __publicField(this, "_color", "BLACK");
9847
+ __publicField(this, "_count", 1);
9848
+ this.key = key;
9849
+ this.value = value;
9786
9850
  }
9787
- _left = void 0;
9788
9851
  /**
9789
9852
  * Gets the left child of the node.
9790
9853
  * @remarks Time O(1), Space O(1)
@@ -9806,7 +9869,6 @@ var AVLTreeNode = class extends BSTNode {
9806
9869
  }
9807
9870
  this._left = v;
9808
9871
  }
9809
- _right = void 0;
9810
9872
  /**
9811
9873
  * Gets the right child of the node.
9812
9874
  * @remarks Time O(1), Space O(1)
@@ -9828,11 +9890,81 @@ var AVLTreeNode = class extends BSTNode {
9828
9890
  }
9829
9891
  this._right = v;
9830
9892
  }
9831
- };
9832
- var AVLTree = class extends BST {
9833
- static {
9834
- __name(this, "AVLTree");
9893
+ /**
9894
+ * Gets the height of the node (used in self-balancing trees).
9895
+ * @remarks Time O(1), Space O(1)
9896
+ *
9897
+ * @returns The height.
9898
+ */
9899
+ get height() {
9900
+ return this._height;
9901
+ }
9902
+ /**
9903
+ * Sets the height of the node.
9904
+ * @remarks Time O(1), Space O(1)
9905
+ *
9906
+ * @param value - The new height.
9907
+ */
9908
+ set height(value) {
9909
+ this._height = value;
9910
+ }
9911
+ /**
9912
+ * Gets the color of the node (used in Red-Black trees).
9913
+ * @remarks Time O(1), Space O(1)
9914
+ *
9915
+ * @returns The node's color.
9916
+ */
9917
+ get color() {
9918
+ return this._color;
9919
+ }
9920
+ /**
9921
+ * Sets the color of the node.
9922
+ * @remarks Time O(1), Space O(1)
9923
+ *
9924
+ * @param value - The new color.
9925
+ */
9926
+ set color(value) {
9927
+ this._color = value;
9928
+ }
9929
+ /**
9930
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
9931
+ * @remarks Time O(1), Space O(1)
9932
+ *
9933
+ * @returns The subtree node count.
9934
+ */
9935
+ get count() {
9936
+ return this._count;
9937
+ }
9938
+ /**
9939
+ * Sets the count of nodes in the subtree.
9940
+ * @remarks Time O(1), Space O(1)
9941
+ *
9942
+ * @param value - The new count.
9943
+ */
9944
+ set count(value) {
9945
+ this._count = value;
9946
+ }
9947
+ /**
9948
+ * Gets the position of the node relative to its parent.
9949
+ * @remarks Time O(1), Space O(1)
9950
+ *
9951
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
9952
+ */
9953
+ get familyPosition() {
9954
+ if (!this.parent) {
9955
+ return this.left || this.right ? "ROOT" : "ISOLATED";
9956
+ }
9957
+ if (this.parent.left === this) {
9958
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
9959
+ } else if (this.parent.right === this) {
9960
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
9961
+ }
9962
+ return "MAL_NODE";
9835
9963
  }
9964
+ };
9965
+ __name(_AVLTreeNode, "AVLTreeNode");
9966
+ var AVLTreeNode = _AVLTreeNode;
9967
+ var _AVLTree = class _AVLTree extends BST {
9836
9968
  /**
9837
9969
  * Creates an instance of AVLTree.
9838
9970
  * @remarks Time O(N log N) (from `addMany` with balanced add). Space O(N).
@@ -9852,7 +9984,7 @@ var AVLTree = class extends BST {
9852
9984
  * @param [value] - The value for the new node.
9853
9985
  * @returns The newly created AVLTreeNode.
9854
9986
  */
9855
- _createNode(key, value) {
9987
+ createNode(key, value) {
9856
9988
  return new AVLTreeNode(key, this._isMapMode ? void 0 : value);
9857
9989
  }
9858
9990
  /**
@@ -9955,7 +10087,7 @@ var AVLTree = class extends BST {
9955
10087
  */
9956
10088
  _createInstance(options) {
9957
10089
  const Ctor = this.constructor;
9958
- return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
10090
+ return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
9959
10091
  }
9960
10092
  /**
9961
10093
  * (Protected) Creates a new instance of the same AVLTree constructor, potentially with different generic types.
@@ -9968,7 +10100,7 @@ var AVLTree = class extends BST {
9968
10100
  */
9969
10101
  _createLike(iter = [], options) {
9970
10102
  const Ctor = this.constructor;
9971
- return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
10103
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
9972
10104
  }
9973
10105
  /**
9974
10106
  * (Protected) Swaps properties of two nodes, including height.
@@ -9983,7 +10115,7 @@ var AVLTree = class extends BST {
9983
10115
  const destNodeEnsured = this.ensureNode(destNode);
9984
10116
  if (srcNodeEnsured && destNodeEnsured) {
9985
10117
  const { key, value, height } = destNodeEnsured;
9986
- const tempNode = this._createNode(key, value);
10118
+ const tempNode = this.createNode(key, value);
9987
10119
  if (tempNode) {
9988
10120
  tempNode.height = height;
9989
10121
  destNodeEnsured.key = srcNodeEnsured.key;
@@ -10037,7 +10169,7 @@ var AVLTree = class extends BST {
10037
10169
  if (A === this.root) {
10038
10170
  if (B) this._setRoot(B);
10039
10171
  } else {
10040
- if (parentOfA?.left === A) {
10172
+ if ((parentOfA == null ? void 0 : parentOfA.left) === A) {
10041
10173
  parentOfA.left = B;
10042
10174
  } else {
10043
10175
  if (parentOfA) parentOfA.right = B;
@@ -10220,13 +10352,11 @@ var AVLTree = class extends BST {
10220
10352
  return super._replaceNode(oldNode, newNode);
10221
10353
  }
10222
10354
  };
10355
+ __name(_AVLTree, "AVLTree");
10356
+ var AVLTree = _AVLTree;
10223
10357
 
10224
10358
  // src/data-structures/binary-tree/red-black-tree.ts
10225
- var RedBlackTreeNode = class extends BSTNode {
10226
- static {
10227
- __name(this, "RedBlackTreeNode");
10228
- }
10229
- parent = void 0;
10359
+ var _RedBlackTreeNode = class _RedBlackTreeNode {
10230
10360
  /**
10231
10361
  * Create a Red-Black Tree and optionally bulk-insert items.
10232
10362
  * @remarks Time O(n log n), Space O(n)
@@ -10236,10 +10366,18 @@ var RedBlackTreeNode = class extends BSTNode {
10236
10366
  * @returns New RedBlackTree instance.
10237
10367
  */
10238
10368
  constructor(key, value, color = "BLACK") {
10239
- super(key, value);
10240
- this._color = color;
10369
+ __publicField(this, "key");
10370
+ __publicField(this, "value");
10371
+ __publicField(this, "parent");
10372
+ __publicField(this, "_left");
10373
+ __publicField(this, "_right");
10374
+ __publicField(this, "_height", 0);
10375
+ __publicField(this, "_color", "BLACK");
10376
+ __publicField(this, "_count", 1);
10377
+ this.key = key;
10378
+ this.value = value;
10379
+ this.color = color;
10241
10380
  }
10242
- _left = void 0;
10243
10381
  /**
10244
10382
  * Get the left child pointer.
10245
10383
  * @remarks Time O(1), Space O(1)
@@ -10260,7 +10398,6 @@ var RedBlackTreeNode = class extends BSTNode {
10260
10398
  }
10261
10399
  this._left = v;
10262
10400
  }
10263
- _right = void 0;
10264
10401
  /**
10265
10402
  * Get the right child pointer.
10266
10403
  * @remarks Time O(1), Space O(1)
@@ -10281,36 +10418,106 @@ var RedBlackTreeNode = class extends BSTNode {
10281
10418
  }
10282
10419
  this._right = v;
10283
10420
  }
10284
- };
10285
- var RedBlackTree = class extends BST {
10286
- static {
10287
- __name(this, "RedBlackTree");
10288
- }
10289
- constructor(keysNodesEntriesOrRaws = [], options) {
10290
- super([], options);
10291
- this._root = this.NIL;
10292
- if (keysNodesEntriesOrRaws) {
10293
- this.addMany(keysNodesEntriesOrRaws);
10294
- }
10295
- }
10296
- _root;
10297
10421
  /**
10298
- * Get the current root node.
10422
+ * Gets the height of the node (used in self-balancing trees).
10299
10423
  * @remarks Time O(1), Space O(1)
10300
- * @returns Root node, or undefined.
10424
+ *
10425
+ * @returns The height.
10301
10426
  */
10302
- get root() {
10303
- return this._root;
10427
+ get height() {
10428
+ return this._height;
10304
10429
  }
10305
10430
  /**
10306
- * Create a red-black node for the given key/value (value ignored in map mode).
10431
+ * Sets the height of the node.
10307
10432
  * @remarks Time O(1), Space O(1)
10308
- * @param key - See parameter type for details.
10309
- * @param [value] - See parameter type for details.
10433
+ *
10434
+ * @param value - The new height.
10435
+ */
10436
+ set height(value) {
10437
+ this._height = value;
10438
+ }
10439
+ /**
10440
+ * Gets the color of the node (used in Red-Black trees).
10441
+ * @remarks Time O(1), Space O(1)
10442
+ *
10443
+ * @returns The node's color.
10444
+ */
10445
+ get color() {
10446
+ return this._color;
10447
+ }
10448
+ /**
10449
+ * Sets the color of the node.
10450
+ * @remarks Time O(1), Space O(1)
10451
+ *
10452
+ * @param value - The new color.
10453
+ */
10454
+ set color(value) {
10455
+ this._color = value;
10456
+ }
10457
+ /**
10458
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
10459
+ * @remarks Time O(1), Space O(1)
10460
+ *
10461
+ * @returns The subtree node count.
10462
+ */
10463
+ get count() {
10464
+ return this._count;
10465
+ }
10466
+ /**
10467
+ * Sets the count of nodes in the subtree.
10468
+ * @remarks Time O(1), Space O(1)
10469
+ *
10470
+ * @param value - The new count.
10471
+ */
10472
+ set count(value) {
10473
+ this._count = value;
10474
+ }
10475
+ /**
10476
+ * Gets the position of the node relative to its parent.
10477
+ * @remarks Time O(1), Space O(1)
10478
+ *
10479
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
10480
+ */
10481
+ get familyPosition() {
10482
+ if (!this.parent) {
10483
+ return this.left || this.right ? "ROOT" : "ISOLATED";
10484
+ }
10485
+ if (this.parent.left === this) {
10486
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
10487
+ } else if (this.parent.right === this) {
10488
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
10489
+ }
10490
+ return "MAL_NODE";
10491
+ }
10492
+ };
10493
+ __name(_RedBlackTreeNode, "RedBlackTreeNode");
10494
+ var RedBlackTreeNode = _RedBlackTreeNode;
10495
+ var _RedBlackTree = class _RedBlackTree extends BST {
10496
+ constructor(keysNodesEntriesOrRaws = [], options) {
10497
+ super([], options);
10498
+ __publicField(this, "_root");
10499
+ this._root = this.NIL;
10500
+ if (keysNodesEntriesOrRaws) {
10501
+ this.addMany(keysNodesEntriesOrRaws);
10502
+ }
10503
+ }
10504
+ /**
10505
+ * Get the current root node.
10506
+ * @remarks Time O(1), Space O(1)
10507
+ * @returns Root node, or undefined.
10508
+ */
10509
+ get root() {
10510
+ return this._root;
10511
+ }
10512
+ /**
10513
+ * Create a red-black node for the given key/value (value ignored in map mode).
10514
+ * @remarks Time O(1), Space O(1)
10515
+ * @param key - See parameter type for details.
10516
+ * @param [value] - See parameter type for details.
10310
10517
  * @param color - See parameter type for details.
10311
10518
  * @returns A new RedBlackTreeNode instance.
10312
10519
  */
10313
- _createNode(key, value, color = "BLACK") {
10520
+ createNode(key, value, color = "BLACK") {
10314
10521
  return new RedBlackTreeNode(key, this._isMapMode ? void 0 : value, color);
10315
10522
  }
10316
10523
  /**
@@ -10438,11 +10645,11 @@ var RedBlackTree = class extends BST {
10438
10645
  }
10439
10646
  _createInstance(options) {
10440
10647
  const Ctor = this.constructor;
10441
- return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
10648
+ return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
10442
10649
  }
10443
10650
  _createLike(iter = [], options) {
10444
10651
  const Ctor = this.constructor;
10445
- return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
10652
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
10446
10653
  }
10447
10654
  _setRoot(v) {
10448
10655
  if (v) {
@@ -10461,15 +10668,16 @@ var RedBlackTree = class extends BST {
10461
10668
  * @returns Status string: 'CREATED' or 'UPDATED'.
10462
10669
  */
10463
10670
  _insert(node) {
10464
- let current = this.root;
10671
+ var _a, _b, _c;
10672
+ let current = (_a = this.root) != null ? _a : this.NIL;
10465
10673
  let parent = void 0;
10466
- while (this.isRealNode(current)) {
10674
+ while (current !== this.NIL) {
10467
10675
  parent = current;
10468
10676
  const compared = this._compare(node.key, current.key);
10469
10677
  if (compared < 0) {
10470
- current = current.left ?? this.NIL;
10678
+ current = (_b = current.left) != null ? _b : this.NIL;
10471
10679
  } else if (compared > 0) {
10472
- current = current.right ?? this.NIL;
10680
+ current = (_c = current.right) != null ? _c : this.NIL;
10473
10681
  } else {
10474
10682
  this._replaceNode(current, node);
10475
10683
  return "UPDATED";
@@ -10515,10 +10723,11 @@ var RedBlackTree = class extends BST {
10515
10723
  * @returns void
10516
10724
  */
10517
10725
  _insertFixup(z) {
10518
- while (z?.parent?.color === "RED") {
10519
- if (z.parent === z.parent.parent?.left) {
10726
+ var _a, _b, _c, _d, _e;
10727
+ while (((_a = z == null ? void 0 : z.parent) == null ? void 0 : _a.color) === "RED") {
10728
+ if (z.parent === ((_b = z.parent.parent) == null ? void 0 : _b.left)) {
10520
10729
  const y = z.parent.parent.right;
10521
- if (y?.color === "RED") {
10730
+ if ((y == null ? void 0 : y.color) === "RED") {
10522
10731
  z.parent.color = "BLACK";
10523
10732
  y.color = "BLACK";
10524
10733
  z.parent.parent.color = "RED";
@@ -10528,15 +10737,15 @@ var RedBlackTree = class extends BST {
10528
10737
  z = z.parent;
10529
10738
  this._leftRotate(z);
10530
10739
  }
10531
- if (z && this.isRealNode(z.parent) && this.isRealNode(z.parent.parent)) {
10740
+ if (z && z.parent && z.parent.parent) {
10532
10741
  z.parent.color = "BLACK";
10533
10742
  z.parent.parent.color = "RED";
10534
10743
  this._rightRotate(z.parent.parent);
10535
10744
  }
10536
10745
  }
10537
10746
  } else {
10538
- const y = z?.parent?.parent?.left ?? void 0;
10539
- if (y?.color === "RED") {
10747
+ 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;
10748
+ if ((y == null ? void 0 : y.color) === "RED") {
10540
10749
  z.parent.color = "BLACK";
10541
10750
  y.color = "BLACK";
10542
10751
  z.parent.parent.color = "RED";
@@ -10546,7 +10755,7 @@ var RedBlackTree = class extends BST {
10546
10755
  z = z.parent;
10547
10756
  this._rightRotate(z);
10548
10757
  }
10549
- if (z && this.isRealNode(z.parent) && this.isRealNode(z.parent.parent)) {
10758
+ if (z && z.parent && z.parent.parent) {
10550
10759
  z.parent.color = "BLACK";
10551
10760
  z.parent.parent.color = "RED";
10552
10761
  this._leftRotate(z.parent.parent);
@@ -10563,6 +10772,7 @@ var RedBlackTree = class extends BST {
10563
10772
  * @returns void
10564
10773
  */
10565
10774
  _deleteFixup(node) {
10775
+ var _a, _b, _c, _d;
10566
10776
  if (!node || node === this.root || node.color === "BLACK") {
10567
10777
  if (node) {
10568
10778
  node.color = "BLACK";
@@ -10576,17 +10786,17 @@ var RedBlackTree = class extends BST {
10576
10786
  }
10577
10787
  if (node === parent.left) {
10578
10788
  let sibling = parent.right;
10579
- if (sibling?.color === "RED") {
10789
+ if ((sibling == null ? void 0 : sibling.color) === "RED") {
10580
10790
  sibling.color = "BLACK";
10581
10791
  parent.color = "RED";
10582
10792
  this._leftRotate(parent);
10583
10793
  sibling = parent.right;
10584
10794
  }
10585
- if ((sibling?.left?.color ?? "BLACK") === "BLACK") {
10795
+ if (((_b = (_a = sibling == null ? void 0 : sibling.left) == null ? void 0 : _a.color) != null ? _b : "BLACK") === "BLACK") {
10586
10796
  if (sibling) sibling.color = "RED";
10587
10797
  node = parent;
10588
10798
  } else {
10589
- if (sibling?.left) sibling.left.color = "BLACK";
10799
+ if (sibling == null ? void 0 : sibling.left) sibling.left.color = "BLACK";
10590
10800
  if (sibling) sibling.color = parent.color;
10591
10801
  parent.color = "BLACK";
10592
10802
  this._rightRotate(parent);
@@ -10594,17 +10804,17 @@ var RedBlackTree = class extends BST {
10594
10804
  }
10595
10805
  } else {
10596
10806
  let sibling = parent.left;
10597
- if (sibling?.color === "RED") {
10807
+ if ((sibling == null ? void 0 : sibling.color) === "RED") {
10598
10808
  sibling.color = "BLACK";
10599
10809
  if (parent) parent.color = "RED";
10600
10810
  this._rightRotate(parent);
10601
10811
  if (parent) sibling = parent.left;
10602
10812
  }
10603
- if ((sibling?.right?.color ?? "BLACK") === "BLACK") {
10813
+ if (((_d = (_c = sibling == null ? void 0 : sibling.right) == null ? void 0 : _c.color) != null ? _d : "BLACK") === "BLACK") {
10604
10814
  if (sibling) sibling.color = "RED";
10605
10815
  node = parent;
10606
10816
  } else {
10607
- if (sibling?.right) sibling.right.color = "BLACK";
10817
+ if (sibling == null ? void 0 : sibling.right) sibling.right.color = "BLACK";
10608
10818
  if (sibling) sibling.color = parent.color;
10609
10819
  if (parent) parent.color = "BLACK";
10610
10820
  this._leftRotate(parent);
@@ -10628,7 +10838,7 @@ var RedBlackTree = class extends BST {
10628
10838
  }
10629
10839
  const y = x.right;
10630
10840
  x.right = y.left;
10631
- if (this.isRealNode(y.left)) {
10841
+ if (y.left && y.left !== this.NIL) {
10632
10842
  y.left.parent = x;
10633
10843
  }
10634
10844
  y.parent = x.parent;
@@ -10654,7 +10864,7 @@ var RedBlackTree = class extends BST {
10654
10864
  }
10655
10865
  const x = y.left;
10656
10866
  y.left = x.right;
10657
- if (this.isRealNode(x.right)) {
10867
+ if (x.right && x.right !== this.NIL) {
10658
10868
  x.right.parent = y;
10659
10869
  }
10660
10870
  x.parent = y.parent;
@@ -10669,13 +10879,11 @@ var RedBlackTree = class extends BST {
10669
10879
  y.parent = x;
10670
10880
  }
10671
10881
  };
10882
+ __name(_RedBlackTree, "RedBlackTree");
10883
+ var RedBlackTree = _RedBlackTree;
10672
10884
 
10673
10885
  // src/data-structures/binary-tree/avl-tree-multi-map.ts
10674
- var AVLTreeMultiMapNode = class extends AVLTreeNode {
10675
- static {
10676
- __name(this, "AVLTreeMultiMapNode");
10677
- }
10678
- parent = void 0;
10886
+ var _AVLTreeMultiMapNode = class _AVLTreeMultiMapNode {
10679
10887
  /**
10680
10888
  * Create an AVLTreeMultiMap node with a value bucket.
10681
10889
  * @remarks Time O(1), Space O(1)
@@ -10683,10 +10891,18 @@ var AVLTreeMultiMapNode = class extends AVLTreeNode {
10683
10891
  * @param value - Initial array of values.
10684
10892
  * @returns New AVLTreeMultiMapNode instance.
10685
10893
  */
10686
- constructor(key, value) {
10687
- super(key, value);
10894
+ constructor(key, value = []) {
10895
+ __publicField(this, "key");
10896
+ __publicField(this, "value");
10897
+ __publicField(this, "parent");
10898
+ __publicField(this, "_left");
10899
+ __publicField(this, "_right");
10900
+ __publicField(this, "_height", 0);
10901
+ __publicField(this, "_color", "BLACK");
10902
+ __publicField(this, "_count", 1);
10903
+ this.key = key;
10904
+ this.value = value;
10688
10905
  }
10689
- _left = void 0;
10690
10906
  /**
10691
10907
  * Get the left child pointer.
10692
10908
  * @remarks Time O(1), Space O(1)
@@ -10707,7 +10923,6 @@ var AVLTreeMultiMapNode = class extends AVLTreeNode {
10707
10923
  }
10708
10924
  this._left = v;
10709
10925
  }
10710
- _right = void 0;
10711
10926
  /**
10712
10927
  * Get the right child pointer.
10713
10928
  * @remarks Time O(1), Space O(1)
@@ -10728,11 +10943,81 @@ var AVLTreeMultiMapNode = class extends AVLTreeNode {
10728
10943
  }
10729
10944
  this._right = v;
10730
10945
  }
10731
- };
10732
- var AVLTreeMultiMap = class extends AVLTree {
10733
- static {
10734
- __name(this, "AVLTreeMultiMap");
10946
+ /**
10947
+ * Gets the height of the node (used in self-balancing trees).
10948
+ * @remarks Time O(1), Space O(1)
10949
+ *
10950
+ * @returns The height.
10951
+ */
10952
+ get height() {
10953
+ return this._height;
10735
10954
  }
10955
+ /**
10956
+ * Sets the height of the node.
10957
+ * @remarks Time O(1), Space O(1)
10958
+ *
10959
+ * @param value - The new height.
10960
+ */
10961
+ set height(value) {
10962
+ this._height = value;
10963
+ }
10964
+ /**
10965
+ * Gets the color of the node (used in Red-Black trees).
10966
+ * @remarks Time O(1), Space O(1)
10967
+ *
10968
+ * @returns The node's color.
10969
+ */
10970
+ get color() {
10971
+ return this._color;
10972
+ }
10973
+ /**
10974
+ * Sets the color of the node.
10975
+ * @remarks Time O(1), Space O(1)
10976
+ *
10977
+ * @param value - The new color.
10978
+ */
10979
+ set color(value) {
10980
+ this._color = value;
10981
+ }
10982
+ /**
10983
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
10984
+ * @remarks Time O(1), Space O(1)
10985
+ *
10986
+ * @returns The subtree node count.
10987
+ */
10988
+ get count() {
10989
+ return this._count;
10990
+ }
10991
+ /**
10992
+ * Sets the count of nodes in the subtree.
10993
+ * @remarks Time O(1), Space O(1)
10994
+ *
10995
+ * @param value - The new count.
10996
+ */
10997
+ set count(value) {
10998
+ this._count = value;
10999
+ }
11000
+ /**
11001
+ * Gets the position of the node relative to its parent.
11002
+ * @remarks Time O(1), Space O(1)
11003
+ *
11004
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
11005
+ */
11006
+ get familyPosition() {
11007
+ if (!this.parent) {
11008
+ return this.left || this.right ? "ROOT" : "ISOLATED";
11009
+ }
11010
+ if (this.parent.left === this) {
11011
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
11012
+ } else if (this.parent.right === this) {
11013
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
11014
+ }
11015
+ return "MAL_NODE";
11016
+ }
11017
+ };
11018
+ __name(_AVLTreeMultiMapNode, "AVLTreeMultiMapNode");
11019
+ var AVLTreeMultiMapNode = _AVLTreeMultiMapNode;
11020
+ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
10736
11021
  /**
10737
11022
  * Create an AVLTreeMultiMap and optionally bulk-insert items.
10738
11023
  * @remarks Time O(N log N), Space O(N)
@@ -10746,9 +11031,19 @@ var AVLTreeMultiMap = class extends AVLTree {
10746
11031
  this.addMany(keysNodesEntriesOrRaws);
10747
11032
  }
10748
11033
  }
10749
- _createNode(key, value = []) {
11034
+ createNode(key, value = []) {
10750
11035
  return new AVLTreeMultiMapNode(key, this._isMapMode ? [] : value);
10751
11036
  }
11037
+ /**
11038
+ * Checks if the given item is a `AVLTreeMultiMapNode` instance.
11039
+ * @remarks Time O(1), Space O(1)
11040
+ *
11041
+ * @param keyNodeOrEntry - The item to check.
11042
+ * @returns True if it's a AVLTreeMultiMapNode, false otherwise.
11043
+ */
11044
+ isNode(keyNodeOrEntry) {
11045
+ return keyNodeOrEntry instanceof AVLTreeMultiMapNode;
11046
+ }
10752
11047
  /**
10753
11048
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
10754
11049
  * @remarks Time O(log N + M), Space O(1)
@@ -10870,8 +11165,9 @@ var AVLTreeMultiMap = class extends AVLTree {
10870
11165
  * @returns An empty like-kind instance.
10871
11166
  */
10872
11167
  _createInstance(options) {
11168
+ var _a, _b;
10873
11169
  const Ctor = this.constructor;
10874
- return new Ctor([], { ...this._snapshotOptions?.() ?? {}, ...options ?? {} });
11170
+ return new Ctor([], { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
10875
11171
  }
10876
11172
  /**
10877
11173
  * (Protected) Create a like-kind instance and seed it from an iterable.
@@ -10884,17 +11180,16 @@ var AVLTreeMultiMap = class extends AVLTree {
10884
11180
  * @returns A like-kind AVLTree built from the iterable.
10885
11181
  */
10886
11182
  _createLike(iter = [], options) {
11183
+ var _a, _b;
10887
11184
  const Ctor = this.constructor;
10888
- return new Ctor(iter, { ...this._snapshotOptions?.() ?? {}, ...options ?? {} });
11185
+ return new Ctor(iter, { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
10889
11186
  }
10890
11187
  };
11188
+ __name(_AVLTreeMultiMap, "AVLTreeMultiMap");
11189
+ var AVLTreeMultiMap = _AVLTreeMultiMap;
10891
11190
 
10892
11191
  // src/data-structures/binary-tree/tree-multi-map.ts
10893
- var TreeMultiMapNode = class extends RedBlackTreeNode {
10894
- static {
10895
- __name(this, "TreeMultiMapNode");
10896
- }
10897
- parent = void 0;
11192
+ var _TreeMultiMapNode = class _TreeMultiMapNode {
10898
11193
  /**
10899
11194
  * Create a TreeMultiMap node with an optional value bucket.
10900
11195
  * @remarks Time O(1), Space O(1)
@@ -10902,10 +11197,19 @@ var TreeMultiMapNode = class extends RedBlackTreeNode {
10902
11197
  * @param [value] - Initial array of values.
10903
11198
  * @returns New TreeMultiMapNode instance.
10904
11199
  */
10905
- constructor(key, value) {
10906
- super(key, value);
11200
+ constructor(key, value = [], color = "BLACK") {
11201
+ __publicField(this, "key");
11202
+ __publicField(this, "value");
11203
+ __publicField(this, "parent");
11204
+ __publicField(this, "_left");
11205
+ __publicField(this, "_right");
11206
+ __publicField(this, "_height", 0);
11207
+ __publicField(this, "_color", "BLACK");
11208
+ __publicField(this, "_count", 1);
11209
+ this.key = key;
11210
+ this.value = value;
11211
+ this.color = color;
10907
11212
  }
10908
- _left = void 0;
10909
11213
  /**
10910
11214
  * Get the left child pointer.
10911
11215
  * @remarks Time O(1), Space O(1)
@@ -10926,7 +11230,6 @@ var TreeMultiMapNode = class extends RedBlackTreeNode {
10926
11230
  }
10927
11231
  this._left = v;
10928
11232
  }
10929
- _right = void 0;
10930
11233
  /**
10931
11234
  * Get the right child pointer.
10932
11235
  * @remarks Time O(1), Space O(1)
@@ -10947,11 +11250,81 @@ var TreeMultiMapNode = class extends RedBlackTreeNode {
10947
11250
  }
10948
11251
  this._right = v;
10949
11252
  }
10950
- };
10951
- var TreeMultiMap = class extends RedBlackTree {
10952
- static {
10953
- __name(this, "TreeMultiMap");
11253
+ /**
11254
+ * Gets the height of the node (used in self-balancing trees).
11255
+ * @remarks Time O(1), Space O(1)
11256
+ *
11257
+ * @returns The height.
11258
+ */
11259
+ get height() {
11260
+ return this._height;
10954
11261
  }
11262
+ /**
11263
+ * Sets the height of the node.
11264
+ * @remarks Time O(1), Space O(1)
11265
+ *
11266
+ * @param value - The new height.
11267
+ */
11268
+ set height(value) {
11269
+ this._height = value;
11270
+ }
11271
+ /**
11272
+ * Gets the color of the node (used in Red-Black trees).
11273
+ * @remarks Time O(1), Space O(1)
11274
+ *
11275
+ * @returns The node's color.
11276
+ */
11277
+ get color() {
11278
+ return this._color;
11279
+ }
11280
+ /**
11281
+ * Sets the color of the node.
11282
+ * @remarks Time O(1), Space O(1)
11283
+ *
11284
+ * @param value - The new color.
11285
+ */
11286
+ set color(value) {
11287
+ this._color = value;
11288
+ }
11289
+ /**
11290
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
11291
+ * @remarks Time O(1), Space O(1)
11292
+ *
11293
+ * @returns The subtree node count.
11294
+ */
11295
+ get count() {
11296
+ return this._count;
11297
+ }
11298
+ /**
11299
+ * Sets the count of nodes in the subtree.
11300
+ * @remarks Time O(1), Space O(1)
11301
+ *
11302
+ * @param value - The new count.
11303
+ */
11304
+ set count(value) {
11305
+ this._count = value;
11306
+ }
11307
+ /**
11308
+ * Gets the position of the node relative to its parent.
11309
+ * @remarks Time O(1), Space O(1)
11310
+ *
11311
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
11312
+ */
11313
+ get familyPosition() {
11314
+ if (!this.parent) {
11315
+ return this.left || this.right ? "ROOT" : "ISOLATED";
11316
+ }
11317
+ if (this.parent.left === this) {
11318
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
11319
+ } else if (this.parent.right === this) {
11320
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
11321
+ }
11322
+ return "MAL_NODE";
11323
+ }
11324
+ };
11325
+ __name(_TreeMultiMapNode, "TreeMultiMapNode");
11326
+ var TreeMultiMapNode = _TreeMultiMapNode;
11327
+ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
10955
11328
  /**
10956
11329
  * Create a TreeMultiMap and optionally bulk-insert items.
10957
11330
  * @remarks Time O(N log N), Space O(N)
@@ -10965,9 +11338,19 @@ var TreeMultiMap = class extends RedBlackTree {
10965
11338
  this.addMany(keysNodesEntriesOrRaws);
10966
11339
  }
10967
11340
  }
10968
- _createNode(key, value = []) {
11341
+ createNode(key, value = []) {
10969
11342
  return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
10970
11343
  }
11344
+ /**
11345
+ * Checks if the given item is a `TreeMultiMapNode` instance.
11346
+ * @remarks Time O(1), Space O(1)
11347
+ *
11348
+ * @param keyNodeOrEntry - The item to check.
11349
+ * @returns True if it's a TreeMultiMapNode, false otherwise.
11350
+ */
11351
+ isNode(keyNodeOrEntry) {
11352
+ return keyNodeOrEntry instanceof TreeMultiMapNode;
11353
+ }
10971
11354
  /**
10972
11355
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
10973
11356
  * @remarks Time O(log N + M), Space O(1)
@@ -11061,8 +11444,9 @@ var TreeMultiMap = class extends RedBlackTree {
11061
11444
  * @returns An empty like-kind instance.
11062
11445
  */
11063
11446
  _createInstance(options) {
11447
+ var _a, _b;
11064
11448
  const Ctor = this.constructor;
11065
- return new Ctor([], { ...this._snapshotOptions?.() ?? {}, ...options ?? {} });
11449
+ return new Ctor([], { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
11066
11450
  }
11067
11451
  /**
11068
11452
  * (Protected) Create a like-kind instance and seed it from an iterable.
@@ -11075,17 +11459,16 @@ var TreeMultiMap = class extends RedBlackTree {
11075
11459
  * @returns A like-kind RedBlackTree built from the iterable.
11076
11460
  */
11077
11461
  _createLike(iter = [], options) {
11462
+ var _a, _b;
11078
11463
  const Ctor = this.constructor;
11079
- return new Ctor(iter, { ...this._snapshotOptions?.() ?? {}, ...options ?? {} });
11464
+ return new Ctor(iter, { ...(_b = (_a = this._snapshotOptions) == null ? void 0 : _a.call(this)) != null ? _b : {}, ...options != null ? options : {} });
11080
11465
  }
11081
11466
  };
11467
+ __name(_TreeMultiMap, "TreeMultiMap");
11468
+ var TreeMultiMap = _TreeMultiMap;
11082
11469
 
11083
11470
  // src/data-structures/binary-tree/tree-counter.ts
11084
- var TreeCounterNode = class extends RedBlackTreeNode {
11085
- static {
11086
- __name(this, "TreeCounterNode");
11087
- }
11088
- parent = void 0;
11471
+ var _TreeCounterNode = class _TreeCounterNode {
11089
11472
  /**
11090
11473
  * Create a tree counter node.
11091
11474
  * @remarks Time O(1), Space O(1)
@@ -11096,10 +11479,19 @@ var TreeCounterNode = class extends RedBlackTreeNode {
11096
11479
  * @returns New TreeCounterNode instance.
11097
11480
  */
11098
11481
  constructor(key, value, count = 1, color = "BLACK") {
11099
- super(key, value, color);
11482
+ __publicField(this, "key");
11483
+ __publicField(this, "value");
11484
+ __publicField(this, "parent");
11485
+ __publicField(this, "_left");
11486
+ __publicField(this, "_right");
11487
+ __publicField(this, "_height", 0);
11488
+ __publicField(this, "_color", "BLACK");
11489
+ __publicField(this, "_count", 1);
11490
+ this.key = key;
11491
+ this.value = value;
11492
+ this.color = color;
11100
11493
  this.count = count;
11101
11494
  }
11102
- _left = void 0;
11103
11495
  /**
11104
11496
  * Get the left child pointer.
11105
11497
  * @remarks Time O(1), Space O(1)
@@ -11120,7 +11512,6 @@ var TreeCounterNode = class extends RedBlackTreeNode {
11120
11512
  }
11121
11513
  this._left = v;
11122
11514
  }
11123
- _right = void 0;
11124
11515
  /**
11125
11516
  * Get the right child pointer.
11126
11517
  * @remarks Time O(1), Space O(1)
@@ -11141,11 +11532,81 @@ var TreeCounterNode = class extends RedBlackTreeNode {
11141
11532
  }
11142
11533
  this._right = v;
11143
11534
  }
11144
- };
11145
- var TreeCounter = class extends RedBlackTree {
11146
- static {
11147
- __name(this, "TreeCounter");
11535
+ /**
11536
+ * Gets the height of the node (used in self-balancing trees).
11537
+ * @remarks Time O(1), Space O(1)
11538
+ *
11539
+ * @returns The height.
11540
+ */
11541
+ get height() {
11542
+ return this._height;
11543
+ }
11544
+ /**
11545
+ * Sets the height of the node.
11546
+ * @remarks Time O(1), Space O(1)
11547
+ *
11548
+ * @param value - The new height.
11549
+ */
11550
+ set height(value) {
11551
+ this._height = value;
11552
+ }
11553
+ /**
11554
+ * Gets the color of the node (used in Red-Black trees).
11555
+ * @remarks Time O(1), Space O(1)
11556
+ *
11557
+ * @returns The node's color.
11558
+ */
11559
+ get color() {
11560
+ return this._color;
11561
+ }
11562
+ /**
11563
+ * Sets the color of the node.
11564
+ * @remarks Time O(1), Space O(1)
11565
+ *
11566
+ * @param value - The new color.
11567
+ */
11568
+ set color(value) {
11569
+ this._color = value;
11570
+ }
11571
+ /**
11572
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
11573
+ * @remarks Time O(1), Space O(1)
11574
+ *
11575
+ * @returns The subtree node count.
11576
+ */
11577
+ get count() {
11578
+ return this._count;
11579
+ }
11580
+ /**
11581
+ * Sets the count of nodes in the subtree.
11582
+ * @remarks Time O(1), Space O(1)
11583
+ *
11584
+ * @param value - The new count.
11585
+ */
11586
+ set count(value) {
11587
+ this._count = value;
11588
+ }
11589
+ /**
11590
+ * Gets the position of the node relative to its parent.
11591
+ * @remarks Time O(1), Space O(1)
11592
+ *
11593
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
11594
+ */
11595
+ get familyPosition() {
11596
+ if (!this.parent) {
11597
+ return this.left || this.right ? "ROOT" : "ISOLATED";
11598
+ }
11599
+ if (this.parent.left === this) {
11600
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
11601
+ } else if (this.parent.right === this) {
11602
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
11603
+ }
11604
+ return "MAL_NODE";
11148
11605
  }
11606
+ };
11607
+ __name(_TreeCounterNode, "TreeCounterNode");
11608
+ var TreeCounterNode = _TreeCounterNode;
11609
+ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11149
11610
  /**
11150
11611
  * Create a TreeCounter and optionally bulk-insert items.
11151
11612
  * @remarks Time O(N log N), Space O(N)
@@ -11155,9 +11616,9 @@ var TreeCounter = class extends RedBlackTree {
11155
11616
  */
11156
11617
  constructor(keysNodesEntriesOrRaws = [], options) {
11157
11618
  super([], options);
11619
+ __publicField(this, "_count", 0);
11158
11620
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
11159
11621
  }
11160
- _count = 0;
11161
11622
  /**
11162
11623
  * Get the total aggregate count across all nodes.
11163
11624
  * @remarks Time O(1), Space O(1)
@@ -11176,7 +11637,7 @@ var TreeCounter = class extends RedBlackTree {
11176
11637
  this.dfs((node) => sum += node ? node.count : 0);
11177
11638
  return sum;
11178
11639
  }
11179
- _createNode(key, value, color = "BLACK", count) {
11640
+ createNode(key, value, color = "BLACK", count) {
11180
11641
  return new TreeCounterNode(key, this._isMapMode ? void 0 : value, count, color);
11181
11642
  }
11182
11643
  /**
@@ -11197,7 +11658,7 @@ var TreeCounter = class extends RedBlackTree {
11197
11658
  */
11198
11659
  add(keyNodeOrEntry, value, count = 1) {
11199
11660
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
11200
- const orgCount = newNode?.count || 0;
11661
+ const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
11201
11662
  const isSuccessAdded = super.add(newNode, newValue);
11202
11663
  if (isSuccessAdded) {
11203
11664
  this._count += orgCount;
@@ -11377,7 +11838,7 @@ var TreeCounter = class extends RedBlackTree {
11377
11838
  */
11378
11839
  _createInstance(options) {
11379
11840
  const Ctor = this.constructor;
11380
- return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
11841
+ return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
11381
11842
  }
11382
11843
  /**
11383
11844
  * (Protected) Create a like-kind instance and seed it from an iterable.
@@ -11393,7 +11854,7 @@ var TreeCounter = class extends RedBlackTree {
11393
11854
  const Ctor = this.constructor;
11394
11855
  return new Ctor(iter, {
11395
11856
  ...this._snapshotOptions(),
11396
- ...options ?? {}
11857
+ ...options != null ? options : {}
11397
11858
  });
11398
11859
  }
11399
11860
  /**
@@ -11410,10 +11871,10 @@ var TreeCounter = class extends RedBlackTree {
11410
11871
  if (this.isEntry(keyNodeOrEntry)) {
11411
11872
  const [key, entryValue] = keyNodeOrEntry;
11412
11873
  if (key === void 0 || key === null) return [void 0, void 0];
11413
- const finalValue = value ?? entryValue;
11414
- return [this._createNode(key, finalValue, "BLACK", count), finalValue];
11874
+ const finalValue = value != null ? value : entryValue;
11875
+ return [this.createNode(key, finalValue, "BLACK", count), finalValue];
11415
11876
  }
11416
- return [this._createNode(keyNodeOrEntry, value, "BLACK", count), value];
11877
+ return [this.createNode(keyNodeOrEntry, value, "BLACK", count), value];
11417
11878
  }
11418
11879
  /**
11419
11880
  * (Protected) Swap keys/values/counters between the source and destination nodes.
@@ -11427,7 +11888,7 @@ var TreeCounter = class extends RedBlackTree {
11427
11888
  destNode = this.ensureNode(destNode);
11428
11889
  if (srcNode && destNode) {
11429
11890
  const { key, value, count, color } = destNode;
11430
- const tempNode = this._createNode(key, value, color, count);
11891
+ const tempNode = this.createNode(key, value, color, count);
11431
11892
  if (tempNode) {
11432
11893
  tempNode.color = color;
11433
11894
  destNode.key = srcNode.key;
@@ -11455,13 +11916,11 @@ var TreeCounter = class extends RedBlackTree {
11455
11916
  return super._replaceNode(oldNode, newNode);
11456
11917
  }
11457
11918
  };
11919
+ __name(_TreeCounter, "TreeCounter");
11920
+ var TreeCounter = _TreeCounter;
11458
11921
 
11459
11922
  // src/data-structures/binary-tree/avl-tree-counter.ts
11460
- var AVLTreeCounterNode = class extends AVLTreeNode {
11461
- static {
11462
- __name(this, "AVLTreeCounterNode");
11463
- }
11464
- parent = void 0;
11923
+ var _AVLTreeCounterNode = class _AVLTreeCounterNode {
11465
11924
  /**
11466
11925
  * Create an AVL counter node.
11467
11926
  * @remarks Time O(1), Space O(1)
@@ -11471,10 +11930,18 @@ var AVLTreeCounterNode = class extends AVLTreeNode {
11471
11930
  * @returns New AVLTreeCounterNode instance.
11472
11931
  */
11473
11932
  constructor(key, value, count = 1) {
11474
- super(key, value);
11933
+ __publicField(this, "key");
11934
+ __publicField(this, "value");
11935
+ __publicField(this, "parent");
11936
+ __publicField(this, "_left");
11937
+ __publicField(this, "_right");
11938
+ __publicField(this, "_height", 0);
11939
+ __publicField(this, "_color", "BLACK");
11940
+ __publicField(this, "_count", 1);
11941
+ this.key = key;
11942
+ this.value = value;
11475
11943
  this.count = count;
11476
11944
  }
11477
- _left = void 0;
11478
11945
  /**
11479
11946
  * Get the left child pointer.
11480
11947
  * @remarks Time O(1), Space O(1)
@@ -11495,7 +11962,6 @@ var AVLTreeCounterNode = class extends AVLTreeNode {
11495
11962
  }
11496
11963
  this._left = v;
11497
11964
  }
11498
- _right = void 0;
11499
11965
  /**
11500
11966
  * Get the right child pointer.
11501
11967
  * @remarks Time O(1), Space O(1)
@@ -11516,11 +11982,81 @@ var AVLTreeCounterNode = class extends AVLTreeNode {
11516
11982
  }
11517
11983
  this._right = v;
11518
11984
  }
11519
- };
11520
- var AVLTreeCounter = class extends AVLTree {
11521
- static {
11522
- __name(this, "AVLTreeCounter");
11985
+ /**
11986
+ * Gets the height of the node (used in self-balancing trees).
11987
+ * @remarks Time O(1), Space O(1)
11988
+ *
11989
+ * @returns The height.
11990
+ */
11991
+ get height() {
11992
+ return this._height;
11993
+ }
11994
+ /**
11995
+ * Sets the height of the node.
11996
+ * @remarks Time O(1), Space O(1)
11997
+ *
11998
+ * @param value - The new height.
11999
+ */
12000
+ set height(value) {
12001
+ this._height = value;
12002
+ }
12003
+ /**
12004
+ * Gets the color of the node (used in Red-Black trees).
12005
+ * @remarks Time O(1), Space O(1)
12006
+ *
12007
+ * @returns The node's color.
12008
+ */
12009
+ get color() {
12010
+ return this._color;
12011
+ }
12012
+ /**
12013
+ * Sets the color of the node.
12014
+ * @remarks Time O(1), Space O(1)
12015
+ *
12016
+ * @param value - The new color.
12017
+ */
12018
+ set color(value) {
12019
+ this._color = value;
12020
+ }
12021
+ /**
12022
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
12023
+ * @remarks Time O(1), Space O(1)
12024
+ *
12025
+ * @returns The subtree node count.
12026
+ */
12027
+ get count() {
12028
+ return this._count;
11523
12029
  }
12030
+ /**
12031
+ * Sets the count of nodes in the subtree.
12032
+ * @remarks Time O(1), Space O(1)
12033
+ *
12034
+ * @param value - The new count.
12035
+ */
12036
+ set count(value) {
12037
+ this._count = value;
12038
+ }
12039
+ /**
12040
+ * Gets the position of the node relative to its parent.
12041
+ * @remarks Time O(1), Space O(1)
12042
+ *
12043
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
12044
+ */
12045
+ get familyPosition() {
12046
+ if (!this.parent) {
12047
+ return this.left || this.right ? "ROOT" : "ISOLATED";
12048
+ }
12049
+ if (this.parent.left === this) {
12050
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
12051
+ } else if (this.parent.right === this) {
12052
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
12053
+ }
12054
+ return "MAL_NODE";
12055
+ }
12056
+ };
12057
+ __name(_AVLTreeCounterNode, "AVLTreeCounterNode");
12058
+ var AVLTreeCounterNode = _AVLTreeCounterNode;
12059
+ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11524
12060
  /**
11525
12061
  * Create a AVLTreeCounter instance
11526
12062
  * @remarks Time O(n), Space O(n)
@@ -11530,9 +12066,9 @@ var AVLTreeCounter = class extends AVLTree {
11530
12066
  */
11531
12067
  constructor(keysNodesEntriesOrRaws = [], options) {
11532
12068
  super([], options);
12069
+ __publicField(this, "_count", 0);
11533
12070
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
11534
12071
  }
11535
- _count = 0;
11536
12072
  get count() {
11537
12073
  return this._count;
11538
12074
  }
@@ -11546,7 +12082,7 @@ var AVLTreeCounter = class extends AVLTree {
11546
12082
  this.dfs((node) => sum += node.count);
11547
12083
  return sum;
11548
12084
  }
11549
- _createNode(key, value, count) {
12085
+ createNode(key, value, count) {
11550
12086
  return new AVLTreeCounterNode(key, this._isMapMode ? void 0 : value, count);
11551
12087
  }
11552
12088
  /**
@@ -11568,7 +12104,7 @@ var AVLTreeCounter = class extends AVLTree {
11568
12104
  add(keyNodeOrEntry, value, count = 1) {
11569
12105
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
11570
12106
  if (newNode === void 0) return false;
11571
- const orgNodeCount = newNode?.count || 0;
12107
+ const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
11572
12108
  const inserted = super.add(newNode, newValue);
11573
12109
  if (inserted) {
11574
12110
  this._count += orgNodeCount;
@@ -11583,11 +12119,12 @@ var AVLTreeCounter = class extends AVLTree {
11583
12119
  * @returns Array of deletion results including deleted node and a rebalance hint when present.
11584
12120
  */
11585
12121
  delete(keyNodeOrEntry, ignoreCount = false) {
12122
+ var _a;
11586
12123
  const deletedResult = [];
11587
12124
  if (!this.root) return deletedResult;
11588
- const curr = this.getNode(keyNodeOrEntry) ?? void 0;
12125
+ const curr = (_a = this.getNode(keyNodeOrEntry)) != null ? _a : void 0;
11589
12126
  if (!curr) return deletedResult;
11590
- const parent = curr?.parent ? curr.parent : void 0;
12127
+ const parent = (curr == null ? void 0 : curr.parent) ? curr.parent : void 0;
11591
12128
  let needBalanced = void 0, orgCurrent = curr;
11592
12129
  if (curr.count > 1 && !ignoreCount) {
11593
12130
  curr.count--;
@@ -11714,7 +12251,7 @@ var AVLTreeCounter = class extends AVLTree {
11714
12251
  */
11715
12252
  _createInstance(options) {
11716
12253
  const Ctor = this.constructor;
11717
- return new Ctor([], { ...this._snapshotOptions(), ...options ?? {} });
12254
+ return new Ctor([], { ...this._snapshotOptions(), ...options != null ? options : {} });
11718
12255
  }
11719
12256
  /**
11720
12257
  * (Protected) Create a like-kind instance and seed it from an iterable.
@@ -11728,7 +12265,7 @@ var AVLTreeCounter = class extends AVLTree {
11728
12265
  */
11729
12266
  _createLike(iter = [], options) {
11730
12267
  const Ctor = this.constructor;
11731
- return new Ctor(iter, { ...this._snapshotOptions(), ...options ?? {} });
12268
+ return new Ctor(iter, { ...this._snapshotOptions(), ...options != null ? options : {} });
11732
12269
  }
11733
12270
  /**
11734
12271
  * (Protected) Normalize input into a node plus its effective value and count.
@@ -11744,10 +12281,10 @@ var AVLTreeCounter = class extends AVLTree {
11744
12281
  if (this.isEntry(keyNodeOrEntry)) {
11745
12282
  const [key, entryValue] = keyNodeOrEntry;
11746
12283
  if (key === void 0 || key === null) return [void 0, void 0];
11747
- const finalValue = value ?? entryValue;
11748
- return [this._createNode(key, finalValue, count), finalValue];
12284
+ const finalValue = value != null ? value : entryValue;
12285
+ return [this.createNode(key, finalValue, count), finalValue];
11749
12286
  }
11750
- return [this._createNode(keyNodeOrEntry, value, count), value];
12287
+ return [this.createNode(keyNodeOrEntry, value, count), value];
11751
12288
  }
11752
12289
  /**
11753
12290
  * (Protected) Swap keys/values/counters between the source and destination nodes.
@@ -11761,7 +12298,7 @@ var AVLTreeCounter = class extends AVLTree {
11761
12298
  destNode = this.ensureNode(destNode);
11762
12299
  if (srcNode && destNode) {
11763
12300
  const { key, value, count, height } = destNode;
11764
- const tempNode = this._createNode(key, value, count);
12301
+ const tempNode = this.createNode(key, value, count);
11765
12302
  if (tempNode) {
11766
12303
  tempNode.height = height;
11767
12304
  destNode.key = srcNode.key;
@@ -11789,22 +12326,20 @@ var AVLTreeCounter = class extends AVLTree {
11789
12326
  return super._replaceNode(oldNode, newNode);
11790
12327
  }
11791
12328
  };
12329
+ __name(_AVLTreeCounter, "AVLTreeCounter");
12330
+ var AVLTreeCounter = _AVLTreeCounter;
11792
12331
 
11793
12332
  // src/data-structures/priority-queue/priority-queue.ts
11794
- var PriorityQueue = class extends Heap {
11795
- static {
11796
- __name(this, "PriorityQueue");
11797
- }
12333
+ var _PriorityQueue = class _PriorityQueue extends Heap {
11798
12334
  constructor(elements = [], options) {
11799
12335
  super(elements, options);
11800
12336
  }
11801
12337
  };
12338
+ __name(_PriorityQueue, "PriorityQueue");
12339
+ var PriorityQueue = _PriorityQueue;
11802
12340
 
11803
12341
  // src/data-structures/priority-queue/min-priority-queue.ts
11804
- var MinPriorityQueue = class extends PriorityQueue {
11805
- static {
11806
- __name(this, "MinPriorityQueue");
11807
- }
12342
+ var _MinPriorityQueue = class _MinPriorityQueue extends PriorityQueue {
11808
12343
  /**
11809
12344
  * Creates a min-priority queue.
11810
12345
  * @param elements Optional initial elements to insert.
@@ -11815,12 +12350,11 @@ var MinPriorityQueue = class extends PriorityQueue {
11815
12350
  super(elements, options);
11816
12351
  }
11817
12352
  };
12353
+ __name(_MinPriorityQueue, "MinPriorityQueue");
12354
+ var MinPriorityQueue = _MinPriorityQueue;
11818
12355
 
11819
12356
  // src/data-structures/priority-queue/max-priority-queue.ts
11820
- var MaxPriorityQueue = class extends PriorityQueue {
11821
- static {
11822
- __name(this, "MaxPriorityQueue");
11823
- }
12357
+ var _MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
11824
12358
  /**
11825
12359
  * Creates a max-priority queue.
11826
12360
  * @param elements Optional initial elements to insert.
@@ -11844,12 +12378,11 @@ var MaxPriorityQueue = class extends PriorityQueue {
11844
12378
  });
11845
12379
  }
11846
12380
  };
12381
+ __name(_MaxPriorityQueue, "MaxPriorityQueue");
12382
+ var MaxPriorityQueue = _MaxPriorityQueue;
11847
12383
 
11848
12384
  // src/data-structures/matrix/matrix.ts
11849
- var Matrix = class _Matrix {
11850
- static {
11851
- __name(this, "Matrix");
11852
- }
12385
+ var _Matrix = class _Matrix {
11853
12386
  /**
11854
12387
  * The constructor function initializes a matrix object with the provided data and options, or with
11855
12388
  * default values if no options are provided.
@@ -11858,18 +12391,22 @@ var Matrix = class _Matrix {
11858
12391
  * properties:
11859
12392
  */
11860
12393
  constructor(data, options) {
12394
+ __publicField(this, "_rows", 0);
12395
+ __publicField(this, "_cols", 0);
12396
+ __publicField(this, "_data");
12397
+ var _a, _b, _c;
11861
12398
  if (options) {
11862
12399
  const { rows, cols, addFn, subtractFn, multiplyFn } = options;
11863
12400
  if (typeof rows === "number" && rows > 0) this._rows = rows;
11864
12401
  else this._rows = data.length;
11865
12402
  if (typeof cols === "number" && cols > 0) this._cols = cols;
11866
- else this._cols = data[0]?.length || 0;
12403
+ else this._cols = ((_a = data[0]) == null ? void 0 : _a.length) || 0;
11867
12404
  if (addFn) this._addFn = addFn;
11868
12405
  if (subtractFn) this._subtractFn = subtractFn;
11869
12406
  if (multiplyFn) this._multiplyFn = multiplyFn;
11870
12407
  } else {
11871
12408
  this._rows = data.length;
11872
- this._cols = data[0]?.length ?? 0;
12409
+ this._cols = (_c = (_b = data[0]) == null ? void 0 : _b.length) != null ? _c : 0;
11873
12410
  }
11874
12411
  if (data.length > 0) {
11875
12412
  this._data = data;
@@ -11880,7 +12417,6 @@ var Matrix = class _Matrix {
11880
12417
  }
11881
12418
  }
11882
12419
  }
11883
- _rows = 0;
11884
12420
  /**
11885
12421
  * The function returns the number of rows.
11886
12422
  * @returns The number of rows.
@@ -11888,7 +12424,6 @@ var Matrix = class _Matrix {
11888
12424
  get rows() {
11889
12425
  return this._rows;
11890
12426
  }
11891
- _cols = 0;
11892
12427
  /**
11893
12428
  * The function returns the value of the protected variable _cols.
11894
12429
  * @returns The number of columns.
@@ -11896,7 +12431,6 @@ var Matrix = class _Matrix {
11896
12431
  get cols() {
11897
12432
  return this._cols;
11898
12433
  }
11899
- _data;
11900
12434
  /**
11901
12435
  * The function returns a two-dimensional array of numbers.
11902
12436
  * @returns The data property, which is a two-dimensional array of numbers.
@@ -12095,6 +12629,7 @@ var Matrix = class _Matrix {
12095
12629
  * @returns a Matrix object, which represents the inverse of the original matrix.
12096
12630
  */
12097
12631
  inverse() {
12632
+ var _a;
12098
12633
  if (this.rows !== this.cols) {
12099
12634
  throw new Error("Matrix must be square for inversion.");
12100
12635
  }
@@ -12121,7 +12656,7 @@ var Matrix = class _Matrix {
12121
12656
  throw new Error("Matrix is singular, and its inverse does not exist.");
12122
12657
  }
12123
12658
  augmentedMatrix._swapRows(i, pivotRow);
12124
- const pivotElement = augmentedMatrix.get(i, i) ?? 1;
12659
+ const pivotElement = (_a = augmentedMatrix.get(i, i)) != null ? _a : 1;
12125
12660
  if (pivotElement === 0) {
12126
12661
  throw new Error("Matrix is singular, and its inverse does not exist (division by zero).");
12127
12662
  }
@@ -12264,14 +12799,11 @@ var Matrix = class _Matrix {
12264
12799
  }
12265
12800
  }
12266
12801
  };
12802
+ __name(_Matrix, "Matrix");
12803
+ var Matrix = _Matrix;
12267
12804
 
12268
12805
  // src/data-structures/matrix/navigator.ts
12269
- var Character = class _Character {
12270
- static {
12271
- __name(this, "Character");
12272
- }
12273
- direction;
12274
- turn;
12806
+ var _Character = class _Character {
12275
12807
  /**
12276
12808
  * The constructor function takes in a direction and turning object and sets the direction and turn properties of the
12277
12809
  * Character class.
@@ -12281,25 +12813,26 @@ var Character = class _Character {
12281
12813
  * turning direction. It is used to determine the new direction when the character turns.
12282
12814
  */
12283
12815
  constructor(direction, turning) {
12816
+ __publicField(this, "direction");
12817
+ __publicField(this, "turn");
12284
12818
  this.direction = direction;
12285
12819
  this.turn = () => new _Character(turning[direction], turning);
12286
12820
  }
12287
12821
  };
12288
- var Navigator = class {
12289
- static {
12290
- __name(this, "Navigator");
12291
- }
12292
- onMove;
12293
- _matrix;
12294
- _cur;
12295
- _character;
12296
- _VISITED;
12822
+ __name(_Character, "Character");
12823
+ var Character = _Character;
12824
+ var _Navigator = class _Navigator {
12297
12825
  /**
12298
12826
  * The constructor initializes the Navigator object with the given parameters and sets the current position as visited
12299
12827
  * in the matrix.
12300
12828
  * @param - - `matrix`: a 2D array representing the grid or map
12301
12829
  */
12302
12830
  constructor({ matrix, turning, onMove, init: { cur, charDir, VISITED } }) {
12831
+ __publicField(this, "onMove");
12832
+ __publicField(this, "_matrix");
12833
+ __publicField(this, "_cur");
12834
+ __publicField(this, "_character");
12835
+ __publicField(this, "_VISITED");
12303
12836
  this._matrix = matrix;
12304
12837
  this._cur = cur;
12305
12838
  this._character = new Character(charDir, turning);
@@ -12377,23 +12910,24 @@ var Navigator = class {
12377
12910
  if (this.onMove) this.onMove(this._cur);
12378
12911
  }
12379
12912
  };
12913
+ __name(_Navigator, "Navigator");
12914
+ var Navigator = _Navigator;
12380
12915
 
12381
12916
  // src/data-structures/trie/trie.ts
12382
- var TrieNode = class {
12383
- static {
12384
- __name(this, "TrieNode");
12385
- }
12917
+ var _TrieNode = class _TrieNode {
12386
12918
  /**
12387
12919
  * Create a Trie node with a character key.
12388
12920
  * @remarks Time O(1), Space O(1)
12389
12921
  * @returns New TrieNode instance.
12390
12922
  */
12391
12923
  constructor(key) {
12924
+ __publicField(this, "_key");
12925
+ __publicField(this, "_children");
12926
+ __publicField(this, "_isEnd");
12392
12927
  this._key = key;
12393
12928
  this._isEnd = false;
12394
12929
  this._children = /* @__PURE__ */ new Map();
12395
12930
  }
12396
- _key;
12397
12931
  /**
12398
12932
  * Get the character key of this node.
12399
12933
  * @remarks Time O(1), Space O(1)
@@ -12411,7 +12945,6 @@ var TrieNode = class {
12411
12945
  set key(value) {
12412
12946
  this._key = value;
12413
12947
  }
12414
- _children;
12415
12948
  /**
12416
12949
  * Get the child map of this node.
12417
12950
  * @remarks Time O(1), Space O(1)
@@ -12429,7 +12962,6 @@ var TrieNode = class {
12429
12962
  set children(value) {
12430
12963
  this._children = value;
12431
12964
  }
12432
- _isEnd;
12433
12965
  /**
12434
12966
  * Check whether this node marks the end of a word.
12435
12967
  * @remarks Time O(1), Space O(1)
@@ -12448,10 +12980,9 @@ var TrieNode = class {
12448
12980
  this._isEnd = value;
12449
12981
  }
12450
12982
  };
12451
- var Trie = class extends IterableElementBase {
12452
- static {
12453
- __name(this, "Trie");
12454
- }
12983
+ __name(_TrieNode, "TrieNode");
12984
+ var TrieNode = _TrieNode;
12985
+ var _Trie = class _Trie extends IterableElementBase {
12455
12986
  /**
12456
12987
  * Create a Trie and optionally bulk-insert words.
12457
12988
  * @remarks Time O(totalChars), Space O(totalChars)
@@ -12461,6 +12992,9 @@ var Trie = class extends IterableElementBase {
12461
12992
  */
12462
12993
  constructor(words = [], options) {
12463
12994
  super(options);
12995
+ __publicField(this, "_size", 0);
12996
+ __publicField(this, "_caseSensitive", true);
12997
+ __publicField(this, "_root", new TrieNode(""));
12464
12998
  if (options) {
12465
12999
  const { caseSensitive } = options;
12466
13000
  if (caseSensitive !== void 0) this._caseSensitive = caseSensitive;
@@ -12469,7 +13003,6 @@ var Trie = class extends IterableElementBase {
12469
13003
  this.addMany(words);
12470
13004
  }
12471
13005
  }
12472
- _size = 0;
12473
13006
  /**
12474
13007
  * Get the number of stored words.
12475
13008
  * @remarks Time O(1), Space O(1)
@@ -12478,7 +13011,6 @@ var Trie = class extends IterableElementBase {
12478
13011
  get size() {
12479
13012
  return this._size;
12480
13013
  }
12481
- _caseSensitive = true;
12482
13014
  /**
12483
13015
  * Get whether comparisons are case-sensitive.
12484
13016
  * @remarks Time O(1), Space O(1)
@@ -12487,7 +13019,6 @@ var Trie = class extends IterableElementBase {
12487
13019
  get caseSensitive() {
12488
13020
  return this._caseSensitive;
12489
13021
  }
12490
- _root = new TrieNode("");
12491
13022
  /**
12492
13023
  * Get the root node.
12493
13024
  * @remarks Time O(1), Space O(1)
@@ -12817,7 +13348,7 @@ var Trie = class extends IterableElementBase {
12817
13348
  const next = new Ctor([], {
12818
13349
  toElementFn: this.toElementFn,
12819
13350
  caseSensitive: this.caseSensitive,
12820
- ...options ?? {}
13351
+ ...options != null ? options : {}
12821
13352
  });
12822
13353
  return next;
12823
13354
  }
@@ -12873,12 +13404,11 @@ var Trie = class extends IterableElementBase {
12873
13404
  return str;
12874
13405
  }
12875
13406
  };
13407
+ __name(_Trie, "Trie");
13408
+ var Trie = _Trie;
12876
13409
 
12877
13410
  // src/data-structures/tree/tree.ts
12878
- var TreeNode = class _TreeNode {
12879
- static {
12880
- __name(this, "TreeNode");
12881
- }
13411
+ var _TreeNode = class _TreeNode {
12882
13412
  /**
12883
13413
  * The constructor function initializes a TreeNode object with a key, optional value, and optional
12884
13414
  * children.
@@ -12890,11 +13420,13 @@ var TreeNode = class _TreeNode {
12890
13420
  * default value is an empty array.
12891
13421
  */
12892
13422
  constructor(key, value, children) {
13423
+ __publicField(this, "_key");
13424
+ __publicField(this, "_value");
13425
+ __publicField(this, "_children");
12893
13426
  this._key = key;
12894
13427
  this._value = value || void 0;
12895
13428
  if (children) this._children = children;
12896
13429
  }
12897
- _key;
12898
13430
  /**
12899
13431
  * The function returns the value of the protected variable _key.
12900
13432
  * @returns The value of the `_key` property, which is a string.
@@ -12910,7 +13442,6 @@ var TreeNode = class _TreeNode {
12910
13442
  set key(value) {
12911
13443
  this._key = value;
12912
13444
  }
12913
- _value;
12914
13445
  /**
12915
13446
  * The function returns the value stored in a variable, or undefined if the variable is empty.
12916
13447
  * @returns The value of the variable `_value` is being returned.
@@ -12926,7 +13457,6 @@ var TreeNode = class _TreeNode {
12926
13457
  set value(value) {
12927
13458
  this._value = value;
12928
13459
  }
12929
- _children;
12930
13460
  /**
12931
13461
  * The function returns an array of TreeNode objects or undefined.
12932
13462
  * @returns The `children` property is being returned. It is of type `TreeNode<V>[] | undefined`,
@@ -12982,6 +13512,8 @@ var TreeNode = class _TreeNode {
12982
13512
  return maxDepth;
12983
13513
  }
12984
13514
  };
13515
+ __name(_TreeNode, "TreeNode");
13516
+ var TreeNode = _TreeNode;
12985
13517
  /**
12986
13518
  * data-structure-typed
12987
13519
  *