min-heap-typed 1.42.6 → 1.42.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/dist/data-structures/binary-tree/avl-tree.d.ts +5 -5
- package/dist/data-structures/binary-tree/avl-tree.js +19 -14
- package/dist/data-structures/binary-tree/binary-tree.d.ts +108 -60
- package/dist/data-structures/binary-tree/binary-tree.js +189 -89
- package/dist/data-structures/binary-tree/bst.d.ts +30 -8
- package/dist/data-structures/binary-tree/bst.js +77 -28
- package/dist/data-structures/binary-tree/rb-tree.d.ts +35 -28
- package/dist/data-structures/binary-tree/rb-tree.js +44 -45
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +7 -12
- package/dist/data-structures/binary-tree/tree-multimap.js +38 -37
- package/dist/interfaces/binary-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +24 -18
- package/src/data-structures/binary-tree/binary-tree.ts +248 -142
- package/src/data-structures/binary-tree/bst.ts +88 -38
- package/src/data-structures/binary-tree/rb-tree.ts +52 -58
- package/src/data-structures/binary-tree/tree-multimap.ts +50 -54
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +7 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { AVLTreeNodeNested, AVLTreeOptions,
|
|
9
|
+
import type { AVLTreeNodeNested, AVLTreeOptions, BiTreeDeleteResult, BTNKey } from '../../types';
|
|
10
10
|
import { BTNCallback } from '../../types';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
12
|
export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
@@ -50,10 +50,10 @@ 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
|
-
* `this.
|
|
54
|
-
* @returns The method is returning an array of `
|
|
53
|
+
* `this._defaultOneParamCallback`
|
|
54
|
+
* @returns The method is returning an array of `BiTreeDeleteResult<N>` objects.
|
|
55
55
|
*/
|
|
56
|
-
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C):
|
|
56
|
+
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BiTreeDeleteResult<N>[];
|
|
57
57
|
/**
|
|
58
58
|
* The function swaps the key, value, and height properties between two nodes in a binary tree.
|
|
59
59
|
* @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
|
|
@@ -62,7 +62,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
62
62
|
* from the source node (`srcNode`) will be swapped to.
|
|
63
63
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
64
64
|
*/
|
|
65
|
-
protected _swap(srcNode: N, destNode: N): N;
|
|
65
|
+
protected _swap(srcNode: BTNKey | N | undefined, destNode: BTNKey | N | undefined): N | undefined;
|
|
66
66
|
/**
|
|
67
67
|
* The function calculates the balance factor of a node in a binary tree.
|
|
68
68
|
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
@@ -64,10 +64,10 @@ 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
|
-
* `this.
|
|
68
|
-
* @returns The method is returning an array of `
|
|
67
|
+
* `this._defaultOneParamCallback`
|
|
68
|
+
* @returns The method is returning an array of `BiTreeDeleteResult<N>` objects.
|
|
69
69
|
*/
|
|
70
|
-
delete(identifier, callback = this.
|
|
70
|
+
delete(identifier, callback = this._defaultOneParamCallback) {
|
|
71
71
|
if (identifier instanceof AVLTreeNode)
|
|
72
72
|
callback = (node => node);
|
|
73
73
|
const deletedResults = super.delete(identifier, callback);
|
|
@@ -87,18 +87,23 @@ class AVLTree extends bst_1.BST {
|
|
|
87
87
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
88
88
|
*/
|
|
89
89
|
_swap(srcNode, destNode) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
srcNode = this.ensureNotKey(srcNode);
|
|
91
|
+
destNode = this.ensureNotKey(destNode);
|
|
92
|
+
if (srcNode && destNode) {
|
|
93
|
+
const { key, value, height } = destNode;
|
|
94
|
+
const tempNode = this.createNode(key, value);
|
|
95
|
+
if (tempNode) {
|
|
96
|
+
tempNode.height = height;
|
|
97
|
+
destNode.key = srcNode.key;
|
|
98
|
+
destNode.value = srcNode.value;
|
|
99
|
+
destNode.height = srcNode.height;
|
|
100
|
+
srcNode.key = tempNode.key;
|
|
101
|
+
srcNode.value = tempNode.value;
|
|
102
|
+
srcNode.height = tempNode.height;
|
|
103
|
+
}
|
|
104
|
+
return destNode;
|
|
100
105
|
}
|
|
101
|
-
return
|
|
106
|
+
return undefined;
|
|
102
107
|
}
|
|
103
108
|
/**
|
|
104
109
|
* The function calculates the balance factor of a node in a binary tree.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKey } from '../../types';
|
|
9
|
-
import {
|
|
9
|
+
import { BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
/**
|
|
12
12
|
* Represents a node in a binary tree.
|
|
@@ -21,18 +21,18 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
|
|
|
21
21
|
/**
|
|
22
22
|
* The value stored in the node.
|
|
23
23
|
*/
|
|
24
|
-
value
|
|
24
|
+
value?: V;
|
|
25
25
|
/**
|
|
26
26
|
* The parent node of the current node.
|
|
27
27
|
*/
|
|
28
|
-
parent
|
|
28
|
+
parent?: N | null;
|
|
29
29
|
/**
|
|
30
30
|
* Creates a new instance of BinaryTreeNode.
|
|
31
31
|
* @param {BTNKey} key - The key associated with the node.
|
|
32
32
|
* @param {V} value - The value stored in the node.
|
|
33
33
|
*/
|
|
34
34
|
constructor(key: BTNKey, value?: V);
|
|
35
|
-
protected _left
|
|
35
|
+
protected _left?: N | null;
|
|
36
36
|
/**
|
|
37
37
|
* Get the left child node.
|
|
38
38
|
*/
|
|
@@ -42,7 +42,7 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
|
|
|
42
42
|
* @param {N | null | undefined} v - The left child node.
|
|
43
43
|
*/
|
|
44
44
|
set left(v: N | null | undefined);
|
|
45
|
-
protected _right
|
|
45
|
+
protected _right?: N | null;
|
|
46
46
|
/**
|
|
47
47
|
* Get the right child node.
|
|
48
48
|
*/
|
|
@@ -69,7 +69,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
69
69
|
* @param {BinaryTreeOptions} [options] - The options for the binary tree.
|
|
70
70
|
*/
|
|
71
71
|
constructor(options?: BinaryTreeOptions);
|
|
72
|
-
protected _root
|
|
72
|
+
protected _root?: N | null;
|
|
73
73
|
/**
|
|
74
74
|
* Get the root node of the binary tree.
|
|
75
75
|
*/
|
|
@@ -86,15 +86,6 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
86
86
|
* @returns {N} - The newly created BinaryTreeNode.
|
|
87
87
|
*/
|
|
88
88
|
createNode(key: BTNKey, value?: V): N;
|
|
89
|
-
/**
|
|
90
|
-
* Clear the binary tree, removing all nodes.
|
|
91
|
-
*/
|
|
92
|
-
clear(): void;
|
|
93
|
-
/**
|
|
94
|
-
* Check if the binary tree is empty.
|
|
95
|
-
* @returns {boolean} - True if the binary tree is empty, false otherwise.
|
|
96
|
-
*/
|
|
97
|
-
isEmpty(): boolean;
|
|
98
89
|
/**
|
|
99
90
|
* Add a node with the given key and value to the binary tree.
|
|
100
91
|
* @param {BTNKey | N | null} keyOrNode - The key or node to add to the binary tree.
|
|
@@ -112,20 +103,20 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
112
103
|
* the value of the nodes will be `undefined`.
|
|
113
104
|
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
114
105
|
*/
|
|
115
|
-
addMany(keysOrNodes: (BTNKey |
|
|
106
|
+
addMany(keysOrNodes: (BTNKey | N | null | undefined)[], values?: (V | undefined)[]): (N | null | undefined)[];
|
|
116
107
|
/**
|
|
117
108
|
* The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
|
|
118
109
|
* @param {(BTNKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
|
|
119
110
|
* `BTNKey` or `N` values.
|
|
120
|
-
* @param {N[] | Array<V>} [
|
|
111
|
+
* @param {N[] | Array<V>} [values] - The `data` parameter is an optional array of values that will be assigned to
|
|
121
112
|
* the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes`
|
|
122
113
|
* array. Each value in the `data` array will be assigned to the
|
|
123
114
|
* @returns The method is returning a boolean value.
|
|
124
115
|
*/
|
|
125
|
-
refill(keysOrNodes: (BTNKey | null | undefined)[]
|
|
126
|
-
delete<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C):
|
|
127
|
-
delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C):
|
|
128
|
-
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C):
|
|
116
|
+
refill(keysOrNodes: (BTNKey | N | null | undefined)[], values?: (V | undefined)[]): boolean;
|
|
117
|
+
delete<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C): BiTreeDeleteResult<N>[];
|
|
118
|
+
delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BiTreeDeleteResult<N>[];
|
|
119
|
+
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BiTreeDeleteResult<N>[];
|
|
129
120
|
/**
|
|
130
121
|
* The function `getDepth` calculates the depth of a given node in a binary tree relative to a
|
|
131
122
|
* specified root node.
|
|
@@ -162,7 +153,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
162
153
|
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
163
154
|
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
164
155
|
*/
|
|
165
|
-
getMinHeight(beginRoot?: N | null | undefined, iterationType?: IterationType): number;
|
|
156
|
+
getMinHeight(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): number;
|
|
166
157
|
/**
|
|
167
158
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
168
159
|
* height of the tree.
|
|
@@ -170,19 +161,52 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
170
161
|
* either be of type `N` (representing a node in a tree) or `null` (representing an empty tree).
|
|
171
162
|
* @returns The method is returning a boolean value.
|
|
172
163
|
*/
|
|
173
|
-
isPerfectlyBalanced(beginRoot?: N | null | undefined): boolean;
|
|
174
|
-
getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, onlyOne?: boolean, beginRoot?: N | null | undefined, iterationType?: IterationType): N[];
|
|
175
|
-
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: N | null | undefined, iterationType?: IterationType): N[];
|
|
176
|
-
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: N | null | undefined, iterationType?: IterationType): N[];
|
|
177
|
-
has<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: N | null | undefined, iterationType?: IterationType): boolean;
|
|
178
|
-
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: N | null | undefined, iterationType?: IterationType): boolean;
|
|
179
|
-
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: N | null | undefined, iterationType?: IterationType): boolean;
|
|
180
|
-
getNode<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
181
|
-
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
182
|
-
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
164
|
+
isPerfectlyBalanced(beginRoot?: BTNKey | N | null | undefined): boolean;
|
|
165
|
+
getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
|
|
166
|
+
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
|
|
167
|
+
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N[];
|
|
168
|
+
has<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
|
|
169
|
+
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
|
|
170
|
+
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
|
|
171
|
+
getNode<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
172
|
+
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
173
|
+
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
174
|
+
/**
|
|
175
|
+
* The function `getNodeByKey` searches for a node in a binary tree by its key, using either
|
|
176
|
+
* recursive or iterative iteration.
|
|
177
|
+
* @param {BTNKey} key - The `key` parameter is the key value that we are searching for in the tree.
|
|
178
|
+
* It is used to find the node with the matching key value.
|
|
179
|
+
* @param iterationType - The `iterationType` parameter is used to determine whether the search for
|
|
180
|
+
* the node with the given key should be performed iteratively or recursively. It has two possible
|
|
181
|
+
* values:
|
|
182
|
+
* @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
|
|
183
|
+
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
184
|
+
*/
|
|
185
|
+
getNodeByKey(key: BTNKey, iterationType?: IterationType): N | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* The function `ensureNotKey` returns the node corresponding to the given key if it is a valid node
|
|
188
|
+
* key, otherwise it returns the key itself.
|
|
189
|
+
* @param {BTNKey | N | null | undefined} key - The `key` parameter can be of type `BTNKey`, `N`,
|
|
190
|
+
* `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
|
|
191
|
+
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
192
|
+
* type of iteration to be used when searching for a node by key. It has a default value of
|
|
193
|
+
* `IterationType.ITERATIVE`.
|
|
194
|
+
* @returns either the node corresponding to the given key if it is a valid node key, or the key
|
|
195
|
+
* itself if it is not a valid node key.
|
|
196
|
+
*/
|
|
197
|
+
ensureNotKey(key: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
198
|
+
get<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
|
|
199
|
+
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
|
|
200
|
+
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): V | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* Clear the binary tree, removing all nodes.
|
|
203
|
+
*/
|
|
204
|
+
clear(): void;
|
|
205
|
+
/**
|
|
206
|
+
* Check if the binary tree is empty.
|
|
207
|
+
* @returns {boolean} - True if the binary tree is empty, false otherwise.
|
|
208
|
+
*/
|
|
209
|
+
isEmpty(): boolean;
|
|
186
210
|
/**
|
|
187
211
|
* The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
|
|
188
212
|
* up to the root node, with the option to reverse the order of the nodes.
|
|
@@ -193,7 +217,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
193
217
|
* reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
|
|
194
218
|
* @returns The function `getPathToRoot` returns an array of type `N[]`.
|
|
195
219
|
*/
|
|
196
|
-
getPathToRoot(beginRoot: N, isReverse?: boolean): N[];
|
|
220
|
+
getPathToRoot(beginRoot: BTNKey | N | null | undefined, isReverse?: boolean): N[];
|
|
197
221
|
/**
|
|
198
222
|
* The function `getLeftMost` returns the leftmost node in a binary tree, either using recursive or
|
|
199
223
|
* iterative traversal.
|
|
@@ -217,7 +241,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
217
241
|
* @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If the
|
|
218
242
|
* `beginRoot` parameter is `null`, it returns `null`.
|
|
219
243
|
*/
|
|
220
|
-
getRightMost(beginRoot?: N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
244
|
+
getRightMost(beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType): N | null | undefined;
|
|
221
245
|
/**
|
|
222
246
|
* The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
|
|
223
247
|
* @param {N} beginRoot - The `beginRoot` parameter is the root node of the binary tree that you want
|
|
@@ -227,7 +251,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
227
251
|
* possible values:
|
|
228
252
|
* @returns The function `isSubtreeBST` returns a boolean value.
|
|
229
253
|
*/
|
|
230
|
-
isSubtreeBST(beginRoot: N | null | undefined, iterationType?: IterationType): boolean;
|
|
254
|
+
isSubtreeBST(beginRoot: BTNKey | N | null | undefined, iterationType?: IterationType): boolean;
|
|
231
255
|
/**
|
|
232
256
|
* The function checks if a binary tree is a binary search tree.
|
|
233
257
|
* @param iterationType - The parameter "iterationType" is used to specify the type of iteration to
|
|
@@ -240,23 +264,41 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
240
264
|
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
241
265
|
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
242
266
|
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
243
|
-
|
|
267
|
+
/**
|
|
268
|
+
* The function checks if a given node is a real node by verifying if it is an instance of
|
|
269
|
+
* BinaryTreeNode and its key is not NaN.
|
|
270
|
+
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
271
|
+
* @returns a boolean value.
|
|
272
|
+
*/
|
|
273
|
+
isRealNode(node: any): node is N;
|
|
274
|
+
/**
|
|
275
|
+
* The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
|
|
276
|
+
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
277
|
+
* @returns a boolean value.
|
|
278
|
+
*/
|
|
244
279
|
isNIL(node: any): boolean;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
250
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
251
|
-
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
252
|
-
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
253
|
-
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
|
|
254
|
-
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
255
|
-
/**
|
|
256
|
-
* The function returns the predecessor node of a given node in a binary tree.
|
|
257
|
-
* @param {N} node - The parameter "node" represents a node in a binary tree.
|
|
258
|
-
* @returns The function `getPredecessor` returns the predecessor node of the given node `node`.
|
|
280
|
+
/**
|
|
281
|
+
* The function checks if a given node is a real node or null.
|
|
282
|
+
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
283
|
+
* @returns a boolean value.
|
|
259
284
|
*/
|
|
285
|
+
isNodeOrNull(node: any): node is (N | null);
|
|
286
|
+
/**
|
|
287
|
+
* The function "isNodeKey" checks if a potential key is a number.
|
|
288
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
289
|
+
* data type.
|
|
290
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
291
|
+
*/
|
|
292
|
+
isNodeKey(potentialKey: any): potentialKey is number;
|
|
293
|
+
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
294
|
+
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
295
|
+
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
296
|
+
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
297
|
+
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
298
|
+
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
299
|
+
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
300
|
+
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
|
|
301
|
+
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKey | N | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
260
302
|
getPredecessor(node: N): N;
|
|
261
303
|
/**
|
|
262
304
|
* The function `getSuccessor` returns the next node in a binary tree given a node `x`, or `null` if
|
|
@@ -265,13 +307,13 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
265
307
|
* @returns The function `getSuccessor` returns a value of type `N` (the successor node), or `null`
|
|
266
308
|
* if there is no successor, or `undefined` if the input `x` is `undefined`.
|
|
267
309
|
*/
|
|
268
|
-
getSuccessor(x
|
|
310
|
+
getSuccessor(x?: BTNKey | N | null): N | null | undefined;
|
|
269
311
|
/**
|
|
270
312
|
* The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
|
|
271
313
|
* algorithm and returns an array of values obtained by applying a callback function to each node.
|
|
272
314
|
* @param callback - The `callback` parameter is a function that will be called on each node in the
|
|
273
315
|
* tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The
|
|
274
|
-
* default value for this parameter is `this.
|
|
316
|
+
* default value for this parameter is `this._defaultOneParamCallback`.
|
|
275
317
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
|
|
276
318
|
* determines the order in which the nodes of a binary tree are traversed. It can have one of the
|
|
277
319
|
* following values:
|
|
@@ -280,7 +322,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
280
322
|
* `beginRoot` is `null`, an empty array will be returned.
|
|
281
323
|
* @returns The `morris` function returns an array of `ReturnType<BTNCallback<N>>` values.
|
|
282
324
|
*/
|
|
283
|
-
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null | undefined): ReturnType<C>[];
|
|
325
|
+
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined): ReturnType<C>[];
|
|
284
326
|
/**
|
|
285
327
|
* The above function is an iterator for a binary tree that can be used to traverse the tree in
|
|
286
328
|
* either an iterative or recursive manner.
|
|
@@ -291,14 +333,14 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
291
333
|
* binary tree nodes in a specific order.
|
|
292
334
|
*/
|
|
293
335
|
[Symbol.iterator](node?: N | null | undefined): Generator<BTNKey, void, undefined>;
|
|
294
|
-
protected
|
|
336
|
+
protected _defaultOneParamCallback: (node: N) => number;
|
|
295
337
|
/**
|
|
296
338
|
* Swap the data of two nodes in the binary tree.
|
|
297
339
|
* @param {N} srcNode - The source node to swap.
|
|
298
340
|
* @param {N} destNode - The destination node to swap.
|
|
299
341
|
* @returns {N} - The destination node after the swap.
|
|
300
342
|
*/
|
|
301
|
-
protected _swap(srcNode: N, destNode: N): N;
|
|
343
|
+
protected _swap(srcNode: BTNKey | N | null | undefined, destNode: BTNKey | N | null | undefined): N | undefined;
|
|
302
344
|
/**
|
|
303
345
|
* The function `_addTo` adds a new node to a binary tree if there is an available position.
|
|
304
346
|
* @param {N | null | undefined} newNode - The `newNode` parameter represents the node that you want to add to
|
|
@@ -310,7 +352,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
310
352
|
* the binary tree. If neither the left nor right child is available, the function returns undefined.
|
|
311
353
|
* If the parent node is null, the function also returns undefined.
|
|
312
354
|
*/
|
|
313
|
-
protected _addTo(newNode: N | null | undefined, parent: N): N | null | undefined;
|
|
355
|
+
protected _addTo(newNode: N | null | undefined, parent: BTNKey | N | null | undefined): N | null | undefined;
|
|
314
356
|
/**
|
|
315
357
|
* The function sets the root property of an object to a given value, and if the value is not null,
|
|
316
358
|
* it also sets the parent property of the value to undefined.
|
|
@@ -318,5 +360,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
318
360
|
* type `N` or `null`.
|
|
319
361
|
*/
|
|
320
362
|
protected _setRoot(v: N | null | undefined): void;
|
|
321
|
-
|
|
363
|
+
/**
|
|
364
|
+
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
365
|
+
* @param {N | null | undefined} root - The `root` parameter in the `print` function represents the
|
|
366
|
+
* root node of a binary tree. It can have one of the following types: `BTNKey`, `N`, `null`, or
|
|
367
|
+
* `undefined`. The default value is `this.root`, which suggests that `this.root` is the
|
|
368
|
+
*/
|
|
369
|
+
print(beginRoot?: BTNKey | N | null | undefined): void;
|
|
322
370
|
}
|