data-structure-typed 1.50.5 → 1.50.6
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 -13
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +168 -144
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -19
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +158 -135
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +415 -386
- 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 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +84 -76
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +19 -19
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +158 -135
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +412 -386
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +84 -76
- package/dist/umd/data-structure-typed.js +477 -431
- 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/binary-tree.ts +19 -19
- package/src/data-structures/binary-tree/rb-tree.ts +437 -395
- package/src/data-structures/binary-tree/tree-multi-map.ts +85 -82
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +26 -16
- package/test/unit/data-structures/binary-tree/overall.test.ts +23 -21
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +168 -105
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +311 -192
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.50.
|
|
3
|
+
"version": "1.50.6",
|
|
4
4
|
"description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/mjs/index.js",
|
|
@@ -934,7 +934,7 @@ export class BinaryTree<
|
|
|
934
934
|
|
|
935
935
|
if (iterationType === IterationType.RECURSIVE) {
|
|
936
936
|
const dfs = (cur: NODE | null | undefined, min: number, max: number): boolean => {
|
|
937
|
-
if (!cur) return true;
|
|
937
|
+
if (!this.isRealNode(cur)) return true;
|
|
938
938
|
const numKey = this.extractor(cur.key);
|
|
939
939
|
if (numKey <= min || numKey >= max) return false;
|
|
940
940
|
return dfs(cur.left, min, numKey) && dfs(cur.right, numKey, max);
|
|
@@ -949,14 +949,14 @@ export class BinaryTree<
|
|
|
949
949
|
let prev = checkMax ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER;
|
|
950
950
|
// @ts-ignore
|
|
951
951
|
let curr: NODE | null | undefined = beginRoot;
|
|
952
|
-
while (curr || stack.length > 0) {
|
|
953
|
-
while (curr) {
|
|
952
|
+
while (this.isRealNode(curr) || stack.length > 0) {
|
|
953
|
+
while (this.isRealNode(curr)) {
|
|
954
954
|
stack.push(curr);
|
|
955
955
|
curr = curr.left;
|
|
956
956
|
}
|
|
957
957
|
curr = stack.pop()!;
|
|
958
958
|
const numKey = this.extractor(curr.key);
|
|
959
|
-
if (!curr || (!checkMax && prev >= numKey) || (checkMax && prev <= numKey)) return false;
|
|
959
|
+
if (!this.isRealNode(curr) || (!checkMax && prev >= numKey) || (checkMax && prev <= numKey)) return false;
|
|
960
960
|
prev = numKey;
|
|
961
961
|
curr = curr.right;
|
|
962
962
|
}
|
|
@@ -1025,7 +1025,7 @@ export class BinaryTree<
|
|
|
1025
1025
|
|
|
1026
1026
|
if (iterationType === IterationType.RECURSIVE) {
|
|
1027
1027
|
const _getMaxHeight = (cur: NODE | null | undefined): number => {
|
|
1028
|
-
if (!cur) return -1;
|
|
1028
|
+
if (!this.isRealNode(cur)) return -1;
|
|
1029
1029
|
const leftHeight = _getMaxHeight(cur.left);
|
|
1030
1030
|
const rightHeight = _getMaxHeight(cur.right);
|
|
1031
1031
|
return Math.max(leftHeight, rightHeight) + 1;
|
|
@@ -1039,8 +1039,8 @@ export class BinaryTree<
|
|
|
1039
1039
|
while (stack.length > 0) {
|
|
1040
1040
|
const { node, depth } = stack.pop()!;
|
|
1041
1041
|
|
|
1042
|
-
if (node.left) stack.push({ node: node.left, depth: depth + 1 });
|
|
1043
|
-
if (node.right) stack.push({ node: node.right, depth: depth + 1 });
|
|
1042
|
+
if (this.isRealNode(node.left)) stack.push({ node: node.left, depth: depth + 1 });
|
|
1043
|
+
if (this.isRealNode(node.right)) stack.push({ node: node.right, depth: depth + 1 });
|
|
1044
1044
|
|
|
1045
1045
|
maxHeight = Math.max(maxHeight, depth);
|
|
1046
1046
|
}
|
|
@@ -1354,34 +1354,34 @@ export class BinaryTree<
|
|
|
1354
1354
|
switch (pattern) {
|
|
1355
1355
|
case 'in':
|
|
1356
1356
|
if (includeNull) {
|
|
1357
|
-
if (node && this.isNodeOrNull(node.left)) _traverse(node.left);
|
|
1357
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.left)) _traverse(node.left);
|
|
1358
1358
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1359
|
-
if (node && this.isNodeOrNull(node.right)) _traverse(node.right);
|
|
1359
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.right)) _traverse(node.right);
|
|
1360
1360
|
} else {
|
|
1361
|
-
if (node && node.left) _traverse(node.left);
|
|
1361
|
+
if (this.isRealNode(node) && this.isRealNode(node.left)) _traverse(node.left);
|
|
1362
1362
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1363
|
-
if (node && node.right) _traverse(node.right);
|
|
1363
|
+
if (this.isRealNode(node) && this.isRealNode(node.right)) _traverse(node.right);
|
|
1364
1364
|
}
|
|
1365
1365
|
break;
|
|
1366
1366
|
case 'pre':
|
|
1367
1367
|
if (includeNull) {
|
|
1368
1368
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1369
|
-
if (node && this.isNodeOrNull(node.left)) _traverse(node.left);
|
|
1370
|
-
if (node && this.isNodeOrNull(node.right)) _traverse(node.right);
|
|
1369
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.left)) _traverse(node.left);
|
|
1370
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.right)) _traverse(node.right);
|
|
1371
1371
|
} else {
|
|
1372
1372
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1373
|
-
if (node && node.left) _traverse(node.left);
|
|
1374
|
-
if (node && node.right) _traverse(node.right);
|
|
1373
|
+
if (this.isRealNode(node) && this.isRealNode(node.left)) _traverse(node.left);
|
|
1374
|
+
if (this.isRealNode(node) && this.isRealNode(node.right)) _traverse(node.right);
|
|
1375
1375
|
}
|
|
1376
1376
|
break;
|
|
1377
1377
|
case 'post':
|
|
1378
1378
|
if (includeNull) {
|
|
1379
|
-
if (node && this.isNodeOrNull(node.left)) _traverse(node.left);
|
|
1380
|
-
if (node && this.isNodeOrNull(node.right)) _traverse(node.right);
|
|
1379
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.left)) _traverse(node.left);
|
|
1380
|
+
if (this.isRealNode(node) && this.isNodeOrNull(node.right)) _traverse(node.right);
|
|
1381
1381
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1382
1382
|
} else {
|
|
1383
|
-
if (node && node.left) _traverse(node.left);
|
|
1384
|
-
if (node && node.right) _traverse(node.right);
|
|
1383
|
+
if (this.isRealNode(node) && this.isRealNode(node.left)) _traverse(node.left);
|
|
1384
|
+
if (this.isRealNode(node) && this.isRealNode(node.right)) _traverse(node.right);
|
|
1385
1385
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1386
1386
|
}
|
|
1387
1387
|
|