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
|
@@ -109,10 +109,10 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
109
109
|
* @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
|
|
110
110
|
* `undefined`.
|
|
111
111
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
112
|
-
* type of iteration to be performed. It has a default value of `
|
|
112
|
+
* type of iteration to be performed. It has a default value of `'ITERATIVE'`.
|
|
113
113
|
* @returns either a node object (NODE) or undefined.
|
|
114
114
|
*/
|
|
115
|
-
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?:
|
|
115
|
+
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: string): NODE | undefined;
|
|
116
116
|
/**
|
|
117
117
|
* The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
|
|
118
118
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
@@ -179,7 +179,7 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
179
179
|
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
180
180
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
181
181
|
*/
|
|
182
|
-
getNodeByKey(key: K, iterationType?:
|
|
182
|
+
getNodeByKey(key: K, iterationType?: string): NODE | undefined;
|
|
183
183
|
/**
|
|
184
184
|
* Time Complexity: O(log n)
|
|
185
185
|
* Space Complexity: O(k + log n)
|
|
@@ -372,8 +372,10 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
372
372
|
* is greater than, less than, or equal to the second value.
|
|
373
373
|
* @param {K} a - The parameter "a" is of type K.
|
|
374
374
|
* @param {K} b - The parameter "b" in the above code represents a K.
|
|
375
|
-
* @returns a value of type CP (ComparisonResult). The possible return values are
|
|
376
|
-
* than),
|
|
375
|
+
* @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
|
|
376
|
+
* than), 'LT' (less than), or 'EQ' (equal).
|
|
377
377
|
*/
|
|
378
378
|
protected _compare(a: K, b: K): CP;
|
|
379
|
+
protected _lt(a: K, b: K): boolean;
|
|
380
|
+
protected _gt(a: K, b: K): boolean;
|
|
379
381
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BSTVariant, CP, IterationType } from '../../types';
|
|
2
1
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
3
2
|
import { Queue } from '../queue';
|
|
4
3
|
export class BSTNode extends BinaryTreeNode {
|
|
@@ -86,7 +85,7 @@ export class BST extends BinaryTree {
|
|
|
86
85
|
get root() {
|
|
87
86
|
return this._root;
|
|
88
87
|
}
|
|
89
|
-
_variant =
|
|
88
|
+
_variant = 'STANDARD';
|
|
90
89
|
/**
|
|
91
90
|
* The function returns the value of the _variant property.
|
|
92
91
|
* @returns The value of the `_variant` property.
|
|
@@ -166,10 +165,10 @@ export class BST extends BinaryTree {
|
|
|
166
165
|
* @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
|
|
167
166
|
* `undefined`.
|
|
168
167
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
169
|
-
* type of iteration to be performed. It has a default value of `
|
|
168
|
+
* type of iteration to be performed. It has a default value of `'ITERATIVE'`.
|
|
170
169
|
* @returns either a node object (NODE) or undefined.
|
|
171
170
|
*/
|
|
172
|
-
ensureNode(keyOrNodeOrEntry, iterationType =
|
|
171
|
+
ensureNode(keyOrNodeOrEntry, iterationType = 'ITERATIVE') {
|
|
173
172
|
let res;
|
|
174
173
|
if (this.isRealNode(keyOrNodeOrEntry)) {
|
|
175
174
|
res = keyOrNodeOrEntry;
|
|
@@ -219,7 +218,7 @@ export class BST extends BinaryTree {
|
|
|
219
218
|
}
|
|
220
219
|
let current = this.root;
|
|
221
220
|
while (current !== undefined) {
|
|
222
|
-
if (this._compare(current.key, newNode.key) ===
|
|
221
|
+
if (this._compare(current.key, newNode.key) === 'EQ') {
|
|
223
222
|
// if (current !== newNode) {
|
|
224
223
|
// The key value is the same but the reference is different, update the value of the existing node
|
|
225
224
|
this._replaceNode(current, newNode);
|
|
@@ -230,7 +229,7 @@ export class BST extends BinaryTree {
|
|
|
230
229
|
// return;
|
|
231
230
|
// }
|
|
232
231
|
}
|
|
233
|
-
else if (this._compare(current.key, newNode.key) ===
|
|
232
|
+
else if (this._compare(current.key, newNode.key) === 'GT') {
|
|
234
233
|
if (current.left === undefined) {
|
|
235
234
|
current.left = newNode;
|
|
236
235
|
this._size++;
|
|
@@ -339,7 +338,7 @@ export class BST extends BinaryTree {
|
|
|
339
338
|
}
|
|
340
339
|
}
|
|
341
340
|
};
|
|
342
|
-
if (iterationType ===
|
|
341
|
+
if (iterationType === 'RECURSIVE') {
|
|
343
342
|
_dfs(sorted);
|
|
344
343
|
}
|
|
345
344
|
else {
|
|
@@ -365,18 +364,18 @@ export class BST extends BinaryTree {
|
|
|
365
364
|
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
366
365
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
367
366
|
*/
|
|
368
|
-
getNodeByKey(key, iterationType =
|
|
367
|
+
getNodeByKey(key, iterationType = 'ITERATIVE') {
|
|
369
368
|
if (!this.isRealNode(this.root))
|
|
370
369
|
return undefined;
|
|
371
|
-
if (iterationType ===
|
|
370
|
+
if (iterationType === 'RECURSIVE') {
|
|
372
371
|
const _dfs = (cur) => {
|
|
373
372
|
if (cur.key === key)
|
|
374
373
|
return cur;
|
|
375
374
|
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
|
|
376
375
|
return;
|
|
377
|
-
if (this._compare(cur.key, key) ===
|
|
376
|
+
if (this._compare(cur.key, key) === 'GT' && this.isRealNode(cur.left))
|
|
378
377
|
return _dfs(cur.left);
|
|
379
|
-
if (this._compare(cur.key, key) ===
|
|
378
|
+
if (this._compare(cur.key, key) === 'LT' && this.isRealNode(cur.right))
|
|
380
379
|
return _dfs(cur.right);
|
|
381
380
|
};
|
|
382
381
|
return _dfs(this.root);
|
|
@@ -386,11 +385,11 @@ export class BST extends BinaryTree {
|
|
|
386
385
|
while (queue.size > 0) {
|
|
387
386
|
const cur = queue.shift();
|
|
388
387
|
if (this.isRealNode(cur)) {
|
|
389
|
-
if (this._compare(cur.key, key) ===
|
|
388
|
+
if (this._compare(cur.key, key) === 'EQ')
|
|
390
389
|
return cur;
|
|
391
|
-
if (this._compare(cur.key, key) ===
|
|
390
|
+
if (this._compare(cur.key, key) === 'GT')
|
|
392
391
|
this.isRealNode(cur.left) && queue.push(cur.left);
|
|
393
|
-
if (this._compare(cur.key, key) ===
|
|
392
|
+
if (this._compare(cur.key, key) === 'LT')
|
|
394
393
|
this.isRealNode(cur.right) && queue.push(cur.right);
|
|
395
394
|
}
|
|
396
395
|
}
|
|
@@ -429,7 +428,7 @@ export class BST extends BinaryTree {
|
|
|
429
428
|
if (!beginRoot)
|
|
430
429
|
return [];
|
|
431
430
|
const ans = [];
|
|
432
|
-
if (iterationType ===
|
|
431
|
+
if (iterationType === 'RECURSIVE') {
|
|
433
432
|
const _traverse = (cur) => {
|
|
434
433
|
const callbackResult = callback(cur);
|
|
435
434
|
if (callbackResult === identifier) {
|
|
@@ -441,10 +440,10 @@ export class BST extends BinaryTree {
|
|
|
441
440
|
return;
|
|
442
441
|
// TODO potential bug
|
|
443
442
|
if (callback === this._defaultOneParamCallback) {
|
|
444
|
-
if (this._compare(cur.key, identifier) ===
|
|
445
|
-
|
|
446
|
-
if (this._compare(cur.key, identifier) ===
|
|
447
|
-
|
|
443
|
+
if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === 'GT')
|
|
444
|
+
_traverse(cur.left);
|
|
445
|
+
if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === 'LT')
|
|
446
|
+
_traverse(cur.right);
|
|
448
447
|
}
|
|
449
448
|
else {
|
|
450
449
|
this.isRealNode(cur.left) && _traverse(cur.left);
|
|
@@ -454,9 +453,9 @@ export class BST extends BinaryTree {
|
|
|
454
453
|
_traverse(beginRoot);
|
|
455
454
|
}
|
|
456
455
|
else {
|
|
457
|
-
const
|
|
458
|
-
while (
|
|
459
|
-
const cur =
|
|
456
|
+
const stack = [beginRoot];
|
|
457
|
+
while (stack.length > 0) {
|
|
458
|
+
const cur = stack.pop();
|
|
460
459
|
if (this.isRealNode(cur)) {
|
|
461
460
|
const callbackResult = callback(cur);
|
|
462
461
|
if (callbackResult === identifier) {
|
|
@@ -466,14 +465,20 @@ export class BST extends BinaryTree {
|
|
|
466
465
|
}
|
|
467
466
|
// TODO potential bug
|
|
468
467
|
if (callback === this._defaultOneParamCallback) {
|
|
469
|
-
if (this._compare(cur.key, identifier) ===
|
|
470
|
-
|
|
471
|
-
if (this._compare(cur.key, identifier) ===
|
|
472
|
-
|
|
468
|
+
if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === 'LT')
|
|
469
|
+
stack.push(cur.right);
|
|
470
|
+
if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === 'GT')
|
|
471
|
+
stack.push(cur.left);
|
|
472
|
+
// if (this.isRealNode(cur.right) && this._lt(cur.key, identifier as K)) stack.push(cur.right);
|
|
473
|
+
// if (this.isRealNode(cur.left) && this._gt(cur.key, identifier as K)) stack.push(cur.left);
|
|
474
|
+
// // @ts-ignore
|
|
475
|
+
// if (this.isRealNode(cur.right) && cur.key > identifier) stack.push(cur.right);
|
|
476
|
+
// // @ts-ignore
|
|
477
|
+
// if (this.isRealNode(cur.left) && cur.key < identifier) stack.push(cur.left);
|
|
473
478
|
}
|
|
474
479
|
else {
|
|
475
|
-
this.isRealNode(cur.
|
|
476
|
-
this.isRealNode(cur.
|
|
480
|
+
this.isRealNode(cur.right) && stack.push(cur.right);
|
|
481
|
+
this.isRealNode(cur.left) && stack.push(cur.left);
|
|
477
482
|
}
|
|
478
483
|
}
|
|
479
484
|
}
|
|
@@ -503,7 +508,7 @@ export class BST extends BinaryTree {
|
|
|
503
508
|
* following values:
|
|
504
509
|
* @returns The method is returning an array of the return type of the callback function.
|
|
505
510
|
*/
|
|
506
|
-
dfs(callback = this._defaultOneParamCallback, pattern = 'in', beginRoot = this.root, iterationType =
|
|
511
|
+
dfs(callback = this._defaultOneParamCallback, pattern = 'in', beginRoot = this.root, iterationType = 'ITERATIVE') {
|
|
507
512
|
return super.dfs(callback, pattern, beginRoot, iterationType, false);
|
|
508
513
|
}
|
|
509
514
|
/**
|
|
@@ -576,7 +581,7 @@ export class BST extends BinaryTree {
|
|
|
576
581
|
let current = this.ensureNode(beginRoot);
|
|
577
582
|
if (!current)
|
|
578
583
|
return undefined;
|
|
579
|
-
if (this._variant ===
|
|
584
|
+
if (this._variant === 'STANDARD') {
|
|
580
585
|
// For BSTVariant.MIN, find the rightmost node
|
|
581
586
|
while (current.right !== undefined) {
|
|
582
587
|
current = current.right;
|
|
@@ -615,7 +620,7 @@ export class BST extends BinaryTree {
|
|
|
615
620
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
616
621
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
617
622
|
*/
|
|
618
|
-
lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater =
|
|
623
|
+
lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater = 'LT', targetNode = this.root, iterationType = this.iterationType) {
|
|
619
624
|
targetNode = this.ensureNode(targetNode);
|
|
620
625
|
const ans = [];
|
|
621
626
|
if (!targetNode)
|
|
@@ -623,7 +628,7 @@ export class BST extends BinaryTree {
|
|
|
623
628
|
if (!this.root)
|
|
624
629
|
return ans;
|
|
625
630
|
const targetKey = targetNode.key;
|
|
626
|
-
if (iterationType ===
|
|
631
|
+
if (iterationType === 'RECURSIVE') {
|
|
627
632
|
const _traverse = (cur) => {
|
|
628
633
|
const compared = this._compare(cur.key, targetKey);
|
|
629
634
|
if (compared === lesserOrGreater)
|
|
@@ -673,7 +678,7 @@ export class BST extends BinaryTree {
|
|
|
673
678
|
this.clear();
|
|
674
679
|
if (sorted.length < 1)
|
|
675
680
|
return false;
|
|
676
|
-
if (iterationType ===
|
|
681
|
+
if (iterationType === 'RECURSIVE') {
|
|
677
682
|
const buildBalanceBST = (l, r) => {
|
|
678
683
|
if (l > r)
|
|
679
684
|
return;
|
|
@@ -730,7 +735,7 @@ export class BST extends BinaryTree {
|
|
|
730
735
|
if (!this.root)
|
|
731
736
|
return true;
|
|
732
737
|
let balanced = true;
|
|
733
|
-
if (iterationType ===
|
|
738
|
+
if (iterationType === 'RECURSIVE') {
|
|
734
739
|
const _height = (cur) => {
|
|
735
740
|
if (!cur)
|
|
736
741
|
return 0;
|
|
@@ -787,13 +792,29 @@ export class BST extends BinaryTree {
|
|
|
787
792
|
* is greater than, less than, or equal to the second value.
|
|
788
793
|
* @param {K} a - The parameter "a" is of type K.
|
|
789
794
|
* @param {K} b - The parameter "b" in the above code represents a K.
|
|
790
|
-
* @returns a value of type CP (ComparisonResult). The possible return values are
|
|
791
|
-
* than),
|
|
795
|
+
* @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
|
|
796
|
+
* than), 'LT' (less than), or 'EQ' (equal).
|
|
792
797
|
*/
|
|
793
798
|
_compare(a, b) {
|
|
794
799
|
const extractedA = this.extractor(a);
|
|
795
800
|
const extractedB = this.extractor(b);
|
|
796
|
-
const compared = this.variant ===
|
|
797
|
-
return compared > 0 ?
|
|
801
|
+
const compared = this.variant === 'STANDARD' ? extractedA - extractedB : extractedB - extractedA;
|
|
802
|
+
return compared > 0 ? 'GT' : compared < 0 ? 'LT' : 'EQ';
|
|
803
|
+
}
|
|
804
|
+
_lt(a, b) {
|
|
805
|
+
const extractedA = this.extractor(a);
|
|
806
|
+
const extractedB = this.extractor(b);
|
|
807
|
+
// return this.variant === BSTVariant.STANDARD ? extractedA < extractedB : extractedA > extractedB;
|
|
808
|
+
return this.variant === 'STANDARD' ? extractedA < extractedB : extractedA > extractedB;
|
|
809
|
+
// return extractedA < extractedB;
|
|
810
|
+
// return a < b;
|
|
811
|
+
}
|
|
812
|
+
_gt(a, b) {
|
|
813
|
+
const extractedA = this.extractor(a);
|
|
814
|
+
const extractedB = this.extractor(b);
|
|
815
|
+
// return this.variant === BSTVariant.STANDARD ? extractedA > extractedB : extractedA < extractedB;
|
|
816
|
+
return this.variant === 'STANDARD' ? extractedA > extractedB : extractedA < extractedB;
|
|
817
|
+
// return extractedA > extractedB;
|
|
818
|
+
// return a > b;
|
|
798
819
|
}
|
|
799
820
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RBTNColor } from '../../types';
|
|
2
2
|
import { BST, BSTNode } from './bst';
|
|
3
3
|
export class RedBlackTreeNode extends BSTNode {
|
|
4
4
|
/**
|
|
@@ -193,9 +193,8 @@ export class RedBlackTree extends BST {
|
|
|
193
193
|
* @returns The method is returning a value of type `NODE | null | undefined`.
|
|
194
194
|
*/
|
|
195
195
|
getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
|
|
196
|
-
if (identifier instanceof RedBlackTreeNode)
|
|
197
|
-
|
|
198
|
-
return super.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined;
|
|
196
|
+
// if ((identifier as any) instanceof RedBlackTreeNode) callback = (node => node) as C;
|
|
197
|
+
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined;
|
|
199
198
|
}
|
|
200
199
|
/**
|
|
201
200
|
* Time Complexity: O(1)
|
|
@@ -234,7 +233,7 @@ export class RedBlackTree extends BST {
|
|
|
234
233
|
if (!this.isRealNode(newNode))
|
|
235
234
|
return false;
|
|
236
235
|
const insertStatus = this._insert(newNode);
|
|
237
|
-
if (insertStatus ===
|
|
236
|
+
if (insertStatus === 'CREATED') {
|
|
238
237
|
// Ensure the root is black
|
|
239
238
|
if (this.isRealNode(this._root)) {
|
|
240
239
|
this._root.color = RBTNColor.BLACK;
|
|
@@ -246,7 +245,7 @@ export class RedBlackTree extends BST {
|
|
|
246
245
|
return true;
|
|
247
246
|
}
|
|
248
247
|
else
|
|
249
|
-
return insertStatus ===
|
|
248
|
+
return insertStatus === 'UPDATED';
|
|
250
249
|
}
|
|
251
250
|
/**
|
|
252
251
|
* Time Complexity: O(log n)
|
|
@@ -378,7 +377,7 @@ export class RedBlackTree extends BST {
|
|
|
378
377
|
}
|
|
379
378
|
else {
|
|
380
379
|
this._replaceNode(current, node);
|
|
381
|
-
return
|
|
380
|
+
return 'UPDATED';
|
|
382
381
|
}
|
|
383
382
|
}
|
|
384
383
|
node.parent = parent;
|
|
@@ -395,7 +394,7 @@ export class RedBlackTree extends BST {
|
|
|
395
394
|
node.right = this.SENTINEL;
|
|
396
395
|
node.color = RBTNColor.RED;
|
|
397
396
|
this._insertFixup(node);
|
|
398
|
-
return
|
|
397
|
+
return 'CREATED';
|
|
399
398
|
}
|
|
400
399
|
/**
|
|
401
400
|
* Time Complexity: O(1)
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
|
|
9
|
-
import { IterationType } from '../../types';
|
|
10
9
|
import { IBinaryTree } from '../../interfaces';
|
|
11
10
|
import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
|
|
12
11
|
export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
|
|
@@ -164,7 +163,7 @@ export declare class TreeMultiMap<K = any, V = any, NODE extends TreeMultiMapNod
|
|
|
164
163
|
* values:
|
|
165
164
|
* @returns a boolean value.
|
|
166
165
|
*/
|
|
167
|
-
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
166
|
+
perfectlyBalance(iterationType?: import("../../types").IterationType): boolean;
|
|
168
167
|
/**
|
|
169
168
|
* Time complexity: O(n)
|
|
170
169
|
* Space complexity: O(n)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RBTNColor } from '../../types';
|
|
2
2
|
import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
|
|
3
3
|
export class TreeMultiMapNode extends RedBlackTreeNode {
|
|
4
4
|
/**
|
|
@@ -311,7 +311,7 @@ export class TreeMultiMap extends RedBlackTree {
|
|
|
311
311
|
if (sorted.length < 1)
|
|
312
312
|
return false;
|
|
313
313
|
this.clear();
|
|
314
|
-
if (iterationType ===
|
|
314
|
+
if (iterationType === 'RECURSIVE') {
|
|
315
315
|
const buildBalanceBST = (l, r) => {
|
|
316
316
|
if (l > r)
|
|
317
317
|
return;
|
|
@@ -1,31 +1,13 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
INVERSE = "INVERSE"
|
|
4
|
-
}
|
|
5
|
-
export declare enum CP {
|
|
6
|
-
lt = "lt",
|
|
7
|
-
eq = "eq",
|
|
8
|
-
gt = "gt"
|
|
9
|
-
}
|
|
1
|
+
export type BSTVariant = 'STANDARD' | 'INVERSE';
|
|
2
|
+
export type CP = 'LT' | 'EQ' | 'GT';
|
|
10
3
|
/**
|
|
11
4
|
* Enum representing different loop types.
|
|
12
5
|
*
|
|
13
6
|
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
14
7
|
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
15
8
|
*/
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
RECURSIVE = "RECURSIVE"
|
|
19
|
-
}
|
|
20
|
-
export declare enum FamilyPosition {
|
|
21
|
-
ROOT = "ROOT",
|
|
22
|
-
LEFT = "LEFT",
|
|
23
|
-
RIGHT = "RIGHT",
|
|
24
|
-
ROOT_LEFT = "ROOT_LEFT",
|
|
25
|
-
ROOT_RIGHT = "ROOT_RIGHT",
|
|
26
|
-
ISOLATED = "ISOLATED",
|
|
27
|
-
MAL_NODE = "MAL_NODE"
|
|
28
|
-
}
|
|
9
|
+
export type IterationType = 'ITERATIVE' | 'RECURSIVE';
|
|
10
|
+
export type FamilyPosition = 'ROOT' | 'LEFT' | 'RIGHT' | 'ROOT_LEFT' | 'ROOT_RIGHT' | 'ISOLATED' | 'MAL_NODE';
|
|
29
11
|
export type Comparator<K> = (a: K, b: K) => number;
|
|
30
12
|
export type DFSOrderPattern = 'pre' | 'in' | 'post';
|
|
31
13
|
export type NodeDisplayLayout = [string[], number, number, number];
|
|
@@ -52,9 +34,4 @@ export type BinaryTreeDeleteResult<N> = {
|
|
|
52
34
|
deleted: N | null | undefined;
|
|
53
35
|
needBalanced: N | null | undefined;
|
|
54
36
|
};
|
|
55
|
-
export
|
|
56
|
-
CREATED = "CREATED",
|
|
57
|
-
READ = "READ",
|
|
58
|
-
UPDATED = "UPDATED",
|
|
59
|
-
DELETED = "DELETED"
|
|
60
|
-
}
|
|
37
|
+
export type CRUD = 'CREATED' | 'READ' | 'UPDATED' | 'DELETED';
|
package/dist/mjs/types/common.js
CHANGED
|
@@ -1,39 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
(function (BSTVariant) {
|
|
3
|
-
BSTVariant["STANDARD"] = "STANDARD";
|
|
4
|
-
BSTVariant["INVERSE"] = "INVERSE";
|
|
5
|
-
})(BSTVariant || (BSTVariant = {}));
|
|
6
|
-
export var CP;
|
|
7
|
-
(function (CP) {
|
|
8
|
-
CP["lt"] = "lt";
|
|
9
|
-
CP["eq"] = "eq";
|
|
10
|
-
CP["gt"] = "gt";
|
|
11
|
-
})(CP || (CP = {}));
|
|
12
|
-
/**
|
|
13
|
-
* Enum representing different loop types.
|
|
14
|
-
*
|
|
15
|
-
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
16
|
-
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
17
|
-
*/
|
|
18
|
-
export var IterationType;
|
|
19
|
-
(function (IterationType) {
|
|
20
|
-
IterationType["ITERATIVE"] = "ITERATIVE";
|
|
21
|
-
IterationType["RECURSIVE"] = "RECURSIVE";
|
|
22
|
-
})(IterationType || (IterationType = {}));
|
|
23
|
-
export var FamilyPosition;
|
|
24
|
-
(function (FamilyPosition) {
|
|
25
|
-
FamilyPosition["ROOT"] = "ROOT";
|
|
26
|
-
FamilyPosition["LEFT"] = "LEFT";
|
|
27
|
-
FamilyPosition["RIGHT"] = "RIGHT";
|
|
28
|
-
FamilyPosition["ROOT_LEFT"] = "ROOT_LEFT";
|
|
29
|
-
FamilyPosition["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
30
|
-
FamilyPosition["ISOLATED"] = "ISOLATED";
|
|
31
|
-
FamilyPosition["MAL_NODE"] = "MAL_NODE";
|
|
32
|
-
})(FamilyPosition || (FamilyPosition = {}));
|
|
33
|
-
export var CRUD;
|
|
34
|
-
(function (CRUD) {
|
|
35
|
-
CRUD["CREATED"] = "CREATED";
|
|
36
|
-
CRUD["READ"] = "READ";
|
|
37
|
-
CRUD["UPDATED"] = "UPDATED";
|
|
38
|
-
CRUD["DELETED"] = "DELETED";
|
|
39
|
-
})(CRUD || (CRUD = {}));
|
|
1
|
+
export {};
|