red-black-tree-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.
- package/dist/cjs/index.cjs +329 -177
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +4019 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +329 -177
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +4010 -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 +61 -5
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +58 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +59 -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 +66 -3
- package/dist/types/types/data-structures/base/base.d.ts +1 -1
- package/dist/umd/red-black-tree-typed.js +176 -22
- package/dist/umd/red-black-tree-typed.js.map +1 -1
- package/dist/umd/red-black-tree-typed.min.js +3 -3
- package/dist/umd/red-black-tree-typed.min.js.map +1 -1
- package/package.json +20 -2
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-counter.ts +103 -12
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
- package/src/data-structures/binary-tree/avl-tree.ts +109 -16
- package/src/data-structures/binary-tree/binary-tree.ts +3 -2
- package/src/data-structures/binary-tree/bst.ts +104 -12
- package/src/data-structures/binary-tree/red-black-tree.ts +110 -19
- package/src/data-structures/binary-tree/tree-counter.ts +102 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +124 -12
- package/src/data-structures/graph/abstract-graph.ts +8 -8
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- package/src/data-structures/hash/hash-map.ts +4 -4
- package/src/types/data-structures/base/base.ts +1 -1
- package/tsup.node.config.js +40 -6
|
@@ -911,7 +911,7 @@ var redBlackTreeTyped = (() => {
|
|
|
911
911
|
every(predicate, thisArg) {
|
|
912
912
|
let index = 0;
|
|
913
913
|
for (const item of this) {
|
|
914
|
-
if (!predicate.call(thisArg, item[
|
|
914
|
+
if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
915
915
|
return false;
|
|
916
916
|
}
|
|
917
917
|
}
|
|
@@ -927,7 +927,7 @@ var redBlackTreeTyped = (() => {
|
|
|
927
927
|
some(predicate, thisArg) {
|
|
928
928
|
let index = 0;
|
|
929
929
|
for (const item of this) {
|
|
930
|
-
if (predicate.call(thisArg, item[
|
|
930
|
+
if (predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
931
931
|
return true;
|
|
932
932
|
}
|
|
933
933
|
}
|
|
@@ -943,7 +943,7 @@ var redBlackTreeTyped = (() => {
|
|
|
943
943
|
let index = 0;
|
|
944
944
|
for (const item of this) {
|
|
945
945
|
const [key, value] = item;
|
|
946
|
-
callbackfn.call(thisArg,
|
|
946
|
+
callbackfn.call(thisArg, value, key, index++, this);
|
|
947
947
|
}
|
|
948
948
|
}
|
|
949
949
|
/**
|
|
@@ -957,7 +957,7 @@ var redBlackTreeTyped = (() => {
|
|
|
957
957
|
let index = 0;
|
|
958
958
|
for (const item of this) {
|
|
959
959
|
const [key, value] = item;
|
|
960
|
-
if (callbackfn.call(thisArg,
|
|
960
|
+
if (callbackfn.call(thisArg, value, key, index++, this)) return item;
|
|
961
961
|
}
|
|
962
962
|
return;
|
|
963
963
|
}
|
|
@@ -2208,7 +2208,7 @@ var redBlackTreeTyped = (() => {
|
|
|
2208
2208
|
filter(predicate, thisArg) {
|
|
2209
2209
|
const out = this._createInstance();
|
|
2210
2210
|
let i = 0;
|
|
2211
|
-
for (const [k, v] of this) if (predicate.call(thisArg,
|
|
2211
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
|
|
2212
2212
|
return out;
|
|
2213
2213
|
}
|
|
2214
2214
|
/**
|
|
@@ -2226,7 +2226,7 @@ var redBlackTreeTyped = (() => {
|
|
|
2226
2226
|
map(cb, options, thisArg) {
|
|
2227
2227
|
const out = this._createLike([], options);
|
|
2228
2228
|
let i = 0;
|
|
2229
|
-
for (const [k, v] of this) out.add(cb.call(thisArg,
|
|
2229
|
+
for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
|
|
2230
2230
|
return out;
|
|
2231
2231
|
}
|
|
2232
2232
|
/**
|
|
@@ -2675,7 +2675,7 @@ var redBlackTreeTyped = (() => {
|
|
|
2675
2675
|
};
|
|
2676
2676
|
|
|
2677
2677
|
// src/data-structures/binary-tree/bst.ts
|
|
2678
|
-
var BSTNode = class
|
|
2678
|
+
var BSTNode = class {
|
|
2679
2679
|
/**
|
|
2680
2680
|
* Creates an instance of BSTNode.
|
|
2681
2681
|
* @remarks Time O(1), Space O(1)
|
|
@@ -2684,10 +2684,16 @@ var redBlackTreeTyped = (() => {
|
|
|
2684
2684
|
* @param [value] - The value associated with the key.
|
|
2685
2685
|
*/
|
|
2686
2686
|
constructor(key, value) {
|
|
2687
|
-
|
|
2687
|
+
__publicField(this, "key");
|
|
2688
|
+
__publicField(this, "value");
|
|
2688
2689
|
__publicField(this, "parent");
|
|
2689
2690
|
__publicField(this, "_left");
|
|
2690
2691
|
__publicField(this, "_right");
|
|
2692
|
+
__publicField(this, "_height", 0);
|
|
2693
|
+
__publicField(this, "_color", "BLACK");
|
|
2694
|
+
__publicField(this, "_count", 1);
|
|
2695
|
+
this.key = key;
|
|
2696
|
+
this.value = value;
|
|
2691
2697
|
}
|
|
2692
2698
|
/**
|
|
2693
2699
|
* Gets the left child of the node.
|
|
@@ -2727,6 +2733,77 @@ var redBlackTreeTyped = (() => {
|
|
|
2727
2733
|
if (v) v.parent = this;
|
|
2728
2734
|
this._right = v;
|
|
2729
2735
|
}
|
|
2736
|
+
/**
|
|
2737
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
2738
|
+
* @remarks Time O(1), Space O(1)
|
|
2739
|
+
*
|
|
2740
|
+
* @returns The height.
|
|
2741
|
+
*/
|
|
2742
|
+
get height() {
|
|
2743
|
+
return this._height;
|
|
2744
|
+
}
|
|
2745
|
+
/**
|
|
2746
|
+
* Sets the height of the node.
|
|
2747
|
+
* @remarks Time O(1), Space O(1)
|
|
2748
|
+
*
|
|
2749
|
+
* @param value - The new height.
|
|
2750
|
+
*/
|
|
2751
|
+
set height(value) {
|
|
2752
|
+
this._height = value;
|
|
2753
|
+
}
|
|
2754
|
+
/**
|
|
2755
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
2756
|
+
* @remarks Time O(1), Space O(1)
|
|
2757
|
+
*
|
|
2758
|
+
* @returns The node's color.
|
|
2759
|
+
*/
|
|
2760
|
+
get color() {
|
|
2761
|
+
return this._color;
|
|
2762
|
+
}
|
|
2763
|
+
/**
|
|
2764
|
+
* Sets the color of the node.
|
|
2765
|
+
* @remarks Time O(1), Space O(1)
|
|
2766
|
+
*
|
|
2767
|
+
* @param value - The new color.
|
|
2768
|
+
*/
|
|
2769
|
+
set color(value) {
|
|
2770
|
+
this._color = value;
|
|
2771
|
+
}
|
|
2772
|
+
/**
|
|
2773
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
2774
|
+
* @remarks Time O(1), Space O(1)
|
|
2775
|
+
*
|
|
2776
|
+
* @returns The subtree node count.
|
|
2777
|
+
*/
|
|
2778
|
+
get count() {
|
|
2779
|
+
return this._count;
|
|
2780
|
+
}
|
|
2781
|
+
/**
|
|
2782
|
+
* Sets the count of nodes in the subtree.
|
|
2783
|
+
* @remarks Time O(1), Space O(1)
|
|
2784
|
+
*
|
|
2785
|
+
* @param value - The new count.
|
|
2786
|
+
*/
|
|
2787
|
+
set count(value) {
|
|
2788
|
+
this._count = value;
|
|
2789
|
+
}
|
|
2790
|
+
/**
|
|
2791
|
+
* Gets the position of the node relative to its parent.
|
|
2792
|
+
* @remarks Time O(1), Space O(1)
|
|
2793
|
+
*
|
|
2794
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
2795
|
+
*/
|
|
2796
|
+
get familyPosition() {
|
|
2797
|
+
if (!this.parent) {
|
|
2798
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
2799
|
+
}
|
|
2800
|
+
if (this.parent.left === this) {
|
|
2801
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
2802
|
+
} else if (this.parent.right === this) {
|
|
2803
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
2804
|
+
}
|
|
2805
|
+
return "MAL_NODE";
|
|
2806
|
+
}
|
|
2730
2807
|
};
|
|
2731
2808
|
var BST = class extends BinaryTree {
|
|
2732
2809
|
/**
|
|
@@ -3245,7 +3322,7 @@ var redBlackTreeTyped = (() => {
|
|
|
3245
3322
|
const out = this._createLike([], options);
|
|
3246
3323
|
let index = 0;
|
|
3247
3324
|
for (const [key, value] of this) {
|
|
3248
|
-
out.add(callback.call(thisArg,
|
|
3325
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
3249
3326
|
}
|
|
3250
3327
|
return out;
|
|
3251
3328
|
}
|
|
@@ -3402,7 +3479,7 @@ var redBlackTreeTyped = (() => {
|
|
|
3402
3479
|
};
|
|
3403
3480
|
|
|
3404
3481
|
// src/data-structures/binary-tree/red-black-tree.ts
|
|
3405
|
-
var RedBlackTreeNode = class
|
|
3482
|
+
var RedBlackTreeNode = class {
|
|
3406
3483
|
/**
|
|
3407
3484
|
* Create a Red-Black Tree and optionally bulk-insert items.
|
|
3408
3485
|
* @remarks Time O(n log n), Space O(n)
|
|
@@ -3412,11 +3489,17 @@ var redBlackTreeTyped = (() => {
|
|
|
3412
3489
|
* @returns New RedBlackTree instance.
|
|
3413
3490
|
*/
|
|
3414
3491
|
constructor(key, value, color = "BLACK") {
|
|
3415
|
-
|
|
3492
|
+
__publicField(this, "key");
|
|
3493
|
+
__publicField(this, "value");
|
|
3416
3494
|
__publicField(this, "parent");
|
|
3417
3495
|
__publicField(this, "_left");
|
|
3418
3496
|
__publicField(this, "_right");
|
|
3419
|
-
this
|
|
3497
|
+
__publicField(this, "_height", 0);
|
|
3498
|
+
__publicField(this, "_color", "BLACK");
|
|
3499
|
+
__publicField(this, "_count", 1);
|
|
3500
|
+
this.key = key;
|
|
3501
|
+
this.value = value;
|
|
3502
|
+
this.color = color;
|
|
3420
3503
|
}
|
|
3421
3504
|
/**
|
|
3422
3505
|
* Get the left child pointer.
|
|
@@ -3458,6 +3541,77 @@ var redBlackTreeTyped = (() => {
|
|
|
3458
3541
|
}
|
|
3459
3542
|
this._right = v;
|
|
3460
3543
|
}
|
|
3544
|
+
/**
|
|
3545
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
3546
|
+
* @remarks Time O(1), Space O(1)
|
|
3547
|
+
*
|
|
3548
|
+
* @returns The height.
|
|
3549
|
+
*/
|
|
3550
|
+
get height() {
|
|
3551
|
+
return this._height;
|
|
3552
|
+
}
|
|
3553
|
+
/**
|
|
3554
|
+
* Sets the height of the node.
|
|
3555
|
+
* @remarks Time O(1), Space O(1)
|
|
3556
|
+
*
|
|
3557
|
+
* @param value - The new height.
|
|
3558
|
+
*/
|
|
3559
|
+
set height(value) {
|
|
3560
|
+
this._height = value;
|
|
3561
|
+
}
|
|
3562
|
+
/**
|
|
3563
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
3564
|
+
* @remarks Time O(1), Space O(1)
|
|
3565
|
+
*
|
|
3566
|
+
* @returns The node's color.
|
|
3567
|
+
*/
|
|
3568
|
+
get color() {
|
|
3569
|
+
return this._color;
|
|
3570
|
+
}
|
|
3571
|
+
/**
|
|
3572
|
+
* Sets the color of the node.
|
|
3573
|
+
* @remarks Time O(1), Space O(1)
|
|
3574
|
+
*
|
|
3575
|
+
* @param value - The new color.
|
|
3576
|
+
*/
|
|
3577
|
+
set color(value) {
|
|
3578
|
+
this._color = value;
|
|
3579
|
+
}
|
|
3580
|
+
/**
|
|
3581
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
3582
|
+
* @remarks Time O(1), Space O(1)
|
|
3583
|
+
*
|
|
3584
|
+
* @returns The subtree node count.
|
|
3585
|
+
*/
|
|
3586
|
+
get count() {
|
|
3587
|
+
return this._count;
|
|
3588
|
+
}
|
|
3589
|
+
/**
|
|
3590
|
+
* Sets the count of nodes in the subtree.
|
|
3591
|
+
* @remarks Time O(1), Space O(1)
|
|
3592
|
+
*
|
|
3593
|
+
* @param value - The new count.
|
|
3594
|
+
*/
|
|
3595
|
+
set count(value) {
|
|
3596
|
+
this._count = value;
|
|
3597
|
+
}
|
|
3598
|
+
/**
|
|
3599
|
+
* Gets the position of the node relative to its parent.
|
|
3600
|
+
* @remarks Time O(1), Space O(1)
|
|
3601
|
+
*
|
|
3602
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
3603
|
+
*/
|
|
3604
|
+
get familyPosition() {
|
|
3605
|
+
if (!this.parent) {
|
|
3606
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
3607
|
+
}
|
|
3608
|
+
if (this.parent.left === this) {
|
|
3609
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
3610
|
+
} else if (this.parent.right === this) {
|
|
3611
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
3612
|
+
}
|
|
3613
|
+
return "MAL_NODE";
|
|
3614
|
+
}
|
|
3461
3615
|
};
|
|
3462
3616
|
var RedBlackTree = class extends BST {
|
|
3463
3617
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -3606,7 +3760,7 @@ var redBlackTreeTyped = (() => {
|
|
|
3606
3760
|
const out = this._createLike([], options);
|
|
3607
3761
|
let index = 0;
|
|
3608
3762
|
for (const [key, value] of this) {
|
|
3609
|
-
out.add(callback.call(thisArg,
|
|
3763
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
3610
3764
|
}
|
|
3611
3765
|
return out;
|
|
3612
3766
|
}
|
|
@@ -3635,16 +3789,16 @@ var redBlackTreeTyped = (() => {
|
|
|
3635
3789
|
* @returns Status string: 'CREATED' or 'UPDATED'.
|
|
3636
3790
|
*/
|
|
3637
3791
|
_insert(node) {
|
|
3638
|
-
var _a, _b;
|
|
3639
|
-
let current = this.root;
|
|
3792
|
+
var _a, _b, _c;
|
|
3793
|
+
let current = (_a = this.root) != null ? _a : this.NIL;
|
|
3640
3794
|
let parent = void 0;
|
|
3641
|
-
while (this.
|
|
3795
|
+
while (current !== this.NIL) {
|
|
3642
3796
|
parent = current;
|
|
3643
3797
|
const compared = this._compare(node.key, current.key);
|
|
3644
3798
|
if (compared < 0) {
|
|
3645
|
-
current = (
|
|
3799
|
+
current = (_b = current.left) != null ? _b : this.NIL;
|
|
3646
3800
|
} else if (compared > 0) {
|
|
3647
|
-
current = (
|
|
3801
|
+
current = (_c = current.right) != null ? _c : this.NIL;
|
|
3648
3802
|
} else {
|
|
3649
3803
|
this._replaceNode(current, node);
|
|
3650
3804
|
return "UPDATED";
|
|
@@ -3704,7 +3858,7 @@ var redBlackTreeTyped = (() => {
|
|
|
3704
3858
|
z = z.parent;
|
|
3705
3859
|
this._leftRotate(z);
|
|
3706
3860
|
}
|
|
3707
|
-
if (z &&
|
|
3861
|
+
if (z && z.parent && z.parent.parent) {
|
|
3708
3862
|
z.parent.color = "BLACK";
|
|
3709
3863
|
z.parent.parent.color = "RED";
|
|
3710
3864
|
this._rightRotate(z.parent.parent);
|
|
@@ -3722,7 +3876,7 @@ var redBlackTreeTyped = (() => {
|
|
|
3722
3876
|
z = z.parent;
|
|
3723
3877
|
this._rightRotate(z);
|
|
3724
3878
|
}
|
|
3725
|
-
if (z &&
|
|
3879
|
+
if (z && z.parent && z.parent.parent) {
|
|
3726
3880
|
z.parent.color = "BLACK";
|
|
3727
3881
|
z.parent.parent.color = "RED";
|
|
3728
3882
|
this._leftRotate(z.parent.parent);
|
|
@@ -3805,7 +3959,7 @@ var redBlackTreeTyped = (() => {
|
|
|
3805
3959
|
}
|
|
3806
3960
|
const y = x.right;
|
|
3807
3961
|
x.right = y.left;
|
|
3808
|
-
if (
|
|
3962
|
+
if (y.left && y.left !== this.NIL) {
|
|
3809
3963
|
y.left.parent = x;
|
|
3810
3964
|
}
|
|
3811
3965
|
y.parent = x.parent;
|
|
@@ -3831,7 +3985,7 @@ var redBlackTreeTyped = (() => {
|
|
|
3831
3985
|
}
|
|
3832
3986
|
const x = y.left;
|
|
3833
3987
|
y.left = x.right;
|
|
3834
|
-
if (
|
|
3988
|
+
if (x.right && x.right !== this.NIL) {
|
|
3835
3989
|
x.right.parent = y;
|
|
3836
3990
|
}
|
|
3837
3991
|
x.parent = y.parent;
|