avl-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 +309 -154
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +4013 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +309 -154
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +4006 -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/avl-tree-typed.js +166 -12
- package/dist/umd/avl-tree-typed.js.map +1 -1
- package/dist/umd/avl-tree-typed.min.js +3 -3
- package/dist/umd/avl-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
|
@@ -909,7 +909,7 @@ var avlTreeTyped = (() => {
|
|
|
909
909
|
every(predicate, thisArg) {
|
|
910
910
|
let index = 0;
|
|
911
911
|
for (const item of this) {
|
|
912
|
-
if (!predicate.call(thisArg, item[
|
|
912
|
+
if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
913
913
|
return false;
|
|
914
914
|
}
|
|
915
915
|
}
|
|
@@ -925,7 +925,7 @@ var avlTreeTyped = (() => {
|
|
|
925
925
|
some(predicate, thisArg) {
|
|
926
926
|
let index = 0;
|
|
927
927
|
for (const item of this) {
|
|
928
|
-
if (predicate.call(thisArg, item[
|
|
928
|
+
if (predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
929
929
|
return true;
|
|
930
930
|
}
|
|
931
931
|
}
|
|
@@ -941,7 +941,7 @@ var avlTreeTyped = (() => {
|
|
|
941
941
|
let index = 0;
|
|
942
942
|
for (const item of this) {
|
|
943
943
|
const [key, value] = item;
|
|
944
|
-
callbackfn.call(thisArg,
|
|
944
|
+
callbackfn.call(thisArg, value, key, index++, this);
|
|
945
945
|
}
|
|
946
946
|
}
|
|
947
947
|
/**
|
|
@@ -955,7 +955,7 @@ var avlTreeTyped = (() => {
|
|
|
955
955
|
let index = 0;
|
|
956
956
|
for (const item of this) {
|
|
957
957
|
const [key, value] = item;
|
|
958
|
-
if (callbackfn.call(thisArg,
|
|
958
|
+
if (callbackfn.call(thisArg, value, key, index++, this)) return item;
|
|
959
959
|
}
|
|
960
960
|
return;
|
|
961
961
|
}
|
|
@@ -2201,7 +2201,7 @@ var avlTreeTyped = (() => {
|
|
|
2201
2201
|
filter(predicate, thisArg) {
|
|
2202
2202
|
const out = this._createInstance();
|
|
2203
2203
|
let i = 0;
|
|
2204
|
-
for (const [k, v] of this) if (predicate.call(thisArg,
|
|
2204
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
|
|
2205
2205
|
return out;
|
|
2206
2206
|
}
|
|
2207
2207
|
/**
|
|
@@ -2219,7 +2219,7 @@ var avlTreeTyped = (() => {
|
|
|
2219
2219
|
map(cb, options, thisArg) {
|
|
2220
2220
|
const out = this._createLike([], options);
|
|
2221
2221
|
let i = 0;
|
|
2222
|
-
for (const [k, v] of this) out.add(cb.call(thisArg,
|
|
2222
|
+
for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
|
|
2223
2223
|
return out;
|
|
2224
2224
|
}
|
|
2225
2225
|
/**
|
|
@@ -2668,7 +2668,7 @@ var avlTreeTyped = (() => {
|
|
|
2668
2668
|
};
|
|
2669
2669
|
|
|
2670
2670
|
// src/data-structures/binary-tree/bst.ts
|
|
2671
|
-
var BSTNode = class
|
|
2671
|
+
var BSTNode = class {
|
|
2672
2672
|
/**
|
|
2673
2673
|
* Creates an instance of BSTNode.
|
|
2674
2674
|
* @remarks Time O(1), Space O(1)
|
|
@@ -2677,10 +2677,16 @@ var avlTreeTyped = (() => {
|
|
|
2677
2677
|
* @param [value] - The value associated with the key.
|
|
2678
2678
|
*/
|
|
2679
2679
|
constructor(key, value) {
|
|
2680
|
-
|
|
2680
|
+
__publicField(this, "key");
|
|
2681
|
+
__publicField(this, "value");
|
|
2681
2682
|
__publicField(this, "parent");
|
|
2682
2683
|
__publicField(this, "_left");
|
|
2683
2684
|
__publicField(this, "_right");
|
|
2685
|
+
__publicField(this, "_height", 0);
|
|
2686
|
+
__publicField(this, "_color", "BLACK");
|
|
2687
|
+
__publicField(this, "_count", 1);
|
|
2688
|
+
this.key = key;
|
|
2689
|
+
this.value = value;
|
|
2684
2690
|
}
|
|
2685
2691
|
/**
|
|
2686
2692
|
* Gets the left child of the node.
|
|
@@ -2720,6 +2726,77 @@ var avlTreeTyped = (() => {
|
|
|
2720
2726
|
if (v) v.parent = this;
|
|
2721
2727
|
this._right = v;
|
|
2722
2728
|
}
|
|
2729
|
+
/**
|
|
2730
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
2731
|
+
* @remarks Time O(1), Space O(1)
|
|
2732
|
+
*
|
|
2733
|
+
* @returns The height.
|
|
2734
|
+
*/
|
|
2735
|
+
get height() {
|
|
2736
|
+
return this._height;
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Sets the height of the node.
|
|
2740
|
+
* @remarks Time O(1), Space O(1)
|
|
2741
|
+
*
|
|
2742
|
+
* @param value - The new height.
|
|
2743
|
+
*/
|
|
2744
|
+
set height(value) {
|
|
2745
|
+
this._height = value;
|
|
2746
|
+
}
|
|
2747
|
+
/**
|
|
2748
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
2749
|
+
* @remarks Time O(1), Space O(1)
|
|
2750
|
+
*
|
|
2751
|
+
* @returns The node's color.
|
|
2752
|
+
*/
|
|
2753
|
+
get color() {
|
|
2754
|
+
return this._color;
|
|
2755
|
+
}
|
|
2756
|
+
/**
|
|
2757
|
+
* Sets the color of the node.
|
|
2758
|
+
* @remarks Time O(1), Space O(1)
|
|
2759
|
+
*
|
|
2760
|
+
* @param value - The new color.
|
|
2761
|
+
*/
|
|
2762
|
+
set color(value) {
|
|
2763
|
+
this._color = value;
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
2767
|
+
* @remarks Time O(1), Space O(1)
|
|
2768
|
+
*
|
|
2769
|
+
* @returns The subtree node count.
|
|
2770
|
+
*/
|
|
2771
|
+
get count() {
|
|
2772
|
+
return this._count;
|
|
2773
|
+
}
|
|
2774
|
+
/**
|
|
2775
|
+
* Sets the count of nodes in the subtree.
|
|
2776
|
+
* @remarks Time O(1), Space O(1)
|
|
2777
|
+
*
|
|
2778
|
+
* @param value - The new count.
|
|
2779
|
+
*/
|
|
2780
|
+
set count(value) {
|
|
2781
|
+
this._count = value;
|
|
2782
|
+
}
|
|
2783
|
+
/**
|
|
2784
|
+
* Gets the position of the node relative to its parent.
|
|
2785
|
+
* @remarks Time O(1), Space O(1)
|
|
2786
|
+
*
|
|
2787
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
2788
|
+
*/
|
|
2789
|
+
get familyPosition() {
|
|
2790
|
+
if (!this.parent) {
|
|
2791
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
2792
|
+
}
|
|
2793
|
+
if (this.parent.left === this) {
|
|
2794
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
2795
|
+
} else if (this.parent.right === this) {
|
|
2796
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
2797
|
+
}
|
|
2798
|
+
return "MAL_NODE";
|
|
2799
|
+
}
|
|
2723
2800
|
};
|
|
2724
2801
|
var BST = class extends BinaryTree {
|
|
2725
2802
|
/**
|
|
@@ -3238,7 +3315,7 @@ var avlTreeTyped = (() => {
|
|
|
3238
3315
|
const out = this._createLike([], options);
|
|
3239
3316
|
let index = 0;
|
|
3240
3317
|
for (const [key, value] of this) {
|
|
3241
|
-
out.add(callback.call(thisArg,
|
|
3318
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
3242
3319
|
}
|
|
3243
3320
|
return out;
|
|
3244
3321
|
}
|
|
@@ -3395,7 +3472,7 @@ var avlTreeTyped = (() => {
|
|
|
3395
3472
|
};
|
|
3396
3473
|
|
|
3397
3474
|
// src/data-structures/binary-tree/avl-tree.ts
|
|
3398
|
-
var AVLTreeNode = class
|
|
3475
|
+
var AVLTreeNode = class {
|
|
3399
3476
|
/**
|
|
3400
3477
|
* Creates an instance of AVLTreeNode.
|
|
3401
3478
|
* @remarks Time O(1), Space O(1)
|
|
@@ -3404,10 +3481,16 @@ var avlTreeTyped = (() => {
|
|
|
3404
3481
|
* @param [value] - The value associated with the key.
|
|
3405
3482
|
*/
|
|
3406
3483
|
constructor(key, value) {
|
|
3407
|
-
|
|
3484
|
+
__publicField(this, "key");
|
|
3485
|
+
__publicField(this, "value");
|
|
3408
3486
|
__publicField(this, "parent");
|
|
3409
3487
|
__publicField(this, "_left");
|
|
3410
3488
|
__publicField(this, "_right");
|
|
3489
|
+
__publicField(this, "_height", 0);
|
|
3490
|
+
__publicField(this, "_color", "BLACK");
|
|
3491
|
+
__publicField(this, "_count", 1);
|
|
3492
|
+
this.key = key;
|
|
3493
|
+
this.value = value;
|
|
3411
3494
|
}
|
|
3412
3495
|
/**
|
|
3413
3496
|
* Gets the left child of the node.
|
|
@@ -3451,6 +3534,77 @@ var avlTreeTyped = (() => {
|
|
|
3451
3534
|
}
|
|
3452
3535
|
this._right = v;
|
|
3453
3536
|
}
|
|
3537
|
+
/**
|
|
3538
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
3539
|
+
* @remarks Time O(1), Space O(1)
|
|
3540
|
+
*
|
|
3541
|
+
* @returns The height.
|
|
3542
|
+
*/
|
|
3543
|
+
get height() {
|
|
3544
|
+
return this._height;
|
|
3545
|
+
}
|
|
3546
|
+
/**
|
|
3547
|
+
* Sets the height of the node.
|
|
3548
|
+
* @remarks Time O(1), Space O(1)
|
|
3549
|
+
*
|
|
3550
|
+
* @param value - The new height.
|
|
3551
|
+
*/
|
|
3552
|
+
set height(value) {
|
|
3553
|
+
this._height = value;
|
|
3554
|
+
}
|
|
3555
|
+
/**
|
|
3556
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
3557
|
+
* @remarks Time O(1), Space O(1)
|
|
3558
|
+
*
|
|
3559
|
+
* @returns The node's color.
|
|
3560
|
+
*/
|
|
3561
|
+
get color() {
|
|
3562
|
+
return this._color;
|
|
3563
|
+
}
|
|
3564
|
+
/**
|
|
3565
|
+
* Sets the color of the node.
|
|
3566
|
+
* @remarks Time O(1), Space O(1)
|
|
3567
|
+
*
|
|
3568
|
+
* @param value - The new color.
|
|
3569
|
+
*/
|
|
3570
|
+
set color(value) {
|
|
3571
|
+
this._color = value;
|
|
3572
|
+
}
|
|
3573
|
+
/**
|
|
3574
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
3575
|
+
* @remarks Time O(1), Space O(1)
|
|
3576
|
+
*
|
|
3577
|
+
* @returns The subtree node count.
|
|
3578
|
+
*/
|
|
3579
|
+
get count() {
|
|
3580
|
+
return this._count;
|
|
3581
|
+
}
|
|
3582
|
+
/**
|
|
3583
|
+
* Sets the count of nodes in the subtree.
|
|
3584
|
+
* @remarks Time O(1), Space O(1)
|
|
3585
|
+
*
|
|
3586
|
+
* @param value - The new count.
|
|
3587
|
+
*/
|
|
3588
|
+
set count(value) {
|
|
3589
|
+
this._count = value;
|
|
3590
|
+
}
|
|
3591
|
+
/**
|
|
3592
|
+
* Gets the position of the node relative to its parent.
|
|
3593
|
+
* @remarks Time O(1), Space O(1)
|
|
3594
|
+
*
|
|
3595
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
3596
|
+
*/
|
|
3597
|
+
get familyPosition() {
|
|
3598
|
+
if (!this.parent) {
|
|
3599
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
3600
|
+
}
|
|
3601
|
+
if (this.parent.left === this) {
|
|
3602
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
3603
|
+
} else if (this.parent.right === this) {
|
|
3604
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
3605
|
+
}
|
|
3606
|
+
return "MAL_NODE";
|
|
3607
|
+
}
|
|
3454
3608
|
};
|
|
3455
3609
|
var AVLTree = class extends BST {
|
|
3456
3610
|
/**
|
|
@@ -3561,7 +3715,7 @@ var avlTreeTyped = (() => {
|
|
|
3561
3715
|
const out = this._createLike([], options);
|
|
3562
3716
|
let index = 0;
|
|
3563
3717
|
for (const [key, value] of this) {
|
|
3564
|
-
out.add(callback.call(thisArg,
|
|
3718
|
+
out.add(callback.call(thisArg, value, key, index++, this));
|
|
3565
3719
|
}
|
|
3566
3720
|
return out;
|
|
3567
3721
|
}
|