data-structure-typed 1.39.3 → 1.39.4
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/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +4 -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 +5 -13
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +17 -25
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.js +6 -6
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +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 +4 -2
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +5 -13
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +17 -25
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.js +6 -6
- package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/tree-multiset.js +2 -2
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +5 -5
- package/src/data-structures/binary-tree/avl-tree.ts +3 -2
- package/src/data-structures/binary-tree/binary-tree.ts +19 -28
- package/src/data-structures/binary-tree/bst.ts +6 -6
- package/src/data-structures/binary-tree/tree-multiset.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-multiset.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multiset.ts"],"names":[],"mappings":";;;AAQA,uCAAoG;AAEpG,yCAAgD;AAEhD,MAAa,gBAGX,SAAQ,sBAAiB;IAGzB;;;;;;;;;OASG;IACH,YAAY,GAAW,EAAE,GAAO,EAAE,KAAK,GAAG,CAAC;QACzC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AApBD,4CAoBC;AAED;;GAEG;AACH,MAAa,YACX,SAAQ,kBAAa;IAGrB;;;;;OAKG;IACH,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QAGT,WAAM,GAAG,CAAC,CAAC;IAFnB,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;;;OAQG;IACM,UAAU,CAAC,GAAW,EAAE,GAAO,EAAE,KAAc;QACtD,OAAO,IAAI,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAM,CAAC;IACpD,CAAC;IAED;;;;;;;;;;;;OAYG;IACM,GAAG,CAAC,SAA4B,EAAE,GAAO,EAAE,KAAK,GAAG,CAAC;QAC3D,IAAI,QAAQ,GAAyB,SAAS,EAC5C,OAAiB,CAAC;QACpB,IAAI,SAAS,YAAY,gBAAgB,EAAE;YACzC,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;SAC1E;aAAM,IAAI,SAAS,KAAK,IAAI,EAAE;YAC7B,OAAO,GAAG,IAAI,CAAC;SAChB;aAAM;YACL,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;SA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C,CAAC,CAAC,CAAC;YAC/C,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;gBACvB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;gBAC3B,IAAI,MAAM,EAAE;oBACV,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;oBACtB,IAAI,CAAC,IAAI,CAAC,EAAE;wBACV,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;wBACtC,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;wBAC1B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;wBAClD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;wBACvB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;qBACxB;iBACF;aACF;YACD,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACM,MAAM,CACb,UAAyB,EACzB,WAAc,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"tree-multiset.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multiset.ts"],"names":[],"mappings":";;;AAQA,uCAAoG;AAEpG,yCAAgD;AAEhD,MAAa,gBAGX,SAAQ,sBAAiB;IAGzB;;;;;;;;;OASG;IACH,YAAY,GAAW,EAAE,GAAO,EAAE,KAAK,GAAG,CAAC;QACzC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AApBD,4CAoBC;AAED;;GAEG;AACH,MAAa,YACX,SAAQ,kB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
|
@@ -50,7 +50,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
50
50
|
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
51
51
|
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
52
52
|
* included in the result. The `callback` parameter has a default value of
|
|
53
|
-
* `
|
|
53
|
+
* `((node: N) => node.key)`
|
|
54
54
|
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
55
55
|
*/
|
|
56
56
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeletedResult<N>[];
|
|
@@ -64,10 +64,12 @@ class AVLTree extends bst_1.BST {
|
|
|
64
64
|
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
65
65
|
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
66
66
|
* included in the result. The `callback` parameter has a default value of
|
|
67
|
-
* `
|
|
67
|
+
* `((node: N) => node.key)`
|
|
68
68
|
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
69
69
|
*/
|
|
70
|
-
delete(identifier, callback =
|
|
70
|
+
delete(identifier, callback = ((node) => node.key)) {
|
|
71
|
+
if (identifier instanceof AVLTreeNode)
|
|
72
|
+
callback = (node => node);
|
|
71
73
|
const deletedResults = super.delete(identifier, callback);
|
|
72
74
|
for (const { needBalanced } of deletedResults) {
|
|
73
75
|
if (needBalanced) {
|
|
@@ -180,8 +180,8 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
180
180
|
* @returns The method is returning a boolean value.
|
|
181
181
|
*/
|
|
182
182
|
isPerfectlyBalanced(beginRoot?: N | null): boolean;
|
|
183
|
-
getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback
|
|
184
|
-
getNodes<C extends BTNCallback<N, N>>(identifier: N | null, callback
|
|
183
|
+
getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
|
|
184
|
+
getNodes<C extends BTNCallback<N, N>>(identifier: N | null, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
|
|
185
185
|
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
|
|
186
186
|
has<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: N, iterationType?: IterationType): boolean;
|
|
187
187
|
has<C extends BTNCallback<N, N>>(identifier: N | null, callback?: C, beginRoot?: N, iterationType?: IterationType): boolean;
|
|
@@ -263,7 +263,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
263
263
|
* function on each node according to a specified order pattern.
|
|
264
264
|
* @param callback - The `callback` parameter is a function that will be called on each node during
|
|
265
265
|
* the depth-first search traversal. It takes a node as input and returns a value. The default value
|
|
266
|
-
* is `
|
|
266
|
+
* is `((node: N) => node.key)`, which is a callback function defined elsewhere in the code.
|
|
267
267
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
|
|
268
268
|
* nodes are visited during the depth-first search. There are three possible values for `pattern`:
|
|
269
269
|
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the depth-first
|
|
@@ -279,7 +279,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
279
279
|
* function on each node.
|
|
280
280
|
* @param callback - The `callback` parameter is a function that will be called for each node in the
|
|
281
281
|
* breadth-first search. It takes a node of type `N` as its argument and returns a value of type
|
|
282
|
-
* `ReturnType<BTNCallback<N>>`. The default value for this parameter is `
|
|
282
|
+
* `ReturnType<BTNCallback<N>>`. The default value for this parameter is `((node: N) => node.key)
|
|
283
283
|
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
|
|
284
284
|
* search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
|
|
285
285
|
* will not be performed and an empty array will be returned.
|
|
@@ -315,7 +315,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
315
315
|
* algorithm and returns an array of values obtained by applying a callback function to each node.
|
|
316
316
|
* @param callback - The `callback` parameter is a function that will be called on each node in the
|
|
317
317
|
* tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The
|
|
318
|
-
* default value for this parameter is `
|
|
318
|
+
* default value for this parameter is `((node: N) => node.key)`.
|
|
319
319
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
|
|
320
320
|
* determines the order in which the nodes of a binary tree are traversed. It can have one of the
|
|
321
321
|
* following values:
|
|
@@ -342,14 +342,6 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
342
342
|
* @returns {N} - The destination node after the swap.
|
|
343
343
|
*/
|
|
344
344
|
protected _swap(srcNode: N, destNode: N): N;
|
|
345
|
-
/**
|
|
346
|
-
* Time complexity is O(n)
|
|
347
|
-
* Space complexity of Iterative dfs equals to recursive dfs which is O(n) because of the stack
|
|
348
|
-
* The Morris algorithm only modifies the tree's structure during traversal; once the traversal is complete,
|
|
349
|
-
* the tree's structure should be restored to its original state to maintain the tree's integrity.
|
|
350
|
-
* This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
|
|
351
|
-
*/
|
|
352
|
-
protected _defaultCallbackByKey: BTNCallback<N, BTNKey>;
|
|
353
345
|
/**
|
|
354
346
|
* The function `_addTo` adds a new node to a binary tree if there is an available position.
|
|
355
347
|
* @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to
|
|
@@ -198,7 +198,7 @@ class BinaryTree {
|
|
|
198
198
|
return;
|
|
199
199
|
}
|
|
200
200
|
const key = typeof keyOrNode === 'number' ? keyOrNode : keyOrNode ? keyOrNode.key : undefined;
|
|
201
|
-
const existNode = key !== undefined ? this.get(key,
|
|
201
|
+
const existNode = key !== undefined ? this.get(key, (node) => node.key) : undefined;
|
|
202
202
|
if (this.root) {
|
|
203
203
|
if (existNode) {
|
|
204
204
|
existNode.val = val;
|
|
@@ -268,9 +268,9 @@ class BinaryTree {
|
|
|
268
268
|
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
269
269
|
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
270
270
|
* included in the result. The `callback` parameter has a default value of
|
|
271
|
-
* `
|
|
271
|
+
* `((node: N) => node.key)`, which
|
|
272
272
|
*/
|
|
273
|
-
delete(identifier, callback =
|
|
273
|
+
delete(identifier, callback = ((node) => node.key)) {
|
|
274
274
|
const bstDeletedResult = [];
|
|
275
275
|
if (!this.root)
|
|
276
276
|
return bstDeletedResult;
|
|
@@ -460,7 +460,7 @@ class BinaryTree {
|
|
|
460
460
|
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
461
461
|
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
462
462
|
* included in the result. The `callback` parameter has a default value of
|
|
463
|
-
* `
|
|
463
|
+
* `((node: N) => node.key)`, which
|
|
464
464
|
* @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the
|
|
465
465
|
* first node that matches the identifier. If set to true, the function will return an array with
|
|
466
466
|
* only one element (or an empty array if no matching node is found). If set to false (default), the
|
|
@@ -472,7 +472,7 @@ class BinaryTree {
|
|
|
472
472
|
* traverse the binary tree. It can have two possible values:
|
|
473
473
|
* @returns The function `getNodes` returns an array of nodes (`N[]`).
|
|
474
474
|
*/
|
|
475
|
-
getNodes(identifier, callback =
|
|
475
|
+
getNodes(identifier, callback = ((node) => node.key), onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
|
|
476
476
|
if (!beginRoot)
|
|
477
477
|
return [];
|
|
478
478
|
if (identifier instanceof BinaryTreeNode)
|
|
@@ -517,7 +517,7 @@ class BinaryTree {
|
|
|
517
517
|
* @param callback - The `callback` parameter is a function that is used to determine whether a node
|
|
518
518
|
* matches the desired criteria. It takes a node as input and returns a boolean value indicating
|
|
519
519
|
* whether the node matches the criteria or not. The default callback function
|
|
520
|
-
* `
|
|
520
|
+
* `((node: N) => node.key)` is used if no callback function is
|
|
521
521
|
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
|
|
522
522
|
* the node from which the search should begin. By default, it is set to `this.root`, which means the
|
|
523
523
|
* search will start from the root node of the binary tree. However, you can provide a different node
|
|
@@ -526,7 +526,7 @@ class BinaryTree {
|
|
|
526
526
|
* performed when searching for nodes in the binary tree. It can have one of the following values:
|
|
527
527
|
* @returns a boolean value.
|
|
528
528
|
*/
|
|
529
|
-
has(identifier, callback =
|
|
529
|
+
has(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
|
|
530
530
|
if (identifier instanceof BinaryTreeNode)
|
|
531
531
|
callback = (node => node);
|
|
532
532
|
// TODO may support finding node by value equal
|
|
@@ -540,14 +540,14 @@ class BinaryTree {
|
|
|
540
540
|
* @param callback - The `callback` parameter is a function that is used to determine whether a node
|
|
541
541
|
* matches the desired criteria. It takes a node as input and returns a boolean value indicating
|
|
542
542
|
* whether the node matches the criteria or not. The default callback function
|
|
543
|
-
* (`
|
|
543
|
+
* (`((node: N) => node.key)`) is used if no callback function is
|
|
544
544
|
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
|
|
545
545
|
* the root node from which the search should begin.
|
|
546
546
|
* @param iterationType - The `iterationType` parameter specifies the type of iteration to be
|
|
547
547
|
* performed when searching for a node in the binary tree. It can have one of the following values:
|
|
548
548
|
* @returns either the found node (of type N) or null if no node is found.
|
|
549
549
|
*/
|
|
550
|
-
get(identifier, callback =
|
|
550
|
+
get(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
|
|
551
551
|
if (identifier instanceof BinaryTreeNode)
|
|
552
552
|
callback = (node => node);
|
|
553
553
|
// TODO may support finding node by value equal
|
|
@@ -709,7 +709,7 @@ class BinaryTree {
|
|
|
709
709
|
* performed on the binary tree. It can have two possible values:
|
|
710
710
|
* @returns The function `subTreeTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
|
|
711
711
|
*/
|
|
712
|
-
subTreeTraverse(callback =
|
|
712
|
+
subTreeTraverse(callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
|
|
713
713
|
if (typeof beginRoot === 'number')
|
|
714
714
|
beginRoot = this.get(beginRoot);
|
|
715
715
|
const ans = [];
|
|
@@ -739,7 +739,7 @@ class BinaryTree {
|
|
|
739
739
|
* function on each node according to a specified order pattern.
|
|
740
740
|
* @param callback - The `callback` parameter is a function that will be called on each node during
|
|
741
741
|
* the depth-first search traversal. It takes a node as input and returns a value. The default value
|
|
742
|
-
* is `
|
|
742
|
+
* is `((node: N) => node.key)`, which is a callback function defined elsewhere in the code.
|
|
743
743
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
|
|
744
744
|
* nodes are visited during the depth-first search. There are three possible values for `pattern`:
|
|
745
745
|
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the depth-first
|
|
@@ -749,7 +749,7 @@ class BinaryTree {
|
|
|
749
749
|
* iteration used in the depth-first search algorithm. It can have two possible values:
|
|
750
750
|
* @returns The function `dfs` returns an array of `ReturnType<BTNCallback<N>>` values.
|
|
751
751
|
*/
|
|
752
|
-
dfs(callback =
|
|
752
|
+
dfs(callback = ((node) => node.key), pattern = 'in', beginRoot = this.root, iterationType = types_1.IterationType.ITERATIVE) {
|
|
753
753
|
if (!beginRoot)
|
|
754
754
|
return [];
|
|
755
755
|
const ans = [];
|
|
@@ -824,7 +824,7 @@ class BinaryTree {
|
|
|
824
824
|
* function on each node.
|
|
825
825
|
* @param callback - The `callback` parameter is a function that will be called for each node in the
|
|
826
826
|
* breadth-first search. It takes a node of type `N` as its argument and returns a value of type
|
|
827
|
-
* `ReturnType<BTNCallback<N>>`. The default value for this parameter is `
|
|
827
|
+
* `ReturnType<BTNCallback<N>>`. The default value for this parameter is `((node: N) => node.key)
|
|
828
828
|
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
|
|
829
829
|
* search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
|
|
830
830
|
* will not be performed and an empty array will be returned.
|
|
@@ -832,7 +832,7 @@ class BinaryTree {
|
|
|
832
832
|
* in the breadth-first search (BFS) algorithm. It can have two possible values:
|
|
833
833
|
* @returns The function `bfs` returns an array of `ReturnType<BTNCallback<N>>[]`.
|
|
834
834
|
*/
|
|
835
|
-
bfs(callback =
|
|
835
|
+
bfs(callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
|
|
836
836
|
if (!beginRoot)
|
|
837
837
|
return [];
|
|
838
838
|
const ans = [];
|
|
@@ -882,7 +882,7 @@ class BinaryTree {
|
|
|
882
882
|
* level in a binary tree. Each inner array contains the return type of the provided callback
|
|
883
883
|
* function `C` applied to the nodes at that level.
|
|
884
884
|
*/
|
|
885
|
-
listLevels(callback =
|
|
885
|
+
listLevels(callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
|
|
886
886
|
if (!beginRoot)
|
|
887
887
|
return [];
|
|
888
888
|
const levelsNodes = [];
|
|
@@ -939,7 +939,7 @@ class BinaryTree {
|
|
|
939
939
|
* algorithm and returns an array of values obtained by applying a callback function to each node.
|
|
940
940
|
* @param callback - The `callback` parameter is a function that will be called on each node in the
|
|
941
941
|
* tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The
|
|
942
|
-
* default value for this parameter is `
|
|
942
|
+
* default value for this parameter is `((node: N) => node.key)`.
|
|
943
943
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
|
|
944
944
|
* determines the order in which the nodes of a binary tree are traversed. It can have one of the
|
|
945
945
|
* following values:
|
|
@@ -948,7 +948,7 @@ class BinaryTree {
|
|
|
948
948
|
* `beginRoot` is `null`, an empty array will be returned.
|
|
949
949
|
* @returns The `morris` function returns an array of `ReturnType<BTNCallback<N>>` values.
|
|
950
950
|
*/
|
|
951
|
-
morris(callback =
|
|
951
|
+
morris(callback = ((node) => node.key), pattern = 'in', beginRoot = this.root) {
|
|
952
952
|
if (beginRoot === null)
|
|
953
953
|
return [];
|
|
954
954
|
const ans = [];
|
|
@@ -1087,14 +1087,6 @@ class BinaryTree {
|
|
|
1087
1087
|
}
|
|
1088
1088
|
return destNode;
|
|
1089
1089
|
}
|
|
1090
|
-
/**
|
|
1091
|
-
* Time complexity is O(n)
|
|
1092
|
-
* Space complexity of Iterative dfs equals to recursive dfs which is O(n) because of the stack
|
|
1093
|
-
* The Morris algorithm only modifies the tree's structure during traversal; once the traversal is complete,
|
|
1094
|
-
* the tree's structure should be restored to its original state to maintain the tree's integrity.
|
|
1095
|
-
* This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
|
|
1096
|
-
*/
|
|
1097
|
-
_defaultCallbackByKey = node => node.key;
|
|
1098
1090
|
/**
|
|
1099
1091
|
* The function `_addTo` adds a new node to a binary tree if there is an available position.
|
|
1100
1092
|
* @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to
|
|
@@ -97,7 +97,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
|
|
|
97
97
|
* generic type `N`.
|
|
98
98
|
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
99
99
|
* value. This value is compared with the `nodeProperty` parameter to determine if the node should be
|
|
100
|
-
* included in the result. The default value for `callback` is `
|
|
100
|
+
* included in the result. The default value for `callback` is `((node: N) => node.key)`, which is
|
|
101
101
|
* a
|
|
102
102
|
* @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
|
|
103
103
|
* the first node that matches the nodeProperty. If set to true, the function will return an array
|
|
@@ -222,7 +222,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
222
222
|
* @returns either the first node that matches the given nodeProperty and callback, or null if no
|
|
223
223
|
* matching node is found.
|
|
224
224
|
*/
|
|
225
|
-
get(identifier, callback =
|
|
225
|
+
get(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
|
|
226
226
|
return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? null;
|
|
227
227
|
}
|
|
228
228
|
/**
|
|
@@ -256,7 +256,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
256
256
|
* generic type `N`.
|
|
257
257
|
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
258
258
|
* value. This value is compared with the `nodeProperty` parameter to determine if the node should be
|
|
259
|
-
* included in the result. The default value for `callback` is `
|
|
259
|
+
* included in the result. The default value for `callback` is `((node: N) => node.key)`, which is
|
|
260
260
|
* a
|
|
261
261
|
* @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
|
|
262
262
|
* the first node that matches the nodeProperty. If set to true, the function will return an array
|
|
@@ -269,7 +269,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
269
269
|
* traverse the binary tree. It can have one of the following values:
|
|
270
270
|
* @returns an array of nodes (N[]).
|
|
271
271
|
*/
|
|
272
|
-
getNodes(identifier, callback =
|
|
272
|
+
getNodes(identifier, callback = ((node) => node.key), onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
|
|
273
273
|
if (!beginRoot)
|
|
274
274
|
return [];
|
|
275
275
|
const ans = [];
|
|
@@ -284,7 +284,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
284
284
|
if (!cur.left && !cur.right)
|
|
285
285
|
return;
|
|
286
286
|
// TODO potential bug
|
|
287
|
-
if (callback ===
|
|
287
|
+
if (callback === ((node) => node.key)) {
|
|
288
288
|
if (this._compare(cur.key, identifier) === types_1.CP.gt)
|
|
289
289
|
cur.left && _traverse(cur.left);
|
|
290
290
|
if (this._compare(cur.key, identifier) === types_1.CP.lt)
|
|
@@ -309,7 +309,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
309
309
|
return ans;
|
|
310
310
|
}
|
|
311
311
|
// TODO potential bug
|
|
312
|
-
if (callback ===
|
|
312
|
+
if (callback === ((node) => node.key)) {
|
|
313
313
|
if (this._compare(cur.key, identifier) === types_1.CP.gt)
|
|
314
314
|
cur.left && queue.push(cur.left);
|
|
315
315
|
if (this._compare(cur.key, identifier) === types_1.CP.lt)
|
|
@@ -342,7 +342,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
342
342
|
* done recursively or iteratively. It can have two possible values:
|
|
343
343
|
* @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
|
|
344
344
|
*/
|
|
345
|
-
lesserOrGreaterTraverse(callback =
|
|
345
|
+
lesserOrGreaterTraverse(callback = ((node) => node.key), lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) {
|
|
346
346
|
if (typeof targetNode === 'number')
|
|
347
347
|
targetNode = this.get(targetNode);
|
|
348
348
|
const ans = [];
|
|
@@ -98,7 +98,7 @@ export declare class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = Tr
|
|
|
98
98
|
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
99
99
|
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
100
100
|
* included in the result. The `callback` parameter has a default value of
|
|
101
|
-
* `
|
|
101
|
+
* `((node: N) => node.key)`
|
|
102
102
|
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
|
|
103
103
|
* being deleted. If set to true, the count of the node will not be considered and the node will be
|
|
104
104
|
* deleted regardless of its count. If set to false (default), the count of the node will be
|
|
@@ -252,14 +252,14 @@ class TreeMultiset extends avl_tree_1.AVLTree {
|
|
|
252
252
|
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
253
253
|
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
254
254
|
* included in the result. The `callback` parameter has a default value of
|
|
255
|
-
* `
|
|
255
|
+
* `((node: N) => node.key)`
|
|
256
256
|
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
|
|
257
257
|
* being deleted. If set to true, the count of the node will not be considered and the node will be
|
|
258
258
|
* deleted regardless of its count. If set to false (default), the count of the node will be
|
|
259
259
|
* decremented by 1 and
|
|
260
260
|
* @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
261
261
|
*/
|
|
262
|
-
delete(identifier, callback =
|
|
262
|
+
delete(identifier, callback = ((node) => node.key), ignoreCount = false) {
|
|
263
263
|
const bstDeletedResult = [];
|
|
264
264
|
if (!this.root)
|
|
265
265
|
return bstDeletedResult;
|