data-structure-typed 1.50.9 → 1.51.1
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 +14 -14
- package/benchmark/report.html +37 -1
- package/benchmark/report.json +378 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +73 -73
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.js +39 -39
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +3 -3
- 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 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +73 -73
- package/dist/mjs/data-structures/binary-tree/bst.js +39 -39
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +3 -3
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +2 -2
- package/dist/umd/data-structure-typed.js +119 -119
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +7 -7
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +71 -71
- package/src/data-structures/binary-tree/bst.ts +33 -33
- package/src/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/data-structures/binary-tree/tree-multi-map.ts +2 -2
- package/test/integration/avl-tree.test.ts +4 -4
- package/test/integration/bst.test.ts +7 -7
- package/test/integration/index.html +2 -2
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +1 -0
- package/test/utils/big-o.ts +12 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-multi-map.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multi-map.ts"],"names":[],"mappings":";;;AAmBA,uCAA2D;AAE3D,MAAa,gBAIX,SAAQ,0BAA4B;IACpC;;;;;;;;;;;OAWG;IACH,YAAY,GAAM,EAAE,KAAS,EAAE,KAAK,GAAG,CAAC,EAAE,QAAmB,OAAO;QAClE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAIjB,WAAM,GAAW,CAAC,CAAC;QAH3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAID;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,IAAI,KAAK,CAAC,KAAa;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;CACF;AAxCD,4CAwCC;AAED,MAAa,YAMX,SAAQ,sBAA8B;IAEtC;;;;;;;;OAQG;IACH,YAAY,uB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,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"tree-multi-map.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multi-map.ts"],"names":[],"mappings":";;;AAmBA,uCAA2D;AAE3D,MAAa,gBAIX,SAAQ,0BAA4B;IACpC;;;;;;;;;;;OAWG;IACH,YAAY,GAAM,EAAE,KAAS,EAAE,KAAK,GAAG,CAAC,EAAE,QAAmB,OAAO;QAClE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAIjB,WAAM,GAAW,CAAC,CAAC;QAH3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAID;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,IAAI,KAAK,CAAC,KAAa;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;CACF;AAxCD,4CAwCC;AAED,MAAa,YAMX,SAAQ,sBAA8B;IAEtC;;;;;;;;OAQG;IACH,YAAY,uBAA+D,EAAE,EAAE,OAAgC;QAC7G,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAIX,WAAM,GAAG,CAAC,CAAC;QAHnB,IAAI,oBAAoB;YAAE,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC/D,CAAC;IAID,6DAA6D;IAC7D;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IAEH;;;;;;;OAOG;IACH,gBAAgB;QACd,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACtC,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;;;;;;;;;;;;OAaG;IACM,UAAU,CAAC,GAAM,EAA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;gBAC/B,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;gBAC/B,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;YACjC,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;;OAOG;IACO,YAAY,CAAC,OAAa,EAAE,OAAa;QACjD,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9C,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF;AAraD,oCAqaC"}
|
|
@@ -194,7 +194,7 @@ export class AVLTreeMultiMap extends AVLTree {
|
|
|
194
194
|
* decremented by 1 and
|
|
195
195
|
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
|
|
196
196
|
*/
|
|
197
|
-
delete(identifier, callback = this.
|
|
197
|
+
delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
|
|
198
198
|
const deletedResult = [];
|
|
199
199
|
if (!this.root)
|
|
200
200
|
return deletedResult;
|
|
@@ -108,7 +108,7 @@ export declare class AVLTree<K = any, V = any, NODE extends AVLTreeNode<K, V, NO
|
|
|
108
108
|
* `callback` function.
|
|
109
109
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
110
110
|
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
111
|
-
* default to the `
|
|
111
|
+
* default to the `_DEFAULT_CALLBACK` function. The `callback` function should have a single
|
|
112
112
|
* parameter of type `NODE
|
|
113
113
|
* @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
|
|
114
114
|
*/
|
|
@@ -134,11 +134,11 @@ export class AVLTree extends BST {
|
|
|
134
134
|
* `callback` function.
|
|
135
135
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
136
136
|
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
137
|
-
* default to the `
|
|
137
|
+
* default to the `_DEFAULT_CALLBACK` function. The `callback` function should have a single
|
|
138
138
|
* parameter of type `NODE
|
|
139
139
|
* @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
|
|
140
140
|
*/
|
|
141
|
-
delete(identifier, callback = this.
|
|
141
|
+
delete(identifier, callback = this._DEFAULT_CALLBACK) {
|
|
142
142
|
if (identifier instanceof AVLTreeNode)
|
|
143
143
|
callback = (node => node);
|
|
144
144
|
const deletedResults = super.delete(identifier, callback);
|
|
@@ -576,7 +576,7 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
576
576
|
* 4. `middleIndex`: The index of the middle character
|
|
577
577
|
*/
|
|
578
578
|
protected _displayAux(node: NODE | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
579
|
-
protected
|
|
579
|
+
protected _DEFAULT_CALLBACK: (node: NODE | null | undefined) => K | undefined;
|
|
580
580
|
/**
|
|
581
581
|
* Swap the data of two nodes in the binary tree.
|
|
582
582
|
* @param {NODE} srcNode - The source node to swap.
|
|
@@ -219,23 +219,23 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
219
219
|
* itself if it is not a valid node key.
|
|
220
220
|
*/
|
|
221
221
|
ensureNode(keyOrNodeOrEntry, iterationType = 'ITERATIVE') {
|
|
222
|
-
let res;
|
|
223
222
|
if (this.isRealNode(keyOrNodeOrEntry)) {
|
|
224
|
-
|
|
223
|
+
return keyOrNodeOrEntry;
|
|
225
224
|
}
|
|
226
225
|
else if (this.isEntry(keyOrNodeOrEntry)) {
|
|
227
226
|
if (keyOrNodeOrEntry[0] === null)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
return null;
|
|
228
|
+
if (keyOrNodeOrEntry[0] === undefined)
|
|
229
|
+
return;
|
|
230
|
+
return this.getNodeByKey(keyOrNodeOrEntry[0], iterationType);
|
|
231
231
|
}
|
|
232
232
|
else {
|
|
233
233
|
if (keyOrNodeOrEntry === null)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
return null;
|
|
235
|
+
if (keyOrNodeOrEntry === undefined)
|
|
236
|
+
return;
|
|
237
|
+
return this.getNodeByKey(keyOrNodeOrEntry, iterationType);
|
|
237
238
|
}
|
|
238
|
-
return res;
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
241
241
|
* The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.
|
|
@@ -411,14 +411,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
411
411
|
* specific node based on its value or object.
|
|
412
412
|
* @param {C} callback - The `callback` parameter is a function that is used to determine the
|
|
413
413
|
* identifier of the node to be deleted. It is optional and has a default value of
|
|
414
|
-
* `this.
|
|
414
|
+
* `this._DEFAULT_CALLBACK`. The `callback` function should return the identifier of the node.
|
|
415
415
|
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
|
|
416
416
|
*/
|
|
417
|
-
delete(identifier, callback = this.
|
|
417
|
+
delete(identifier, callback = this._DEFAULT_CALLBACK) {
|
|
418
418
|
const deletedResult = [];
|
|
419
419
|
if (!this.root)
|
|
420
420
|
return deletedResult;
|
|
421
|
-
if ((!callback || callback === this.
|
|
421
|
+
if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
|
|
422
422
|
callback = (node => node);
|
|
423
423
|
const curr = this.getNode(identifier, callback);
|
|
424
424
|
if (!curr)
|
|
@@ -477,7 +477,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
477
477
|
* specific value.
|
|
478
478
|
* @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as
|
|
479
479
|
* input and returns a value of type `C`. It is used to determine if a node matches the given
|
|
480
|
-
* identifier. If no callback is provided, the `
|
|
480
|
+
* identifier. If no callback is provided, the `_DEFAULT_CALLBACK` function is used as the
|
|
481
481
|
* default
|
|
482
482
|
* @param [onlyOne=false] - A boolean value indicating whether to only return the first node that
|
|
483
483
|
* matches the identifier. If set to true, the function will stop iterating once it finds a matching
|
|
@@ -490,15 +490,15 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
490
490
|
* traverse the binary tree. It can have two possible values:
|
|
491
491
|
* @returns an array of nodes of type `NODE`.
|
|
492
492
|
*/
|
|
493
|
-
getNodes(identifier, callback = this.
|
|
494
|
-
if ((!callback || callback === this.
|
|
493
|
+
getNodes(identifier, callback = this._DEFAULT_CALLBACK, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
|
|
494
|
+
if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
|
|
495
495
|
callback = (node => node);
|
|
496
496
|
beginRoot = this.ensureNode(beginRoot);
|
|
497
497
|
if (!beginRoot)
|
|
498
498
|
return [];
|
|
499
499
|
const ans = [];
|
|
500
500
|
if (iterationType === 'RECURSIVE') {
|
|
501
|
-
const
|
|
501
|
+
const dfs = (cur) => {
|
|
502
502
|
if (callback(cur) === identifier) {
|
|
503
503
|
ans.push(cur);
|
|
504
504
|
if (onlyOne)
|
|
@@ -506,23 +506,23 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
506
506
|
}
|
|
507
507
|
if (!cur.left && !cur.right)
|
|
508
508
|
return;
|
|
509
|
-
cur.left &&
|
|
510
|
-
cur.right &&
|
|
509
|
+
cur.left && dfs(cur.left);
|
|
510
|
+
cur.right && dfs(cur.right);
|
|
511
511
|
};
|
|
512
|
-
|
|
512
|
+
dfs(beginRoot);
|
|
513
513
|
}
|
|
514
514
|
else {
|
|
515
|
-
const
|
|
516
|
-
while (
|
|
517
|
-
const cur =
|
|
515
|
+
const stack = [beginRoot];
|
|
516
|
+
while (stack.length > 0) {
|
|
517
|
+
const cur = stack.pop();
|
|
518
518
|
if (cur) {
|
|
519
519
|
if (callback(cur) === identifier) {
|
|
520
520
|
ans.push(cur);
|
|
521
521
|
if (onlyOne)
|
|
522
522
|
return ans;
|
|
523
523
|
}
|
|
524
|
-
cur.left &&
|
|
525
|
-
cur.right &&
|
|
524
|
+
cur.left && stack.push(cur.left);
|
|
525
|
+
cur.right && stack.push(cur.right);
|
|
526
526
|
}
|
|
527
527
|
}
|
|
528
528
|
}
|
|
@@ -553,8 +553,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
553
553
|
* nodes are visited during the search.
|
|
554
554
|
* @returns a value of type `NODE | null | undefined`.
|
|
555
555
|
*/
|
|
556
|
-
getNode(identifier, callback = this.
|
|
557
|
-
if ((!callback || callback === this.
|
|
556
|
+
getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
557
|
+
if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
|
|
558
558
|
callback = (node => node);
|
|
559
559
|
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? null;
|
|
560
560
|
}
|
|
@@ -580,27 +580,27 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
580
580
|
if (!this.root)
|
|
581
581
|
return undefined;
|
|
582
582
|
if (iterationType === 'RECURSIVE') {
|
|
583
|
-
const
|
|
583
|
+
const dfs = (cur) => {
|
|
584
584
|
if (cur.key === key)
|
|
585
585
|
return cur;
|
|
586
586
|
if (!cur.left && !cur.right)
|
|
587
587
|
return;
|
|
588
588
|
if (cur.left)
|
|
589
|
-
return
|
|
589
|
+
return dfs(cur.left);
|
|
590
590
|
if (cur.right)
|
|
591
|
-
return
|
|
591
|
+
return dfs(cur.right);
|
|
592
592
|
};
|
|
593
|
-
return
|
|
593
|
+
return dfs(this.root);
|
|
594
594
|
}
|
|
595
595
|
else {
|
|
596
|
-
const
|
|
597
|
-
while (
|
|
598
|
-
const cur =
|
|
596
|
+
const stack = [this.root];
|
|
597
|
+
while (stack.length > 0) {
|
|
598
|
+
const cur = stack.pop();
|
|
599
599
|
if (cur) {
|
|
600
600
|
if (cur.key === key)
|
|
601
601
|
return cur;
|
|
602
|
-
cur.left &&
|
|
603
|
-
cur.right &&
|
|
602
|
+
cur.left && stack.push(cur.left);
|
|
603
|
+
cur.right && stack.push(cur.right);
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
}
|
|
@@ -631,8 +631,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
631
631
|
* @returns The value of the node with the given identifier is being returned. If the node is not
|
|
632
632
|
* found, `undefined` is returned.
|
|
633
633
|
*/
|
|
634
|
-
get(identifier, callback = this.
|
|
635
|
-
if ((!callback || callback === this.
|
|
634
|
+
get(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
635
|
+
if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
|
|
636
636
|
callback = (node => node);
|
|
637
637
|
return this.getNode(identifier, callback, beginRoot, iterationType)?.value ?? undefined;
|
|
638
638
|
}
|
|
@@ -661,8 +661,8 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
661
661
|
* be performed in a pre-order, in-order, or post-order manner.
|
|
662
662
|
* @returns a boolean value.
|
|
663
663
|
*/
|
|
664
|
-
has(identifier, callback = this.
|
|
665
|
-
if ((!callback || callback === this.
|
|
664
|
+
has(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
665
|
+
if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
|
|
666
666
|
callback = (node => node);
|
|
667
667
|
return this.getNodes(identifier, callback, true, beginRoot, iterationType).length > 0;
|
|
668
668
|
}
|
|
@@ -966,21 +966,21 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
966
966
|
if (!this.isRealNode(beginRoot))
|
|
967
967
|
return beginRoot;
|
|
968
968
|
if (iterationType === 'RECURSIVE') {
|
|
969
|
-
const
|
|
969
|
+
const dfs = (cur) => {
|
|
970
970
|
if (!this.isRealNode(cur.left))
|
|
971
971
|
return cur;
|
|
972
|
-
return
|
|
972
|
+
return dfs(cur.left);
|
|
973
973
|
};
|
|
974
|
-
return
|
|
974
|
+
return dfs(beginRoot);
|
|
975
975
|
}
|
|
976
976
|
else {
|
|
977
977
|
// Indirect implementation of iteration using tail recursion optimization
|
|
978
|
-
const
|
|
978
|
+
const dfs = trampoline((cur) => {
|
|
979
979
|
if (!this.isRealNode(cur.left))
|
|
980
980
|
return cur;
|
|
981
|
-
return
|
|
981
|
+
return dfs.cont(cur.left);
|
|
982
982
|
});
|
|
983
|
-
return
|
|
983
|
+
return dfs(beginRoot);
|
|
984
984
|
}
|
|
985
985
|
}
|
|
986
986
|
/**
|
|
@@ -1010,21 +1010,21 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1010
1010
|
if (!beginRoot)
|
|
1011
1011
|
return beginRoot;
|
|
1012
1012
|
if (iterationType === 'RECURSIVE') {
|
|
1013
|
-
const
|
|
1013
|
+
const dfs = (cur) => {
|
|
1014
1014
|
if (!this.isRealNode(cur.right))
|
|
1015
1015
|
return cur;
|
|
1016
|
-
return
|
|
1016
|
+
return dfs(cur.right);
|
|
1017
1017
|
};
|
|
1018
|
-
return
|
|
1018
|
+
return dfs(beginRoot);
|
|
1019
1019
|
}
|
|
1020
1020
|
else {
|
|
1021
1021
|
// Indirect implementation of iteration using tail recursion optimization
|
|
1022
|
-
const
|
|
1022
|
+
const dfs = trampoline((cur) => {
|
|
1023
1023
|
if (!this.isRealNode(cur.right))
|
|
1024
1024
|
return cur;
|
|
1025
|
-
return
|
|
1025
|
+
return dfs.cont(cur.right);
|
|
1026
1026
|
});
|
|
1027
|
-
return
|
|
1027
|
+
return dfs(beginRoot);
|
|
1028
1028
|
}
|
|
1029
1029
|
}
|
|
1030
1030
|
/**
|
|
@@ -1109,65 +1109,65 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1109
1109
|
* `false`, null or undefined
|
|
1110
1110
|
* @returns an array of values that are the return values of the callback function.
|
|
1111
1111
|
*/
|
|
1112
|
-
dfs(callback = this.
|
|
1112
|
+
dfs(callback = this._DEFAULT_CALLBACK, pattern = 'IN', beginRoot = this.root, iterationType = 'ITERATIVE', includeNull = false) {
|
|
1113
1113
|
beginRoot = this.ensureNode(beginRoot);
|
|
1114
1114
|
if (!beginRoot)
|
|
1115
1115
|
return [];
|
|
1116
1116
|
const ans = [];
|
|
1117
1117
|
if (iterationType === 'RECURSIVE') {
|
|
1118
|
-
const
|
|
1118
|
+
const dfs = (node) => {
|
|
1119
1119
|
switch (pattern) {
|
|
1120
1120
|
case 'IN':
|
|
1121
1121
|
if (includeNull) {
|
|
1122
1122
|
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1123
|
-
|
|
1123
|
+
dfs(node.left);
|
|
1124
1124
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1125
1125
|
if (this.isRealNode(node) && this.isNodeOrNull(node.right))
|
|
1126
|
-
|
|
1126
|
+
dfs(node.right);
|
|
1127
1127
|
}
|
|
1128
1128
|
else {
|
|
1129
1129
|
if (this.isRealNode(node) && this.isRealNode(node.left))
|
|
1130
|
-
|
|
1130
|
+
dfs(node.left);
|
|
1131
1131
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1132
1132
|
if (this.isRealNode(node) && this.isRealNode(node.right))
|
|
1133
|
-
|
|
1133
|
+
dfs(node.right);
|
|
1134
1134
|
}
|
|
1135
1135
|
break;
|
|
1136
1136
|
case 'PRE':
|
|
1137
1137
|
if (includeNull) {
|
|
1138
1138
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1139
1139
|
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1140
|
-
|
|
1140
|
+
dfs(node.left);
|
|
1141
1141
|
if (this.isRealNode(node) && this.isNodeOrNull(node.right))
|
|
1142
|
-
|
|
1142
|
+
dfs(node.right);
|
|
1143
1143
|
}
|
|
1144
1144
|
else {
|
|
1145
1145
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1146
1146
|
if (this.isRealNode(node) && this.isRealNode(node.left))
|
|
1147
|
-
|
|
1147
|
+
dfs(node.left);
|
|
1148
1148
|
if (this.isRealNode(node) && this.isRealNode(node.right))
|
|
1149
|
-
|
|
1149
|
+
dfs(node.right);
|
|
1150
1150
|
}
|
|
1151
1151
|
break;
|
|
1152
1152
|
case 'POST':
|
|
1153
1153
|
if (includeNull) {
|
|
1154
1154
|
if (this.isRealNode(node) && this.isNodeOrNull(node.left))
|
|
1155
|
-
|
|
1155
|
+
dfs(node.left);
|
|
1156
1156
|
if (this.isRealNode(node) && this.isNodeOrNull(node.right))
|
|
1157
|
-
|
|
1157
|
+
dfs(node.right);
|
|
1158
1158
|
this.isNodeOrNull(node) && ans.push(callback(node));
|
|
1159
1159
|
}
|
|
1160
1160
|
else {
|
|
1161
1161
|
if (this.isRealNode(node) && this.isRealNode(node.left))
|
|
1162
|
-
|
|
1162
|
+
dfs(node.left);
|
|
1163
1163
|
if (this.isRealNode(node) && this.isRealNode(node.right))
|
|
1164
|
-
|
|
1164
|
+
dfs(node.right);
|
|
1165
1165
|
this.isRealNode(node) && ans.push(callback(node));
|
|
1166
1166
|
}
|
|
1167
1167
|
break;
|
|
1168
1168
|
}
|
|
1169
1169
|
};
|
|
1170
|
-
|
|
1170
|
+
dfs(beginRoot);
|
|
1171
1171
|
}
|
|
1172
1172
|
else {
|
|
1173
1173
|
// 0: visit, 1: print
|
|
@@ -1240,14 +1240,14 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1240
1240
|
* @returns an array of values that are the result of invoking the callback function on each node in
|
|
1241
1241
|
* the breadth-first traversal of a binary tree.
|
|
1242
1242
|
*/
|
|
1243
|
-
bfs(callback = this.
|
|
1243
|
+
bfs(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
|
|
1244
1244
|
beginRoot = this.ensureNode(beginRoot);
|
|
1245
1245
|
if (!beginRoot)
|
|
1246
1246
|
return [];
|
|
1247
1247
|
const ans = [];
|
|
1248
1248
|
if (iterationType === 'RECURSIVE') {
|
|
1249
1249
|
const queue = new Queue([beginRoot]);
|
|
1250
|
-
const
|
|
1250
|
+
const dfs = (level) => {
|
|
1251
1251
|
if (queue.size === 0)
|
|
1252
1252
|
return;
|
|
1253
1253
|
const current = queue.shift();
|
|
@@ -1264,9 +1264,9 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1264
1264
|
if (this.isRealNode(current.right))
|
|
1265
1265
|
queue.push(current.right);
|
|
1266
1266
|
}
|
|
1267
|
-
|
|
1267
|
+
dfs(level + 1);
|
|
1268
1268
|
};
|
|
1269
|
-
|
|
1269
|
+
dfs(0);
|
|
1270
1270
|
}
|
|
1271
1271
|
else {
|
|
1272
1272
|
const queue = new Queue([beginRoot]);
|
|
@@ -1317,7 +1317,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1317
1317
|
* be excluded
|
|
1318
1318
|
* @returns The function `listLevels` returns a two-dimensional array of type `ReturnType<C>[][]`.
|
|
1319
1319
|
*/
|
|
1320
|
-
listLevels(callback = this.
|
|
1320
|
+
listLevels(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
|
|
1321
1321
|
beginRoot = this.ensureNode(beginRoot);
|
|
1322
1322
|
const levelsNodes = [];
|
|
1323
1323
|
if (!beginRoot)
|
|
@@ -1389,7 +1389,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1389
1389
|
* `callback` function on each node in the binary tree. The type of the array nodes is determined
|
|
1390
1390
|
* by the return type of the `callback` function.
|
|
1391
1391
|
*/
|
|
1392
|
-
morris(callback = this.
|
|
1392
|
+
morris(callback = this._DEFAULT_CALLBACK, pattern = 'IN', beginRoot = this.root) {
|
|
1393
1393
|
beginRoot = this.ensureNode(beginRoot);
|
|
1394
1394
|
if (beginRoot === null)
|
|
1395
1395
|
return [];
|
|
@@ -1700,7 +1700,7 @@ export class BinaryTree extends IterableEntryBase {
|
|
|
1700
1700
|
];
|
|
1701
1701
|
}
|
|
1702
1702
|
}
|
|
1703
|
-
|
|
1703
|
+
_DEFAULT_CALLBACK = (node) => (node ? node.key : undefined);
|
|
1704
1704
|
/**
|
|
1705
1705
|
* Swap the data of two nodes in the binary tree.
|
|
1706
1706
|
* @param {NODE} srcNode - The source node to swap.
|
|
@@ -169,19 +169,19 @@ export class BST extends BinaryTree {
|
|
|
169
169
|
* @returns either a node object (NODE) or undefined.
|
|
170
170
|
*/
|
|
171
171
|
ensureNode(keyOrNodeOrEntry, iterationType = 'ITERATIVE') {
|
|
172
|
-
let res;
|
|
173
172
|
if (this.isRealNode(keyOrNodeOrEntry)) {
|
|
174
|
-
|
|
173
|
+
return keyOrNodeOrEntry;
|
|
175
174
|
}
|
|
176
175
|
else if (this.isEntry(keyOrNodeOrEntry)) {
|
|
177
|
-
if (keyOrNodeOrEntry[0])
|
|
178
|
-
|
|
176
|
+
if (keyOrNodeOrEntry[0] === null || keyOrNodeOrEntry[0] === undefined)
|
|
177
|
+
return;
|
|
178
|
+
return this.getNodeByKey(keyOrNodeOrEntry[0], iterationType);
|
|
179
179
|
}
|
|
180
180
|
else {
|
|
181
|
-
if (keyOrNodeOrEntry)
|
|
182
|
-
|
|
181
|
+
if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined)
|
|
182
|
+
return;
|
|
183
|
+
return this.getNodeByKey(keyOrNodeOrEntry, iterationType);
|
|
183
184
|
}
|
|
184
|
-
return res;
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
187
|
* The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
|
|
@@ -365,33 +365,33 @@ export class BST extends BinaryTree {
|
|
|
365
365
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
366
366
|
*/
|
|
367
367
|
getNodeByKey(key, iterationType = 'ITERATIVE') {
|
|
368
|
-
// return this.getNodes(key, this.
|
|
368
|
+
// return this.getNodes(key, this._DEFAULT_CALLBACK, true, this.root, iterationType)[0];
|
|
369
369
|
if (!this.isRealNode(this.root))
|
|
370
|
-
return
|
|
370
|
+
return;
|
|
371
371
|
if (iterationType === 'RECURSIVE') {
|
|
372
|
-
const
|
|
372
|
+
const dfs = (cur) => {
|
|
373
373
|
if (cur.key === key)
|
|
374
374
|
return cur;
|
|
375
375
|
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
|
|
376
376
|
return;
|
|
377
|
-
if (this._compare(cur.key, key) === 'GT'
|
|
378
|
-
return
|
|
379
|
-
if (this._compare(cur.key, key) === 'LT'
|
|
380
|
-
return
|
|
377
|
+
if (this.isRealNode(cur.left) && this._compare(cur.key, key) === 'GT')
|
|
378
|
+
return dfs(cur.left);
|
|
379
|
+
if (this.isRealNode(cur.right) && this._compare(cur.key, key) === 'LT')
|
|
380
|
+
return dfs(cur.right);
|
|
381
381
|
};
|
|
382
|
-
return
|
|
382
|
+
return dfs(this.root);
|
|
383
383
|
}
|
|
384
384
|
else {
|
|
385
|
-
const
|
|
386
|
-
while (
|
|
387
|
-
const cur =
|
|
385
|
+
const stack = [this.root];
|
|
386
|
+
while (stack.length > 0) {
|
|
387
|
+
const cur = stack.pop();
|
|
388
388
|
if (this.isRealNode(cur)) {
|
|
389
389
|
if (this._compare(cur.key, key) === 'EQ')
|
|
390
390
|
return cur;
|
|
391
|
-
if (this._compare(cur.key, key) === 'GT')
|
|
392
|
-
|
|
393
|
-
if (this._compare(cur.key, key) === 'LT')
|
|
394
|
-
|
|
391
|
+
if (this.isRealNode(cur.left) && this._compare(cur.key, key) === 'GT')
|
|
392
|
+
stack.push(cur.left);
|
|
393
|
+
if (this.isRealNode(cur.right) && this._compare(cur.key, key) === 'LT')
|
|
394
|
+
stack.push(cur.right);
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
}
|
|
@@ -424,13 +424,13 @@ export class BST extends BinaryTree {
|
|
|
424
424
|
* performed on the binary tree. It can have two possible values:
|
|
425
425
|
* @returns The method returns an array of nodes (`NODE[]`).
|
|
426
426
|
*/
|
|
427
|
-
getNodes(identifier, callback = this.
|
|
427
|
+
getNodes(identifier, callback = this._DEFAULT_CALLBACK, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
|
|
428
428
|
beginRoot = this.ensureNode(beginRoot);
|
|
429
429
|
if (!beginRoot)
|
|
430
430
|
return [];
|
|
431
431
|
const ans = [];
|
|
432
432
|
if (iterationType === 'RECURSIVE') {
|
|
433
|
-
const
|
|
433
|
+
const dfs = (cur) => {
|
|
434
434
|
const callbackResult = callback(cur);
|
|
435
435
|
if (callbackResult === identifier) {
|
|
436
436
|
ans.push(cur);
|
|
@@ -440,18 +440,18 @@ export class BST extends BinaryTree {
|
|
|
440
440
|
if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
|
|
441
441
|
return;
|
|
442
442
|
// TODO potential bug
|
|
443
|
-
if (callback === this.
|
|
443
|
+
if (callback === this._DEFAULT_CALLBACK) {
|
|
444
444
|
if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === 'GT')
|
|
445
|
-
|
|
445
|
+
dfs(cur.left);
|
|
446
446
|
if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === 'LT')
|
|
447
|
-
|
|
447
|
+
dfs(cur.right);
|
|
448
448
|
}
|
|
449
449
|
else {
|
|
450
|
-
this.isRealNode(cur.left) &&
|
|
451
|
-
this.isRealNode(cur.right) &&
|
|
450
|
+
this.isRealNode(cur.left) && dfs(cur.left);
|
|
451
|
+
this.isRealNode(cur.right) && dfs(cur.right);
|
|
452
452
|
}
|
|
453
453
|
};
|
|
454
|
-
|
|
454
|
+
dfs(beginRoot);
|
|
455
455
|
}
|
|
456
456
|
else {
|
|
457
457
|
const stack = [beginRoot];
|
|
@@ -465,7 +465,7 @@ export class BST extends BinaryTree {
|
|
|
465
465
|
return ans;
|
|
466
466
|
}
|
|
467
467
|
// TODO potential bug
|
|
468
|
-
if (callback === this.
|
|
468
|
+
if (callback === this._DEFAULT_CALLBACK) {
|
|
469
469
|
if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === 'LT')
|
|
470
470
|
stack.push(cur.right);
|
|
471
471
|
if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === 'GT')
|
|
@@ -509,7 +509,7 @@ export class BST extends BinaryTree {
|
|
|
509
509
|
* following values:
|
|
510
510
|
* @returns The method is returning an array of the return type of the callback function.
|
|
511
511
|
*/
|
|
512
|
-
dfs(callback = this.
|
|
512
|
+
dfs(callback = this._DEFAULT_CALLBACK, pattern = 'IN', beginRoot = this.root, iterationType = 'ITERATIVE') {
|
|
513
513
|
return super.dfs(callback, pattern, beginRoot, iterationType, false);
|
|
514
514
|
}
|
|
515
515
|
/**
|
|
@@ -533,7 +533,7 @@ export class BST extends BinaryTree {
|
|
|
533
533
|
* nodes are visited.
|
|
534
534
|
* @returns The method is returning an array of the return type of the callback function.
|
|
535
535
|
*/
|
|
536
|
-
bfs(callback = this.
|
|
536
|
+
bfs(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
537
537
|
return super.bfs(callback, beginRoot, iterationType, false);
|
|
538
538
|
}
|
|
539
539
|
/**
|
|
@@ -558,7 +558,7 @@ export class BST extends BinaryTree {
|
|
|
558
558
|
* @returns The method is returning a two-dimensional array of the return type of the callback
|
|
559
559
|
* function.
|
|
560
560
|
*/
|
|
561
|
-
listLevels(callback = this.
|
|
561
|
+
listLevels(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
562
562
|
return super.listLevels(callback, beginRoot, iterationType, false);
|
|
563
563
|
}
|
|
564
564
|
/**
|
|
@@ -621,7 +621,7 @@ export class BST extends BinaryTree {
|
|
|
621
621
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
622
622
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
623
623
|
*/
|
|
624
|
-
lesserOrGreaterTraverse(callback = this.
|
|
624
|
+
lesserOrGreaterTraverse(callback = this._DEFAULT_CALLBACK, lesserOrGreater = 'LT', targetNode = this.root, iterationType = this.iterationType) {
|
|
625
625
|
targetNode = this.ensureNode(targetNode);
|
|
626
626
|
const ans = [];
|
|
627
627
|
if (!targetNode)
|
|
@@ -630,16 +630,16 @@ export class BST extends BinaryTree {
|
|
|
630
630
|
return ans;
|
|
631
631
|
const targetKey = targetNode.key;
|
|
632
632
|
if (iterationType === 'RECURSIVE') {
|
|
633
|
-
const
|
|
633
|
+
const dfs = (cur) => {
|
|
634
634
|
const compared = this._compare(cur.key, targetKey);
|
|
635
635
|
if (compared === lesserOrGreater)
|
|
636
636
|
ans.push(callback(cur));
|
|
637
637
|
if (this.isRealNode(cur.left))
|
|
638
|
-
|
|
638
|
+
dfs(cur.left);
|
|
639
639
|
if (this.isRealNode(cur.right))
|
|
640
|
-
|
|
640
|
+
dfs(cur.right);
|
|
641
641
|
};
|
|
642
|
-
|
|
642
|
+
dfs(this.root);
|
|
643
643
|
return ans;
|
|
644
644
|
}
|
|
645
645
|
else {
|