data-structure-typed 1.48.9 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +8 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +9 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +15 -6
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -15
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +8 -1
- package/dist/cjs/data-structures/binary-tree/bst.js +9 -0
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +10 -16
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +16 -29
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +8 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +9 -0
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +8 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +9 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +15 -6
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +19 -15
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +8 -1
- package/dist/mjs/data-structures/binary-tree/bst.js +9 -0
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +10 -16
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +16 -28
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +8 -1
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +9 -0
- package/dist/umd/data-structure-typed.js +62 -44
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +11 -1
- package/src/data-structures/binary-tree/binary-tree.ts +22 -23
- package/src/data-structures/binary-tree/bst.ts +11 -1
- package/src/data-structures/binary-tree/rb-tree.ts +18 -32
- package/src/data-structures/binary-tree/tree-multimap.ts +17 -1
|
@@ -8248,7 +8248,7 @@ var dataStructureTyped = (() => {
|
|
|
8248
8248
|
* @returns a boolean value.
|
|
8249
8249
|
*/
|
|
8250
8250
|
isRealNode(node) {
|
|
8251
|
-
return node instanceof BinaryTreeNode && node.key
|
|
8251
|
+
return node instanceof BinaryTreeNode && String(node.key) !== "NaN";
|
|
8252
8252
|
}
|
|
8253
8253
|
/**
|
|
8254
8254
|
* The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
|
|
@@ -8256,7 +8256,7 @@ var dataStructureTyped = (() => {
|
|
|
8256
8256
|
* @returns a boolean value.
|
|
8257
8257
|
*/
|
|
8258
8258
|
isNIL(node) {
|
|
8259
|
-
return node instanceof BinaryTreeNode && node.key
|
|
8259
|
+
return node instanceof BinaryTreeNode && String(node.key) === "NaN";
|
|
8260
8260
|
}
|
|
8261
8261
|
/**
|
|
8262
8262
|
* The function checks if a given node is a real node or null.
|
|
@@ -8267,7 +8267,7 @@ var dataStructureTyped = (() => {
|
|
|
8267
8267
|
return this.isRealNode(node) || node === null;
|
|
8268
8268
|
}
|
|
8269
8269
|
/**
|
|
8270
|
-
* The function "isNotNodeInstance" checks if a potential key is a
|
|
8270
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
8271
8271
|
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
8272
8272
|
* data type.
|
|
8273
8273
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
@@ -8535,19 +8535,23 @@ var dataStructureTyped = (() => {
|
|
|
8535
8535
|
return levelsNodes;
|
|
8536
8536
|
}
|
|
8537
8537
|
/**
|
|
8538
|
-
*
|
|
8539
|
-
*
|
|
8540
|
-
|
|
8541
|
-
|
|
8538
|
+
* Time Complexity: O(log n)
|
|
8539
|
+
* Space Complexity: O(1)
|
|
8540
|
+
*/
|
|
8541
|
+
/**
|
|
8542
|
+
* Time Complexity: O(log n)
|
|
8543
|
+
* Space Complexity: O(1)
|
|
8544
|
+
*
|
|
8545
|
+
* The function returns the predecessor of a given node in a tree.
|
|
8546
|
+
* @param {N} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
|
|
8547
|
+
* tree.
|
|
8548
|
+
* @returns the predecessor of the given 'node'.
|
|
8542
8549
|
*/
|
|
8543
8550
|
getPredecessor(node) {
|
|
8544
|
-
|
|
8545
|
-
if (!this.isRealNode(node))
|
|
8546
|
-
return void 0;
|
|
8547
|
-
if (node.left) {
|
|
8551
|
+
if (this.isRealNode(node.left)) {
|
|
8548
8552
|
let predecessor = node.left;
|
|
8549
8553
|
while (!this.isRealNode(predecessor) || this.isRealNode(predecessor.right) && predecessor.right !== node) {
|
|
8550
|
-
if (predecessor) {
|
|
8554
|
+
if (this.isRealNode(predecessor)) {
|
|
8551
8555
|
predecessor = predecessor.right;
|
|
8552
8556
|
}
|
|
8553
8557
|
}
|
|
@@ -8564,13 +8568,13 @@ var dataStructureTyped = (() => {
|
|
|
8564
8568
|
*/
|
|
8565
8569
|
getSuccessor(x) {
|
|
8566
8570
|
x = this.ensureNode(x);
|
|
8567
|
-
if (!x)
|
|
8571
|
+
if (!this.isRealNode(x))
|
|
8568
8572
|
return void 0;
|
|
8569
|
-
if (x.right) {
|
|
8573
|
+
if (this.isRealNode(x.right)) {
|
|
8570
8574
|
return this.getLeftMost(x.right);
|
|
8571
8575
|
}
|
|
8572
8576
|
let y = x.parent;
|
|
8573
|
-
while (y &&
|
|
8577
|
+
while (this.isRealNode(y) && x === y.right) {
|
|
8574
8578
|
x = y;
|
|
8575
8579
|
y = y.parent;
|
|
8576
8580
|
}
|
|
@@ -9299,6 +9303,15 @@ var dataStructureTyped = (() => {
|
|
|
9299
9303
|
}
|
|
9300
9304
|
}
|
|
9301
9305
|
}
|
|
9306
|
+
/**
|
|
9307
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
9308
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
9309
|
+
* data type.
|
|
9310
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
9311
|
+
*/
|
|
9312
|
+
isNotNodeInstance(potentialKey) {
|
|
9313
|
+
return !(potentialKey instanceof BSTNode);
|
|
9314
|
+
}
|
|
9302
9315
|
/**
|
|
9303
9316
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
9304
9317
|
* Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
|
|
@@ -10072,6 +10085,15 @@ var dataStructureTyped = (() => {
|
|
|
10072
10085
|
isNode(exemplar) {
|
|
10073
10086
|
return exemplar instanceof AVLTreeNode;
|
|
10074
10087
|
}
|
|
10088
|
+
/**
|
|
10089
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
10090
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
10091
|
+
* data type.
|
|
10092
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
10093
|
+
*/
|
|
10094
|
+
isNotNodeInstance(potentialKey) {
|
|
10095
|
+
return !(potentialKey instanceof AVLTreeNode);
|
|
10096
|
+
}
|
|
10075
10097
|
/**
|
|
10076
10098
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
10077
10099
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -10503,6 +10525,15 @@ var dataStructureTyped = (() => {
|
|
|
10503
10525
|
isNode(exemplar) {
|
|
10504
10526
|
return exemplar instanceof RedBlackTreeNode;
|
|
10505
10527
|
}
|
|
10528
|
+
/**
|
|
10529
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
10530
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
10531
|
+
* data type.
|
|
10532
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
10533
|
+
*/
|
|
10534
|
+
isNotNodeInstance(potentialKey) {
|
|
10535
|
+
return !(potentialKey instanceof RedBlackTreeNode);
|
|
10536
|
+
}
|
|
10506
10537
|
/**
|
|
10507
10538
|
* The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
|
|
10508
10539
|
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
|
|
@@ -10667,7 +10698,9 @@ var dataStructureTyped = (() => {
|
|
|
10667
10698
|
* Space Complexity: O(1)
|
|
10668
10699
|
*/
|
|
10669
10700
|
isRealNode(node) {
|
|
10670
|
-
|
|
10701
|
+
if (node === this.Sentinel || node === void 0)
|
|
10702
|
+
return false;
|
|
10703
|
+
return node instanceof RedBlackTreeNode;
|
|
10671
10704
|
}
|
|
10672
10705
|
/**
|
|
10673
10706
|
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
|
|
@@ -10702,35 +10735,11 @@ var dataStructureTyped = (() => {
|
|
|
10702
10735
|
return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
|
|
10703
10736
|
}
|
|
10704
10737
|
/**
|
|
10705
|
-
* Time Complexity: O(log n)
|
|
10706
|
-
* Space Complexity: O(1)
|
|
10707
|
-
*/
|
|
10708
|
-
/**
|
|
10709
|
-
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
|
|
10710
|
-
* Space Complexity: O(1)
|
|
10711
|
-
*
|
|
10712
|
-
* The function returns the successor of a given node in a red-black tree.
|
|
10713
|
-
* @param {RedBlackTreeNode} x - RedBlackTreeNode - The node for which we want to find the successor.
|
|
10714
|
-
* @returns the successor of the given RedBlackTreeNode.
|
|
10715
|
-
*/
|
|
10716
|
-
getSuccessor(x) {
|
|
10717
|
-
var _a;
|
|
10718
|
-
if (x.right !== this.Sentinel) {
|
|
10719
|
-
return (_a = this.getLeftMost(x.right)) != null ? _a : void 0;
|
|
10720
|
-
}
|
|
10721
|
-
let y = x.parent;
|
|
10722
|
-
while (y !== this.Sentinel && y !== void 0 && x === y.right) {
|
|
10723
|
-
x = y;
|
|
10724
|
-
y = y.parent;
|
|
10725
|
-
}
|
|
10726
|
-
return y;
|
|
10727
|
-
}
|
|
10728
|
-
/**
|
|
10729
|
-
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
|
|
10738
|
+
* Time Complexity: O(log n)
|
|
10730
10739
|
* Space Complexity: O(1)
|
|
10731
10740
|
*/
|
|
10732
10741
|
/**
|
|
10733
|
-
* Time Complexity: O(log n)
|
|
10742
|
+
* Time Complexity: O(log n)
|
|
10734
10743
|
* Space Complexity: O(1)
|
|
10735
10744
|
*
|
|
10736
10745
|
* The function returns the predecessor of a given node in a red-black tree.
|
|
@@ -10739,11 +10748,11 @@ var dataStructureTyped = (() => {
|
|
|
10739
10748
|
* @returns the predecessor of the given RedBlackTreeNode 'x'.
|
|
10740
10749
|
*/
|
|
10741
10750
|
getPredecessor(x) {
|
|
10742
|
-
if (x.left
|
|
10751
|
+
if (this.isRealNode(x.left)) {
|
|
10743
10752
|
return this.getRightMost(x.left);
|
|
10744
10753
|
}
|
|
10745
10754
|
let y = x.parent;
|
|
10746
|
-
while (
|
|
10755
|
+
while (this.isRealNode(y) && x === y.left) {
|
|
10747
10756
|
x = y;
|
|
10748
10757
|
y = y.parent;
|
|
10749
10758
|
}
|
|
@@ -11047,6 +11056,15 @@ var dataStructureTyped = (() => {
|
|
|
11047
11056
|
isNode(exemplar) {
|
|
11048
11057
|
return exemplar instanceof TreeMultimapNode;
|
|
11049
11058
|
}
|
|
11059
|
+
/**
|
|
11060
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
11061
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
11062
|
+
* data type.
|
|
11063
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
11064
|
+
*/
|
|
11065
|
+
isNotNodeInstance(potentialKey) {
|
|
11066
|
+
return !(potentialKey instanceof TreeMultimapNode);
|
|
11067
|
+
}
|
|
11050
11068
|
/**
|
|
11051
11069
|
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
11052
11070
|
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, which means it
|