data-structure-typed 1.50.7 → 1.50.8
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 +27 -19
- package/benchmark/report.html +1 -37
- package/benchmark/report.json +16 -394
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -2
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +3 -4
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +23 -24
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +7 -5
- package/dist/cjs/data-structures/binary-tree/bst.js +59 -38
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -7
- 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 +1 -2
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/types/common.d.ts +5 -28
- package/dist/cjs/types/common.js +0 -40
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -2
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +3 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +23 -24
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +7 -5
- package/dist/mjs/data-structures/binary-tree/bst.js +59 -38
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +7 -8
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -2
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +2 -2
- package/dist/mjs/types/common.d.ts +5 -28
- package/dist/mjs/types/common.js +1 -39
- package/dist/umd/data-structure-typed.js +86 -118
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
- package/src/data-structures/binary-tree/binary-tree.ts +23 -26
- package/src/data-structures/binary-tree/bst.ts +59 -36
- package/src/data-structures/binary-tree/rb-tree.ts +6 -6
- package/src/data-structures/binary-tree/tree-multi-map.ts +2 -2
- package/src/types/common.ts +5 -29
- package/test/integration/all-in-one.test.ts +2 -2
- package/test/integration/avl-tree.test.ts +1 -1
- package/test/integration/bst.test.ts +2 -2
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +13 -22
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +8 -16
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +118 -65
- package/test/unit/data-structures/binary-tree/bst.test.ts +12 -12
- package/test/unit/data-structures/binary-tree/overall.test.ts +7 -7
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +10 -5
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +7 -15
|
@@ -110,12 +110,9 @@ var dataStructureTyped = (() => {
|
|
|
110
110
|
AbstractVertex: () => AbstractVertex,
|
|
111
111
|
BST: () => BST,
|
|
112
112
|
BSTNode: () => BSTNode,
|
|
113
|
-
BSTVariant: () => BSTVariant,
|
|
114
113
|
BinaryIndexedTree: () => BinaryIndexedTree,
|
|
115
114
|
BinaryTree: () => BinaryTree,
|
|
116
115
|
BinaryTreeNode: () => BinaryTreeNode,
|
|
117
|
-
CP: () => CP,
|
|
118
|
-
CRUD: () => CRUD,
|
|
119
116
|
Character: () => Character,
|
|
120
117
|
Deque: () => Deque,
|
|
121
118
|
DirectedEdge: () => DirectedEdge,
|
|
@@ -123,14 +120,12 @@ var dataStructureTyped = (() => {
|
|
|
123
120
|
DirectedVertex: () => DirectedVertex,
|
|
124
121
|
DoublyLinkedList: () => DoublyLinkedList,
|
|
125
122
|
DoublyLinkedListNode: () => DoublyLinkedListNode,
|
|
126
|
-
FamilyPosition: () => FamilyPosition,
|
|
127
123
|
FibonacciHeap: () => FibonacciHeap,
|
|
128
124
|
FibonacciHeapNode: () => FibonacciHeapNode,
|
|
129
125
|
HashMap: () => HashMap,
|
|
130
126
|
Heap: () => Heap,
|
|
131
127
|
IterableElementBase: () => IterableElementBase,
|
|
132
128
|
IterableEntryBase: () => IterableEntryBase,
|
|
133
|
-
IterationType: () => IterationType,
|
|
134
129
|
LinkedHashMap: () => LinkedHashMap,
|
|
135
130
|
LinkedListQueue: () => LinkedListQueue,
|
|
136
131
|
MapEdge: () => MapEdge,
|
|
@@ -7656,48 +7651,6 @@ var dataStructureTyped = (() => {
|
|
|
7656
7651
|
}
|
|
7657
7652
|
};
|
|
7658
7653
|
|
|
7659
|
-
// src/types/data-structures/binary-tree/rb-tree.ts
|
|
7660
|
-
var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
|
|
7661
|
-
RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
|
|
7662
|
-
RBTNColor2[RBTNColor2["BLACK"] = 0] = "BLACK";
|
|
7663
|
-
return RBTNColor2;
|
|
7664
|
-
})(RBTNColor || {});
|
|
7665
|
-
|
|
7666
|
-
// src/types/common.ts
|
|
7667
|
-
var BSTVariant = /* @__PURE__ */ ((BSTVariant2) => {
|
|
7668
|
-
BSTVariant2["STANDARD"] = "STANDARD";
|
|
7669
|
-
BSTVariant2["INVERSE"] = "INVERSE";
|
|
7670
|
-
return BSTVariant2;
|
|
7671
|
-
})(BSTVariant || {});
|
|
7672
|
-
var CP = /* @__PURE__ */ ((CP2) => {
|
|
7673
|
-
CP2["lt"] = "lt";
|
|
7674
|
-
CP2["eq"] = "eq";
|
|
7675
|
-
CP2["gt"] = "gt";
|
|
7676
|
-
return CP2;
|
|
7677
|
-
})(CP || {});
|
|
7678
|
-
var IterationType = /* @__PURE__ */ ((IterationType2) => {
|
|
7679
|
-
IterationType2["ITERATIVE"] = "ITERATIVE";
|
|
7680
|
-
IterationType2["RECURSIVE"] = "RECURSIVE";
|
|
7681
|
-
return IterationType2;
|
|
7682
|
-
})(IterationType || {});
|
|
7683
|
-
var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
|
|
7684
|
-
FamilyPosition2["ROOT"] = "ROOT";
|
|
7685
|
-
FamilyPosition2["LEFT"] = "LEFT";
|
|
7686
|
-
FamilyPosition2["RIGHT"] = "RIGHT";
|
|
7687
|
-
FamilyPosition2["ROOT_LEFT"] = "ROOT_LEFT";
|
|
7688
|
-
FamilyPosition2["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
7689
|
-
FamilyPosition2["ISOLATED"] = "ISOLATED";
|
|
7690
|
-
FamilyPosition2["MAL_NODE"] = "MAL_NODE";
|
|
7691
|
-
return FamilyPosition2;
|
|
7692
|
-
})(FamilyPosition || {});
|
|
7693
|
-
var CRUD = /* @__PURE__ */ ((CRUD2) => {
|
|
7694
|
-
CRUD2["CREATED"] = "CREATED";
|
|
7695
|
-
CRUD2["READ"] = "READ";
|
|
7696
|
-
CRUD2["UPDATED"] = "UPDATED";
|
|
7697
|
-
CRUD2["DELETED"] = "DELETED";
|
|
7698
|
-
return CRUD2;
|
|
7699
|
-
})(CRUD || {});
|
|
7700
|
-
|
|
7701
7654
|
// src/data-structures/binary-tree/binary-tree.ts
|
|
7702
7655
|
var BinaryTreeNode = class {
|
|
7703
7656
|
/**
|
|
@@ -7762,14 +7715,14 @@ var dataStructureTyped = (() => {
|
|
|
7762
7715
|
get familyPosition() {
|
|
7763
7716
|
const that = this;
|
|
7764
7717
|
if (!this.parent) {
|
|
7765
|
-
return this.left || this.right ? "ROOT"
|
|
7718
|
+
return this.left || this.right ? "ROOT" : "ISOLATED";
|
|
7766
7719
|
}
|
|
7767
7720
|
if (this.parent.left === that) {
|
|
7768
|
-
return this.left || this.right ? "ROOT_LEFT"
|
|
7721
|
+
return this.left || this.right ? "ROOT_LEFT" : "LEFT";
|
|
7769
7722
|
} else if (this.parent.right === that) {
|
|
7770
|
-
return this.left || this.right ? "ROOT_RIGHT"
|
|
7723
|
+
return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
|
|
7771
7724
|
}
|
|
7772
|
-
return "MAL_NODE"
|
|
7725
|
+
return "MAL_NODE";
|
|
7773
7726
|
}
|
|
7774
7727
|
};
|
|
7775
7728
|
var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
@@ -7784,8 +7737,8 @@ var dataStructureTyped = (() => {
|
|
|
7784
7737
|
*/
|
|
7785
7738
|
constructor(keysOrNodesOrEntries = [], options) {
|
|
7786
7739
|
super();
|
|
7787
|
-
__publicField(this, "iterationType", "ITERATIVE"
|
|
7788
|
-
__publicField(this, "_extractor", (key) => Number(key));
|
|
7740
|
+
__publicField(this, "iterationType", "ITERATIVE");
|
|
7741
|
+
__publicField(this, "_extractor", (key) => typeof key === "number" ? key : Number(key));
|
|
7789
7742
|
__publicField(this, "_root");
|
|
7790
7743
|
__publicField(this, "_size");
|
|
7791
7744
|
__publicField(this, "_defaultOneParamCallback", (node) => node ? node.key : void 0);
|
|
@@ -7887,11 +7840,11 @@ var dataStructureTyped = (() => {
|
|
|
7887
7840
|
* `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
|
|
7888
7841
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
7889
7842
|
* type of iteration to be used when searching for a node by key. It has a default value of
|
|
7890
|
-
* `
|
|
7843
|
+
* `'ITERATIVE'`.
|
|
7891
7844
|
* @returns either the node corresponding to the given key if it is a valid node key, or the key
|
|
7892
7845
|
* itself if it is not a valid node key.
|
|
7893
7846
|
*/
|
|
7894
|
-
ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE"
|
|
7847
|
+
ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE") {
|
|
7895
7848
|
let res;
|
|
7896
7849
|
if (this.isRealNode(keyOrNodeOrEntry)) {
|
|
7897
7850
|
res = keyOrNodeOrEntry;
|
|
@@ -8107,9 +8060,9 @@ var dataStructureTyped = (() => {
|
|
|
8107
8060
|
}
|
|
8108
8061
|
} else if (parent) {
|
|
8109
8062
|
const { familyPosition: fp } = curr;
|
|
8110
|
-
if (fp === "LEFT"
|
|
8063
|
+
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
8111
8064
|
parent.left = curr.right;
|
|
8112
|
-
} else if (fp === "RIGHT"
|
|
8065
|
+
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
8113
8066
|
parent.right = curr.right;
|
|
8114
8067
|
}
|
|
8115
8068
|
needBalanced = parent;
|
|
@@ -8157,7 +8110,7 @@ var dataStructureTyped = (() => {
|
|
|
8157
8110
|
if (!beginRoot)
|
|
8158
8111
|
return [];
|
|
8159
8112
|
const ans = [];
|
|
8160
|
-
if (iterationType === "RECURSIVE"
|
|
8113
|
+
if (iterationType === "RECURSIVE") {
|
|
8161
8114
|
const _traverse = (cur) => {
|
|
8162
8115
|
if (callback(cur) === identifier) {
|
|
8163
8116
|
ans.push(cur);
|
|
@@ -8236,10 +8189,10 @@ var dataStructureTyped = (() => {
|
|
|
8236
8189
|
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
8237
8190
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
8238
8191
|
*/
|
|
8239
|
-
getNodeByKey(key, iterationType = "ITERATIVE"
|
|
8192
|
+
getNodeByKey(key, iterationType = "ITERATIVE") {
|
|
8240
8193
|
if (!this.root)
|
|
8241
8194
|
return void 0;
|
|
8242
|
-
if (iterationType === "RECURSIVE"
|
|
8195
|
+
if (iterationType === "RECURSIVE") {
|
|
8243
8196
|
const _dfs = (cur) => {
|
|
8244
8197
|
if (cur.key === key)
|
|
8245
8198
|
return cur;
|
|
@@ -8392,7 +8345,7 @@ var dataStructureTyped = (() => {
|
|
|
8392
8345
|
beginRoot = this.ensureNode(beginRoot);
|
|
8393
8346
|
if (!beginRoot)
|
|
8394
8347
|
return true;
|
|
8395
|
-
if (iterationType === "RECURSIVE"
|
|
8348
|
+
if (iterationType === "RECURSIVE") {
|
|
8396
8349
|
const dfs = (cur, min, max) => {
|
|
8397
8350
|
if (!this.isRealNode(cur))
|
|
8398
8351
|
return true;
|
|
@@ -8479,7 +8432,7 @@ var dataStructureTyped = (() => {
|
|
|
8479
8432
|
beginRoot = this.ensureNode(beginRoot);
|
|
8480
8433
|
if (!this.isRealNode(beginRoot))
|
|
8481
8434
|
return -1;
|
|
8482
|
-
if (iterationType === "RECURSIVE"
|
|
8435
|
+
if (iterationType === "RECURSIVE") {
|
|
8483
8436
|
const _getMaxHeight = (cur) => {
|
|
8484
8437
|
if (!this.isRealNode(cur))
|
|
8485
8438
|
return -1;
|
|
@@ -8524,7 +8477,7 @@ var dataStructureTyped = (() => {
|
|
|
8524
8477
|
beginRoot = this.ensureNode(beginRoot);
|
|
8525
8478
|
if (!beginRoot)
|
|
8526
8479
|
return -1;
|
|
8527
|
-
if (iterationType === "RECURSIVE"
|
|
8480
|
+
if (iterationType === "RECURSIVE") {
|
|
8528
8481
|
const _getMinHeight = (cur) => {
|
|
8529
8482
|
if (!this.isRealNode(cur))
|
|
8530
8483
|
return 0;
|
|
@@ -8616,7 +8569,7 @@ var dataStructureTyped = (() => {
|
|
|
8616
8569
|
beginRoot = this.ensureNode(beginRoot);
|
|
8617
8570
|
if (!this.isRealNode(beginRoot))
|
|
8618
8571
|
return beginRoot;
|
|
8619
|
-
if (iterationType === "RECURSIVE"
|
|
8572
|
+
if (iterationType === "RECURSIVE") {
|
|
8620
8573
|
const _traverse = (cur) => {
|
|
8621
8574
|
if (!this.isRealNode(cur.left))
|
|
8622
8575
|
return cur;
|
|
@@ -8657,7 +8610,7 @@ var dataStructureTyped = (() => {
|
|
|
8657
8610
|
beginRoot = this.ensureNode(beginRoot);
|
|
8658
8611
|
if (!beginRoot)
|
|
8659
8612
|
return beginRoot;
|
|
8660
|
-
if (iterationType === "RECURSIVE"
|
|
8613
|
+
if (iterationType === "RECURSIVE") {
|
|
8661
8614
|
const _traverse = (cur) => {
|
|
8662
8615
|
if (!this.isRealNode(cur.right))
|
|
8663
8616
|
return cur;
|
|
@@ -8754,12 +8707,12 @@ var dataStructureTyped = (() => {
|
|
|
8754
8707
|
* `false`, null or undefined
|
|
8755
8708
|
* @returns an array of values that are the return values of the callback function.
|
|
8756
8709
|
*/
|
|
8757
|
-
dfs(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root, iterationType = "ITERATIVE"
|
|
8710
|
+
dfs(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root, iterationType = "ITERATIVE", includeNull = false) {
|
|
8758
8711
|
beginRoot = this.ensureNode(beginRoot);
|
|
8759
8712
|
if (!beginRoot)
|
|
8760
8713
|
return [];
|
|
8761
8714
|
const ans = [];
|
|
8762
|
-
if (iterationType === "RECURSIVE"
|
|
8715
|
+
if (iterationType === "RECURSIVE") {
|
|
8763
8716
|
const _traverse = (node) => {
|
|
8764
8717
|
switch (pattern) {
|
|
8765
8718
|
case "in":
|
|
@@ -8883,7 +8836,7 @@ var dataStructureTyped = (() => {
|
|
|
8883
8836
|
if (!beginRoot)
|
|
8884
8837
|
return [];
|
|
8885
8838
|
const ans = [];
|
|
8886
|
-
if (iterationType === "RECURSIVE"
|
|
8839
|
+
if (iterationType === "RECURSIVE") {
|
|
8887
8840
|
const queue = new Queue([beginRoot]);
|
|
8888
8841
|
const traverse = (level) => {
|
|
8889
8842
|
if (queue.size === 0)
|
|
@@ -8957,7 +8910,7 @@ var dataStructureTyped = (() => {
|
|
|
8957
8910
|
const levelsNodes = [];
|
|
8958
8911
|
if (!beginRoot)
|
|
8959
8912
|
return levelsNodes;
|
|
8960
|
-
if (iterationType === "RECURSIVE"
|
|
8913
|
+
if (iterationType === "RECURSIVE") {
|
|
8961
8914
|
const _recursive = (node, level) => {
|
|
8962
8915
|
if (!levelsNodes[level])
|
|
8963
8916
|
levelsNodes[level] = [];
|
|
@@ -9242,7 +9195,7 @@ var dataStructureTyped = (() => {
|
|
|
9242
9195
|
*_getIterator(node = this.root) {
|
|
9243
9196
|
if (!node)
|
|
9244
9197
|
return;
|
|
9245
|
-
if (this.iterationType === "ITERATIVE"
|
|
9198
|
+
if (this.iterationType === "ITERATIVE") {
|
|
9246
9199
|
const stack = [];
|
|
9247
9200
|
let current = node;
|
|
9248
9201
|
while (current || stack.length > 0) {
|
|
@@ -9441,7 +9394,7 @@ var dataStructureTyped = (() => {
|
|
|
9441
9394
|
constructor(keysOrNodesOrEntries = [], options) {
|
|
9442
9395
|
super([], options);
|
|
9443
9396
|
__publicField(this, "_root");
|
|
9444
|
-
__publicField(this, "_variant", "STANDARD"
|
|
9397
|
+
__publicField(this, "_variant", "STANDARD");
|
|
9445
9398
|
if (options) {
|
|
9446
9399
|
const { variant } = options;
|
|
9447
9400
|
if (variant)
|
|
@@ -9531,10 +9484,10 @@ var dataStructureTyped = (() => {
|
|
|
9531
9484
|
* @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
|
|
9532
9485
|
* `undefined`.
|
|
9533
9486
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
9534
|
-
* type of iteration to be performed. It has a default value of `
|
|
9487
|
+
* type of iteration to be performed. It has a default value of `'ITERATIVE'`.
|
|
9535
9488
|
* @returns either a node object (NODE) or undefined.
|
|
9536
9489
|
*/
|
|
9537
|
-
ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE"
|
|
9490
|
+
ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE") {
|
|
9538
9491
|
let res;
|
|
9539
9492
|
if (this.isRealNode(keyOrNodeOrEntry)) {
|
|
9540
9493
|
res = keyOrNodeOrEntry;
|
|
@@ -9582,10 +9535,10 @@ var dataStructureTyped = (() => {
|
|
|
9582
9535
|
}
|
|
9583
9536
|
let current = this.root;
|
|
9584
9537
|
while (current !== void 0) {
|
|
9585
|
-
if (this._compare(current.key, newNode.key) === "
|
|
9538
|
+
if (this._compare(current.key, newNode.key) === "EQ") {
|
|
9586
9539
|
this._replaceNode(current, newNode);
|
|
9587
9540
|
return true;
|
|
9588
|
-
} else if (this._compare(current.key, newNode.key) === "
|
|
9541
|
+
} else if (this._compare(current.key, newNode.key) === "GT") {
|
|
9589
9542
|
if (current.left === void 0) {
|
|
9590
9543
|
current.left = newNode;
|
|
9591
9544
|
this._size++;
|
|
@@ -9693,7 +9646,7 @@ var dataStructureTyped = (() => {
|
|
|
9693
9646
|
}
|
|
9694
9647
|
}
|
|
9695
9648
|
};
|
|
9696
|
-
if (iterationType === "RECURSIVE"
|
|
9649
|
+
if (iterationType === "RECURSIVE") {
|
|
9697
9650
|
_dfs(sorted);
|
|
9698
9651
|
} else {
|
|
9699
9652
|
_iterate();
|
|
@@ -9718,18 +9671,18 @@ var dataStructureTyped = (() => {
|
|
|
9718
9671
|
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
9719
9672
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
9720
9673
|
*/
|
|
9721
|
-
getNodeByKey(key, iterationType = "ITERATIVE"
|
|
9674
|
+
getNodeByKey(key, iterationType = "ITERATIVE") {
|
|
9722
9675
|
if (!this.isRealNode(this.root))
|
|
9723
9676
|
return void 0;
|
|
9724
|
-
if (iterationType === "RECURSIVE"
|
|
9677
|
+
if (iterationType === "RECURSIVE") {
|
|
9725
9678
|
const _dfs = (cur) => {
|
|
9726
9679
|
if (cur.key === key)
|
|
9727
9680
|
return cur;
|
|
9728
9681
|
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
|
|
9729
9682
|
return;
|
|
9730
|
-
if (this._compare(cur.key, key) === "
|
|
9683
|
+
if (this._compare(cur.key, key) === "GT" && this.isRealNode(cur.left))
|
|
9731
9684
|
return _dfs(cur.left);
|
|
9732
|
-
if (this._compare(cur.key, key) === "
|
|
9685
|
+
if (this._compare(cur.key, key) === "LT" && this.isRealNode(cur.right))
|
|
9733
9686
|
return _dfs(cur.right);
|
|
9734
9687
|
};
|
|
9735
9688
|
return _dfs(this.root);
|
|
@@ -9738,11 +9691,11 @@ var dataStructureTyped = (() => {
|
|
|
9738
9691
|
while (queue.size > 0) {
|
|
9739
9692
|
const cur = queue.shift();
|
|
9740
9693
|
if (this.isRealNode(cur)) {
|
|
9741
|
-
if (this._compare(cur.key, key) === "
|
|
9694
|
+
if (this._compare(cur.key, key) === "EQ")
|
|
9742
9695
|
return cur;
|
|
9743
|
-
if (this._compare(cur.key, key) === "
|
|
9696
|
+
if (this._compare(cur.key, key) === "GT")
|
|
9744
9697
|
this.isRealNode(cur.left) && queue.push(cur.left);
|
|
9745
|
-
if (this._compare(cur.key, key) === "
|
|
9698
|
+
if (this._compare(cur.key, key) === "LT")
|
|
9746
9699
|
this.isRealNode(cur.right) && queue.push(cur.right);
|
|
9747
9700
|
}
|
|
9748
9701
|
}
|
|
@@ -9781,7 +9734,7 @@ var dataStructureTyped = (() => {
|
|
|
9781
9734
|
if (!beginRoot)
|
|
9782
9735
|
return [];
|
|
9783
9736
|
const ans = [];
|
|
9784
|
-
if (iterationType === "RECURSIVE"
|
|
9737
|
+
if (iterationType === "RECURSIVE") {
|
|
9785
9738
|
const _traverse = (cur) => {
|
|
9786
9739
|
const callbackResult = callback(cur);
|
|
9787
9740
|
if (callbackResult === identifier) {
|
|
@@ -9792,10 +9745,10 @@ var dataStructureTyped = (() => {
|
|
|
9792
9745
|
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
|
|
9793
9746
|
return;
|
|
9794
9747
|
if (callback === this._defaultOneParamCallback) {
|
|
9795
|
-
if (this._compare(cur.key, identifier) === "
|
|
9796
|
-
|
|
9797
|
-
if (this._compare(cur.key, identifier) === "
|
|
9798
|
-
|
|
9748
|
+
if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === "GT")
|
|
9749
|
+
_traverse(cur.left);
|
|
9750
|
+
if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === "LT")
|
|
9751
|
+
_traverse(cur.right);
|
|
9799
9752
|
} else {
|
|
9800
9753
|
this.isRealNode(cur.left) && _traverse(cur.left);
|
|
9801
9754
|
this.isRealNode(cur.right) && _traverse(cur.right);
|
|
@@ -9803,9 +9756,9 @@ var dataStructureTyped = (() => {
|
|
|
9803
9756
|
};
|
|
9804
9757
|
_traverse(beginRoot);
|
|
9805
9758
|
} else {
|
|
9806
|
-
const
|
|
9807
|
-
while (
|
|
9808
|
-
const cur =
|
|
9759
|
+
const stack = [beginRoot];
|
|
9760
|
+
while (stack.length > 0) {
|
|
9761
|
+
const cur = stack.pop();
|
|
9809
9762
|
if (this.isRealNode(cur)) {
|
|
9810
9763
|
const callbackResult = callback(cur);
|
|
9811
9764
|
if (callbackResult === identifier) {
|
|
@@ -9814,13 +9767,13 @@ var dataStructureTyped = (() => {
|
|
|
9814
9767
|
return ans;
|
|
9815
9768
|
}
|
|
9816
9769
|
if (callback === this._defaultOneParamCallback) {
|
|
9817
|
-
if (this._compare(cur.key, identifier) === "
|
|
9818
|
-
|
|
9819
|
-
if (this._compare(cur.key, identifier) === "
|
|
9820
|
-
|
|
9770
|
+
if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === "LT")
|
|
9771
|
+
stack.push(cur.right);
|
|
9772
|
+
if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === "GT")
|
|
9773
|
+
stack.push(cur.left);
|
|
9821
9774
|
} else {
|
|
9822
|
-
this.isRealNode(cur.
|
|
9823
|
-
this.isRealNode(cur.
|
|
9775
|
+
this.isRealNode(cur.right) && stack.push(cur.right);
|
|
9776
|
+
this.isRealNode(cur.left) && stack.push(cur.left);
|
|
9824
9777
|
}
|
|
9825
9778
|
}
|
|
9826
9779
|
}
|
|
@@ -9850,7 +9803,7 @@ var dataStructureTyped = (() => {
|
|
|
9850
9803
|
* following values:
|
|
9851
9804
|
* @returns The method is returning an array of the return type of the callback function.
|
|
9852
9805
|
*/
|
|
9853
|
-
dfs(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root, iterationType = "ITERATIVE"
|
|
9806
|
+
dfs(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root, iterationType = "ITERATIVE") {
|
|
9854
9807
|
return super.dfs(callback, pattern, beginRoot, iterationType, false);
|
|
9855
9808
|
}
|
|
9856
9809
|
/**
|
|
@@ -9923,7 +9876,7 @@ var dataStructureTyped = (() => {
|
|
|
9923
9876
|
let current = this.ensureNode(beginRoot);
|
|
9924
9877
|
if (!current)
|
|
9925
9878
|
return void 0;
|
|
9926
|
-
if (this._variant === "STANDARD"
|
|
9879
|
+
if (this._variant === "STANDARD") {
|
|
9927
9880
|
while (current.right !== void 0) {
|
|
9928
9881
|
current = current.right;
|
|
9929
9882
|
}
|
|
@@ -9959,7 +9912,7 @@ var dataStructureTyped = (() => {
|
|
|
9959
9912
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
9960
9913
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
9961
9914
|
*/
|
|
9962
|
-
lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater = "
|
|
9915
|
+
lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater = "LT", targetNode = this.root, iterationType = this.iterationType) {
|
|
9963
9916
|
targetNode = this.ensureNode(targetNode);
|
|
9964
9917
|
const ans = [];
|
|
9965
9918
|
if (!targetNode)
|
|
@@ -9967,7 +9920,7 @@ var dataStructureTyped = (() => {
|
|
|
9967
9920
|
if (!this.root)
|
|
9968
9921
|
return ans;
|
|
9969
9922
|
const targetKey = targetNode.key;
|
|
9970
|
-
if (iterationType === "RECURSIVE"
|
|
9923
|
+
if (iterationType === "RECURSIVE") {
|
|
9971
9924
|
const _traverse = (cur) => {
|
|
9972
9925
|
const compared = this._compare(cur.key, targetKey);
|
|
9973
9926
|
if (compared === lesserOrGreater)
|
|
@@ -10016,7 +9969,7 @@ var dataStructureTyped = (() => {
|
|
|
10016
9969
|
this.clear();
|
|
10017
9970
|
if (sorted.length < 1)
|
|
10018
9971
|
return false;
|
|
10019
|
-
if (iterationType === "RECURSIVE"
|
|
9972
|
+
if (iterationType === "RECURSIVE") {
|
|
10020
9973
|
const buildBalanceBST = (l, r) => {
|
|
10021
9974
|
if (l > r)
|
|
10022
9975
|
return;
|
|
@@ -10073,7 +10026,7 @@ var dataStructureTyped = (() => {
|
|
|
10073
10026
|
if (!this.root)
|
|
10074
10027
|
return true;
|
|
10075
10028
|
let balanced = true;
|
|
10076
|
-
if (iterationType === "RECURSIVE"
|
|
10029
|
+
if (iterationType === "RECURSIVE") {
|
|
10077
10030
|
const _height = (cur) => {
|
|
10078
10031
|
if (!cur)
|
|
10079
10032
|
return 0;
|
|
@@ -10127,14 +10080,24 @@ var dataStructureTyped = (() => {
|
|
|
10127
10080
|
* is greater than, less than, or equal to the second value.
|
|
10128
10081
|
* @param {K} a - The parameter "a" is of type K.
|
|
10129
10082
|
* @param {K} b - The parameter "b" in the above code represents a K.
|
|
10130
|
-
* @returns a value of type CP (ComparisonResult). The possible return values are
|
|
10131
|
-
* than),
|
|
10083
|
+
* @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
|
|
10084
|
+
* than), 'LT' (less than), or 'EQ' (equal).
|
|
10132
10085
|
*/
|
|
10133
10086
|
_compare(a, b) {
|
|
10134
10087
|
const extractedA = this.extractor(a);
|
|
10135
10088
|
const extractedB = this.extractor(b);
|
|
10136
|
-
const compared = this.variant === "STANDARD"
|
|
10137
|
-
return compared > 0 ? "
|
|
10089
|
+
const compared = this.variant === "STANDARD" ? extractedA - extractedB : extractedB - extractedA;
|
|
10090
|
+
return compared > 0 ? "GT" : compared < 0 ? "LT" : "EQ";
|
|
10091
|
+
}
|
|
10092
|
+
_lt(a, b) {
|
|
10093
|
+
const extractedA = this.extractor(a);
|
|
10094
|
+
const extractedB = this.extractor(b);
|
|
10095
|
+
return this.variant === "STANDARD" ? extractedA < extractedB : extractedA > extractedB;
|
|
10096
|
+
}
|
|
10097
|
+
_gt(a, b) {
|
|
10098
|
+
const extractedA = this.extractor(a);
|
|
10099
|
+
const extractedB = this.extractor(b);
|
|
10100
|
+
return this.variant === "STANDARD" ? extractedA > extractedB : extractedA < extractedB;
|
|
10138
10101
|
}
|
|
10139
10102
|
};
|
|
10140
10103
|
|
|
@@ -11153,6 +11116,13 @@ var dataStructureTyped = (() => {
|
|
|
11153
11116
|
}
|
|
11154
11117
|
};
|
|
11155
11118
|
|
|
11119
|
+
// src/types/data-structures/binary-tree/rb-tree.ts
|
|
11120
|
+
var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
|
|
11121
|
+
RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
|
|
11122
|
+
RBTNColor2[RBTNColor2["BLACK"] = 0] = "BLACK";
|
|
11123
|
+
return RBTNColor2;
|
|
11124
|
+
})(RBTNColor || {});
|
|
11125
|
+
|
|
11156
11126
|
// src/data-structures/binary-tree/rb-tree.ts
|
|
11157
11127
|
var RedBlackTreeNode = class extends BSTNode {
|
|
11158
11128
|
/**
|
|
@@ -11342,9 +11312,7 @@ var dataStructureTyped = (() => {
|
|
|
11342
11312
|
*/
|
|
11343
11313
|
getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
|
|
11344
11314
|
var _a;
|
|
11345
|
-
|
|
11346
|
-
callback = (node) => node;
|
|
11347
|
-
return (_a = super.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
|
|
11315
|
+
return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
|
|
11348
11316
|
}
|
|
11349
11317
|
/**
|
|
11350
11318
|
* Time Complexity: O(1)
|
|
@@ -11383,7 +11351,7 @@ var dataStructureTyped = (() => {
|
|
|
11383
11351
|
if (!this.isRealNode(newNode))
|
|
11384
11352
|
return false;
|
|
11385
11353
|
const insertStatus = this._insert(newNode);
|
|
11386
|
-
if (insertStatus === "CREATED"
|
|
11354
|
+
if (insertStatus === "CREATED") {
|
|
11387
11355
|
if (this.isRealNode(this._root)) {
|
|
11388
11356
|
this._root.color = 0 /* BLACK */;
|
|
11389
11357
|
} else {
|
|
@@ -11392,7 +11360,7 @@ var dataStructureTyped = (() => {
|
|
|
11392
11360
|
this._size++;
|
|
11393
11361
|
return true;
|
|
11394
11362
|
} else
|
|
11395
|
-
return insertStatus === "UPDATED"
|
|
11363
|
+
return insertStatus === "UPDATED";
|
|
11396
11364
|
}
|
|
11397
11365
|
/**
|
|
11398
11366
|
* Time Complexity: O(log n)
|
|
@@ -11519,7 +11487,7 @@ var dataStructureTyped = (() => {
|
|
|
11519
11487
|
current = (_b = current.right) != null ? _b : this.SENTINEL;
|
|
11520
11488
|
} else {
|
|
11521
11489
|
this._replaceNode(current, node);
|
|
11522
|
-
return "UPDATED"
|
|
11490
|
+
return "UPDATED";
|
|
11523
11491
|
}
|
|
11524
11492
|
}
|
|
11525
11493
|
node.parent = parent;
|
|
@@ -11534,7 +11502,7 @@ var dataStructureTyped = (() => {
|
|
|
11534
11502
|
node.right = this.SENTINEL;
|
|
11535
11503
|
node.color = 1 /* RED */;
|
|
11536
11504
|
this._insertFixup(node);
|
|
11537
|
-
return "CREATED"
|
|
11505
|
+
return "CREATED";
|
|
11538
11506
|
}
|
|
11539
11507
|
/**
|
|
11540
11508
|
* Time Complexity: O(1)
|
|
@@ -11958,9 +11926,9 @@ var dataStructureTyped = (() => {
|
|
|
11958
11926
|
this._setRoot(curr.right);
|
|
11959
11927
|
} else {
|
|
11960
11928
|
const { familyPosition: fp } = curr;
|
|
11961
|
-
if (fp === "LEFT"
|
|
11929
|
+
if (fp === "LEFT" || fp === "ROOT_LEFT") {
|
|
11962
11930
|
parent.left = curr.right;
|
|
11963
|
-
} else if (fp === "RIGHT"
|
|
11931
|
+
} else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
|
|
11964
11932
|
parent.right = curr.right;
|
|
11965
11933
|
}
|
|
11966
11934
|
needBalanced = parent;
|
|
@@ -12024,7 +11992,7 @@ var dataStructureTyped = (() => {
|
|
|
12024
11992
|
if (sorted.length < 1)
|
|
12025
11993
|
return false;
|
|
12026
11994
|
this.clear();
|
|
12027
|
-
if (iterationType === "RECURSIVE"
|
|
11995
|
+
if (iterationType === "RECURSIVE") {
|
|
12028
11996
|
const buildBalanceBST = (l, r) => {
|
|
12029
11997
|
if (l > r)
|
|
12030
11998
|
return;
|
|
@@ -12411,7 +12379,7 @@ var dataStructureTyped = (() => {
|
|
|
12411
12379
|
if (sorted.length < 1)
|
|
12412
12380
|
return false;
|
|
12413
12381
|
this.clear();
|
|
12414
|
-
if (iterationType === "RECURSIVE"
|
|
12382
|
+
if (iterationType === "RECURSIVE") {
|
|
12415
12383
|
const buildBalanceBST = (l, r) => {
|
|
12416
12384
|
if (l > r)
|
|
12417
12385
|
return;
|