tree-multimap-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/dist/cjs/index.cjs +424 -184
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +4300 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +424 -184
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +4289 -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/tree-multimap-typed.js +259 -17
- package/dist/umd/tree-multimap-typed.js.map +1 -1
- package/dist/umd/tree-multimap-typed.min.js +3 -3
- package/dist/umd/tree-multimap-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/tsup.node.config.js +40 -6
|
@@ -2677,7 +2677,7 @@ var treeMultimapTyped = (() => {
|
|
|
2677
2677
|
};
|
|
2678
2678
|
|
|
2679
2679
|
// src/data-structures/binary-tree/bst.ts
|
|
2680
|
-
var BSTNode = class
|
|
2680
|
+
var BSTNode = class {
|
|
2681
2681
|
/**
|
|
2682
2682
|
* Creates an instance of BSTNode.
|
|
2683
2683
|
* @remarks Time O(1), Space O(1)
|
|
@@ -2686,10 +2686,16 @@ var treeMultimapTyped = (() => {
|
|
|
2686
2686
|
* @param [value] - The value associated with the key.
|
|
2687
2687
|
*/
|
|
2688
2688
|
constructor(key, value) {
|
|
2689
|
-
|
|
2689
|
+
__publicField(this, "key");
|
|
2690
|
+
__publicField(this, "value");
|
|
2690
2691
|
__publicField(this, "parent");
|
|
2691
2692
|
__publicField(this, "_left");
|
|
2692
2693
|
__publicField(this, "_right");
|
|
2694
|
+
__publicField(this, "_height", 0);
|
|
2695
|
+
__publicField(this, "_color", "BLACK");
|
|
2696
|
+
__publicField(this, "_count", 1);
|
|
2697
|
+
this.key = key;
|
|
2698
|
+
this.value = value;
|
|
2693
2699
|
}
|
|
2694
2700
|
/**
|
|
2695
2701
|
* Gets the left child of the node.
|
|
@@ -2729,6 +2735,77 @@ var treeMultimapTyped = (() => {
|
|
|
2729
2735
|
if (v) v.parent = this;
|
|
2730
2736
|
this._right = v;
|
|
2731
2737
|
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
2740
|
+
* @remarks Time O(1), Space O(1)
|
|
2741
|
+
*
|
|
2742
|
+
* @returns The height.
|
|
2743
|
+
*/
|
|
2744
|
+
get height() {
|
|
2745
|
+
return this._height;
|
|
2746
|
+
}
|
|
2747
|
+
/**
|
|
2748
|
+
* Sets the height of the node.
|
|
2749
|
+
* @remarks Time O(1), Space O(1)
|
|
2750
|
+
*
|
|
2751
|
+
* @param value - The new height.
|
|
2752
|
+
*/
|
|
2753
|
+
set height(value) {
|
|
2754
|
+
this._height = value;
|
|
2755
|
+
}
|
|
2756
|
+
/**
|
|
2757
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
2758
|
+
* @remarks Time O(1), Space O(1)
|
|
2759
|
+
*
|
|
2760
|
+
* @returns The node's color.
|
|
2761
|
+
*/
|
|
2762
|
+
get color() {
|
|
2763
|
+
return this._color;
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Sets the color of the node.
|
|
2767
|
+
* @remarks Time O(1), Space O(1)
|
|
2768
|
+
*
|
|
2769
|
+
* @param value - The new color.
|
|
2770
|
+
*/
|
|
2771
|
+
set color(value) {
|
|
2772
|
+
this._color = value;
|
|
2773
|
+
}
|
|
2774
|
+
/**
|
|
2775
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
2776
|
+
* @remarks Time O(1), Space O(1)
|
|
2777
|
+
*
|
|
2778
|
+
* @returns The subtree node count.
|
|
2779
|
+
*/
|
|
2780
|
+
get count() {
|
|
2781
|
+
return this._count;
|
|
2782
|
+
}
|
|
2783
|
+
/**
|
|
2784
|
+
* Sets the count of nodes in the subtree.
|
|
2785
|
+
* @remarks Time O(1), Space O(1)
|
|
2786
|
+
*
|
|
2787
|
+
* @param value - The new count.
|
|
2788
|
+
*/
|
|
2789
|
+
set count(value) {
|
|
2790
|
+
this._count = value;
|
|
2791
|
+
}
|
|
2792
|
+
/**
|
|
2793
|
+
* Gets the position of the node relative to its parent.
|
|
2794
|
+
* @remarks Time O(1), Space O(1)
|
|
2795
|
+
*
|
|
2796
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
2797
|
+
*/
|
|
2798
|
+
get familyPosition() {
|
|
2799
|
+
if (!this.parent) {
|
|
2800
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
2801
|
+
}
|
|
2802
|
+
if (this.parent.left === this) {
|
|
2803
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
2804
|
+
} else if (this.parent.right === this) {
|
|
2805
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
2806
|
+
}
|
|
2807
|
+
return "MAL_NODE";
|
|
2808
|
+
}
|
|
2732
2809
|
};
|
|
2733
2810
|
var BST = class extends BinaryTree {
|
|
2734
2811
|
/**
|
|
@@ -3404,7 +3481,7 @@ var treeMultimapTyped = (() => {
|
|
|
3404
3481
|
};
|
|
3405
3482
|
|
|
3406
3483
|
// src/data-structures/binary-tree/red-black-tree.ts
|
|
3407
|
-
var RedBlackTreeNode = class
|
|
3484
|
+
var RedBlackTreeNode = class {
|
|
3408
3485
|
/**
|
|
3409
3486
|
* Create a Red-Black Tree and optionally bulk-insert items.
|
|
3410
3487
|
* @remarks Time O(n log n), Space O(n)
|
|
@@ -3414,11 +3491,17 @@ var treeMultimapTyped = (() => {
|
|
|
3414
3491
|
* @returns New RedBlackTree instance.
|
|
3415
3492
|
*/
|
|
3416
3493
|
constructor(key, value, color = "BLACK") {
|
|
3417
|
-
|
|
3494
|
+
__publicField(this, "key");
|
|
3495
|
+
__publicField(this, "value");
|
|
3418
3496
|
__publicField(this, "parent");
|
|
3419
3497
|
__publicField(this, "_left");
|
|
3420
3498
|
__publicField(this, "_right");
|
|
3421
|
-
this
|
|
3499
|
+
__publicField(this, "_height", 0);
|
|
3500
|
+
__publicField(this, "_color", "BLACK");
|
|
3501
|
+
__publicField(this, "_count", 1);
|
|
3502
|
+
this.key = key;
|
|
3503
|
+
this.value = value;
|
|
3504
|
+
this.color = color;
|
|
3422
3505
|
}
|
|
3423
3506
|
/**
|
|
3424
3507
|
* Get the left child pointer.
|
|
@@ -3460,6 +3543,77 @@ var treeMultimapTyped = (() => {
|
|
|
3460
3543
|
}
|
|
3461
3544
|
this._right = v;
|
|
3462
3545
|
}
|
|
3546
|
+
/**
|
|
3547
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
3548
|
+
* @remarks Time O(1), Space O(1)
|
|
3549
|
+
*
|
|
3550
|
+
* @returns The height.
|
|
3551
|
+
*/
|
|
3552
|
+
get height() {
|
|
3553
|
+
return this._height;
|
|
3554
|
+
}
|
|
3555
|
+
/**
|
|
3556
|
+
* Sets the height of the node.
|
|
3557
|
+
* @remarks Time O(1), Space O(1)
|
|
3558
|
+
*
|
|
3559
|
+
* @param value - The new height.
|
|
3560
|
+
*/
|
|
3561
|
+
set height(value) {
|
|
3562
|
+
this._height = value;
|
|
3563
|
+
}
|
|
3564
|
+
/**
|
|
3565
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
3566
|
+
* @remarks Time O(1), Space O(1)
|
|
3567
|
+
*
|
|
3568
|
+
* @returns The node's color.
|
|
3569
|
+
*/
|
|
3570
|
+
get color() {
|
|
3571
|
+
return this._color;
|
|
3572
|
+
}
|
|
3573
|
+
/**
|
|
3574
|
+
* Sets the color of the node.
|
|
3575
|
+
* @remarks Time O(1), Space O(1)
|
|
3576
|
+
*
|
|
3577
|
+
* @param value - The new color.
|
|
3578
|
+
*/
|
|
3579
|
+
set color(value) {
|
|
3580
|
+
this._color = value;
|
|
3581
|
+
}
|
|
3582
|
+
/**
|
|
3583
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
3584
|
+
* @remarks Time O(1), Space O(1)
|
|
3585
|
+
*
|
|
3586
|
+
* @returns The subtree node count.
|
|
3587
|
+
*/
|
|
3588
|
+
get count() {
|
|
3589
|
+
return this._count;
|
|
3590
|
+
}
|
|
3591
|
+
/**
|
|
3592
|
+
* Sets the count of nodes in the subtree.
|
|
3593
|
+
* @remarks Time O(1), Space O(1)
|
|
3594
|
+
*
|
|
3595
|
+
* @param value - The new count.
|
|
3596
|
+
*/
|
|
3597
|
+
set count(value) {
|
|
3598
|
+
this._count = value;
|
|
3599
|
+
}
|
|
3600
|
+
/**
|
|
3601
|
+
* Gets the position of the node relative to its parent.
|
|
3602
|
+
* @remarks Time O(1), Space O(1)
|
|
3603
|
+
*
|
|
3604
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
3605
|
+
*/
|
|
3606
|
+
get familyPosition() {
|
|
3607
|
+
if (!this.parent) {
|
|
3608
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
3609
|
+
}
|
|
3610
|
+
if (this.parent.left === this) {
|
|
3611
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
3612
|
+
} else if (this.parent.right === this) {
|
|
3613
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
3614
|
+
}
|
|
3615
|
+
return "MAL_NODE";
|
|
3616
|
+
}
|
|
3463
3617
|
};
|
|
3464
3618
|
var RedBlackTree = class extends BST {
|
|
3465
3619
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -3637,16 +3791,16 @@ var treeMultimapTyped = (() => {
|
|
|
3637
3791
|
* @returns Status string: 'CREATED' or 'UPDATED'.
|
|
3638
3792
|
*/
|
|
3639
3793
|
_insert(node) {
|
|
3640
|
-
var _a, _b;
|
|
3641
|
-
let current = this.root;
|
|
3794
|
+
var _a, _b, _c;
|
|
3795
|
+
let current = (_a = this.root) != null ? _a : this.NIL;
|
|
3642
3796
|
let parent = void 0;
|
|
3643
|
-
while (this.
|
|
3797
|
+
while (current !== this.NIL) {
|
|
3644
3798
|
parent = current;
|
|
3645
3799
|
const compared = this._compare(node.key, current.key);
|
|
3646
3800
|
if (compared < 0) {
|
|
3647
|
-
current = (
|
|
3801
|
+
current = (_b = current.left) != null ? _b : this.NIL;
|
|
3648
3802
|
} else if (compared > 0) {
|
|
3649
|
-
current = (
|
|
3803
|
+
current = (_c = current.right) != null ? _c : this.NIL;
|
|
3650
3804
|
} else {
|
|
3651
3805
|
this._replaceNode(current, node);
|
|
3652
3806
|
return "UPDATED";
|
|
@@ -3706,7 +3860,7 @@ var treeMultimapTyped = (() => {
|
|
|
3706
3860
|
z = z.parent;
|
|
3707
3861
|
this._leftRotate(z);
|
|
3708
3862
|
}
|
|
3709
|
-
if (z &&
|
|
3863
|
+
if (z && z.parent && z.parent.parent) {
|
|
3710
3864
|
z.parent.color = "BLACK";
|
|
3711
3865
|
z.parent.parent.color = "RED";
|
|
3712
3866
|
this._rightRotate(z.parent.parent);
|
|
@@ -3724,7 +3878,7 @@ var treeMultimapTyped = (() => {
|
|
|
3724
3878
|
z = z.parent;
|
|
3725
3879
|
this._rightRotate(z);
|
|
3726
3880
|
}
|
|
3727
|
-
if (z &&
|
|
3881
|
+
if (z && z.parent && z.parent.parent) {
|
|
3728
3882
|
z.parent.color = "BLACK";
|
|
3729
3883
|
z.parent.parent.color = "RED";
|
|
3730
3884
|
this._leftRotate(z.parent.parent);
|
|
@@ -3807,7 +3961,7 @@ var treeMultimapTyped = (() => {
|
|
|
3807
3961
|
}
|
|
3808
3962
|
const y = x.right;
|
|
3809
3963
|
x.right = y.left;
|
|
3810
|
-
if (
|
|
3964
|
+
if (y.left && y.left !== this.NIL) {
|
|
3811
3965
|
y.left.parent = x;
|
|
3812
3966
|
}
|
|
3813
3967
|
y.parent = x.parent;
|
|
@@ -3833,7 +3987,7 @@ var treeMultimapTyped = (() => {
|
|
|
3833
3987
|
}
|
|
3834
3988
|
const x = y.left;
|
|
3835
3989
|
y.left = x.right;
|
|
3836
|
-
if (
|
|
3990
|
+
if (x.right && x.right !== this.NIL) {
|
|
3837
3991
|
x.right.parent = y;
|
|
3838
3992
|
}
|
|
3839
3993
|
x.parent = y.parent;
|
|
@@ -3850,7 +4004,7 @@ var treeMultimapTyped = (() => {
|
|
|
3850
4004
|
};
|
|
3851
4005
|
|
|
3852
4006
|
// src/data-structures/binary-tree/tree-multi-map.ts
|
|
3853
|
-
var TreeMultiMapNode = class
|
|
4007
|
+
var TreeMultiMapNode = class {
|
|
3854
4008
|
/**
|
|
3855
4009
|
* Create a TreeMultiMap node with an optional value bucket.
|
|
3856
4010
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3858,11 +4012,18 @@ var treeMultimapTyped = (() => {
|
|
|
3858
4012
|
* @param [value] - Initial array of values.
|
|
3859
4013
|
* @returns New TreeMultiMapNode instance.
|
|
3860
4014
|
*/
|
|
3861
|
-
constructor(key, value) {
|
|
3862
|
-
|
|
4015
|
+
constructor(key, value = [], color = "BLACK") {
|
|
4016
|
+
__publicField(this, "key");
|
|
4017
|
+
__publicField(this, "value");
|
|
3863
4018
|
__publicField(this, "parent");
|
|
3864
4019
|
__publicField(this, "_left");
|
|
3865
4020
|
__publicField(this, "_right");
|
|
4021
|
+
__publicField(this, "_height", 0);
|
|
4022
|
+
__publicField(this, "_color", "BLACK");
|
|
4023
|
+
__publicField(this, "_count", 1);
|
|
4024
|
+
this.key = key;
|
|
4025
|
+
this.value = value;
|
|
4026
|
+
this.color = color;
|
|
3866
4027
|
}
|
|
3867
4028
|
/**
|
|
3868
4029
|
* Get the left child pointer.
|
|
@@ -3904,6 +4065,77 @@ var treeMultimapTyped = (() => {
|
|
|
3904
4065
|
}
|
|
3905
4066
|
this._right = v;
|
|
3906
4067
|
}
|
|
4068
|
+
/**
|
|
4069
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
4070
|
+
* @remarks Time O(1), Space O(1)
|
|
4071
|
+
*
|
|
4072
|
+
* @returns The height.
|
|
4073
|
+
*/
|
|
4074
|
+
get height() {
|
|
4075
|
+
return this._height;
|
|
4076
|
+
}
|
|
4077
|
+
/**
|
|
4078
|
+
* Sets the height of the node.
|
|
4079
|
+
* @remarks Time O(1), Space O(1)
|
|
4080
|
+
*
|
|
4081
|
+
* @param value - The new height.
|
|
4082
|
+
*/
|
|
4083
|
+
set height(value) {
|
|
4084
|
+
this._height = value;
|
|
4085
|
+
}
|
|
4086
|
+
/**
|
|
4087
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
4088
|
+
* @remarks Time O(1), Space O(1)
|
|
4089
|
+
*
|
|
4090
|
+
* @returns The node's color.
|
|
4091
|
+
*/
|
|
4092
|
+
get color() {
|
|
4093
|
+
return this._color;
|
|
4094
|
+
}
|
|
4095
|
+
/**
|
|
4096
|
+
* Sets the color of the node.
|
|
4097
|
+
* @remarks Time O(1), Space O(1)
|
|
4098
|
+
*
|
|
4099
|
+
* @param value - The new color.
|
|
4100
|
+
*/
|
|
4101
|
+
set color(value) {
|
|
4102
|
+
this._color = value;
|
|
4103
|
+
}
|
|
4104
|
+
/**
|
|
4105
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
4106
|
+
* @remarks Time O(1), Space O(1)
|
|
4107
|
+
*
|
|
4108
|
+
* @returns The subtree node count.
|
|
4109
|
+
*/
|
|
4110
|
+
get count() {
|
|
4111
|
+
return this._count;
|
|
4112
|
+
}
|
|
4113
|
+
/**
|
|
4114
|
+
* Sets the count of nodes in the subtree.
|
|
4115
|
+
* @remarks Time O(1), Space O(1)
|
|
4116
|
+
*
|
|
4117
|
+
* @param value - The new count.
|
|
4118
|
+
*/
|
|
4119
|
+
set count(value) {
|
|
4120
|
+
this._count = value;
|
|
4121
|
+
}
|
|
4122
|
+
/**
|
|
4123
|
+
* Gets the position of the node relative to its parent.
|
|
4124
|
+
* @remarks Time O(1), Space O(1)
|
|
4125
|
+
*
|
|
4126
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
4127
|
+
*/
|
|
4128
|
+
get familyPosition() {
|
|
4129
|
+
if (!this.parent) {
|
|
4130
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
4131
|
+
}
|
|
4132
|
+
if (this.parent.left === this) {
|
|
4133
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
4134
|
+
} else if (this.parent.right === this) {
|
|
4135
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
4136
|
+
}
|
|
4137
|
+
return "MAL_NODE";
|
|
4138
|
+
}
|
|
3907
4139
|
};
|
|
3908
4140
|
var TreeMultiMap = class extends RedBlackTree {
|
|
3909
4141
|
/**
|
|
@@ -3922,6 +4154,16 @@ var treeMultimapTyped = (() => {
|
|
|
3922
4154
|
createNode(key, value = []) {
|
|
3923
4155
|
return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
|
|
3924
4156
|
}
|
|
4157
|
+
/**
|
|
4158
|
+
* Checks if the given item is a `TreeMultiMapNode` instance.
|
|
4159
|
+
* @remarks Time O(1), Space O(1)
|
|
4160
|
+
*
|
|
4161
|
+
* @param keyNodeOrEntry - The item to check.
|
|
4162
|
+
* @returns True if it's a TreeMultiMapNode, false otherwise.
|
|
4163
|
+
*/
|
|
4164
|
+
isNode(keyNodeOrEntry) {
|
|
4165
|
+
return keyNodeOrEntry instanceof TreeMultiMapNode;
|
|
4166
|
+
}
|
|
3925
4167
|
/**
|
|
3926
4168
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
3927
4169
|
* @remarks Time O(log N + M), Space O(1)
|