data-structure-typed 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +4 -0
- package/dist/cjs/index.cjs +1153 -563
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +13623 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +1153 -563
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +13545 -0
- package/dist/esm-legacy/index.mjs.map +1 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +65 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +65 -3
- package/dist/umd/data-structure-typed.js +594 -33
- package/dist/umd/data-structure-typed.js.map +1 -1
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +20 -2
- package/src/data-structures/binary-tree/avl-tree-counter.ts +102 -11
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +115 -11
- package/src/data-structures/binary-tree/avl-tree.ts +105 -14
- package/src/data-structures/binary-tree/bst.ts +102 -11
- package/src/data-structures/binary-tree/red-black-tree.ts +108 -18
- package/src/data-structures/binary-tree/tree-counter.ts +101 -10
- package/src/data-structures/binary-tree/tree-multi-map.ts +122 -11
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +5 -4
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/bst.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +5 -4
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +4 -4
- package/tsup.node.config.js +40 -6
|
@@ -8465,7 +8465,7 @@ var dataStructureTyped = (() => {
|
|
|
8465
8465
|
};
|
|
8466
8466
|
|
|
8467
8467
|
// src/data-structures/binary-tree/bst.ts
|
|
8468
|
-
var BSTNode = class
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -9755,7 +9832,7 @@ var dataStructureTyped = (() => {
|
|
|
9755
9832
|
};
|
|
9756
9833
|
|
|
9757
9834
|
// src/data-structures/binary-tree/avl-tree.ts
|
|
9758
|
-
var AVLTreeNode = class
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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) {
|
|
@@ -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.
|
|
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 = (
|
|
10676
|
+
current = (_b = current.left) != null ? _b : this.NIL;
|
|
10446
10677
|
} else if (compared > 0) {
|
|
10447
|
-
current = (
|
|
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 &&
|
|
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 &&
|
|
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 (
|
|
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 (
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
10709
|
-
* @remarks Time O(
|
|
10710
|
-
*
|
|
10711
|
-
* @
|
|
10712
|
-
|
|
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)
|
|
@@ -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
|
|
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
|
-
|
|
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)
|
|
@@ -11050,7 +11456,7 @@ var dataStructureTyped = (() => {
|
|
|
11050
11456
|
};
|
|
11051
11457
|
|
|
11052
11458
|
// src/data-structures/binary-tree/tree-counter.ts
|
|
11053
|
-
var TreeCounterNode = class
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -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
|
|
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
|
-
|
|
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
|
/**
|