data-structure-typed 1.52.0 → 1.52.2
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/README.md +141 -54
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +162 -162
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +11 -11
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +11 -11
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +97 -97
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +52 -52
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +35 -35
- package/dist/cjs/data-structures/binary-tree/bst.js +17 -17
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +8 -8
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +10 -10
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.js +2 -1
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +7 -0
- package/dist/cjs/data-structures/queue/deque.js +16 -1
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +18 -1
- package/dist/cjs/data-structures/queue/queue.js +32 -7
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/common.d.ts +1 -22
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +18 -1
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -0
- package/dist/cjs/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/cjs/types/data-structures/queue/queue.d.ts +3 -1
- package/dist/cjs/utils/number.js +1 -2
- package/dist/cjs/utils/number.js.map +1 -1
- package/dist/cjs/utils/utils.js +2 -2
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +97 -97
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +52 -52
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +35 -35
- package/dist/mjs/data-structures/binary-tree/bst.js +17 -17
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +8 -8
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +10 -10
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/mjs/data-structures/graph/directed-graph.js +2 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +7 -0
- package/dist/mjs/data-structures/queue/deque.js +16 -1
- package/dist/mjs/data-structures/queue/queue.d.ts +18 -1
- package/dist/mjs/data-structures/queue/queue.js +32 -7
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +1 -22
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +18 -1
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -0
- package/dist/mjs/types/data-structures/queue/deque.d.ts +1 -0
- package/dist/mjs/types/data-structures/queue/queue.d.ts +3 -1
- package/dist/umd/data-structure-typed.js +137 -95
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +8 -8
- package/src/data-structures/base/iterable-element-base.ts +2 -2
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +25 -24
- package/src/data-structures/binary-tree/avl-tree.ts +20 -19
- package/src/data-structures/binary-tree/binary-tree.ts +162 -157
- package/src/data-structures/binary-tree/bst.ts +54 -50
- package/src/data-structures/binary-tree/rb-tree.ts +18 -17
- package/src/data-structures/binary-tree/tree-multi-map.ts +18 -17
- package/src/data-structures/graph/abstract-graph.ts +15 -14
- package/src/data-structures/graph/directed-graph.ts +9 -7
- package/src/data-structures/graph/undirected-graph.ts +7 -6
- package/src/data-structures/hash/hash-map.ts +4 -4
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/queue/deque.ts +18 -4
- package/src/data-structures/queue/queue.ts +38 -8
- package/src/data-structures/stack/stack.ts +1 -1
- package/src/data-structures/trie/trie.ts +1 -1
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +2 -24
- package/src/types/data-structures/binary-tree/binary-tree.ts +21 -1
- package/src/types/data-structures/binary-tree/bst.ts +7 -0
- package/src/types/data-structures/graph/abstract-graph.ts +8 -8
- package/src/types/data-structures/queue/deque.ts +4 -1
- package/src/types/data-structures/queue/queue.ts +3 -1
- package/src/types/utils/utils.ts +4 -4
- package/test/integration/bst.test.ts +4 -1
- package/test/performance/data-structures/comparison/comparison.test.ts +12 -4
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +6 -2
- package/test/performance/reportor.ts +23 -8
- package/test/performance/types/reportor.ts +5 -1
- package/test/types/utils/json2html.ts +5 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +6 -2
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +8 -2
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +36 -11
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -1
- package/test/unit/data-structures/binary-tree/bst.test.ts +18 -5
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +2 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +27 -0
- package/test/unit/data-structures/hash/hash-map.test.ts +6 -2
- package/test/unit/data-structures/heap/heap.test.ts +64 -12
- package/test/unit/data-structures/heap/max-heap.test.ts +10 -3
- package/test/unit/data-structures/heap/min-heap.test.ts +3 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +3 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +6 -2
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +22 -6
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +12 -4
- package/test/unit/data-structures/queue/deque.test.ts +31 -6
- package/test/unit/data-structures/queue/queue.test.ts +14 -1
- package/test/unit/data-structures/trie/trie.test.ts +3 -1
- package/test/unit/unrestricted-interconversion.test.ts +3 -1
- package/test/utils/big-o.ts +3 -1
- package/test/utils/json2html.ts +2 -6
|
@@ -3564,6 +3564,11 @@ var dataStructureTyped = (() => {
|
|
|
3564
3564
|
super(options);
|
|
3565
3565
|
__publicField(this, "_elements", []);
|
|
3566
3566
|
__publicField(this, "_offset", 0);
|
|
3567
|
+
__publicField(this, "_autoCompactRatio", 0.5);
|
|
3568
|
+
if (options) {
|
|
3569
|
+
const { autoCompactRatio = 0.5 } = options;
|
|
3570
|
+
this._autoCompactRatio = autoCompactRatio;
|
|
3571
|
+
}
|
|
3567
3572
|
if (elements) {
|
|
3568
3573
|
for (const el of elements) {
|
|
3569
3574
|
if (this.toElementFn)
|
|
@@ -3624,6 +3629,21 @@ var dataStructureTyped = (() => {
|
|
|
3624
3629
|
get last() {
|
|
3625
3630
|
return this.size > 0 ? this.elements[this.elements.length - 1] : void 0;
|
|
3626
3631
|
}
|
|
3632
|
+
/**
|
|
3633
|
+
* This function returns the value of the autoCompactRatio property.
|
|
3634
|
+
* @returns The `autoCompactRatio` property of the object, which is a number.
|
|
3635
|
+
*/
|
|
3636
|
+
get autoCompactRatio() {
|
|
3637
|
+
return this._autoCompactRatio;
|
|
3638
|
+
}
|
|
3639
|
+
/**
|
|
3640
|
+
* The above function sets the autoCompactRatio property to a specified number in TypeScript.
|
|
3641
|
+
* @param {number} v - The parameter `v` represents the value that will be assigned to the
|
|
3642
|
+
* `_autoCompactRatio` property.
|
|
3643
|
+
*/
|
|
3644
|
+
set autoCompactRatio(v) {
|
|
3645
|
+
this._autoCompactRatio = v;
|
|
3646
|
+
}
|
|
3627
3647
|
/**
|
|
3628
3648
|
* Time Complexity: O(n)
|
|
3629
3649
|
* Space Complexity: O(n)
|
|
@@ -3634,7 +3654,6 @@ var dataStructureTyped = (() => {
|
|
|
3634
3654
|
*
|
|
3635
3655
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
3636
3656
|
* @public
|
|
3637
|
-
* @static
|
|
3638
3657
|
* @param {E[]} elements - The "elements" parameter is an array of elements of type E.
|
|
3639
3658
|
* @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
|
|
3640
3659
|
* array.
|
|
@@ -3675,10 +3694,8 @@ var dataStructureTyped = (() => {
|
|
|
3675
3694
|
return void 0;
|
|
3676
3695
|
const first = this.first;
|
|
3677
3696
|
this._offset += 1;
|
|
3678
|
-
if (this.offset
|
|
3679
|
-
|
|
3680
|
-
this._elements = this.elements.slice(this.offset);
|
|
3681
|
-
this._offset = 0;
|
|
3697
|
+
if (this.offset / this.elements.length > this.autoCompactRatio)
|
|
3698
|
+
this.compact();
|
|
3682
3699
|
return first;
|
|
3683
3700
|
}
|
|
3684
3701
|
/**
|
|
@@ -3754,6 +3771,16 @@ var dataStructureTyped = (() => {
|
|
|
3754
3771
|
this._elements = [];
|
|
3755
3772
|
this._offset = 0;
|
|
3756
3773
|
}
|
|
3774
|
+
/**
|
|
3775
|
+
* The `compact` function in TypeScript slices the elements array based on the offset and resets the
|
|
3776
|
+
* offset to zero.
|
|
3777
|
+
* @returns The `compact()` method is returning a boolean value of `true`.
|
|
3778
|
+
*/
|
|
3779
|
+
compact() {
|
|
3780
|
+
this._elements = this.elements.slice(this.offset);
|
|
3781
|
+
this._offset = 0;
|
|
3782
|
+
return true;
|
|
3783
|
+
}
|
|
3757
3784
|
/**
|
|
3758
3785
|
* Time Complexity: O(n)
|
|
3759
3786
|
* Space Complexity: O(n)
|
|
@@ -3863,6 +3890,7 @@ var dataStructureTyped = (() => {
|
|
|
3863
3890
|
constructor(elements = [], options) {
|
|
3864
3891
|
super(options);
|
|
3865
3892
|
__publicField(this, "_bucketSize", 1 << 12);
|
|
3893
|
+
__publicField(this, "_maxLen", -1);
|
|
3866
3894
|
__publicField(this, "_bucketFirst", 0);
|
|
3867
3895
|
__publicField(this, "_firstInBucket", 0);
|
|
3868
3896
|
__publicField(this, "_bucketLast", 0);
|
|
@@ -3871,9 +3899,11 @@ var dataStructureTyped = (() => {
|
|
|
3871
3899
|
__publicField(this, "_buckets", []);
|
|
3872
3900
|
__publicField(this, "_size", 0);
|
|
3873
3901
|
if (options) {
|
|
3874
|
-
const { bucketSize } = options;
|
|
3902
|
+
const { bucketSize, maxLen } = options;
|
|
3875
3903
|
if (typeof bucketSize === "number")
|
|
3876
3904
|
this._bucketSize = bucketSize;
|
|
3905
|
+
if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0)
|
|
3906
|
+
this._maxLen = maxLen;
|
|
3877
3907
|
}
|
|
3878
3908
|
let _size;
|
|
3879
3909
|
if ("length" in elements) {
|
|
@@ -3910,6 +3940,14 @@ var dataStructureTyped = (() => {
|
|
|
3910
3940
|
get bucketSize() {
|
|
3911
3941
|
return this._bucketSize;
|
|
3912
3942
|
}
|
|
3943
|
+
/**
|
|
3944
|
+
* The maxLen function returns the max length of the deque.
|
|
3945
|
+
*
|
|
3946
|
+
* @return The max length of the deque
|
|
3947
|
+
*/
|
|
3948
|
+
get maxLen() {
|
|
3949
|
+
return this._maxLen;
|
|
3950
|
+
}
|
|
3913
3951
|
/**
|
|
3914
3952
|
* The function returns the value of the protected variable `_bucketFirst`.
|
|
3915
3953
|
* @returns The value of the `_bucketFirst` property.
|
|
@@ -4009,6 +4047,8 @@ var dataStructureTyped = (() => {
|
|
|
4009
4047
|
}
|
|
4010
4048
|
this._size += 1;
|
|
4011
4049
|
this._buckets[this._bucketLast][this._lastInBucket] = element;
|
|
4050
|
+
if (this._maxLen > 0 && this._size > this._maxLen)
|
|
4051
|
+
this.shift();
|
|
4012
4052
|
return true;
|
|
4013
4053
|
}
|
|
4014
4054
|
/**
|
|
@@ -4071,6 +4111,8 @@ var dataStructureTyped = (() => {
|
|
|
4071
4111
|
}
|
|
4072
4112
|
this._size += 1;
|
|
4073
4113
|
this._buckets[this._bucketFirst][this._firstInBucket] = element;
|
|
4114
|
+
if (this._maxLen > 0 && this._size > this._maxLen)
|
|
4115
|
+
this.pop();
|
|
4074
4116
|
return true;
|
|
4075
4117
|
}
|
|
4076
4118
|
/**
|
|
@@ -6710,7 +6752,7 @@ var dataStructureTyped = (() => {
|
|
|
6710
6752
|
if (vertex) {
|
|
6711
6753
|
const neighbors = this.getNeighbors(vertex);
|
|
6712
6754
|
for (const neighbor of neighbors) {
|
|
6713
|
-
this.
|
|
6755
|
+
this.deleteEdgeSrcToDest(vertex, neighbor);
|
|
6714
6756
|
}
|
|
6715
6757
|
this._outEdgeMap.delete(vertex);
|
|
6716
6758
|
this._inEdgeMap.delete(vertex);
|
|
@@ -7791,7 +7833,7 @@ var dataStructureTyped = (() => {
|
|
|
7791
7833
|
}
|
|
7792
7834
|
/**
|
|
7793
7835
|
* The function sets the left child of a node and updates its parent reference.
|
|
7794
|
-
* @param {NODE
|
|
7836
|
+
* @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
|
|
7795
7837
|
* `undefined`.
|
|
7796
7838
|
*/
|
|
7797
7839
|
set left(v) {
|
|
@@ -7810,7 +7852,7 @@ var dataStructureTyped = (() => {
|
|
|
7810
7852
|
}
|
|
7811
7853
|
/**
|
|
7812
7854
|
* The function sets the right child of a node and updates its parent.
|
|
7813
|
-
* @param {NODE
|
|
7855
|
+
* @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
|
|
7814
7856
|
* `undefined`.
|
|
7815
7857
|
*/
|
|
7816
7858
|
set right(v) {
|
|
@@ -7839,7 +7881,7 @@ var dataStructureTyped = (() => {
|
|
|
7839
7881
|
var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
7840
7882
|
/**
|
|
7841
7883
|
* The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
|
|
7842
|
-
* @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of
|
|
7884
|
+
* @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of BTNKeyOrNodeOrEntry objects. These objects represent the
|
|
7843
7885
|
* nodes to be added to the binary tree.
|
|
7844
7886
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
7845
7887
|
* configuration options for the binary tree. In this case, it is of type
|
|
@@ -7917,8 +7959,8 @@ var dataStructureTyped = (() => {
|
|
|
7917
7959
|
/**
|
|
7918
7960
|
* The function `keyValueOrEntryOrRawElementToNode` converts a key-value pair, entry, or raw element
|
|
7919
7961
|
* into a node object.
|
|
7920
|
-
* @param {R |
|
|
7921
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
7962
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
7963
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
7922
7964
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
7923
7965
|
* `keyValueOrEntryOrRawElementToNode` function. It represents the value associated with a key in a
|
|
7924
7966
|
* key-value pair. If provided, it will be used to create a node with the specified key and value.
|
|
@@ -7962,8 +8004,8 @@ var dataStructureTyped = (() => {
|
|
|
7962
8004
|
*
|
|
7963
8005
|
* The `ensureNode` function checks if the input is a valid node and returns it, or converts it to a
|
|
7964
8006
|
* node if it is a key or entry.
|
|
7965
|
-
* @param {R |
|
|
7966
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `
|
|
8007
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
8008
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
|
|
7967
8009
|
* a raw element.
|
|
7968
8010
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
7969
8011
|
* parameter that specifies the type of iteration to be used when searching for a node. It has a
|
|
@@ -7998,8 +8040,8 @@ var dataStructureTyped = (() => {
|
|
|
7998
8040
|
}
|
|
7999
8041
|
/**
|
|
8000
8042
|
* The function checks if the input is an instance of the BinaryTreeNode class.
|
|
8001
|
-
* @param {R |
|
|
8002
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
8043
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
8044
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
8003
8045
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
8004
8046
|
* an instance of the `BinaryTreeNode` class.
|
|
8005
8047
|
*/
|
|
@@ -8008,8 +8050,8 @@ var dataStructureTyped = (() => {
|
|
|
8008
8050
|
}
|
|
8009
8051
|
/**
|
|
8010
8052
|
* The function checks if a given node is a valid node in a binary search tree.
|
|
8011
|
-
* @param {R |
|
|
8012
|
-
* `
|
|
8053
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
8054
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
8013
8055
|
* @returns a boolean value.
|
|
8014
8056
|
*/
|
|
8015
8057
|
isRealNode(node) {
|
|
@@ -8019,8 +8061,8 @@ var dataStructureTyped = (() => {
|
|
|
8019
8061
|
}
|
|
8020
8062
|
/**
|
|
8021
8063
|
* The function checks if a given node is a real node or null.
|
|
8022
|
-
* @param {R |
|
|
8023
|
-
* `
|
|
8064
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
8065
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
8024
8066
|
* @returns a boolean value.
|
|
8025
8067
|
*/
|
|
8026
8068
|
isNodeOrNull(node) {
|
|
@@ -8028,8 +8070,8 @@ var dataStructureTyped = (() => {
|
|
|
8028
8070
|
}
|
|
8029
8071
|
/**
|
|
8030
8072
|
* The function checks if a given node is equal to the NIL value.
|
|
8031
|
-
* @param {R |
|
|
8032
|
-
* `
|
|
8073
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
8074
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
8033
8075
|
* @returns a boolean value.
|
|
8034
8076
|
*/
|
|
8035
8077
|
isNIL(node) {
|
|
@@ -8038,8 +8080,8 @@ var dataStructureTyped = (() => {
|
|
|
8038
8080
|
/**
|
|
8039
8081
|
* The function checks if the input is an array with two elements, indicating it is a binary tree
|
|
8040
8082
|
* node entry.
|
|
8041
|
-
* @param {R |
|
|
8042
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
8083
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
8084
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
8043
8085
|
* @returns a boolean value.
|
|
8044
8086
|
*/
|
|
8045
8087
|
isEntry(keyOrNodeOrEntryOrRawElement) {
|
|
@@ -8087,10 +8129,10 @@ var dataStructureTyped = (() => {
|
|
|
8087
8129
|
*
|
|
8088
8130
|
* The `add` function is used to insert a new node into a binary tree, checking for duplicate keys
|
|
8089
8131
|
* and finding the appropriate insertion position.
|
|
8090
|
-
* @param {R |
|
|
8132
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
8091
8133
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which represents the key,
|
|
8092
8134
|
* node, entry, or raw element to be added to the tree. It can also accept a value of type
|
|
8093
|
-
* `
|
|
8135
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>
|
|
8094
8136
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
8095
8137
|
* key being added to the tree. It represents the value that will be stored in the tree for the given
|
|
8096
8138
|
* key.
|
|
@@ -8185,7 +8227,7 @@ var dataStructureTyped = (() => {
|
|
|
8185
8227
|
*
|
|
8186
8228
|
* The `refill` function clears the current data and adds new data to the collection.
|
|
8187
8229
|
* @param keysOrNodesOrEntriesOrRawElements - An iterable collection of keys, nodes, entries, or raw
|
|
8188
|
-
* elements. These can be of any type (R) or a specific type (
|
|
8230
|
+
* elements. These can be of any type (R) or a specific type (BTNKeyOrNodeOrEntry<K, V, NODE>).
|
|
8189
8231
|
* @param [values] - The `values` parameter is an optional iterable of values that will be associated
|
|
8190
8232
|
* with the keys or nodes being added. If provided, the values will be assigned to the corresponding
|
|
8191
8233
|
* keys or nodes. If not provided, the values will be set to `undefined`.
|
|
@@ -8276,7 +8318,7 @@ var dataStructureTyped = (() => {
|
|
|
8276
8318
|
* the identifier or all nodes that match the identifier. If set to true, only the first matching
|
|
8277
8319
|
* node will be returned. If set to false, all matching nodes will be returned. The default value is
|
|
8278
8320
|
* false.
|
|
8279
|
-
* @param {R |
|
|
8321
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
8280
8322
|
* point for the search. It can be either a node object, a key-value pair, or a key. If it is not
|
|
8281
8323
|
* provided, the `root` of the data structure is used as the starting point.
|
|
8282
8324
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
@@ -8334,7 +8376,7 @@ var dataStructureTyped = (() => {
|
|
|
8334
8376
|
* the `C` callback function, or it can be `null` or `undefined`.
|
|
8335
8377
|
* @param {C} callback - The `callback` parameter is a function that will be used to determine if a
|
|
8336
8378
|
* node matches the desired criteria. It should return a value that can be used to identify the node.
|
|
8337
|
-
* @param {R |
|
|
8379
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
8338
8380
|
* point for searching nodes in a tree structure. It can be either a root node, a key-value pair, or
|
|
8339
8381
|
* a node entry. If not provided, the search will start from the root of the tree.
|
|
8340
8382
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -8379,7 +8421,7 @@ var dataStructureTyped = (() => {
|
|
|
8379
8421
|
* callback function `C`. It can also be `null` or `undefined` if no identifier is provided.
|
|
8380
8422
|
* @param {C} callback - The `callback` parameter is a function that will be used to determine if a
|
|
8381
8423
|
* node matches the given identifier. It is optional and defaults to `this._DEFAULT_CALLBACK`.
|
|
8382
|
-
* @param {R |
|
|
8424
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
8383
8425
|
* point for the search in the binary tree. It can be either a root node of the tree or a key, node,
|
|
8384
8426
|
* or entry object that exists in the tree. If no specific starting point is provided, the search
|
|
8385
8427
|
* will begin from the root of the
|
|
@@ -8410,7 +8452,7 @@ var dataStructureTyped = (() => {
|
|
|
8410
8452
|
* @param {C} callback - The `callback` parameter is a function that will be used to determine
|
|
8411
8453
|
* whether a node should be included in the result or not. It is of type `C`, which extends the
|
|
8412
8454
|
* `BTNCallback<NODE>` type.
|
|
8413
|
-
* @param {R |
|
|
8455
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
8414
8456
|
* point for the iteration in the data structure. It can be either a root node, a key-value pair, or
|
|
8415
8457
|
* a node entry. If not specified, it defaults to the root of the data structure.
|
|
8416
8458
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -8459,10 +8501,10 @@ var dataStructureTyped = (() => {
|
|
|
8459
8501
|
*
|
|
8460
8502
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
8461
8503
|
* height of the tree.
|
|
8462
|
-
* @param {R |
|
|
8504
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The parameter `beginRoot` is optional and
|
|
8463
8505
|
* has a default value of `this.root`. It represents the starting point for checking if the tree is
|
|
8464
8506
|
* perfectly balanced. It can be either a root node (`R`), a key or node or entry
|
|
8465
|
-
* (`
|
|
8507
|
+
* (`BTNKeyOrNodeOrEntry<K, V, NODE
|
|
8466
8508
|
* @returns a boolean value.
|
|
8467
8509
|
*/
|
|
8468
8510
|
isPerfectlyBalanced(beginRoot = this.root) {
|
|
@@ -8477,7 +8519,7 @@ var dataStructureTyped = (() => {
|
|
|
8477
8519
|
* Space Complexity: O(1)
|
|
8478
8520
|
*
|
|
8479
8521
|
* The function `isBST` checks if a binary search tree is valid, either recursively or iteratively.
|
|
8480
|
-
* @param {R |
|
|
8522
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
8481
8523
|
* starting point for checking if a binary search tree (BST) is valid. It can be either a root node
|
|
8482
8524
|
* of the BST, a key value of a node in the BST, or an entry object containing both the key and value
|
|
8483
8525
|
* of a node in the BST
|
|
@@ -8534,10 +8576,10 @@ var dataStructureTyped = (() => {
|
|
|
8534
8576
|
* Space Complexity: O(1)
|
|
8535
8577
|
*
|
|
8536
8578
|
* The function calculates the depth of a given node or key in a tree-like data structure.
|
|
8537
|
-
* @param {R |
|
|
8538
|
-
* (representing a root node), or a `
|
|
8579
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} dist - The `dist` parameter can be either a `R`
|
|
8580
|
+
* (representing a root node), or a `BTNKeyOrNodeOrEntry<K, V, NODE>` (representing a key, node, or
|
|
8539
8581
|
* entry).
|
|
8540
|
-
* @param {R |
|
|
8582
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is optional and
|
|
8541
8583
|
* represents the starting point from which to calculate the depth. It can be either a reference to a
|
|
8542
8584
|
* node in the tree or a key-value pair or an entry object. If not provided, the default value is
|
|
8543
8585
|
* `this.root`, which refers to the root node
|
|
@@ -8566,9 +8608,9 @@ var dataStructureTyped = (() => {
|
|
|
8566
8608
|
*
|
|
8567
8609
|
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive
|
|
8568
8610
|
* or iterative approach.
|
|
8569
|
-
* @param {R |
|
|
8611
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
8570
8612
|
* starting point for calculating the height of a tree. It can be either a root node (`R`), a key or
|
|
8571
|
-
* node or entry (`
|
|
8613
|
+
* node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current tree.
|
|
8572
8614
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
8573
8615
|
* iteration used to calculate the height of the tree. It can have two possible values:
|
|
8574
8616
|
* @returns the maximum height of the binary tree.
|
|
@@ -8610,9 +8652,9 @@ var dataStructureTyped = (() => {
|
|
|
8610
8652
|
*
|
|
8611
8653
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
8612
8654
|
* recursive or iterative approach.
|
|
8613
|
-
* @param {R |
|
|
8655
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
8614
8656
|
* starting point for calculating the minimum height of a tree. It can be either a root node (`R`), a
|
|
8615
|
-
* key or node or entry (`
|
|
8657
|
+
* key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current
|
|
8616
8658
|
* tree.
|
|
8617
8659
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
8618
8660
|
* iteration to be used when calculating the minimum height of the tree. It can have two possible
|
|
@@ -8672,8 +8714,8 @@ var dataStructureTyped = (() => {
|
|
|
8672
8714
|
*
|
|
8673
8715
|
* The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
|
|
8674
8716
|
* up to the root node, with an option to reverse the order of the nodes.
|
|
8675
|
-
* @param {R |
|
|
8676
|
-
* type `R` or `
|
|
8717
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginNode - The `beginNode` parameter can be either of
|
|
8718
|
+
* type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
8677
8719
|
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
|
|
8678
8720
|
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
|
|
8679
8721
|
* reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
|
|
@@ -8701,9 +8743,9 @@ var dataStructureTyped = (() => {
|
|
|
8701
8743
|
*
|
|
8702
8744
|
* The `getLeftMost` function returns the leftmost node in a binary tree, either using recursive or
|
|
8703
8745
|
* iterative traversal.
|
|
8704
|
-
* @param {R |
|
|
8746
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
8705
8747
|
* starting point for finding the leftmost node in a binary tree. It can be either a root node (`R`),
|
|
8706
|
-
* a key or node or entry (`
|
|
8748
|
+
* a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
|
|
8707
8749
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
8708
8750
|
* of iteration to be performed. It can have two possible values:
|
|
8709
8751
|
* @returns The function `getLeftMost` returns the leftmost node in a binary tree.
|
|
@@ -8740,9 +8782,9 @@ var dataStructureTyped = (() => {
|
|
|
8740
8782
|
*
|
|
8741
8783
|
* The `getRightMost` function returns the rightmost node in a binary tree, either recursively or
|
|
8742
8784
|
* iteratively.
|
|
8743
|
-
* @param {R |
|
|
8785
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
8744
8786
|
* starting point for finding the rightmost node in a binary tree. It can be either a root node
|
|
8745
|
-
* (`R`), a key or node or entry (`
|
|
8787
|
+
* (`R`), a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
|
|
8746
8788
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
8747
8789
|
* of iteration to be performed when finding the rightmost node in a binary tree. It can have two
|
|
8748
8790
|
* possible values:
|
|
@@ -8838,7 +8880,7 @@ var dataStructureTyped = (() => {
|
|
|
8838
8880
|
* return type of the callback function is determined by the generic type `C`.
|
|
8839
8881
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter determines the order in which the
|
|
8840
8882
|
* nodes are visited during the depth-first search. It can have one of the following values:
|
|
8841
|
-
* @param {R |
|
|
8883
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
8842
8884
|
* point of the depth-first search. It can be either a node object, a key-value pair, or a key. If it
|
|
8843
8885
|
* is a key or key-value pair, the method will find the corresponding node in the tree and start the
|
|
8844
8886
|
* search from there.
|
|
@@ -8962,7 +9004,7 @@ var dataStructureTyped = (() => {
|
|
|
8962
9004
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
8963
9005
|
* the breadth-first search traversal. It takes a single argument, which is the current node being
|
|
8964
9006
|
* visited, and returns a value of any type.
|
|
8965
|
-
* @param {R |
|
|
9007
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
8966
9008
|
* starting point of the breadth-first search. It can be either a root node of a tree or a key, node,
|
|
8967
9009
|
* or entry object. If no value is provided, the `root` property of the class is used as the default
|
|
8968
9010
|
* starting point.
|
|
@@ -9037,7 +9079,7 @@ var dataStructureTyped = (() => {
|
|
|
9037
9079
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
9038
9080
|
* the tree. It takes a node as an argument and returns a value. The return type of the callback
|
|
9039
9081
|
* function is determined by the generic type `C` which extends `BTNCallback<NODE | null>`.
|
|
9040
|
-
* @param {R |
|
|
9082
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
9041
9083
|
* starting point for traversing the tree. It can be either a root node, a key-value pair, or a node
|
|
9042
9084
|
* entry. If no value is provided, the `root` property of the class is used as the default starting
|
|
9043
9085
|
* point.
|
|
@@ -9112,7 +9154,7 @@ var dataStructureTyped = (() => {
|
|
|
9112
9154
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function is used
|
|
9113
9155
|
* to specify the order in which the nodes of a binary tree are traversed. It can take one of the
|
|
9114
9156
|
* following values:
|
|
9115
|
-
* @param {R |
|
|
9157
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
9116
9158
|
* point for the traversal. It can be either a node object, a key, or an entry object. If no value is
|
|
9117
9159
|
* provided, the `root` of the tree is used as the starting point.
|
|
9118
9160
|
* @returns The function `morris` returns an array of values that are the return values of the
|
|
@@ -9299,7 +9341,7 @@ var dataStructureTyped = (() => {
|
|
|
9299
9341
|
* Space Complexity: O(n)
|
|
9300
9342
|
*
|
|
9301
9343
|
* The `print` function in TypeScript prints the binary tree structure with customizable options.
|
|
9302
|
-
* @param {R |
|
|
9344
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
9303
9345
|
* point for printing the binary tree. It can be either a node of the binary tree or a key or entry
|
|
9304
9346
|
* that exists in the binary tree. If no value is provided, the root of the binary tree will be used
|
|
9305
9347
|
* as the starting point.
|
|
@@ -9381,7 +9423,7 @@ var dataStructureTyped = (() => {
|
|
|
9381
9423
|
*
|
|
9382
9424
|
* The `_displayAux` function is responsible for generating the display layout of a binary tree node,
|
|
9383
9425
|
* taking into account various options such as whether to show null, undefined, or NaN nodes.
|
|
9384
|
-
* @param {NODE
|
|
9426
|
+
* @param {OptBTNOrNull<NODE>} node - The `node` parameter represents a node in a binary tree.
|
|
9385
9427
|
* It can be of type `NODE`, `null`, or `undefined`.
|
|
9386
9428
|
* @param {BinaryTreePrintOptions} options - The `options` parameter is an object that contains the
|
|
9387
9429
|
* following properties:
|
|
@@ -9441,10 +9483,10 @@ var dataStructureTyped = (() => {
|
|
|
9441
9483
|
* Space Complexity: O(1)
|
|
9442
9484
|
*
|
|
9443
9485
|
* The function `_swapProperties` swaps the key-value properties between two nodes.
|
|
9444
|
-
* @param {R |
|
|
9486
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} srcNode - The source node that will be swapped with the
|
|
9445
9487
|
* destination node. It can be either an instance of the class `R`, or an object of type
|
|
9446
|
-
* `
|
|
9447
|
-
* @param {R |
|
|
9488
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
9489
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} destNode - The `destNode` parameter is the node where
|
|
9448
9490
|
* the properties will be swapped with the `srcNode`.
|
|
9449
9491
|
* @returns either the `destNode` object with its properties swapped with the `srcNode` object's
|
|
9450
9492
|
* properties, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
@@ -9507,7 +9549,7 @@ var dataStructureTyped = (() => {
|
|
|
9507
9549
|
*
|
|
9508
9550
|
* The function sets the root property of an object to the provided value, and also updates the
|
|
9509
9551
|
* parent property of the new root.
|
|
9510
|
-
* @param {NODE
|
|
9552
|
+
* @param {OptBTNOrNull<NODE>} v - The parameter `v` is of type `OptBTNOrNull<NODE>`. This
|
|
9511
9553
|
* means that it can accept a value of type `NODE`, `null`, or `undefined`.
|
|
9512
9554
|
*/
|
|
9513
9555
|
_setRoot(v) {
|
|
@@ -9561,7 +9603,7 @@ var dataStructureTyped = (() => {
|
|
|
9561
9603
|
}
|
|
9562
9604
|
/**
|
|
9563
9605
|
* The function sets the left child of a node and updates the parent reference of the child.
|
|
9564
|
-
* @param {NODE
|
|
9606
|
+
* @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be an
|
|
9565
9607
|
* instance of the `NODE` class or `undefined`.
|
|
9566
9608
|
*/
|
|
9567
9609
|
set left(v) {
|
|
@@ -9580,7 +9622,7 @@ var dataStructureTyped = (() => {
|
|
|
9580
9622
|
}
|
|
9581
9623
|
/**
|
|
9582
9624
|
* The function sets the right child of a node and updates the parent reference of the child.
|
|
9583
|
-
* @param {NODE
|
|
9625
|
+
* @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be a
|
|
9584
9626
|
* `NODE` object or `undefined`.
|
|
9585
9627
|
*/
|
|
9586
9628
|
set right(v) {
|
|
@@ -9656,8 +9698,8 @@ var dataStructureTyped = (() => {
|
|
|
9656
9698
|
}
|
|
9657
9699
|
/**
|
|
9658
9700
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
9659
|
-
* @param {R |
|
|
9660
|
-
* type R or
|
|
9701
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
|
|
9702
|
+
* type R or BTNKeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
9661
9703
|
* element.
|
|
9662
9704
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
9663
9705
|
* value associated with a key in a key-value pair.
|
|
@@ -9673,7 +9715,7 @@ var dataStructureTyped = (() => {
|
|
|
9673
9715
|
*
|
|
9674
9716
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
9675
9717
|
* it doesn't exist.
|
|
9676
|
-
* @param {R |
|
|
9718
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
9677
9719
|
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
|
|
9678
9720
|
* entry, or raw element that needs to be ensured in the tree.
|
|
9679
9721
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
@@ -9688,8 +9730,8 @@ var dataStructureTyped = (() => {
|
|
|
9688
9730
|
}
|
|
9689
9731
|
/**
|
|
9690
9732
|
* The function checks if the input is an instance of the BSTNode class.
|
|
9691
|
-
* @param {R |
|
|
9692
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
9733
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
9734
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
9693
9735
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
9694
9736
|
* an instance of the `BSTNode` class.
|
|
9695
9737
|
*/
|
|
@@ -9701,8 +9743,8 @@ var dataStructureTyped = (() => {
|
|
|
9701
9743
|
* Space Complexity: O(1)
|
|
9702
9744
|
*
|
|
9703
9745
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
9704
|
-
* @param {R |
|
|
9705
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
9746
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
9747
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
9706
9748
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
9707
9749
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
9708
9750
|
* @returns a boolean value.
|
|
@@ -9861,7 +9903,7 @@ var dataStructureTyped = (() => {
|
|
|
9861
9903
|
* @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
|
|
9862
9904
|
* or all matching nodes. If set to true, only the first matching node will be returned. If set to
|
|
9863
9905
|
* false, all matching nodes will be returned. The default value is false.
|
|
9864
|
-
* @param {R |
|
|
9906
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
9865
9907
|
* point for the search in the binary tree. It can be either a node object, a key-value pair, or an
|
|
9866
9908
|
* entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
|
|
9867
9909
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
@@ -9983,7 +10025,7 @@ var dataStructureTyped = (() => {
|
|
|
9983
10025
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
9984
10026
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
9985
10027
|
* take one of the following values:
|
|
9986
|
-
* @param {R |
|
|
10028
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
9987
10029
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
9988
10030
|
* node entry. If not specified, the default value is the root of the tree.
|
|
9989
10031
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -10007,7 +10049,7 @@ var dataStructureTyped = (() => {
|
|
|
10007
10049
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
10008
10050
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
10009
10051
|
* node being visited, and it can return a value of any type.
|
|
10010
|
-
* @param {R |
|
|
10052
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
10011
10053
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
10012
10054
|
* object. If no value is provided, the default value is the root of the tree.
|
|
10013
10055
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -10031,7 +10073,7 @@ var dataStructureTyped = (() => {
|
|
|
10031
10073
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
10032
10074
|
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
|
|
10033
10075
|
* tree during the iteration process.
|
|
10034
|
-
* @param {R |
|
|
10076
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
10035
10077
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
10036
10078
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
10037
10079
|
* value is provided, the root of
|
|
@@ -10059,7 +10101,7 @@ var dataStructureTyped = (() => {
|
|
|
10059
10101
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
10060
10102
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
10061
10103
|
* 0, or 1, where:
|
|
10062
|
-
* @param {R |
|
|
10104
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
|
|
10063
10105
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
10064
10106
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
10065
10107
|
* `targetNode` is provided,
|
|
@@ -10229,7 +10271,7 @@ var dataStructureTyped = (() => {
|
|
|
10229
10271
|
/**
|
|
10230
10272
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
10231
10273
|
* root.
|
|
10232
|
-
* @param {NODE
|
|
10274
|
+
* @param {OptBSTN<NODE>} v - v is a parameter of type NODE or undefined.
|
|
10233
10275
|
*/
|
|
10234
10276
|
_setRoot(v) {
|
|
10235
10277
|
if (v) {
|
|
@@ -10879,8 +10921,8 @@ var dataStructureTyped = (() => {
|
|
|
10879
10921
|
}
|
|
10880
10922
|
/**
|
|
10881
10923
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
10882
|
-
* @param {R |
|
|
10883
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
10924
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
10925
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
10884
10926
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
10885
10927
|
* an instance of the `AVLTreeNode` class.
|
|
10886
10928
|
*/
|
|
@@ -10898,8 +10940,8 @@ var dataStructureTyped = (() => {
|
|
|
10898
10940
|
*
|
|
10899
10941
|
* The function overrides the add method of a class and inserts a key-value pair into a data
|
|
10900
10942
|
* structure, then balances the path.
|
|
10901
|
-
* @param {R |
|
|
10902
|
-
* `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `
|
|
10943
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
10944
|
+
* `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
|
|
10903
10945
|
* `RawElement`.
|
|
10904
10946
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
10905
10947
|
* the key or node being added to the data structure.
|
|
@@ -11218,8 +11260,8 @@ var dataStructureTyped = (() => {
|
|
|
11218
11260
|
*
|
|
11219
11261
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
11220
11262
|
* to restore balance in an AVL tree after inserting a node.
|
|
11221
|
-
* @param {R |
|
|
11222
|
-
* `
|
|
11263
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter can be of type `R` or
|
|
11264
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
11223
11265
|
*/
|
|
11224
11266
|
_balancePath(node) {
|
|
11225
11267
|
node = this.ensureNode(node);
|
|
@@ -11367,8 +11409,8 @@ var dataStructureTyped = (() => {
|
|
|
11367
11409
|
* Space Complexity: O(1)
|
|
11368
11410
|
*
|
|
11369
11411
|
* The function checks if the input is an instance of the RedBlackTreeNode class.
|
|
11370
|
-
* @param {R |
|
|
11371
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
11412
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
11413
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
11372
11414
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
11373
11415
|
* an instance of the `RedBlackTreeNode` class.
|
|
11374
11416
|
*/
|
|
@@ -11386,11 +11428,11 @@ var dataStructureTyped = (() => {
|
|
|
11386
11428
|
// *
|
|
11387
11429
|
// * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
|
|
11388
11430
|
// * valid, otherwise it returns undefined.
|
|
11389
|
-
// * @param {
|
|
11431
|
+
// * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
|
|
11390
11432
|
// * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
|
|
11391
11433
|
// * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
|
|
11392
11434
|
// */
|
|
11393
|
-
// override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R |
|
|
11435
|
+
// override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
|
|
11394
11436
|
//
|
|
11395
11437
|
// if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
|
|
11396
11438
|
// if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
|
|
@@ -11435,8 +11477,8 @@ var dataStructureTyped = (() => {
|
|
|
11435
11477
|
*
|
|
11436
11478
|
* The function adds a new node to a binary search tree and returns true if the node was successfully
|
|
11437
11479
|
* added.
|
|
11438
|
-
* @param {R |
|
|
11439
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
11480
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
11481
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
11440
11482
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
11441
11483
|
* the key in the data structure. It represents the value that you want to add or update in the data
|
|
11442
11484
|
* structure.
|
|
@@ -11942,8 +11984,8 @@ var dataStructureTyped = (() => {
|
|
|
11942
11984
|
}
|
|
11943
11985
|
/**
|
|
11944
11986
|
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
11945
|
-
* @param {R |
|
|
11946
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
11987
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
11988
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
11947
11989
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
11948
11990
|
* an instance of the `AVLTreeMultiMapNode` class.
|
|
11949
11991
|
*/
|
|
@@ -11953,8 +11995,8 @@ var dataStructureTyped = (() => {
|
|
|
11953
11995
|
/**
|
|
11954
11996
|
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
11955
11997
|
* a node object.
|
|
11956
|
-
* @param {R |
|
|
11957
|
-
* `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `
|
|
11998
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
11999
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
11958
12000
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
11959
12001
|
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
11960
12002
|
* value is provided, it will default to `undefined`.
|
|
@@ -11993,9 +12035,9 @@ var dataStructureTyped = (() => {
|
|
|
11993
12035
|
*
|
|
11994
12036
|
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
11995
12037
|
* and update the count.
|
|
11996
|
-
* @param {R |
|
|
12038
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
11997
12039
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
|
|
11998
|
-
* can also accept a value of type `
|
|
12040
|
+
* can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
11999
12041
|
* entry, or raw element
|
|
12000
12042
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
12001
12043
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -12340,8 +12382,8 @@ var dataStructureTyped = (() => {
|
|
|
12340
12382
|
/**
|
|
12341
12383
|
* The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
|
|
12342
12384
|
* node based on the input.
|
|
12343
|
-
* @param {R |
|
|
12344
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
12385
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
12386
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
12345
12387
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
12346
12388
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
12347
12389
|
* an existing node.
|
|
@@ -12372,8 +12414,8 @@ var dataStructureTyped = (() => {
|
|
|
12372
12414
|
}
|
|
12373
12415
|
/**
|
|
12374
12416
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
12375
|
-
* @param {R |
|
|
12376
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
12417
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
12418
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
12377
12419
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
12378
12420
|
* an instance of the `TreeMultiMapNode` class.
|
|
12379
12421
|
*/
|
|
@@ -12390,7 +12432,7 @@ var dataStructureTyped = (() => {
|
|
|
12390
12432
|
*
|
|
12391
12433
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
12392
12434
|
* the count and returning a boolean indicating success.
|
|
12393
|
-
* @param {R |
|
|
12435
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
12394
12436
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
|
|
12395
12437
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
12396
12438
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|