data-structure-typed 2.1.2 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/CONTRIBUTING.md +4 -0
  3. package/README.md +66 -21
  4. package/benchmark/report.html +1 -1
  5. package/benchmark/report.json +145 -169
  6. package/dist/cjs/index.cjs +1173 -583
  7. package/dist/cjs/index.cjs.map +1 -1
  8. package/dist/cjs-legacy/index.cjs +13623 -0
  9. package/dist/cjs-legacy/index.cjs.map +1 -0
  10. package/dist/esm/index.mjs +1173 -583
  11. package/dist/esm/index.mjs.map +1 -1
  12. package/dist/esm-legacy/index.mjs +13545 -0
  13. package/dist/esm-legacy/index.mjs.map +1 -0
  14. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +57 -3
  15. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +65 -3
  16. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +61 -5
  17. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  18. package/dist/types/data-structures/binary-tree/bst.d.ts +58 -3
  19. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +59 -4
  20. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +66 -3
  22. package/dist/types/types/data-structures/base/base.d.ts +1 -1
  23. package/dist/umd/data-structure-typed.js +614 -53
  24. package/dist/umd/data-structure-typed.js.map +1 -1
  25. package/dist/umd/data-structure-typed.min.js +3 -3
  26. package/dist/umd/data-structure-typed.min.js.map +1 -1
  27. package/package.json +20 -2
  28. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  29. package/src/data-structures/binary-tree/avl-tree-counter.ts +103 -12
  30. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
  31. package/src/data-structures/binary-tree/avl-tree.ts +109 -16
  32. package/src/data-structures/binary-tree/binary-tree.ts +3 -2
  33. package/src/data-structures/binary-tree/bst.ts +104 -12
  34. package/src/data-structures/binary-tree/red-black-tree.ts +110 -19
  35. package/src/data-structures/binary-tree/tree-counter.ts +102 -11
  36. package/src/data-structures/binary-tree/tree-multi-map.ts +124 -12
  37. package/src/data-structures/graph/abstract-graph.ts +8 -8
  38. package/src/data-structures/graph/directed-graph.ts +5 -5
  39. package/src/data-structures/graph/undirected-graph.ts +5 -5
  40. package/src/data-structures/hash/hash-map.ts +4 -4
  41. package/src/types/data-structures/base/base.ts +1 -1
  42. package/test/performance/data-structures/binary-tree/red-black-tree.test.ts +39 -36
  43. package/test/performance/runner-config.json +4 -4
  44. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +8 -7
  45. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +3 -3
  46. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +6 -6
  47. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +4 -4
  48. package/test/unit/data-structures/binary-tree/bst.test.ts +5 -5
  49. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +6 -6
  50. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +8 -7
  51. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +7 -7
  52. package/test/unit/data-structures/graph/directed-graph.test.ts +3 -3
  53. package/test/unit/data-structures/hash/hash-map.test.ts +14 -14
  54. package/tsup.node.config.js +40 -6
  55. package/test/performance/reportor.mjs +0 -505
@@ -152,7 +152,7 @@ var dataStructureTyped = (() => {
152
152
  every(predicate, thisArg) {
153
153
  let index = 0;
154
154
  for (const item of this) {
155
- if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
155
+ if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
156
156
  return false;
157
157
  }
158
158
  }
@@ -168,7 +168,7 @@ var dataStructureTyped = (() => {
168
168
  some(predicate, thisArg) {
169
169
  let index = 0;
170
170
  for (const item of this) {
171
- if (predicate.call(thisArg, item[0], item[1], index++, this)) {
171
+ if (predicate.call(thisArg, item[1], item[0], index++, this)) {
172
172
  return true;
173
173
  }
174
174
  }
@@ -184,7 +184,7 @@ var dataStructureTyped = (() => {
184
184
  let index = 0;
185
185
  for (const item of this) {
186
186
  const [key, value] = item;
187
- callbackfn.call(thisArg, key, value, index++, this);
187
+ callbackfn.call(thisArg, value, key, index++, this);
188
188
  }
189
189
  }
190
190
  /**
@@ -198,7 +198,7 @@ var dataStructureTyped = (() => {
198
198
  let index = 0;
199
199
  for (const item of this) {
200
200
  const [key, value] = item;
201
- if (callbackfn.call(thisArg, key, value, index++, this)) return item;
201
+ if (callbackfn.call(thisArg, value, key, index++, this)) return item;
202
202
  }
203
203
  return;
204
204
  }
@@ -800,7 +800,7 @@ var dataStructureTyped = (() => {
800
800
  map(callbackfn, thisArg) {
801
801
  const out = this._createLike();
802
802
  let index = 0;
803
- for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, key, value, index++, this));
803
+ for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, value, key, index++, this));
804
804
  return out;
805
805
  }
806
806
  /**
@@ -813,7 +813,7 @@ var dataStructureTyped = (() => {
813
813
  filter(predicate, thisArg) {
814
814
  const out = this._createLike();
815
815
  let index = 0;
816
- for (const [key, value] of this) if (predicate.call(thisArg, key, value, index++, this)) out.set(key, value);
816
+ for (const [key, value] of this) if (predicate.call(thisArg, value, key, index++, this)) out.set(key, value);
817
817
  return out;
818
818
  }
819
819
  /**
@@ -1135,7 +1135,7 @@ var dataStructureTyped = (() => {
1135
1135
  const out = this._createLike();
1136
1136
  let index = 0;
1137
1137
  for (const [key, value] of this) {
1138
- if (predicate.call(thisArg, key, value, index, this)) out.set(key, value);
1138
+ if (predicate.call(thisArg, value, key, index, this)) out.set(key, value);
1139
1139
  index++;
1140
1140
  }
1141
1141
  return out;
@@ -1153,7 +1153,7 @@ var dataStructureTyped = (() => {
1153
1153
  const out = this._createLike();
1154
1154
  let index = 0;
1155
1155
  for (const [key, value] of this) {
1156
- const [newKey, newValue] = callback.call(thisArg, key, value, index, this);
1156
+ const [newKey, newValue] = callback.call(thisArg, value, key, index, this);
1157
1157
  out.set(newKey, newValue);
1158
1158
  index++;
1159
1159
  }
@@ -5719,7 +5719,7 @@ var dataStructureTyped = (() => {
5719
5719
  const filtered = [];
5720
5720
  let index = 0;
5721
5721
  for (const [key, value] of this) {
5722
- if (predicate.call(thisArg, key, value, index, this)) {
5722
+ if (predicate.call(thisArg, value, key, index, this)) {
5723
5723
  filtered.push([key, value]);
5724
5724
  }
5725
5725
  index++;
@@ -5734,7 +5734,7 @@ var dataStructureTyped = (() => {
5734
5734
  const filtered = [];
5735
5735
  let index = 0;
5736
5736
  for (const [key, value] of this) {
5737
- if (predicate.call(thisArg, key, value, index, this)) {
5737
+ if (predicate.call(thisArg, value, key, index, this)) {
5738
5738
  filtered.push([key, value]);
5739
5739
  }
5740
5740
  index++;
@@ -5745,7 +5745,7 @@ var dataStructureTyped = (() => {
5745
5745
  const mapped = [];
5746
5746
  let index = 0;
5747
5747
  for (const [key, value] of this) {
5748
- mapped.push(callback.call(thisArg, key, value, index, this));
5748
+ mapped.push(callback.call(thisArg, value, key, index, this));
5749
5749
  index++;
5750
5750
  }
5751
5751
  return mapped;
@@ -7998,7 +7998,7 @@ var dataStructureTyped = (() => {
7998
7998
  filter(predicate, thisArg) {
7999
7999
  const out = this._createInstance();
8000
8000
  let i = 0;
8001
- for (const [k, v] of this) if (predicate.call(thisArg, k, v, i++, this)) out.add([k, v]);
8001
+ for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
8002
8002
  return out;
8003
8003
  }
8004
8004
  /**
@@ -8016,7 +8016,7 @@ var dataStructureTyped = (() => {
8016
8016
  map(cb, options, thisArg) {
8017
8017
  const out = this._createLike([], options);
8018
8018
  let i = 0;
8019
- for (const [k, v] of this) out.add(cb.call(thisArg, k, v, i++, this));
8019
+ for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
8020
8020
  return out;
8021
8021
  }
8022
8022
  /**
@@ -8465,7 +8465,7 @@ var dataStructureTyped = (() => {
8465
8465
  };
8466
8466
 
8467
8467
  // src/data-structures/binary-tree/bst.ts
8468
- var BSTNode = class extends BinaryTreeNode {
8468
+ var BSTNode = class {
8469
8469
  /**
8470
8470
  * Creates an instance of BSTNode.
8471
8471
  * @remarks Time O(1), Space O(1)
@@ -8474,10 +8474,16 @@ var dataStructureTyped = (() => {
8474
8474
  * @param [value] - The value associated with the key.
8475
8475
  */
8476
8476
  constructor(key, value) {
8477
- super(key, value);
8477
+ __publicField(this, "key");
8478
+ __publicField(this, "value");
8478
8479
  __publicField(this, "parent");
8479
8480
  __publicField(this, "_left");
8480
8481
  __publicField(this, "_right");
8482
+ __publicField(this, "_height", 0);
8483
+ __publicField(this, "_color", "BLACK");
8484
+ __publicField(this, "_count", 1);
8485
+ this.key = key;
8486
+ this.value = value;
8481
8487
  }
8482
8488
  /**
8483
8489
  * Gets the left child of the node.
@@ -8517,6 +8523,77 @@ var dataStructureTyped = (() => {
8517
8523
  if (v) v.parent = this;
8518
8524
  this._right = v;
8519
8525
  }
8526
+ /**
8527
+ * Gets the height of the node (used in self-balancing trees).
8528
+ * @remarks Time O(1), Space O(1)
8529
+ *
8530
+ * @returns The height.
8531
+ */
8532
+ get height() {
8533
+ return this._height;
8534
+ }
8535
+ /**
8536
+ * Sets the height of the node.
8537
+ * @remarks Time O(1), Space O(1)
8538
+ *
8539
+ * @param value - The new height.
8540
+ */
8541
+ set height(value) {
8542
+ this._height = value;
8543
+ }
8544
+ /**
8545
+ * Gets the color of the node (used in Red-Black trees).
8546
+ * @remarks Time O(1), Space O(1)
8547
+ *
8548
+ * @returns The node's color.
8549
+ */
8550
+ get color() {
8551
+ return this._color;
8552
+ }
8553
+ /**
8554
+ * Sets the color of the node.
8555
+ * @remarks Time O(1), Space O(1)
8556
+ *
8557
+ * @param value - The new color.
8558
+ */
8559
+ set color(value) {
8560
+ this._color = value;
8561
+ }
8562
+ /**
8563
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
8564
+ * @remarks Time O(1), Space O(1)
8565
+ *
8566
+ * @returns The subtree node count.
8567
+ */
8568
+ get count() {
8569
+ return this._count;
8570
+ }
8571
+ /**
8572
+ * Sets the count of nodes in the subtree.
8573
+ * @remarks Time O(1), Space O(1)
8574
+ *
8575
+ * @param value - The new count.
8576
+ */
8577
+ set count(value) {
8578
+ this._count = value;
8579
+ }
8580
+ /**
8581
+ * Gets the position of the node relative to its parent.
8582
+ * @remarks Time O(1), Space O(1)
8583
+ *
8584
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
8585
+ */
8586
+ get familyPosition() {
8587
+ if (!this.parent) {
8588
+ return this.left || this.right ? "ROOT" : "ISOLATED";
8589
+ }
8590
+ if (this.parent.left === this) {
8591
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
8592
+ } else if (this.parent.right === this) {
8593
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
8594
+ }
8595
+ return "MAL_NODE";
8596
+ }
8520
8597
  };
8521
8598
  var BST = class extends BinaryTree {
8522
8599
  /**
@@ -9035,7 +9112,7 @@ var dataStructureTyped = (() => {
9035
9112
  const out = this._createLike([], options);
9036
9113
  let index = 0;
9037
9114
  for (const [key, value] of this) {
9038
- out.add(callback.call(thisArg, key, value, index++, this));
9115
+ out.add(callback.call(thisArg, value, key, index++, this));
9039
9116
  }
9040
9117
  return out;
9041
9118
  }
@@ -9755,7 +9832,7 @@ var dataStructureTyped = (() => {
9755
9832
  };
9756
9833
 
9757
9834
  // src/data-structures/binary-tree/avl-tree.ts
9758
- var AVLTreeNode = class extends BSTNode {
9835
+ var AVLTreeNode = class {
9759
9836
  /**
9760
9837
  * Creates an instance of AVLTreeNode.
9761
9838
  * @remarks Time O(1), Space O(1)
@@ -9764,10 +9841,16 @@ var dataStructureTyped = (() => {
9764
9841
  * @param [value] - The value associated with the key.
9765
9842
  */
9766
9843
  constructor(key, value) {
9767
- super(key, value);
9844
+ __publicField(this, "key");
9845
+ __publicField(this, "value");
9768
9846
  __publicField(this, "parent");
9769
9847
  __publicField(this, "_left");
9770
9848
  __publicField(this, "_right");
9849
+ __publicField(this, "_height", 0);
9850
+ __publicField(this, "_color", "BLACK");
9851
+ __publicField(this, "_count", 1);
9852
+ this.key = key;
9853
+ this.value = value;
9771
9854
  }
9772
9855
  /**
9773
9856
  * Gets the left child of the node.
@@ -9811,6 +9894,77 @@ var dataStructureTyped = (() => {
9811
9894
  }
9812
9895
  this._right = v;
9813
9896
  }
9897
+ /**
9898
+ * Gets the height of the node (used in self-balancing trees).
9899
+ * @remarks Time O(1), Space O(1)
9900
+ *
9901
+ * @returns The height.
9902
+ */
9903
+ get height() {
9904
+ return this._height;
9905
+ }
9906
+ /**
9907
+ * Sets the height of the node.
9908
+ * @remarks Time O(1), Space O(1)
9909
+ *
9910
+ * @param value - The new height.
9911
+ */
9912
+ set height(value) {
9913
+ this._height = value;
9914
+ }
9915
+ /**
9916
+ * Gets the color of the node (used in Red-Black trees).
9917
+ * @remarks Time O(1), Space O(1)
9918
+ *
9919
+ * @returns The node's color.
9920
+ */
9921
+ get color() {
9922
+ return this._color;
9923
+ }
9924
+ /**
9925
+ * Sets the color of the node.
9926
+ * @remarks Time O(1), Space O(1)
9927
+ *
9928
+ * @param value - The new color.
9929
+ */
9930
+ set color(value) {
9931
+ this._color = value;
9932
+ }
9933
+ /**
9934
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
9935
+ * @remarks Time O(1), Space O(1)
9936
+ *
9937
+ * @returns The subtree node count.
9938
+ */
9939
+ get count() {
9940
+ return this._count;
9941
+ }
9942
+ /**
9943
+ * Sets the count of nodes in the subtree.
9944
+ * @remarks Time O(1), Space O(1)
9945
+ *
9946
+ * @param value - The new count.
9947
+ */
9948
+ set count(value) {
9949
+ this._count = value;
9950
+ }
9951
+ /**
9952
+ * Gets the position of the node relative to its parent.
9953
+ * @remarks Time O(1), Space O(1)
9954
+ *
9955
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
9956
+ */
9957
+ get familyPosition() {
9958
+ if (!this.parent) {
9959
+ return this.left || this.right ? "ROOT" : "ISOLATED";
9960
+ }
9961
+ if (this.parent.left === this) {
9962
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
9963
+ } else if (this.parent.right === this) {
9964
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
9965
+ }
9966
+ return "MAL_NODE";
9967
+ }
9814
9968
  };
9815
9969
  var AVLTree = class extends BST {
9816
9970
  /**
@@ -9921,7 +10075,7 @@ var dataStructureTyped = (() => {
9921
10075
  const out = this._createLike([], options);
9922
10076
  let index = 0;
9923
10077
  for (const [key, value] of this) {
9924
- out.add(callback.call(thisArg, key, value, index++, this));
10078
+ out.add(callback.call(thisArg, value, key, index++, this));
9925
10079
  }
9926
10080
  return out;
9927
10081
  }
@@ -10202,7 +10356,7 @@ var dataStructureTyped = (() => {
10202
10356
  };
10203
10357
 
10204
10358
  // src/data-structures/binary-tree/red-black-tree.ts
10205
- var RedBlackTreeNode = class extends BSTNode {
10359
+ var RedBlackTreeNode = class {
10206
10360
  /**
10207
10361
  * Create a Red-Black Tree and optionally bulk-insert items.
10208
10362
  * @remarks Time O(n log n), Space O(n)
@@ -10212,11 +10366,17 @@ var dataStructureTyped = (() => {
10212
10366
  * @returns New RedBlackTree instance.
10213
10367
  */
10214
10368
  constructor(key, value, color = "BLACK") {
10215
- super(key, value);
10369
+ __publicField(this, "key");
10370
+ __publicField(this, "value");
10216
10371
  __publicField(this, "parent");
10217
10372
  __publicField(this, "_left");
10218
10373
  __publicField(this, "_right");
10219
- this._color = color;
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;
10220
10380
  }
10221
10381
  /**
10222
10382
  * Get the left child pointer.
@@ -10258,6 +10418,77 @@ var dataStructureTyped = (() => {
10258
10418
  }
10259
10419
  this._right = v;
10260
10420
  }
10421
+ /**
10422
+ * Gets the height of the node (used in self-balancing trees).
10423
+ * @remarks Time O(1), Space O(1)
10424
+ *
10425
+ * @returns The height.
10426
+ */
10427
+ get height() {
10428
+ return this._height;
10429
+ }
10430
+ /**
10431
+ * Sets the height of the node.
10432
+ * @remarks Time O(1), Space O(1)
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
+ }
10261
10492
  };
10262
10493
  var RedBlackTree = class extends BST {
10263
10494
  constructor(keysNodesEntriesOrRaws = [], options) {
@@ -10406,7 +10637,7 @@ var dataStructureTyped = (() => {
10406
10637
  const out = this._createLike([], options);
10407
10638
  let index = 0;
10408
10639
  for (const [key, value] of this) {
10409
- out.add(callback.call(thisArg, key, value, index++, this));
10640
+ out.add(callback.call(thisArg, value, key, index++, this));
10410
10641
  }
10411
10642
  return out;
10412
10643
  }
@@ -10435,16 +10666,16 @@ var dataStructureTyped = (() => {
10435
10666
  * @returns Status string: 'CREATED' or 'UPDATED'.
10436
10667
  */
10437
10668
  _insert(node) {
10438
- var _a, _b;
10439
- let current = this.root;
10669
+ var _a, _b, _c;
10670
+ let current = (_a = this.root) != null ? _a : this.NIL;
10440
10671
  let parent = void 0;
10441
- while (this.isRealNode(current)) {
10672
+ while (current !== this.NIL) {
10442
10673
  parent = current;
10443
10674
  const compared = this._compare(node.key, current.key);
10444
10675
  if (compared < 0) {
10445
- current = (_a = current.left) != null ? _a : this.NIL;
10676
+ current = (_b = current.left) != null ? _b : this.NIL;
10446
10677
  } else if (compared > 0) {
10447
- current = (_b = current.right) != null ? _b : this.NIL;
10678
+ current = (_c = current.right) != null ? _c : this.NIL;
10448
10679
  } else {
10449
10680
  this._replaceNode(current, node);
10450
10681
  return "UPDATED";
@@ -10504,7 +10735,7 @@ var dataStructureTyped = (() => {
10504
10735
  z = z.parent;
10505
10736
  this._leftRotate(z);
10506
10737
  }
10507
- if (z && this.isRealNode(z.parent) && this.isRealNode(z.parent.parent)) {
10738
+ if (z && z.parent && z.parent.parent) {
10508
10739
  z.parent.color = "BLACK";
10509
10740
  z.parent.parent.color = "RED";
10510
10741
  this._rightRotate(z.parent.parent);
@@ -10522,7 +10753,7 @@ var dataStructureTyped = (() => {
10522
10753
  z = z.parent;
10523
10754
  this._rightRotate(z);
10524
10755
  }
10525
- if (z && this.isRealNode(z.parent) && this.isRealNode(z.parent.parent)) {
10756
+ if (z && z.parent && z.parent.parent) {
10526
10757
  z.parent.color = "BLACK";
10527
10758
  z.parent.parent.color = "RED";
10528
10759
  this._leftRotate(z.parent.parent);
@@ -10605,7 +10836,7 @@ var dataStructureTyped = (() => {
10605
10836
  }
10606
10837
  const y = x.right;
10607
10838
  x.right = y.left;
10608
- if (this.isRealNode(y.left)) {
10839
+ if (y.left && y.left !== this.NIL) {
10609
10840
  y.left.parent = x;
10610
10841
  }
10611
10842
  y.parent = x.parent;
@@ -10631,7 +10862,7 @@ var dataStructureTyped = (() => {
10631
10862
  }
10632
10863
  const x = y.left;
10633
10864
  y.left = x.right;
10634
- if (this.isRealNode(x.right)) {
10865
+ if (x.right && x.right !== this.NIL) {
10635
10866
  x.right.parent = y;
10636
10867
  }
10637
10868
  x.parent = y.parent;
@@ -10648,7 +10879,7 @@ var dataStructureTyped = (() => {
10648
10879
  };
10649
10880
 
10650
10881
  // src/data-structures/binary-tree/avl-tree-multi-map.ts
10651
- var AVLTreeMultiMapNode = class extends AVLTreeNode {
10882
+ var AVLTreeMultiMapNode = class {
10652
10883
  /**
10653
10884
  * Create an AVLTreeMultiMap node with a value bucket.
10654
10885
  * @remarks Time O(1), Space O(1)
@@ -10656,11 +10887,17 @@ var dataStructureTyped = (() => {
10656
10887
  * @param value - Initial array of values.
10657
10888
  * @returns New AVLTreeMultiMapNode instance.
10658
10889
  */
10659
- constructor(key, value) {
10660
- super(key, value);
10890
+ constructor(key, value = []) {
10891
+ __publicField(this, "key");
10892
+ __publicField(this, "value");
10661
10893
  __publicField(this, "parent");
10662
10894
  __publicField(this, "_left");
10663
10895
  __publicField(this, "_right");
10896
+ __publicField(this, "_height", 0);
10897
+ __publicField(this, "_color", "BLACK");
10898
+ __publicField(this, "_count", 1);
10899
+ this.key = key;
10900
+ this.value = value;
10664
10901
  }
10665
10902
  /**
10666
10903
  * Get the left child pointer.
@@ -10702,14 +10939,85 @@ var dataStructureTyped = (() => {
10702
10939
  }
10703
10940
  this._right = v;
10704
10941
  }
10705
- };
10706
- var AVLTreeMultiMap = class extends AVLTree {
10707
10942
  /**
10708
- * Create an AVLTreeMultiMap and optionally bulk-insert items.
10709
- * @remarks Time O(N log N), Space O(N)
10710
- * @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
10711
- * @param [options] - Options for AVLTreeMultiMap (comparator, reverse, map mode).
10712
- * @returns New AVLTreeMultiMap instance.
10943
+ * Gets the height of the node (used in self-balancing trees).
10944
+ * @remarks Time O(1), Space O(1)
10945
+ *
10946
+ * @returns The height.
10947
+ */
10948
+ get height() {
10949
+ return this._height;
10950
+ }
10951
+ /**
10952
+ * Sets the height of the node.
10953
+ * @remarks Time O(1), Space O(1)
10954
+ *
10955
+ * @param value - The new height.
10956
+ */
10957
+ set height(value) {
10958
+ this._height = value;
10959
+ }
10960
+ /**
10961
+ * Gets the color of the node (used in Red-Black trees).
10962
+ * @remarks Time O(1), Space O(1)
10963
+ *
10964
+ * @returns The node's color.
10965
+ */
10966
+ get color() {
10967
+ return this._color;
10968
+ }
10969
+ /**
10970
+ * Sets the color of the node.
10971
+ * @remarks Time O(1), Space O(1)
10972
+ *
10973
+ * @param value - The new color.
10974
+ */
10975
+ set color(value) {
10976
+ this._color = value;
10977
+ }
10978
+ /**
10979
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
10980
+ * @remarks Time O(1), Space O(1)
10981
+ *
10982
+ * @returns The subtree node count.
10983
+ */
10984
+ get count() {
10985
+ return this._count;
10986
+ }
10987
+ /**
10988
+ * Sets the count of nodes in the subtree.
10989
+ * @remarks Time O(1), Space O(1)
10990
+ *
10991
+ * @param value - The new count.
10992
+ */
10993
+ set count(value) {
10994
+ this._count = value;
10995
+ }
10996
+ /**
10997
+ * Gets the position of the node relative to its parent.
10998
+ * @remarks Time O(1), Space O(1)
10999
+ *
11000
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
11001
+ */
11002
+ get familyPosition() {
11003
+ if (!this.parent) {
11004
+ return this.left || this.right ? "ROOT" : "ISOLATED";
11005
+ }
11006
+ if (this.parent.left === this) {
11007
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
11008
+ } else if (this.parent.right === this) {
11009
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
11010
+ }
11011
+ return "MAL_NODE";
11012
+ }
11013
+ };
11014
+ var AVLTreeMultiMap = class extends AVLTree {
11015
+ /**
11016
+ * Create an AVLTreeMultiMap and optionally bulk-insert items.
11017
+ * @remarks Time O(N log N), Space O(N)
11018
+ * @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
11019
+ * @param [options] - Options for AVLTreeMultiMap (comparator, reverse, map mode).
11020
+ * @returns New AVLTreeMultiMap instance.
10713
11021
  */
10714
11022
  constructor(keysNodesEntriesOrRaws = [], options) {
10715
11023
  super([], { ...options, isMapMode: true });
@@ -10720,6 +11028,16 @@ var dataStructureTyped = (() => {
10720
11028
  createNode(key, value = []) {
10721
11029
  return new AVLTreeMultiMapNode(key, this._isMapMode ? [] : value);
10722
11030
  }
11031
+ /**
11032
+ * Checks if the given item is a `AVLTreeMultiMapNode` instance.
11033
+ * @remarks Time O(1), Space O(1)
11034
+ *
11035
+ * @param keyNodeOrEntry - The item to check.
11036
+ * @returns True if it's a AVLTreeMultiMapNode, false otherwise.
11037
+ */
11038
+ isNode(keyNodeOrEntry) {
11039
+ return keyNodeOrEntry instanceof AVLTreeMultiMapNode;
11040
+ }
10723
11041
  /**
10724
11042
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
10725
11043
  * @remarks Time O(log N + M), Space O(1)
@@ -10828,7 +11146,7 @@ var dataStructureTyped = (() => {
10828
11146
  map(callback, options, thisArg) {
10829
11147
  const out = this._createLike([], options);
10830
11148
  let i = 0;
10831
- for (const [k, v] of this) out.add(callback.call(thisArg, k, v, i++, this));
11149
+ for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
10832
11150
  return out;
10833
11151
  }
10834
11152
  /**
@@ -10863,7 +11181,7 @@ var dataStructureTyped = (() => {
10863
11181
  };
10864
11182
 
10865
11183
  // src/data-structures/binary-tree/tree-multi-map.ts
10866
- var TreeMultiMapNode = class extends RedBlackTreeNode {
11184
+ var TreeMultiMapNode = class {
10867
11185
  /**
10868
11186
  * Create a TreeMultiMap node with an optional value bucket.
10869
11187
  * @remarks Time O(1), Space O(1)
@@ -10871,11 +11189,18 @@ var dataStructureTyped = (() => {
10871
11189
  * @param [value] - Initial array of values.
10872
11190
  * @returns New TreeMultiMapNode instance.
10873
11191
  */
10874
- constructor(key, value) {
10875
- super(key, value);
11192
+ constructor(key, value = [], color = "BLACK") {
11193
+ __publicField(this, "key");
11194
+ __publicField(this, "value");
10876
11195
  __publicField(this, "parent");
10877
11196
  __publicField(this, "_left");
10878
11197
  __publicField(this, "_right");
11198
+ __publicField(this, "_height", 0);
11199
+ __publicField(this, "_color", "BLACK");
11200
+ __publicField(this, "_count", 1);
11201
+ this.key = key;
11202
+ this.value = value;
11203
+ this.color = color;
10879
11204
  }
10880
11205
  /**
10881
11206
  * Get the left child pointer.
@@ -10917,6 +11242,77 @@ var dataStructureTyped = (() => {
10917
11242
  }
10918
11243
  this._right = v;
10919
11244
  }
11245
+ /**
11246
+ * Gets the height of the node (used in self-balancing trees).
11247
+ * @remarks Time O(1), Space O(1)
11248
+ *
11249
+ * @returns The height.
11250
+ */
11251
+ get height() {
11252
+ return this._height;
11253
+ }
11254
+ /**
11255
+ * Sets the height of the node.
11256
+ * @remarks Time O(1), Space O(1)
11257
+ *
11258
+ * @param value - The new height.
11259
+ */
11260
+ set height(value) {
11261
+ this._height = value;
11262
+ }
11263
+ /**
11264
+ * Gets the color of the node (used in Red-Black trees).
11265
+ * @remarks Time O(1), Space O(1)
11266
+ *
11267
+ * @returns The node's color.
11268
+ */
11269
+ get color() {
11270
+ return this._color;
11271
+ }
11272
+ /**
11273
+ * Sets the color of the node.
11274
+ * @remarks Time O(1), Space O(1)
11275
+ *
11276
+ * @param value - The new color.
11277
+ */
11278
+ set color(value) {
11279
+ this._color = value;
11280
+ }
11281
+ /**
11282
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
11283
+ * @remarks Time O(1), Space O(1)
11284
+ *
11285
+ * @returns The subtree node count.
11286
+ */
11287
+ get count() {
11288
+ return this._count;
11289
+ }
11290
+ /**
11291
+ * Sets the count of nodes in the subtree.
11292
+ * @remarks Time O(1), Space O(1)
11293
+ *
11294
+ * @param value - The new count.
11295
+ */
11296
+ set count(value) {
11297
+ this._count = value;
11298
+ }
11299
+ /**
11300
+ * Gets the position of the node relative to its parent.
11301
+ * @remarks Time O(1), Space O(1)
11302
+ *
11303
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
11304
+ */
11305
+ get familyPosition() {
11306
+ if (!this.parent) {
11307
+ return this.left || this.right ? "ROOT" : "ISOLATED";
11308
+ }
11309
+ if (this.parent.left === this) {
11310
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
11311
+ } else if (this.parent.right === this) {
11312
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
11313
+ }
11314
+ return "MAL_NODE";
11315
+ }
10920
11316
  };
10921
11317
  var TreeMultiMap = class extends RedBlackTree {
10922
11318
  /**
@@ -10935,6 +11331,16 @@ var dataStructureTyped = (() => {
10935
11331
  createNode(key, value = []) {
10936
11332
  return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
10937
11333
  }
11334
+ /**
11335
+ * Checks if the given item is a `TreeMultiMapNode` instance.
11336
+ * @remarks Time O(1), Space O(1)
11337
+ *
11338
+ * @param keyNodeOrEntry - The item to check.
11339
+ * @returns True if it's a TreeMultiMapNode, false otherwise.
11340
+ */
11341
+ isNode(keyNodeOrEntry) {
11342
+ return keyNodeOrEntry instanceof TreeMultiMapNode;
11343
+ }
10938
11344
  /**
10939
11345
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
10940
11346
  * @remarks Time O(log N + M), Space O(1)
@@ -11015,7 +11421,7 @@ var dataStructureTyped = (() => {
11015
11421
  map(callback, options, thisArg) {
11016
11422
  const out = this._createLike([], options);
11017
11423
  let i = 0;
11018
- for (const [k, v] of this) out.add(callback.call(thisArg, k, v, i++, this));
11424
+ for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
11019
11425
  return out;
11020
11426
  }
11021
11427
  /**
@@ -11050,7 +11456,7 @@ var dataStructureTyped = (() => {
11050
11456
  };
11051
11457
 
11052
11458
  // src/data-structures/binary-tree/tree-counter.ts
11053
- var TreeCounterNode = class extends RedBlackTreeNode {
11459
+ var TreeCounterNode = class {
11054
11460
  /**
11055
11461
  * Create a tree counter node.
11056
11462
  * @remarks Time O(1), Space O(1)
@@ -11061,10 +11467,17 @@ var dataStructureTyped = (() => {
11061
11467
  * @returns New TreeCounterNode instance.
11062
11468
  */
11063
11469
  constructor(key, value, count = 1, color = "BLACK") {
11064
- super(key, value, color);
11470
+ __publicField(this, "key");
11471
+ __publicField(this, "value");
11065
11472
  __publicField(this, "parent");
11066
11473
  __publicField(this, "_left");
11067
11474
  __publicField(this, "_right");
11475
+ __publicField(this, "_height", 0);
11476
+ __publicField(this, "_color", "BLACK");
11477
+ __publicField(this, "_count", 1);
11478
+ this.key = key;
11479
+ this.value = value;
11480
+ this.color = color;
11068
11481
  this.count = count;
11069
11482
  }
11070
11483
  /**
@@ -11107,6 +11520,77 @@ var dataStructureTyped = (() => {
11107
11520
  }
11108
11521
  this._right = v;
11109
11522
  }
11523
+ /**
11524
+ * Gets the height of the node (used in self-balancing trees).
11525
+ * @remarks Time O(1), Space O(1)
11526
+ *
11527
+ * @returns The height.
11528
+ */
11529
+ get height() {
11530
+ return this._height;
11531
+ }
11532
+ /**
11533
+ * Sets the height of the node.
11534
+ * @remarks Time O(1), Space O(1)
11535
+ *
11536
+ * @param value - The new height.
11537
+ */
11538
+ set height(value) {
11539
+ this._height = value;
11540
+ }
11541
+ /**
11542
+ * Gets the color of the node (used in Red-Black trees).
11543
+ * @remarks Time O(1), Space O(1)
11544
+ *
11545
+ * @returns The node's color.
11546
+ */
11547
+ get color() {
11548
+ return this._color;
11549
+ }
11550
+ /**
11551
+ * Sets the color of the node.
11552
+ * @remarks Time O(1), Space O(1)
11553
+ *
11554
+ * @param value - The new color.
11555
+ */
11556
+ set color(value) {
11557
+ this._color = value;
11558
+ }
11559
+ /**
11560
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
11561
+ * @remarks Time O(1), Space O(1)
11562
+ *
11563
+ * @returns The subtree node count.
11564
+ */
11565
+ get count() {
11566
+ return this._count;
11567
+ }
11568
+ /**
11569
+ * Sets the count of nodes in the subtree.
11570
+ * @remarks Time O(1), Space O(1)
11571
+ *
11572
+ * @param value - The new count.
11573
+ */
11574
+ set count(value) {
11575
+ this._count = value;
11576
+ }
11577
+ /**
11578
+ * Gets the position of the node relative to its parent.
11579
+ * @remarks Time O(1), Space O(1)
11580
+ *
11581
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
11582
+ */
11583
+ get familyPosition() {
11584
+ if (!this.parent) {
11585
+ return this.left || this.right ? "ROOT" : "ISOLATED";
11586
+ }
11587
+ if (this.parent.left === this) {
11588
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
11589
+ } else if (this.parent.right === this) {
11590
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
11591
+ }
11592
+ return "MAL_NODE";
11593
+ }
11110
11594
  };
11111
11595
  var TreeCounter = class extends RedBlackTree {
11112
11596
  /**
@@ -11314,7 +11798,7 @@ var dataStructureTyped = (() => {
11314
11798
  const out = this._createLike([], options);
11315
11799
  let index = 0;
11316
11800
  for (const [key, value] of this) {
11317
- out.add(callback.call(thisArg, key, value, index++, this));
11801
+ out.add(callback.call(thisArg, value, key, index++, this));
11318
11802
  }
11319
11803
  return out;
11320
11804
  }
@@ -11420,7 +11904,7 @@ var dataStructureTyped = (() => {
11420
11904
  };
11421
11905
 
11422
11906
  // src/data-structures/binary-tree/avl-tree-counter.ts
11423
- var AVLTreeCounterNode = class extends AVLTreeNode {
11907
+ var AVLTreeCounterNode = class {
11424
11908
  /**
11425
11909
  * Create an AVL counter node.
11426
11910
  * @remarks Time O(1), Space O(1)
@@ -11430,10 +11914,16 @@ var dataStructureTyped = (() => {
11430
11914
  * @returns New AVLTreeCounterNode instance.
11431
11915
  */
11432
11916
  constructor(key, value, count = 1) {
11433
- super(key, value);
11917
+ __publicField(this, "key");
11918
+ __publicField(this, "value");
11434
11919
  __publicField(this, "parent");
11435
11920
  __publicField(this, "_left");
11436
11921
  __publicField(this, "_right");
11922
+ __publicField(this, "_height", 0);
11923
+ __publicField(this, "_color", "BLACK");
11924
+ __publicField(this, "_count", 1);
11925
+ this.key = key;
11926
+ this.value = value;
11437
11927
  this.count = count;
11438
11928
  }
11439
11929
  /**
@@ -11476,6 +11966,77 @@ var dataStructureTyped = (() => {
11476
11966
  }
11477
11967
  this._right = v;
11478
11968
  }
11969
+ /**
11970
+ * Gets the height of the node (used in self-balancing trees).
11971
+ * @remarks Time O(1), Space O(1)
11972
+ *
11973
+ * @returns The height.
11974
+ */
11975
+ get height() {
11976
+ return this._height;
11977
+ }
11978
+ /**
11979
+ * Sets the height of the node.
11980
+ * @remarks Time O(1), Space O(1)
11981
+ *
11982
+ * @param value - The new height.
11983
+ */
11984
+ set height(value) {
11985
+ this._height = value;
11986
+ }
11987
+ /**
11988
+ * Gets the color of the node (used in Red-Black trees).
11989
+ * @remarks Time O(1), Space O(1)
11990
+ *
11991
+ * @returns The node's color.
11992
+ */
11993
+ get color() {
11994
+ return this._color;
11995
+ }
11996
+ /**
11997
+ * Sets the color of the node.
11998
+ * @remarks Time O(1), Space O(1)
11999
+ *
12000
+ * @param value - The new color.
12001
+ */
12002
+ set color(value) {
12003
+ this._color = value;
12004
+ }
12005
+ /**
12006
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
12007
+ * @remarks Time O(1), Space O(1)
12008
+ *
12009
+ * @returns The subtree node count.
12010
+ */
12011
+ get count() {
12012
+ return this._count;
12013
+ }
12014
+ /**
12015
+ * Sets the count of nodes in the subtree.
12016
+ * @remarks Time O(1), Space O(1)
12017
+ *
12018
+ * @param value - The new count.
12019
+ */
12020
+ set count(value) {
12021
+ this._count = value;
12022
+ }
12023
+ /**
12024
+ * Gets the position of the node relative to its parent.
12025
+ * @remarks Time O(1), Space O(1)
12026
+ *
12027
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
12028
+ */
12029
+ get familyPosition() {
12030
+ if (!this.parent) {
12031
+ return this.left || this.right ? "ROOT" : "ISOLATED";
12032
+ }
12033
+ if (this.parent.left === this) {
12034
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
12035
+ } else if (this.parent.right === this) {
12036
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
12037
+ }
12038
+ return "MAL_NODE";
12039
+ }
11479
12040
  };
11480
12041
  var AVLTreeCounter = class extends AVLTree {
11481
12042
  /**
@@ -11657,7 +12218,7 @@ var dataStructureTyped = (() => {
11657
12218
  const out = this._createLike([], options);
11658
12219
  let index = 0;
11659
12220
  for (const [key, value] of this) {
11660
- out.add(callback.call(thisArg, key, value, index++, this));
12221
+ out.add(callback.call(thisArg, value, key, index++, this));
11661
12222
  }
11662
12223
  return out;
11663
12224
  }