priority-queue-typed 1.52.9 → 1.53.0
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-multi-map.d.ts +21 -21
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +63 -46
- package/dist/data-structures/binary-tree/avl-tree.d.ts +20 -20
- package/dist/data-structures/binary-tree/avl-tree.js +28 -26
- package/dist/data-structures/binary-tree/binary-tree.d.ts +186 -144
- package/dist/data-structures/binary-tree/binary-tree.js +375 -264
- package/dist/data-structures/binary-tree/bst.d.ts +56 -56
- package/dist/data-structures/binary-tree/bst.js +105 -77
- package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -13
- package/dist/data-structures/binary-tree/rb-tree.js +35 -33
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +21 -21
- package/dist/data-structures/binary-tree/tree-multi-map.js +58 -48
- package/dist/data-structures/trie/trie.js +3 -3
- package/dist/interfaces/binary-tree.d.ts +5 -5
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +13 -13
- package/dist/types/data-structures/binary-tree/bst.d.ts +3 -3
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +59 -53
- package/src/data-structures/binary-tree/avl-tree.ts +31 -34
- package/src/data-structures/binary-tree/binary-tree.ts +439 -359
- package/src/data-structures/binary-tree/bst.ts +142 -112
- package/src/data-structures/binary-tree/rb-tree.ts +37 -41
- package/src/data-structures/binary-tree/tree-multi-map.ts +56 -60
- package/src/data-structures/trie/trie.ts +3 -3
- package/src/interfaces/binary-tree.ts +6 -6
- package/src/types/data-structures/binary-tree/binary-tree.ts +14 -15
- package/src/types/data-structures/binary-tree/bst.ts +4 -4
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
8
|
+
import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNEntry, BTNRep, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeCallback, NodeDisplayLayout, NodePredicate, OptNodeOrNull, ToEntryFn } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { IterableEntryBase } from '../base';
|
|
11
11
|
/**
|
|
@@ -18,12 +18,12 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
|
|
|
18
18
|
value?: V;
|
|
19
19
|
parent?: NODE;
|
|
20
20
|
constructor(key: K, value?: V);
|
|
21
|
-
protected _left?:
|
|
22
|
-
get left():
|
|
23
|
-
set left(v:
|
|
24
|
-
protected _right?:
|
|
25
|
-
get right():
|
|
26
|
-
set right(v:
|
|
21
|
+
protected _left?: OptNodeOrNull<NODE>;
|
|
22
|
+
get left(): OptNodeOrNull<NODE>;
|
|
23
|
+
set left(v: OptNodeOrNull<NODE>);
|
|
24
|
+
protected _right?: OptNodeOrNull<NODE>;
|
|
25
|
+
get right(): OptNodeOrNull<NODE>;
|
|
26
|
+
set right(v: OptNodeOrNull<NODE>);
|
|
27
27
|
get familyPosition(): FamilyPosition;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
@@ -33,26 +33,30 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
|
|
|
33
33
|
* 4. Subtrees: Each child of a node forms the root of a subtree.
|
|
34
34
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
35
35
|
*/
|
|
36
|
-
export declare class BinaryTree<K = any, V = any, R =
|
|
36
|
+
export declare class BinaryTree<K = any, V = any, R = object, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
37
37
|
iterationType: IterationType;
|
|
38
38
|
/**
|
|
39
39
|
* The constructor initializes a binary tree with optional options and adds keys, nodes, entries, or
|
|
40
40
|
* raw data if provided.
|
|
41
|
-
* @param
|
|
42
|
-
* is an iterable that can contain elements of type `
|
|
41
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor
|
|
42
|
+
* is an iterable that can contain elements of type `BTNRep<K, V, NODE>` or `R`. It is
|
|
43
43
|
* initialized with an empty array `[]` by default.
|
|
44
44
|
* @param [options] - The `options` parameter in the constructor is an object that can contain the
|
|
45
45
|
* following properties:
|
|
46
46
|
*/
|
|
47
|
-
constructor(
|
|
48
|
-
protected
|
|
49
|
-
get
|
|
47
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V, NODE> | R>, options?: BinaryTreeOptions<K, V, R>);
|
|
48
|
+
protected _isMapMode: boolean;
|
|
49
|
+
get isMapMode(): boolean;
|
|
50
|
+
protected _store: Map<K, V | undefined>;
|
|
51
|
+
get store(): Map<K, V | undefined>;
|
|
52
|
+
protected _root?: OptNodeOrNull<NODE>;
|
|
53
|
+
get root(): OptNodeOrNull<NODE>;
|
|
50
54
|
protected _size: number;
|
|
51
55
|
get size(): number;
|
|
52
56
|
protected _NIL: NODE;
|
|
53
57
|
get NIL(): NODE;
|
|
54
|
-
protected _toEntryFn?:
|
|
55
|
-
get toEntryFn():
|
|
58
|
+
protected _toEntryFn?: ToEntryFn<K, V, R>;
|
|
59
|
+
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
56
60
|
/**
|
|
57
61
|
* The function creates a new binary tree node with a specified key and optional value.
|
|
58
62
|
* @param {K} key - The `key` parameter is the key of the node being created in the binary tree.
|
|
@@ -73,29 +77,29 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
73
77
|
*/
|
|
74
78
|
createTree(options?: BinaryTreeOptions<K, V, R>): TREE;
|
|
75
79
|
/**
|
|
76
|
-
* The function `
|
|
80
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
77
81
|
* or returns null.
|
|
78
|
-
* @param {
|
|
79
|
-
* `
|
|
80
|
-
* can be of type `
|
|
82
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
83
|
+
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
|
|
84
|
+
* can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
|
|
81
85
|
* node, an entry
|
|
82
|
-
* @param {V} [value] - The `value` parameter in the `
|
|
86
|
+
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
83
87
|
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
84
88
|
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
85
|
-
* @returns The `
|
|
86
|
-
* (`
|
|
87
|
-
* input parameter (`
|
|
89
|
+
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
90
|
+
* (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
|
|
91
|
+
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
88
92
|
* value.
|
|
89
93
|
*/
|
|
90
|
-
|
|
94
|
+
keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): [OptNodeOrNull<NODE>, V | undefined];
|
|
91
95
|
/**
|
|
92
96
|
* Time Complexity: O(n)
|
|
93
97
|
* Space Complexity: O(log n)
|
|
94
98
|
*
|
|
95
99
|
* The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
|
|
96
100
|
* value and returns the corresponding node or null.
|
|
97
|
-
* @param {
|
|
98
|
-
* parameter in the `ensureNode` function can be of type `
|
|
101
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
|
|
102
|
+
* parameter in the `ensureNode` function can be of type `BTNRep<K, V, NODE>` or `R`. It
|
|
99
103
|
* is used to determine whether the input is a key, node, entry, or raw data. The
|
|
100
104
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
|
|
101
105
|
* is used to specify the type of iteration to be performed. It has a default value of
|
|
@@ -103,70 +107,71 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
103
107
|
* @returns The `ensureNode` function returns either a node, `null`, or `undefined` based on the
|
|
104
108
|
* conditions specified in the code snippet.
|
|
105
109
|
*/
|
|
106
|
-
ensureNode(
|
|
110
|
+
ensureNode(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, iterationType?: IterationType): OptNodeOrNull<NODE>;
|
|
107
111
|
/**
|
|
108
112
|
* The function isNode checks if the input is an instance of BinaryTreeNode.
|
|
109
|
-
* @param {
|
|
110
|
-
* `
|
|
113
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
114
|
+
* `keyNodeEntryOrRaw` can be either a key, a node, an entry, or raw data. The function is
|
|
111
115
|
* checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
|
|
112
116
|
* accordingly.
|
|
113
|
-
* @returns The function `isNode` is checking if the input `
|
|
117
|
+
* @returns The function `isNode` is checking if the input `keyNodeEntryOrRaw` is an instance of
|
|
114
118
|
* `BinaryTreeNode`. If it is, the function returns `true`, indicating that the input is a node. If
|
|
115
119
|
* it is not an instance of `BinaryTreeNode`, the function returns `false`, indicating that the input
|
|
116
120
|
* is not a node.
|
|
117
121
|
*/
|
|
118
|
-
isNode(
|
|
122
|
+
isNode(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is NODE;
|
|
123
|
+
isRaw(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is R;
|
|
119
124
|
/**
|
|
120
125
|
* The function `isRealNode` checks if a given input is a valid node in a binary tree.
|
|
121
|
-
* @param {
|
|
122
|
-
* parameter in the `isRealNode` function can be of type `
|
|
126
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
|
|
127
|
+
* parameter in the `isRealNode` function can be of type `BTNRep<K, V, NODE>` or `R`.
|
|
123
128
|
* The function checks if the input parameter is a `NODE` type by verifying if it is not equal
|
|
124
|
-
* @returns The function `isRealNode` is checking if the input `
|
|
129
|
+
* @returns The function `isRealNode` is checking if the input `keyNodeEntryOrRaw` is a valid
|
|
125
130
|
* node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
|
|
126
131
|
* values, it then calls the `isNode` method to further determine if the input is a node. The
|
|
127
132
|
* function will return a boolean value indicating whether the
|
|
128
133
|
*/
|
|
129
|
-
isRealNode(
|
|
134
|
+
isRealNode(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is NODE;
|
|
130
135
|
/**
|
|
131
136
|
* The function checks if a given input is a valid node or null.
|
|
132
|
-
* @param {
|
|
133
|
-
* `
|
|
137
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
138
|
+
* `keyNodeEntryOrRaw` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
|
|
134
139
|
* V, NODE>` or `R`. It is a union type that can either be a key, a node, an entry, or
|
|
135
140
|
* @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
|
|
136
|
-
* `
|
|
141
|
+
* `keyNodeEntryOrRaw` is either `null` or a real node, and returns `true` if it is a node or
|
|
137
142
|
* `null`, and `false` otherwise.
|
|
138
143
|
*/
|
|
139
|
-
isRealNodeOrNull(
|
|
144
|
+
isRealNodeOrNull(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is NODE | null;
|
|
140
145
|
/**
|
|
141
146
|
* The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
|
|
142
|
-
* @param {
|
|
147
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - BTNRep<K, V,
|
|
143
148
|
* NODE> | R
|
|
144
|
-
* @returns The function is checking if the `
|
|
149
|
+
* @returns The function is checking if the `keyNodeEntryOrRaw` parameter is equal to the `_NIL`
|
|
145
150
|
* property of the current object and returning a boolean value based on that comparison.
|
|
146
151
|
*/
|
|
147
|
-
isNIL(
|
|
152
|
+
isNIL(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): boolean;
|
|
148
153
|
/**
|
|
149
154
|
* The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
|
|
150
155
|
* tree.
|
|
151
|
-
* @param {
|
|
152
|
-
* `
|
|
156
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
157
|
+
* `keyNodeEntryOrRaw` can be of type `BTNRep<K, V, NODE>` or `R`. It represents a
|
|
153
158
|
* key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
|
|
154
159
|
* provided
|
|
155
160
|
* @returns The function `isLeaf` returns a boolean value indicating whether the input
|
|
156
|
-
* `
|
|
161
|
+
* `keyNodeEntryOrRaw` is a leaf node in a binary tree.
|
|
157
162
|
*/
|
|
158
|
-
isLeaf(
|
|
163
|
+
isLeaf(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): boolean;
|
|
159
164
|
/**
|
|
160
165
|
* The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
|
|
161
166
|
* with a length of 2.
|
|
162
|
-
* @param {
|
|
163
|
-
* parameter in the `isEntry` function can be of type `
|
|
164
|
-
* The function checks if the provided `
|
|
165
|
-
* @returns The `isEntry` function is checking if the `
|
|
167
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
|
|
168
|
+
* parameter in the `isEntry` function can be of type `BTNRep<K, V, NODE>` or type `R`.
|
|
169
|
+
* The function checks if the provided `keyNodeEntryOrRaw` is of type `BTN
|
|
170
|
+
* @returns The `isEntry` function is checking if the `keyNodeEntryOrRaw` parameter is an array
|
|
166
171
|
* with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
|
|
167
172
|
* `BTNEntry<K, V>`. If the condition is not met, it returns `false`.
|
|
168
173
|
*/
|
|
169
|
-
isEntry(
|
|
174
|
+
isEntry(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is BTNEntry<K, V>;
|
|
170
175
|
/**
|
|
171
176
|
* Time Complexity O(1)
|
|
172
177
|
* Space Complexity O(1)
|
|
@@ -185,8 +190,8 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
185
190
|
*
|
|
186
191
|
* The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
|
|
187
192
|
* and finding the correct insertion position.
|
|
188
|
-
* @param {
|
|
189
|
-
* seems to be for adding a new node to a binary tree structure. The `
|
|
193
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `add` method you provided
|
|
194
|
+
* seems to be for adding a new node to a binary tree structure. The `keyNodeEntryOrRaw`
|
|
190
195
|
* parameter in the method can accept different types of values:
|
|
191
196
|
* @param {V} [value] - The `value` parameter in the `add` method represents the value associated
|
|
192
197
|
* with the key that you want to add to the binary tree. When adding a key-value pair to the binary
|
|
@@ -196,7 +201,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
196
201
|
* node was successful, and `false` if the insertion position could not be found or if a duplicate
|
|
197
202
|
* key was found and the node was replaced instead of inserted.
|
|
198
203
|
*/
|
|
199
|
-
add(
|
|
204
|
+
add(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): boolean;
|
|
200
205
|
/**
|
|
201
206
|
* Time Complexity: O(k * n)
|
|
202
207
|
* Space Complexity: O(1)
|
|
@@ -204,38 +209,38 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
204
209
|
* The `addMany` function takes in multiple keys or nodes or entries or raw values along with
|
|
205
210
|
* optional values, and adds them to a data structure while returning an array indicating whether
|
|
206
211
|
* each insertion was successful.
|
|
207
|
-
* @param
|
|
212
|
+
* @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
|
|
208
213
|
* mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
|
|
209
|
-
* `
|
|
214
|
+
* `BTNRep<K, V, NODE>` or `R`.
|
|
210
215
|
* @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
|
|
211
216
|
* accepts an iterable of values. These values correspond to the keys or nodes being added in the
|
|
212
|
-
* `
|
|
217
|
+
* `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
|
|
213
218
|
* assign them
|
|
214
219
|
* @returns The `addMany` method returns an array of boolean values indicating whether each key,
|
|
215
220
|
* node, entry, or raw value was successfully added to the data structure. Each boolean value
|
|
216
221
|
* corresponds to the success of adding the corresponding key or value in the input iterable.
|
|
217
222
|
*/
|
|
218
|
-
addMany(
|
|
223
|
+
addMany(keysNodesEntriesOrRaws: Iterable<BTNRep<K, V, NODE> | R>, values?: Iterable<V | undefined>): boolean[];
|
|
219
224
|
/**
|
|
220
225
|
* Time Complexity: O(k * n)
|
|
221
226
|
* Space Complexity: O(1)
|
|
222
227
|
*
|
|
223
228
|
* The `refill` function clears the existing data structure and then adds new key-value pairs based
|
|
224
229
|
* on the provided input.
|
|
225
|
-
* @param
|
|
226
|
-
* method can accept an iterable containing a mix of `
|
|
230
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
|
|
231
|
+
* method can accept an iterable containing a mix of `BTNRep<K, V, NODE>` objects or `R`
|
|
227
232
|
* objects.
|
|
228
233
|
* @param [values] - The `values` parameter in the `refill` method is an optional parameter that
|
|
229
234
|
* accepts an iterable of values of type `V` or `undefined`.
|
|
230
235
|
*/
|
|
231
|
-
refill(
|
|
236
|
+
refill(keysNodesEntriesOrRaws: Iterable<BTNRep<K, V, NODE> | R>, values?: Iterable<V | undefined>): void;
|
|
232
237
|
/**
|
|
233
238
|
* Time Complexity: O(n)
|
|
234
239
|
* Space Complexity: O(1)
|
|
235
240
|
*
|
|
236
241
|
* The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
|
|
237
242
|
* the deleted node along with information for tree balancing.
|
|
238
|
-
* @param {
|
|
243
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw
|
|
239
244
|
* - The `delete` method you provided is used to delete a node from a binary tree based on the key,
|
|
240
245
|
* node, entry or raw data. The method returns an array of
|
|
241
246
|
* `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
|
|
@@ -244,19 +249,19 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
244
249
|
* the array contains information about the node that was deleted (`deleted`) and the node that may
|
|
245
250
|
* need to be balanced (`needBalanced`).
|
|
246
251
|
*/
|
|
247
|
-
delete(
|
|
252
|
+
delete(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
|
|
248
253
|
/**
|
|
249
254
|
* Time Complexity: O(n)
|
|
250
255
|
* Space Complexity: O(k + log n)
|
|
251
256
|
*
|
|
252
257
|
* The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
|
|
253
258
|
* or predicate, with options for recursive or iterative traversal.
|
|
254
|
-
* @param {
|
|
259
|
+
* @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
|
|
255
260
|
* - The `getNodes` function you provided takes several parameters:
|
|
256
261
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
|
|
257
262
|
* determines whether to return only the first node that matches the criteria specified by the
|
|
258
|
-
* `
|
|
259
|
-
* @param {
|
|
263
|
+
* `keyNodeEntryRawOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
|
|
264
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
|
|
260
265
|
* `getNodes` function is used to specify the starting point for traversing the binary tree. It
|
|
261
266
|
* represents the root node of the binary tree or the node from which the traversal should begin. If
|
|
262
267
|
* not provided, the default value is set to `this._root
|
|
@@ -266,17 +271,17 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
266
271
|
* @returns The `getNodes` function returns an array of nodes that satisfy the provided condition
|
|
267
272
|
* based on the input parameters and the iteration type specified.
|
|
268
273
|
*/
|
|
269
|
-
getNodes(
|
|
274
|
+
getNodes(keyNodeEntryRawOrPredicate: BTNRep<K, V, NODE> | R | NodePredicate<NODE>, onlyOne?: boolean, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): NODE[];
|
|
270
275
|
/**
|
|
271
276
|
* Time Complexity: O(n)
|
|
272
277
|
* Space Complexity: O(log n).
|
|
273
278
|
*
|
|
274
279
|
* The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
|
|
275
280
|
* predicate.
|
|
276
|
-
* @param {
|
|
277
|
-
* - The `
|
|
281
|
+
* @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
|
|
282
|
+
* - The `keyNodeEntryRawOrPredicate` parameter in the `getNode` function can accept a key,
|
|
278
283
|
* node, entry, raw data, or a predicate function.
|
|
279
|
-
* @param {
|
|
284
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
|
|
280
285
|
* `getNode` function is used to specify the starting point for searching for a node in a binary
|
|
281
286
|
* tree. If no specific starting point is provided, the default value is set to `this._root`, which
|
|
282
287
|
* is typically the root node of the binary tree.
|
|
@@ -287,7 +292,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
287
292
|
* @returns The `getNode` function is returning the first node that matches the specified criteria,
|
|
288
293
|
* or `null` if no matching node is found.
|
|
289
294
|
*/
|
|
290
|
-
getNode(
|
|
295
|
+
getNode(keyNodeEntryRawOrPredicate: BTNRep<K, V, NODE> | R | NodePredicate<NODE>, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): OptNodeOrNull<NODE>;
|
|
291
296
|
/**
|
|
292
297
|
* Time Complexity: O(n)
|
|
293
298
|
* Space Complexity: O(log n)
|
|
@@ -299,19 +304,19 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
299
304
|
* specifies how the tree nodes should be traversed when searching for a node with the given key. It
|
|
300
305
|
* is an optional parameter with a default value of `this.iterationType`.
|
|
301
306
|
* @returns The `getNodeByKey` function is returning an optional binary tree node
|
|
302
|
-
* (`
|
|
307
|
+
* (`OptNodeOrNull<NODE>`).
|
|
303
308
|
*/
|
|
304
|
-
getNodeByKey(key: K, iterationType?: IterationType):
|
|
309
|
+
getNodeByKey(key: K, iterationType?: IterationType): OptNodeOrNull<NODE>;
|
|
305
310
|
/**
|
|
306
311
|
* Time Complexity: O(n)
|
|
307
312
|
* Space Complexity: O(log n)
|
|
308
313
|
*
|
|
309
314
|
* This function overrides the `get` method to retrieve the value associated with a specified key,
|
|
310
315
|
* node, entry, raw data, or predicate in a data structure.
|
|
311
|
-
* @param {
|
|
312
|
-
* - The `
|
|
316
|
+
* @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
|
|
317
|
+
* - The `keyNodeEntryRawOrPredicate` parameter in the `get` method can accept one of the
|
|
313
318
|
* following types:
|
|
314
|
-
* @param {
|
|
319
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `get`
|
|
315
320
|
* method is used to specify the starting point for searching for a key or node in the binary tree.
|
|
316
321
|
* If no specific starting point is provided, the default starting point is the root of the binary
|
|
317
322
|
* tree (`this._root`).
|
|
@@ -324,17 +329,17 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
324
329
|
* the method returns the corresponding value. If the key or node is not found, it returns
|
|
325
330
|
* `undefined`.
|
|
326
331
|
*/
|
|
327
|
-
get(
|
|
332
|
+
get(keyNodeEntryRawOrPredicate: BTNRep<K, V, NODE> | R, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): V | undefined;
|
|
328
333
|
/**
|
|
329
334
|
* Time Complexity: O(n)
|
|
330
335
|
* Space Complexity: O(log n)
|
|
331
336
|
*
|
|
332
337
|
* The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
|
|
333
338
|
* exists in the data structure.
|
|
334
|
-
* @param {
|
|
335
|
-
* - The `
|
|
339
|
+
* @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
|
|
340
|
+
* - The `keyNodeEntryRawOrPredicate` parameter in the `override has` method can accept one of
|
|
336
341
|
* the following types:
|
|
337
|
-
* @param {
|
|
342
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
|
|
338
343
|
* `override` method is used to specify the starting point for the search operation within the data
|
|
339
344
|
* structure. It defaults to `this._root` if not provided explicitly.
|
|
340
345
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
|
|
@@ -346,7 +351,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
346
351
|
* are matching nodes, it returns `true`, indicating that the tree contains the specified element.
|
|
347
352
|
* Otherwise, it returns `false`.
|
|
348
353
|
*/
|
|
349
|
-
has(
|
|
354
|
+
has(keyNodeEntryRawOrPredicate: BTNRep<K, V, NODE> | R | NodePredicate<NODE>, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): boolean;
|
|
350
355
|
/**
|
|
351
356
|
* Time Complexity: O(1)
|
|
352
357
|
* Space Complexity: O(1)
|
|
@@ -370,23 +375,23 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
370
375
|
*
|
|
371
376
|
* The function checks if a binary tree is perfectly balanced by comparing its minimum height with
|
|
372
377
|
* its height.
|
|
373
|
-
* @param {
|
|
378
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
|
|
374
379
|
* point for checking if the binary tree is perfectly balanced. It represents the root node of the
|
|
375
380
|
* binary tree or a specific node from which the balance check should begin.
|
|
376
381
|
* @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
|
|
377
|
-
* the tree starting from the `
|
|
382
|
+
* the tree starting from the `startNode` node is perfectly balanced or not. The return value is
|
|
378
383
|
* determined by comparing the minimum height of the tree with the height of the tree. If the minimum
|
|
379
384
|
* height plus 1 is greater than or equal to the height of the tree, then it is considered perfectly
|
|
380
385
|
* balanced and
|
|
381
386
|
*/
|
|
382
|
-
isPerfectlyBalanced(
|
|
387
|
+
isPerfectlyBalanced(startNode?: BTNRep<K, V, NODE> | R): boolean;
|
|
383
388
|
/**
|
|
384
389
|
* Time Complexity: O(n)
|
|
385
390
|
* Space Complexity: O(1)
|
|
386
391
|
*
|
|
387
392
|
* The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
|
|
388
393
|
* or iterative methods.
|
|
389
|
-
* @param {
|
|
394
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `isBST`
|
|
390
395
|
* function represents the starting point for checking whether a binary search tree (BST) is valid.
|
|
391
396
|
* It can be a node in the BST or a reference to the root of the BST. If no specific node is
|
|
392
397
|
* provided, the function will default to
|
|
@@ -398,31 +403,31 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
398
403
|
* the tree satisfies the BST property, where for every node, all nodes in its left subtree have keys
|
|
399
404
|
* less than the node's key, and all nodes in its right subtree have keys greater than the node's
|
|
400
405
|
*/
|
|
401
|
-
isBST(
|
|
406
|
+
isBST(startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): boolean;
|
|
402
407
|
/**
|
|
403
408
|
* Time Complexity: O(n)
|
|
404
409
|
* Space Complexity: O(1)
|
|
405
410
|
*
|
|
406
411
|
* The `getDepth` function calculates the depth between two nodes in a binary tree.
|
|
407
|
-
* @param {
|
|
412
|
+
* @param {BTNRep<K, V, NODE> | R} dist - The `dist` parameter in the `getDepth`
|
|
408
413
|
* function represents the node or entry in a binary tree map, or a reference to a node in the tree.
|
|
409
|
-
* It is the target node for which you want to calculate the depth from the `
|
|
410
|
-
* @param {
|
|
414
|
+
* It is the target node for which you want to calculate the depth from the `startNode` node.
|
|
415
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
|
|
411
416
|
* `getDepth` function represents the starting point from which you want to calculate the depth of a
|
|
412
417
|
* given node or entry in a binary tree. If no specific starting point is provided, the default value
|
|
413
|
-
* for `
|
|
418
|
+
* for `startNode` is set to the root of the binary
|
|
414
419
|
* @returns The `getDepth` method returns the depth of a given node `dist` relative to the
|
|
415
|
-
* `
|
|
420
|
+
* `startNode` node in a binary tree. If the `dist` node is not found in the path to the `startNode`
|
|
416
421
|
* node, it returns the depth of the `dist` node from the root of the tree.
|
|
417
422
|
*/
|
|
418
|
-
getDepth(dist:
|
|
423
|
+
getDepth(dist: BTNRep<K, V, NODE> | R, startNode?: BTNRep<K, V, NODE> | R): number;
|
|
419
424
|
/**
|
|
420
425
|
* Time Complexity: O(n)
|
|
421
426
|
* Space Complexity: O(1)
|
|
422
427
|
*
|
|
423
428
|
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive
|
|
424
429
|
* or iterative approach in TypeScript.
|
|
425
|
-
* @param {
|
|
430
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
|
|
426
431
|
* point from which the height of the binary tree will be calculated. It can be a node in the binary
|
|
427
432
|
* tree or a reference to the root of the tree. If not provided, it defaults to the root of the
|
|
428
433
|
* binary tree data structure.
|
|
@@ -433,14 +438,14 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
433
438
|
* root node. The height is calculated based on the maximum depth of the tree, considering either a
|
|
434
439
|
* recursive approach or an iterative approach depending on the `iterationType` parameter.
|
|
435
440
|
*/
|
|
436
|
-
getHeight(
|
|
441
|
+
getHeight(startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): number;
|
|
437
442
|
/**
|
|
438
443
|
* Time Complexity: O(n)
|
|
439
444
|
* Space Complexity: O(log n)
|
|
440
445
|
*
|
|
441
446
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
442
447
|
* recursive or iterative approach in TypeScript.
|
|
443
|
-
* @param {
|
|
448
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
|
|
444
449
|
* `getMinHeight` function represents the starting node from which the minimum height of the binary
|
|
445
450
|
* tree will be calculated. It is either a node in the binary tree or a reference to the root of the
|
|
446
451
|
* tree. If not provided, the default value is the root
|
|
@@ -452,7 +457,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
452
457
|
* leaf node in the tree. The method uses either a recursive approach or an iterative approach (using
|
|
453
458
|
* a stack) based on the `iterationType` parameter.
|
|
454
459
|
*/
|
|
455
|
-
getMinHeight(
|
|
460
|
+
getMinHeight(startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): number;
|
|
456
461
|
/**
|
|
457
462
|
* Time Complexity: O(log n)
|
|
458
463
|
* Space Complexity: O(log n)
|
|
@@ -463,7 +468,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
463
468
|
* the path to the root. It is expected to be a function that takes a node as an argument and returns
|
|
464
469
|
* a value based on that node. The return type of the callback function is determined by the generic
|
|
465
470
|
* type `C
|
|
466
|
-
* @param {
|
|
471
|
+
* @param {BTNRep<K, V, NODE> | R} beginNode - The `beginNode` parameter in the
|
|
467
472
|
* `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
|
|
468
473
|
* @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
|
|
469
474
|
* whether the resulting path from the given `beginNode` to the root should be in reverse order or
|
|
@@ -473,7 +478,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
473
478
|
* array is either in reverse order or in the original order based on the value of the `isReverse`
|
|
474
479
|
* parameter.
|
|
475
480
|
*/
|
|
476
|
-
getPathToRoot<C extends
|
|
481
|
+
getPathToRoot<C extends NodeCallback<OptNodeOrNull<NODE>>>(callback: C | undefined, beginNode: BTNRep<K, V, NODE> | R, isReverse?: boolean): ReturnType<C>[];
|
|
477
482
|
/**
|
|
478
483
|
* Time Complexity: O(log n)
|
|
479
484
|
* Space Complexity: O(1)
|
|
@@ -482,8 +487,8 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
482
487
|
* tail-recursive iteration.
|
|
483
488
|
* @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
|
|
484
489
|
* node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
|
|
485
|
-
* value of `
|
|
486
|
-
* @param {
|
|
490
|
+
* value of `_DEFAULT_NODE_CALLBACK` if not specified.
|
|
491
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
|
|
487
492
|
* `getLeftMost` function represents the starting point for finding the leftmost node in a binary
|
|
488
493
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
489
494
|
* starting point is provided, the function will default
|
|
@@ -491,11 +496,11 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
491
496
|
* specifies the type of iteration to be used when traversing the binary tree nodes. It can have two
|
|
492
497
|
* possible values:
|
|
493
498
|
* @returns The `getLeftMost` function returns the result of the callback function `C` applied to the
|
|
494
|
-
* leftmost node in the binary tree starting from the `
|
|
495
|
-
* `NIL`, it returns the result of the callback function applied to `undefined`. If the `
|
|
499
|
+
* leftmost node in the binary tree starting from the `startNode` node. If the `startNode` node is
|
|
500
|
+
* `NIL`, it returns the result of the callback function applied to `undefined`. If the `startNode`
|
|
496
501
|
* node is not a real node, it returns the result of the callback
|
|
497
502
|
*/
|
|
498
|
-
getLeftMost<C extends
|
|
503
|
+
getLeftMost<C extends NodeCallback<OptNodeOrNull<NODE>>>(callback?: C, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>;
|
|
499
504
|
/**
|
|
500
505
|
* Time Complexity: O(log n)
|
|
501
506
|
* Space Complexity: O(1)
|
|
@@ -503,10 +508,10 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
503
508
|
* The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
|
|
504
509
|
* or iterative traversal methods.
|
|
505
510
|
* @param {C} callback - The `callback` parameter is a function that will be called with the result
|
|
506
|
-
* of finding the rightmost node in a binary tree. It is of type `
|
|
511
|
+
* of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<NODE>>`,
|
|
507
512
|
* which means it is a callback function that can accept either an optional binary tree node or null
|
|
508
513
|
* as
|
|
509
|
-
* @param {
|
|
514
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
|
|
510
515
|
* `getRightMost` function represents the starting point for finding the rightmost node in a binary
|
|
511
516
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
512
517
|
* starting point is provided, the function will default
|
|
@@ -518,7 +523,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
518
523
|
* the binary tree structure, determined based on the specified iteration type ('RECURSIVE' or
|
|
519
524
|
* other).
|
|
520
525
|
*/
|
|
521
|
-
getRightMost<C extends
|
|
526
|
+
getRightMost<C extends NodeCallback<OptNodeOrNull<NODE>>>(callback?: C, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>;
|
|
522
527
|
/**
|
|
523
528
|
* Time Complexity: O(log n)
|
|
524
529
|
* Space Complexity: O(1)
|
|
@@ -546,11 +551,11 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
546
551
|
* have a right child, the function traverses up the parent nodes until it finds a node that is not
|
|
547
552
|
* the right child of its parent, and returns that node
|
|
548
553
|
*/
|
|
549
|
-
getSuccessor(x?: K | NODE | null):
|
|
550
|
-
dfs<C extends
|
|
551
|
-
dfs<C extends
|
|
552
|
-
bfs<C extends
|
|
553
|
-
bfs<C extends
|
|
554
|
+
getSuccessor(x?: K | NODE | null): OptNodeOrNull<NODE>;
|
|
555
|
+
dfs<C extends NodeCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>[];
|
|
556
|
+
dfs<C extends NodeCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
|
|
557
|
+
bfs<C extends NodeCallback<NODE>>(callback?: C, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
558
|
+
bfs<C extends NodeCallback<NODE | null>>(callback?: C, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
554
559
|
/**
|
|
555
560
|
* Time complexity: O(n)
|
|
556
561
|
* Space complexity: O(n)
|
|
@@ -559,7 +564,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
559
564
|
* structure based on a specified callback and iteration type.
|
|
560
565
|
* @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
|
|
561
566
|
* in the binary tree. It is optional and defaults to a default callback function if not provided.
|
|
562
|
-
* @param {
|
|
567
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `leaves`
|
|
563
568
|
* method is used to specify the starting point for finding and processing the leaves of a binary
|
|
564
569
|
* tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
|
|
565
570
|
* explicitly provided, the default value
|
|
@@ -569,9 +574,9 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
569
574
|
* @returns The `leaves` method returns an array of values that are the result of applying the
|
|
570
575
|
* provided callback function to each leaf node in the binary tree.
|
|
571
576
|
*/
|
|
572
|
-
leaves<C extends
|
|
573
|
-
listLevels<C extends
|
|
574
|
-
listLevels<C extends
|
|
577
|
+
leaves<C extends NodeCallback<NODE | null>>(callback?: C, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>[];
|
|
578
|
+
listLevels<C extends NodeCallback<NODE>>(callback?: C, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
579
|
+
listLevels<C extends NodeCallback<NODE | null>>(callback?: C, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
575
580
|
/**
|
|
576
581
|
* Time complexity: O(n)
|
|
577
582
|
* Space complexity: O(n)
|
|
@@ -580,11 +585,11 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
580
585
|
* Morris Traversal algorithm with different order patterns.
|
|
581
586
|
* @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
|
|
582
587
|
* called on each node in the binary tree during the traversal. It is of type `C`, which extends the
|
|
583
|
-
* `
|
|
588
|
+
* `NodeCallback<NODE>` type. The default value for `callback` is `this._DEFAULT
|
|
584
589
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
|
|
585
590
|
* the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
|
|
586
591
|
* values for the `pattern` parameter are:
|
|
587
|
-
* @param {
|
|
592
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `morris`
|
|
588
593
|
* function is the starting point for the Morris traversal algorithm. It represents the root node of
|
|
589
594
|
* the binary tree or the node from which the traversal should begin. It can be provided as either a
|
|
590
595
|
* key, a node, an entry, or a reference
|
|
@@ -592,7 +597,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
592
597
|
* provided callback function to each node in the binary tree in the specified order pattern (IN,
|
|
593
598
|
* PRE, or POST).
|
|
594
599
|
*/
|
|
595
|
-
morris<C extends
|
|
600
|
+
morris<C extends NodeCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, startNode?: BTNRep<K, V, NODE> | R): ReturnType<C>[];
|
|
596
601
|
/**
|
|
597
602
|
* Time complexity: O(n)
|
|
598
603
|
* Space complexity: O(n)
|
|
@@ -644,7 +649,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
644
649
|
*
|
|
645
650
|
* The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
|
|
646
651
|
* customizable options for displaying undefined, null, and sentinel nodes.
|
|
647
|
-
* @param {
|
|
652
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
|
|
648
653
|
* `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
|
|
649
654
|
* It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
|
|
650
655
|
* the default is set to the root
|
|
@@ -656,7 +661,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
656
661
|
* the lines to the output string. The final output string contains the visual representation of the
|
|
657
662
|
* binary tree with the specified options.
|
|
658
663
|
*/
|
|
659
|
-
toVisual(
|
|
664
|
+
toVisual(startNode?: BTNRep<K, V, NODE> | R, options?: BinaryTreePrintOptions): string;
|
|
660
665
|
/**
|
|
661
666
|
* Time Complexity: O(n)
|
|
662
667
|
* Space Complexity: O(n)
|
|
@@ -667,12 +672,12 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
667
672
|
* printing options for the binary tree. It is an optional parameter that allows you to customize how
|
|
668
673
|
* the binary tree is printed, such as choosing between different traversal orders or formatting
|
|
669
674
|
* options.
|
|
670
|
-
* @param {
|
|
675
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
|
|
671
676
|
* `override print` method is used to specify the starting point for printing the binary tree. It can
|
|
672
677
|
* be either a key, a node, an entry, or the root of the tree. If no specific starting point is
|
|
673
678
|
* provided, the default value is set to
|
|
674
679
|
*/
|
|
675
|
-
print(options?: BinaryTreePrintOptions,
|
|
680
|
+
print(options?: BinaryTreePrintOptions, startNode?: BTNRep<K, V, NODE> | R): void;
|
|
676
681
|
/**
|
|
677
682
|
* Time complexity: O(n)
|
|
678
683
|
* Space complexity: O(n)
|
|
@@ -681,13 +686,13 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
681
686
|
* the specified order pattern and callback function.
|
|
682
687
|
* @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
|
|
683
688
|
* called on each node visited during the depth-first search traversal. It is of type `C`, which
|
|
684
|
-
* extends `
|
|
689
|
+
* extends `NodeCallback<OptNodeOrNull<NODE>>`. The default value for this parameter is `this._DEFAULT
|
|
685
690
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
|
|
686
691
|
* order in which the nodes are visited during the Depth-First Search traversal. It can have one of
|
|
687
692
|
* the following values:
|
|
688
|
-
* @param {
|
|
693
|
+
* @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `_dfs`
|
|
689
694
|
* method is used to specify the starting point for the depth-first search traversal in a binary
|
|
690
|
-
* tree. It can be provided as either a `
|
|
695
|
+
* tree. It can be provided as either a `BTNRep` object or a reference to the root node
|
|
691
696
|
* of the tree. If no specific
|
|
692
697
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `_dfs` method
|
|
693
698
|
* specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
|
|
@@ -715,7 +720,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
715
720
|
* @returns The function `_dfs` returns an array of the return type of the callback function provided
|
|
716
721
|
* as input.
|
|
717
722
|
*/
|
|
718
|
-
protected _dfs<C extends
|
|
723
|
+
protected _dfs<C extends NodeCallback<OptNodeOrNull<NODE>>>(callback?: C, pattern?: DFSOrderPattern, startNode?: BTNRep<K, V, NODE> | R, iterationType?: IterationType, includeNull?: boolean, shouldVisitLeft?: (node: OptNodeOrNull<NODE>) => boolean, shouldVisitRight?: (node: OptNodeOrNull<NODE>) => boolean, shouldVisitRoot?: (node: OptNodeOrNull<NODE>) => boolean, shouldProcessRoot?: (node: OptNodeOrNull<NODE>) => boolean): ReturnType<C>[];
|
|
719
724
|
/**
|
|
720
725
|
* Time Complexity: O(1)
|
|
721
726
|
* Space Complexity: O(1)
|
|
@@ -731,7 +736,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
731
736
|
* the `iterationType` property. If the `iterationType` is set to 'ITERATIVE', the method uses a
|
|
732
737
|
* stack to perform an in-order traversal of the tree. If the `iterationType` is not 'ITERATIVE
|
|
733
738
|
*/
|
|
734
|
-
protected _getIterator(node?:
|
|
739
|
+
protected _getIterator(node?: OptNodeOrNull<NODE>): IterableIterator<[K, V | undefined]>;
|
|
735
740
|
/**
|
|
736
741
|
* Time Complexity: O(n)
|
|
737
742
|
* Space Complexity: O(n)
|
|
@@ -747,24 +752,24 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
747
752
|
* information about how to display a node in a binary tree. The `NodeDisplayLayout` consists of four
|
|
748
753
|
* elements:
|
|
749
754
|
*/
|
|
750
|
-
protected _displayAux(node:
|
|
751
|
-
protected
|
|
755
|
+
protected _displayAux(node: OptNodeOrNull<NODE>, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
756
|
+
protected _DEFAULT_NODE_CALLBACK: (node: OptNodeOrNull<NODE>) => K | undefined;
|
|
752
757
|
/**
|
|
753
758
|
* Time Complexity: O(1)
|
|
754
759
|
* Space Complexity: O(1)
|
|
755
760
|
*
|
|
756
761
|
* The _swapProperties function swaps key and value properties between two nodes in a binary tree.
|
|
757
|
-
* @param {
|
|
758
|
-
* `_swapProperties` method can be either a
|
|
762
|
+
* @param {BTNRep<K, V, NODE> | R} srcNode - The `srcNode` parameter in the
|
|
763
|
+
* `_swapProperties` method can be either a BTNRep object containing key and value
|
|
759
764
|
* properties, or it can be of type R.
|
|
760
|
-
* @param {
|
|
765
|
+
* @param {BTNRep<K, V, NODE> | R} destNode - The `destNode` parameter in the
|
|
761
766
|
* `_swapProperties` method represents the node or entry where the properties will be swapped with
|
|
762
|
-
* the `srcNode`. It can be of type `
|
|
767
|
+
* the `srcNode`. It can be of type `BTNRep<K, V, NODE>` or `R`. The method ensures that
|
|
763
768
|
* both `srcNode
|
|
764
769
|
* @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
|
|
765
770
|
* with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
766
771
|
*/
|
|
767
|
-
protected _swapProperties(srcNode:
|
|
772
|
+
protected _swapProperties(srcNode: BTNRep<K, V, NODE> | R, destNode: BTNRep<K, V, NODE> | R): NODE | undefined;
|
|
768
773
|
/**
|
|
769
774
|
* Time Complexity: O(1)
|
|
770
775
|
* Space Complexity: O(1)
|
|
@@ -786,34 +791,71 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
786
791
|
*
|
|
787
792
|
* The function _setRoot sets the root node of a data structure while updating the parent reference
|
|
788
793
|
* of the previous root node.
|
|
789
|
-
* @param v - The parameter `v` in the `_setRoot` method is of type `
|
|
794
|
+
* @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<NODE>`, which means
|
|
790
795
|
* it can either be an optional `NODE` type or `null`.
|
|
791
796
|
*/
|
|
792
|
-
protected _setRoot(v:
|
|
797
|
+
protected _setRoot(v: OptNodeOrNull<NODE>): void;
|
|
793
798
|
/**
|
|
794
799
|
* Time Complexity: O(1)
|
|
795
800
|
* Space Complexity: O(1)
|
|
796
801
|
*
|
|
797
802
|
* The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
|
|
798
803
|
* predicate function for a binary tree node.
|
|
799
|
-
* @param {
|
|
804
|
+
* @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The
|
|
800
805
|
* `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
|
|
801
|
-
* parameter `
|
|
806
|
+
* parameter `keyNodeEntryRawOrPredicate` is transformed into a valid predicate function that can be
|
|
802
807
|
* used for filtering nodes in a binary tree.
|
|
803
|
-
* @returns A
|
|
808
|
+
* @returns A NodePredicate<NODE> function is being returned.
|
|
804
809
|
*/
|
|
805
|
-
protected _ensurePredicate(
|
|
810
|
+
protected _ensurePredicate(keyNodeEntryRawOrPredicate: BTNRep<K, V, NODE> | R | NodePredicate<NODE>): NodePredicate<NODE>;
|
|
806
811
|
/**
|
|
807
812
|
* Time Complexity: O(1)
|
|
808
813
|
* Space Complexity: O(1)
|
|
809
814
|
*
|
|
810
|
-
* The function `
|
|
815
|
+
* The function `_isPredicate` checks if a given parameter is a function.
|
|
811
816
|
* @param {any} p - The parameter `p` is a variable of type `any`, which means it can hold any type
|
|
812
|
-
* of value. In this context, the function `
|
|
813
|
-
* satisfies the type `
|
|
817
|
+
* of value. In this context, the function `_isPredicate` is checking if `p` is a function that
|
|
818
|
+
* satisfies the type `NodePredicate<NODE>`.
|
|
814
819
|
* @returns The function is checking if the input `p` is a function and returning a boolean value
|
|
815
820
|
* based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
|
|
816
821
|
* predicate function for a binary tree node. If `p` is not a function, it will return `false`.
|
|
817
822
|
*/
|
|
818
|
-
protected
|
|
823
|
+
protected _isPredicate(p: any): p is NodePredicate<NODE>;
|
|
824
|
+
/**
|
|
825
|
+
* Time Complexity: O(1)
|
|
826
|
+
* Space Complexity: O(1)
|
|
827
|
+
*
|
|
828
|
+
* The function `_getKey` in TypeScript returns the key from a given input, which can be a node,
|
|
829
|
+
* entry, raw data, or null/undefined.
|
|
830
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `_getKey` method you provided is a
|
|
831
|
+
* TypeScript method that takes in a parameter `keyNodeEntryOrRaw` of type `BTNRep<K, V, NODE> | R`,
|
|
832
|
+
* where `BTNRep` is a generic type with keys `K`, `V`, and `NODE`, and `
|
|
833
|
+
* @returns The `_getKey` method returns the key value extracted from the `keyNodeEntryOrRaw`
|
|
834
|
+
* parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
|
|
835
|
+
* the conditions checked in the method.
|
|
836
|
+
*/
|
|
837
|
+
protected _getKey(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): K | null | undefined;
|
|
838
|
+
/**
|
|
839
|
+
* Time Complexity: O(1)
|
|
840
|
+
* Space Complexity: O(1)
|
|
841
|
+
*
|
|
842
|
+
* The function `_setValue` sets a value in a store based on a key, handling cases where the key or
|
|
843
|
+
* value is null or undefined.
|
|
844
|
+
* @param {K | null | undefined} key - The `key` parameter can be of type `K`, `null`, or
|
|
845
|
+
* `undefined`.
|
|
846
|
+
* @param {V | undefined} value - The `value` parameter in the `_setValue` method can be of type `V`
|
|
847
|
+
* or `undefined`.
|
|
848
|
+
* @returns The method `_setValue` returns `false` if either the `key` is `null` or `undefined`, or
|
|
849
|
+
* if the `value` is `undefined`. Otherwise, it returns the result of calling the `set` method on the
|
|
850
|
+
* `_store` object with the `key` and `value` arguments.
|
|
851
|
+
*/
|
|
852
|
+
protected _setValue(key: K | null | undefined, value: V | undefined): false | Map<K, V | undefined>;
|
|
853
|
+
/**
|
|
854
|
+
* The _clearNodes function sets the root node to undefined and resets the size to 0.
|
|
855
|
+
*/
|
|
856
|
+
protected _clearNodes(): void;
|
|
857
|
+
/**
|
|
858
|
+
* The _clearValues function clears all values stored in the _store object.
|
|
859
|
+
*/
|
|
860
|
+
protected _clearValues(): void;
|
|
819
861
|
}
|