data-structure-typed 1.50.6 → 1.50.7
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 +13 -18
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +155 -155
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +3 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +13 -9
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- 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 +2 -8
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +7 -16
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/types/common.d.ts +6 -0
- package/dist/cjs/types/common.js +8 -1
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -0
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +3 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +13 -9
- package/dist/mjs/data-structures/binary-tree/bst.js +17 -17
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +2 -8
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +8 -17
- package/dist/mjs/types/common.d.ts +6 -0
- package/dist/mjs/types/common.js +7 -0
- package/dist/umd/data-structure-typed.js +48 -42
- 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-multi-map.ts +5 -1
- package/src/data-structures/binary-tree/avl-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +12 -10
- package/src/data-structures/binary-tree/bst.ts +18 -18
- package/src/data-structures/binary-tree/rb-tree.ts +11 -22
- package/src/types/common.ts +7 -0
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +4 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +266 -266
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +247 -235
|
@@ -115,6 +115,7 @@ var dataStructureTyped = (() => {
|
|
|
115
115
|
BinaryTree: () => BinaryTree,
|
|
116
116
|
BinaryTreeNode: () => BinaryTreeNode,
|
|
117
117
|
CP: () => CP,
|
|
118
|
+
CRUD: () => CRUD,
|
|
118
119
|
Character: () => Character,
|
|
119
120
|
Deque: () => Deque,
|
|
120
121
|
DirectedEdge: () => DirectedEdge,
|
|
@@ -7689,6 +7690,13 @@ var dataStructureTyped = (() => {
|
|
|
7689
7690
|
FamilyPosition2["MAL_NODE"] = "MAL_NODE";
|
|
7690
7691
|
return FamilyPosition2;
|
|
7691
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 || {});
|
|
7692
7700
|
|
|
7693
7701
|
// src/data-structures/binary-tree/binary-tree.ts
|
|
7694
7702
|
var BinaryTreeNode = class {
|
|
@@ -8469,7 +8477,7 @@ var dataStructureTyped = (() => {
|
|
|
8469
8477
|
*/
|
|
8470
8478
|
getHeight(beginRoot = this.root, iterationType = this.iterationType) {
|
|
8471
8479
|
beginRoot = this.ensureNode(beginRoot);
|
|
8472
|
-
if (!beginRoot)
|
|
8480
|
+
if (!this.isRealNode(beginRoot))
|
|
8473
8481
|
return -1;
|
|
8474
8482
|
if (iterationType === "RECURSIVE" /* RECURSIVE */) {
|
|
8475
8483
|
const _getMaxHeight = (cur) => {
|
|
@@ -8518,9 +8526,9 @@ var dataStructureTyped = (() => {
|
|
|
8518
8526
|
return -1;
|
|
8519
8527
|
if (iterationType === "RECURSIVE" /* RECURSIVE */) {
|
|
8520
8528
|
const _getMinHeight = (cur) => {
|
|
8521
|
-
if (!cur)
|
|
8529
|
+
if (!this.isRealNode(cur))
|
|
8522
8530
|
return 0;
|
|
8523
|
-
if (!cur.left && !cur.right)
|
|
8531
|
+
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
|
|
8524
8532
|
return 0;
|
|
8525
8533
|
const leftMinHeight = _getMinHeight(cur.left);
|
|
8526
8534
|
const rightMinHeight = _getMinHeight(cur.right);
|
|
@@ -8532,16 +8540,16 @@ var dataStructureTyped = (() => {
|
|
|
8532
8540
|
let node = beginRoot, last = null;
|
|
8533
8541
|
const depths = /* @__PURE__ */ new Map();
|
|
8534
8542
|
while (stack.length > 0 || node) {
|
|
8535
|
-
if (node) {
|
|
8543
|
+
if (this.isRealNode(node)) {
|
|
8536
8544
|
stack.push(node);
|
|
8537
8545
|
node = node.left;
|
|
8538
8546
|
} else {
|
|
8539
8547
|
node = stack[stack.length - 1];
|
|
8540
|
-
if (!node.right || last === node.right) {
|
|
8548
|
+
if (!this.isRealNode(node.right) || last === node.right) {
|
|
8541
8549
|
node = stack.pop();
|
|
8542
|
-
if (node) {
|
|
8543
|
-
const leftMinHeight = node.left ? (_a = depths.get(node.left)) != null ? _a : -1 : -1;
|
|
8544
|
-
const rightMinHeight = node.right ? (_b = depths.get(node.right)) != null ? _b : -1 : -1;
|
|
8550
|
+
if (this.isRealNode(node)) {
|
|
8551
|
+
const leftMinHeight = this.isRealNode(node.left) ? (_a = depths.get(node.left)) != null ? _a : -1 : -1;
|
|
8552
|
+
const rightMinHeight = this.isRealNode(node.right) ? (_b = depths.get(node.right)) != null ? _b : -1 : -1;
|
|
8545
8553
|
depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
|
|
8546
8554
|
last = node;
|
|
8547
8555
|
node = null;
|
|
@@ -8603,8 +8611,10 @@ var dataStructureTyped = (() => {
|
|
|
8603
8611
|
* is no leftmost node, it returns `null` or `undefined` depending on the input.
|
|
8604
8612
|
*/
|
|
8605
8613
|
getLeftMost(beginRoot = this.root, iterationType = this.iterationType) {
|
|
8614
|
+
if (this.isNIL(beginRoot))
|
|
8615
|
+
return beginRoot;
|
|
8606
8616
|
beginRoot = this.ensureNode(beginRoot);
|
|
8607
|
-
if (!beginRoot)
|
|
8617
|
+
if (!this.isRealNode(beginRoot))
|
|
8608
8618
|
return beginRoot;
|
|
8609
8619
|
if (iterationType === "RECURSIVE" /* RECURSIVE */) {
|
|
8610
8620
|
const _traverse = (cur) => {
|
|
@@ -8642,6 +8652,8 @@ var dataStructureTyped = (() => {
|
|
|
8642
8652
|
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
|
|
8643
8653
|
*/
|
|
8644
8654
|
getRightMost(beginRoot = this.root, iterationType = this.iterationType) {
|
|
8655
|
+
if (this.isNIL(beginRoot))
|
|
8656
|
+
return beginRoot;
|
|
8645
8657
|
beginRoot = this.ensureNode(beginRoot);
|
|
8646
8658
|
if (!beginRoot)
|
|
8647
8659
|
return beginRoot;
|
|
@@ -9707,17 +9719,17 @@ var dataStructureTyped = (() => {
|
|
|
9707
9719
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
9708
9720
|
*/
|
|
9709
9721
|
getNodeByKey(key, iterationType = "ITERATIVE" /* ITERATIVE */) {
|
|
9710
|
-
if (!this.root)
|
|
9722
|
+
if (!this.isRealNode(this.root))
|
|
9711
9723
|
return void 0;
|
|
9712
9724
|
if (iterationType === "RECURSIVE" /* RECURSIVE */) {
|
|
9713
9725
|
const _dfs = (cur) => {
|
|
9714
9726
|
if (cur.key === key)
|
|
9715
9727
|
return cur;
|
|
9716
|
-
if (!cur.left && !cur.right)
|
|
9728
|
+
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
|
|
9717
9729
|
return;
|
|
9718
|
-
if (this._compare(cur.key, key) === "gt" /* gt */ && cur.left)
|
|
9730
|
+
if (this._compare(cur.key, key) === "gt" /* gt */ && this.isRealNode(cur.left))
|
|
9719
9731
|
return _dfs(cur.left);
|
|
9720
|
-
if (this._compare(cur.key, key) === "lt" /* lt */ && cur.right)
|
|
9732
|
+
if (this._compare(cur.key, key) === "lt" /* lt */ && this.isRealNode(cur.right))
|
|
9721
9733
|
return _dfs(cur.right);
|
|
9722
9734
|
};
|
|
9723
9735
|
return _dfs(this.root);
|
|
@@ -9725,13 +9737,13 @@ var dataStructureTyped = (() => {
|
|
|
9725
9737
|
const queue = new Queue([this.root]);
|
|
9726
9738
|
while (queue.size > 0) {
|
|
9727
9739
|
const cur = queue.shift();
|
|
9728
|
-
if (cur) {
|
|
9740
|
+
if (this.isRealNode(cur)) {
|
|
9729
9741
|
if (this._compare(cur.key, key) === "eq" /* eq */)
|
|
9730
9742
|
return cur;
|
|
9731
9743
|
if (this._compare(cur.key, key) === "gt" /* gt */)
|
|
9732
|
-
cur.left && queue.push(cur.left);
|
|
9744
|
+
this.isRealNode(cur.left) && queue.push(cur.left);
|
|
9733
9745
|
if (this._compare(cur.key, key) === "lt" /* lt */)
|
|
9734
|
-
cur.right && queue.push(cur.right);
|
|
9746
|
+
this.isRealNode(cur.right) && queue.push(cur.right);
|
|
9735
9747
|
}
|
|
9736
9748
|
}
|
|
9737
9749
|
}
|
|
@@ -9777,16 +9789,16 @@ var dataStructureTyped = (() => {
|
|
|
9777
9789
|
if (onlyOne)
|
|
9778
9790
|
return;
|
|
9779
9791
|
}
|
|
9780
|
-
if (!cur.left && !cur.right)
|
|
9792
|
+
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
|
|
9781
9793
|
return;
|
|
9782
9794
|
if (callback === this._defaultOneParamCallback) {
|
|
9783
9795
|
if (this._compare(cur.key, identifier) === "gt" /* gt */)
|
|
9784
|
-
cur.left && _traverse(cur.left);
|
|
9796
|
+
this.isRealNode(cur.left) && _traverse(cur.left);
|
|
9785
9797
|
if (this._compare(cur.key, identifier) === "lt" /* lt */)
|
|
9786
|
-
cur.right && _traverse(cur.right);
|
|
9798
|
+
this.isRealNode(cur.right) && _traverse(cur.right);
|
|
9787
9799
|
} else {
|
|
9788
|
-
cur.left && _traverse(cur.left);
|
|
9789
|
-
cur.right && _traverse(cur.right);
|
|
9800
|
+
this.isRealNode(cur.left) && _traverse(cur.left);
|
|
9801
|
+
this.isRealNode(cur.right) && _traverse(cur.right);
|
|
9790
9802
|
}
|
|
9791
9803
|
};
|
|
9792
9804
|
_traverse(beginRoot);
|
|
@@ -9794,7 +9806,7 @@ var dataStructureTyped = (() => {
|
|
|
9794
9806
|
const queue = new Queue([beginRoot]);
|
|
9795
9807
|
while (queue.size > 0) {
|
|
9796
9808
|
const cur = queue.shift();
|
|
9797
|
-
if (cur) {
|
|
9809
|
+
if (this.isRealNode(cur)) {
|
|
9798
9810
|
const callbackResult = callback(cur);
|
|
9799
9811
|
if (callbackResult === identifier) {
|
|
9800
9812
|
ans.push(cur);
|
|
@@ -9803,12 +9815,12 @@ var dataStructureTyped = (() => {
|
|
|
9803
9815
|
}
|
|
9804
9816
|
if (callback === this._defaultOneParamCallback) {
|
|
9805
9817
|
if (this._compare(cur.key, identifier) === "gt" /* gt */)
|
|
9806
|
-
cur.left && queue.push(cur.left);
|
|
9818
|
+
this.isRealNode(cur.left) && queue.push(cur.left);
|
|
9807
9819
|
if (this._compare(cur.key, identifier) === "lt" /* lt */)
|
|
9808
|
-
cur.right && queue.push(cur.right);
|
|
9820
|
+
this.isRealNode(cur.right) && queue.push(cur.right);
|
|
9809
9821
|
} else {
|
|
9810
|
-
cur.left && queue.push(cur.left);
|
|
9811
|
-
cur.right && queue.push(cur.right);
|
|
9822
|
+
this.isRealNode(cur.left) && queue.push(cur.left);
|
|
9823
|
+
this.isRealNode(cur.right) && queue.push(cur.right);
|
|
9812
9824
|
}
|
|
9813
9825
|
}
|
|
9814
9826
|
}
|
|
@@ -11189,7 +11201,6 @@ var dataStructureTyped = (() => {
|
|
|
11189
11201
|
super([], options);
|
|
11190
11202
|
__publicField(this, "_SENTINEL", new RedBlackTreeNode(NaN));
|
|
11191
11203
|
__publicField(this, "_root");
|
|
11192
|
-
__publicField(this, "_size", 0);
|
|
11193
11204
|
this._root = this.SENTINEL;
|
|
11194
11205
|
if (keysOrNodesOrEntries) {
|
|
11195
11206
|
this.addMany(keysOrNodesOrEntries);
|
|
@@ -11209,13 +11220,6 @@ var dataStructureTyped = (() => {
|
|
|
11209
11220
|
get root() {
|
|
11210
11221
|
return this._root;
|
|
11211
11222
|
}
|
|
11212
|
-
/**
|
|
11213
|
-
* The function returns the size of an object.
|
|
11214
|
-
* @returns The size of the object, which is a number.
|
|
11215
|
-
*/
|
|
11216
|
-
get size() {
|
|
11217
|
-
return this._size;
|
|
11218
|
-
}
|
|
11219
11223
|
/**
|
|
11220
11224
|
* The function creates a new Red-Black Tree node with the specified key, value, and color.
|
|
11221
11225
|
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
@@ -11307,7 +11311,7 @@ var dataStructureTyped = (() => {
|
|
|
11307
11311
|
* @returns a boolean value.
|
|
11308
11312
|
*/
|
|
11309
11313
|
isRealNode(node) {
|
|
11310
|
-
if (node === this.
|
|
11314
|
+
if (node === this.SENTINEL || node === void 0)
|
|
11311
11315
|
return false;
|
|
11312
11316
|
return node instanceof RedBlackTreeNode;
|
|
11313
11317
|
}
|
|
@@ -11340,8 +11344,7 @@ var dataStructureTyped = (() => {
|
|
|
11340
11344
|
var _a;
|
|
11341
11345
|
if (identifier instanceof RedBlackTreeNode)
|
|
11342
11346
|
callback = (node) => node;
|
|
11343
|
-
|
|
11344
|
-
return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
|
|
11347
|
+
return (_a = super.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
|
|
11345
11348
|
}
|
|
11346
11349
|
/**
|
|
11347
11350
|
* Time Complexity: O(1)
|
|
@@ -11355,8 +11358,8 @@ var dataStructureTyped = (() => {
|
|
|
11355
11358
|
* size counter to zero.
|
|
11356
11359
|
*/
|
|
11357
11360
|
clear() {
|
|
11361
|
+
super.clear();
|
|
11358
11362
|
this._root = this.SENTINEL;
|
|
11359
|
-
this._size = 0;
|
|
11360
11363
|
}
|
|
11361
11364
|
/**
|
|
11362
11365
|
* Time Complexity: O(log n)
|
|
@@ -11380,7 +11383,7 @@ var dataStructureTyped = (() => {
|
|
|
11380
11383
|
if (!this.isRealNode(newNode))
|
|
11381
11384
|
return false;
|
|
11382
11385
|
const insertStatus = this._insert(newNode);
|
|
11383
|
-
if (insertStatus === "
|
|
11386
|
+
if (insertStatus === "CREATED" /* CREATED */) {
|
|
11384
11387
|
if (this.isRealNode(this._root)) {
|
|
11385
11388
|
this._root.color = 0 /* BLACK */;
|
|
11386
11389
|
} else {
|
|
@@ -11389,7 +11392,7 @@ var dataStructureTyped = (() => {
|
|
|
11389
11392
|
this._size++;
|
|
11390
11393
|
return true;
|
|
11391
11394
|
} else
|
|
11392
|
-
return insertStatus === "
|
|
11395
|
+
return insertStatus === "UPDATED" /* UPDATED */;
|
|
11393
11396
|
}
|
|
11394
11397
|
/**
|
|
11395
11398
|
* Time Complexity: O(log n)
|
|
@@ -11516,7 +11519,7 @@ var dataStructureTyped = (() => {
|
|
|
11516
11519
|
current = (_b = current.right) != null ? _b : this.SENTINEL;
|
|
11517
11520
|
} else {
|
|
11518
11521
|
this._replaceNode(current, node);
|
|
11519
|
-
return "
|
|
11522
|
+
return "UPDATED" /* UPDATED */;
|
|
11520
11523
|
}
|
|
11521
11524
|
}
|
|
11522
11525
|
node.parent = parent;
|
|
@@ -11531,7 +11534,7 @@ var dataStructureTyped = (() => {
|
|
|
11531
11534
|
node.right = this.SENTINEL;
|
|
11532
11535
|
node.color = 1 /* RED */;
|
|
11533
11536
|
this._insertFixup(node);
|
|
11534
|
-
return "
|
|
11537
|
+
return "CREATED" /* CREATED */;
|
|
11535
11538
|
}
|
|
11536
11539
|
/**
|
|
11537
11540
|
* Time Complexity: O(1)
|
|
@@ -11807,6 +11810,9 @@ var dataStructureTyped = (() => {
|
|
|
11807
11810
|
* @returns the sum of the count property of all nodes in the tree.
|
|
11808
11811
|
*/
|
|
11809
11812
|
get count() {
|
|
11813
|
+
return this._count;
|
|
11814
|
+
}
|
|
11815
|
+
getMutableCount() {
|
|
11810
11816
|
let sum = 0;
|
|
11811
11817
|
this.dfs((node) => sum += node.count);
|
|
11812
11818
|
return sum;
|