directed-graph-typed 1.49.5 → 1.49.7
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 +53 -48
- package/dist/data-structures/binary-tree/avl-tree.js +55 -49
- package/dist/data-structures/binary-tree/binary-tree.d.ts +153 -130
- package/dist/data-structures/binary-tree/binary-tree.js +194 -153
- package/dist/data-structures/binary-tree/bst.d.ts +83 -71
- package/dist/data-structures/binary-tree/bst.js +114 -91
- package/dist/data-structures/binary-tree/rb-tree.d.ts +37 -35
- package/dist/data-structures/binary-tree/rb-tree.js +62 -59
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +46 -39
- package/dist/data-structures/binary-tree/tree-multimap.js +58 -51
- package/dist/data-structures/hash/hash-map.d.ts +24 -27
- package/dist/data-structures/hash/hash-map.js +35 -35
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -1
- package/dist/data-structures/heap/heap.d.ts +2 -1
- package/dist/data-structures/heap/heap.js +13 -13
- package/dist/data-structures/heap/max-heap.js +1 -1
- package/dist/data-structures/heap/min-heap.js +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +1 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +1 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -8
- package/dist/data-structures/linked-list/skip-linked-list.js +15 -18
- package/dist/data-structures/matrix/matrix.d.ts +2 -7
- package/dist/data-structures/matrix/matrix.js +0 -7
- package/dist/data-structures/priority-queue/max-priority-queue.js +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +1 -1
- package/dist/data-structures/queue/deque.d.ts +2 -11
- package/dist/data-structures/queue/deque.js +9 -13
- package/dist/data-structures/queue/queue.d.ts +13 -13
- package/dist/data-structures/queue/queue.js +29 -25
- package/dist/data-structures/stack/stack.js +2 -3
- package/dist/data-structures/trie/trie.d.ts +2 -2
- package/dist/data-structures/trie/trie.js +9 -5
- package/dist/interfaces/binary-tree.d.ts +3 -3
- package/dist/types/common.d.ts +3 -3
- package/dist/types/common.js +2 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +5 -2
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/index.js +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/types/data-structures/linked-list/index.d.ts +1 -0
- package/dist/types/data-structures/linked-list/index.js +1 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
- package/dist/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/types/data-structures/matrix/index.js +1 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +7 -1
- package/dist/types/data-structures/queue/deque.d.ts +3 -1
- package/dist/types/data-structures/trie/trie.d.ts +3 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +58 -53
- package/src/data-structures/binary-tree/binary-tree.ts +255 -211
- package/src/data-structures/binary-tree/bst.ts +126 -107
- package/src/data-structures/binary-tree/rb-tree.ts +66 -64
- package/src/data-structures/binary-tree/tree-multimap.ts +62 -56
- package/src/data-structures/hash/hash-map.ts +46 -50
- package/src/data-structures/hash/index.ts +0 -1
- package/src/data-structures/heap/heap.ts +20 -19
- package/src/data-structures/heap/max-heap.ts +1 -1
- package/src/data-structures/heap/min-heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -5
- package/src/data-structures/linked-list/skip-linked-list.ts +15 -16
- package/src/data-structures/matrix/matrix.ts +2 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/data-structures/queue/deque.ts +11 -15
- package/src/data-structures/queue/queue.ts +29 -28
- package/src/data-structures/stack/stack.ts +3 -6
- package/src/data-structures/trie/trie.ts +10 -11
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +6 -2
- package/src/types/data-structures/hash/index.ts +0 -1
- package/src/types/data-structures/heap/heap.ts +1 -1
- package/src/types/data-structures/linked-list/index.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -1
- package/src/types/data-structures/matrix/index.ts +1 -0
- package/src/types/data-structures/matrix/matrix.ts +7 -1
- package/src/types/data-structures/queue/deque.ts +1 -1
- package/src/types/data-structures/trie/trie.ts +1 -1
- package/dist/data-structures/hash/hash-table.d.ts +0 -108
- package/dist/data-structures/hash/hash-table.js +0 -281
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/hash-table.js +0 -2
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -1
- package/dist/types/data-structures/matrix/matrix2d.js +0 -2
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -1
- package/dist/types/data-structures/matrix/vector2d.js +0 -2
- package/src/data-structures/hash/hash-table.ts +0 -318
- package/src/types/data-structures/hash/hash-table.ts +0 -1
- package/src/types/data-structures/matrix/matrix2d.ts +0 -1
- package/src/types/data-structures/matrix/vector2d.ts +0 -1
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry,
|
|
8
|
+
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, DFSOrderPattern, EntryCallback, KeyOrNodeOrEntry, NodeDisplayLayout } from '../../types';
|
|
9
9
|
import { FamilyPosition, IterationType } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { IterableEntryBase } from '../base';
|
|
@@ -41,15 +41,15 @@ export declare class BinaryTreeNode<K = any, V = any, N extends BinaryTreeNode<K
|
|
|
41
41
|
export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTree<K, V, N, BinaryTreeNested<K, V, N>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, N, TREE> {
|
|
42
42
|
iterationType: IterationType;
|
|
43
43
|
/**
|
|
44
|
-
* The constructor function initializes a binary tree object with optional
|
|
45
|
-
* @param [
|
|
46
|
-
*
|
|
44
|
+
* The constructor function initializes a binary tree object with optional keysOrNodesOrEntries and options.
|
|
45
|
+
* @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
|
|
46
|
+
* nodes to be added to the binary tree.
|
|
47
47
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
48
48
|
* configuration options for the binary tree. In this case, it is of type
|
|
49
49
|
* `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
|
|
50
50
|
* required.
|
|
51
51
|
*/
|
|
52
|
-
constructor(
|
|
52
|
+
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: BinaryTreeOptions<K>);
|
|
53
53
|
protected _extractor: (key: K) => number;
|
|
54
54
|
get extractor(): (key: K) => number;
|
|
55
55
|
protected _root?: N | null;
|
|
@@ -72,27 +72,76 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
72
72
|
*/
|
|
73
73
|
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
74
74
|
/**
|
|
75
|
-
* The function
|
|
76
|
-
* @param
|
|
77
|
-
* @returns a boolean value indicating whether the exemplar is an instance of the class N.
|
|
78
|
-
*/
|
|
79
|
-
isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
|
|
80
|
-
/**
|
|
81
|
-
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
82
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
|
|
75
|
+
* The function `exemplarToNode` converts an keyOrNodeOrEntry object into a node object.
|
|
76
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
|
|
83
77
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
84
|
-
* `exemplarToNode` function. It represents the value associated with the
|
|
78
|
+
* `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If no value
|
|
85
79
|
* is provided, it will be `undefined`.
|
|
86
80
|
* @returns a value of type N (node), or null, or undefined.
|
|
87
81
|
*/
|
|
88
|
-
exemplarToNode(
|
|
82
|
+
exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | null | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Time Complexity: O(n)
|
|
85
|
+
* Space Complexity: O(log n)
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* Time Complexity: O(n)
|
|
89
|
+
* Space Complexity: O(log n)
|
|
90
|
+
*
|
|
91
|
+
* The function `ensureNode` returns the node corresponding to the given key if it is a valid node
|
|
92
|
+
* key, otherwise it returns the key itself.
|
|
93
|
+
* @param {K | N | null | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`,
|
|
94
|
+
* `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
|
|
95
|
+
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
96
|
+
* type of iteration to be used when searching for a node by key. It has a default value of
|
|
97
|
+
* `IterationType.ITERATIVE`.
|
|
98
|
+
* @returns either the node corresponding to the given key if it is a valid node key, or the key
|
|
99
|
+
* itself if it is not a valid node key.
|
|
100
|
+
*/
|
|
101
|
+
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.
|
|
104
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,N>`.
|
|
105
|
+
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the class N.
|
|
106
|
+
*/
|
|
107
|
+
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
|
|
89
108
|
/**
|
|
90
109
|
* The function checks if a given value is an entry in a binary tree node.
|
|
91
|
-
* @param
|
|
110
|
+
* @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,N> - A generic type representing a node in a binary tree. It has
|
|
92
111
|
* two type parameters V and N, representing the value and node type respectively.
|
|
93
112
|
* @returns a boolean value.
|
|
94
113
|
*/
|
|
95
|
-
isEntry(
|
|
114
|
+
isEntry(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is BTNEntry<K, V>;
|
|
115
|
+
/**
|
|
116
|
+
* Time complexity: O(n)
|
|
117
|
+
* Space complexity: O(log n)
|
|
118
|
+
*/
|
|
119
|
+
/**
|
|
120
|
+
* The function checks if a given node is a real node by verifying if it is an instance of
|
|
121
|
+
* BinaryTreeNode and its key is not NaN.
|
|
122
|
+
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
123
|
+
* @returns a boolean value.
|
|
124
|
+
*/
|
|
125
|
+
isRealNode(node: KeyOrNodeOrEntry<K, V, N>): node is N;
|
|
126
|
+
/**
|
|
127
|
+
* The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
|
|
128
|
+
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
129
|
+
* @returns a boolean value.
|
|
130
|
+
*/
|
|
131
|
+
isNIL(node: KeyOrNodeOrEntry<K, V, N>): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* The function checks if a given node is a real node or null.
|
|
134
|
+
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
135
|
+
* @returns a boolean value.
|
|
136
|
+
*/
|
|
137
|
+
isNodeOrNull(node: KeyOrNodeOrEntry<K, V, N>): node is N | null;
|
|
138
|
+
/**
|
|
139
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
140
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
141
|
+
* data type.
|
|
142
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
143
|
+
*/
|
|
144
|
+
isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
|
|
96
145
|
/**
|
|
97
146
|
* Time Complexity O(log n) - O(n)
|
|
98
147
|
* Space Complexity O(1)
|
|
@@ -107,7 +156,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
107
156
|
* @param {V} [value] - The value to be inserted into the binary tree.
|
|
108
157
|
* @returns The function `add` returns either a node (`N`), `null`, or `undefined`.
|
|
109
158
|
*/
|
|
110
|
-
add(keyOrNodeOrEntry:
|
|
159
|
+
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
|
|
111
160
|
/**
|
|
112
161
|
* Time Complexity: O(k log n) - O(k * n)
|
|
113
162
|
* Space Complexity: O(1)
|
|
@@ -117,21 +166,35 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
117
166
|
* Time Complexity: O(k log n) - O(k * n)
|
|
118
167
|
* Space Complexity: O(1)
|
|
119
168
|
*
|
|
120
|
-
* The `addMany` function takes in a collection of
|
|
169
|
+
* The `addMany` function takes in a collection of keysOrNodesOrEntries and an optional collection of values, and
|
|
121
170
|
* adds each node with its corresponding value to the data structure.
|
|
122
|
-
* @param
|
|
171
|
+
* @param keysOrNodesOrEntries - An iterable collection of KeyOrNodeOrEntry objects.
|
|
123
172
|
* @param [values] - An optional iterable of values that will be assigned to each node being added.
|
|
124
173
|
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
125
174
|
*/
|
|
126
|
-
addMany(
|
|
175
|
+
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>, values?: Iterable<V | undefined>): boolean[];
|
|
127
176
|
/**
|
|
128
|
-
* Time Complexity: O(k * n)
|
|
177
|
+
* Time Complexity: O(k * n)
|
|
129
178
|
* Space Complexity: O(1)
|
|
179
|
+
* "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
130
180
|
*/
|
|
131
|
-
refill(nodesOrKeysOrEntries: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>): void;
|
|
132
181
|
/**
|
|
133
|
-
* Time Complexity: O(k * n)
|
|
182
|
+
* Time Complexity: O(k * n)
|
|
134
183
|
* Space Complexity: O(1)
|
|
184
|
+
*
|
|
185
|
+
* The `refill` function clears the current data and adds new key-value pairs to the data structure.
|
|
186
|
+
* @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries. These can be of type
|
|
187
|
+
* KeyOrNodeOrEntry<K, V, N>.
|
|
188
|
+
* @param [values] - The `values` parameter is an optional iterable that contains the values to be
|
|
189
|
+
* associated with the keys or nodes or entries in the `keysOrNodesOrEntries` parameter. If provided,
|
|
190
|
+
* the values will be associated with the corresponding keys or nodes or entries in the
|
|
191
|
+
* `keysOrNodesOrEntries` iterable
|
|
192
|
+
*/
|
|
193
|
+
refill(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>, values?: Iterable<V | undefined>): void;
|
|
194
|
+
/**
|
|
195
|
+
* Time Complexity: O(k * n)
|
|
196
|
+
* Space Complexity: O(1)
|
|
197
|
+
* "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
135
198
|
*/
|
|
136
199
|
delete<C extends BTNCallback<N, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<N>[];
|
|
137
200
|
delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BinaryTreeDeleteResult<N>[];
|
|
@@ -145,15 +208,15 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
145
208
|
* Space Complexity: O(1)
|
|
146
209
|
*
|
|
147
210
|
* The function calculates the depth of a given node in a binary tree.
|
|
148
|
-
* @param {K | N | null | undefined}
|
|
211
|
+
* @param {K | N | null | undefined} dist - The `dist` parameter represents the node in
|
|
149
212
|
* the binary tree whose depth we want to find. It can be of type `K`, `N`, `null`, or
|
|
150
213
|
* `undefined`.
|
|
151
214
|
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
152
215
|
* from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
|
|
153
216
|
* `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
|
|
154
|
-
* @returns the depth of the `
|
|
217
|
+
* @returns the depth of the `dist` relative to the `beginRoot`.
|
|
155
218
|
*/
|
|
156
|
-
getDepth(
|
|
219
|
+
getDepth(dist: KeyOrNodeOrEntry<K, V, N>, beginRoot?: KeyOrNodeOrEntry<K, V, N>): number;
|
|
157
220
|
/**
|
|
158
221
|
* Time Complexity: O(n)
|
|
159
222
|
* Space Complexity: O(1)
|
|
@@ -172,7 +235,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
172
235
|
* values:
|
|
173
236
|
* @returns the height of the binary tree.
|
|
174
237
|
*/
|
|
175
|
-
getHeight(beginRoot?:
|
|
238
|
+
getHeight(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): number;
|
|
176
239
|
/**
|
|
177
240
|
* Time Complexity: O(n)
|
|
178
241
|
* Space Complexity: O(log n)
|
|
@@ -191,7 +254,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
191
254
|
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
192
255
|
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
193
256
|
*/
|
|
194
|
-
getMinHeight(beginRoot?:
|
|
257
|
+
getMinHeight(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): number;
|
|
195
258
|
/**
|
|
196
259
|
* Time Complexity: O(n)
|
|
197
260
|
* Space Complexity: O(log n)
|
|
@@ -208,28 +271,28 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
208
271
|
* value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
|
|
209
272
|
* @returns a boolean value.
|
|
210
273
|
*/
|
|
211
|
-
isPerfectlyBalanced(beginRoot?:
|
|
274
|
+
isPerfectlyBalanced(beginRoot?: KeyOrNodeOrEntry<K, V, N>): boolean;
|
|
212
275
|
/**
|
|
213
276
|
* Time Complexity: O(n)
|
|
214
277
|
* Space Complexity: O(log n)
|
|
215
278
|
*/
|
|
216
|
-
getNodes<C extends BTNCallback<N, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?:
|
|
217
|
-
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?:
|
|
218
|
-
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?:
|
|
279
|
+
getNodes<C extends BTNCallback<N, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
|
|
280
|
+
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
|
|
281
|
+
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N[];
|
|
219
282
|
/**
|
|
220
283
|
* Time Complexity: O(n)
|
|
221
284
|
* Space Complexity: O(log n).
|
|
222
285
|
*/
|
|
223
|
-
has<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?:
|
|
224
|
-
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?:
|
|
225
|
-
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?:
|
|
286
|
+
has<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
|
|
287
|
+
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
|
|
288
|
+
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
|
|
226
289
|
/**
|
|
227
290
|
* Time Complexity: O(n)
|
|
228
291
|
* Space Complexity: O(log n).
|
|
229
292
|
*/
|
|
230
|
-
getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?:
|
|
231
|
-
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?:
|
|
232
|
-
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?:
|
|
293
|
+
getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
|
|
294
|
+
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
|
|
295
|
+
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
|
|
233
296
|
/**
|
|
234
297
|
* Time Complexity: O(n)
|
|
235
298
|
* Space Complexity: O(log n)
|
|
@@ -249,34 +312,28 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
249
312
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
250
313
|
*/
|
|
251
314
|
getNodeByKey(key: K, iterationType?: IterationType): N | undefined;
|
|
315
|
+
get<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): V | undefined;
|
|
316
|
+
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): V | undefined;
|
|
317
|
+
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): V | undefined;
|
|
252
318
|
/**
|
|
253
|
-
* Time Complexity: O(
|
|
254
|
-
* Space Complexity: O(
|
|
255
|
-
*/
|
|
256
|
-
/**
|
|
257
|
-
* The function `ensureNode` returns the node corresponding to the given key if it is a valid node
|
|
258
|
-
* key, otherwise it returns the key itself.
|
|
259
|
-
* @param {K | N | null | undefined} key - The `key` parameter can be of type `K`, `N`,
|
|
260
|
-
* `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
|
|
261
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
262
|
-
* type of iteration to be used when searching for a node by key. It has a default value of
|
|
263
|
-
* `IterationType.ITERATIVE`.
|
|
264
|
-
* @returns either the node corresponding to the given key if it is a valid node key, or the key
|
|
265
|
-
* itself if it is not a valid node key.
|
|
266
|
-
*/
|
|
267
|
-
ensureNode(key: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
268
|
-
get<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
269
|
-
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
270
|
-
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
271
|
-
/**
|
|
272
|
-
* Time Complexity: O(n)
|
|
273
|
-
* Space Complexity: O(log n)
|
|
319
|
+
* Time Complexity: O(1)
|
|
320
|
+
* Space Complexity: O(1)
|
|
274
321
|
*/
|
|
275
322
|
/**
|
|
323
|
+
* Time Complexity: O(1)
|
|
324
|
+
* Space Complexity: O(1)
|
|
325
|
+
*
|
|
276
326
|
* Clear the binary tree, removing all nodes.
|
|
277
327
|
*/
|
|
278
328
|
clear(): void;
|
|
279
329
|
/**
|
|
330
|
+
* Time Complexity: O(1)
|
|
331
|
+
* Space Complexity: O(1)
|
|
332
|
+
*/
|
|
333
|
+
/**
|
|
334
|
+
* Time Complexity: O(1)
|
|
335
|
+
* Space Complexity: O(1)
|
|
336
|
+
*
|
|
280
337
|
* Check if the binary tree is empty.
|
|
281
338
|
* @returns {boolean} - True if the binary tree is empty, false otherwise.
|
|
282
339
|
*/
|
|
@@ -295,10 +352,10 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
295
352
|
* reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
|
|
296
353
|
* @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
|
|
297
354
|
*/
|
|
298
|
-
getPathToRoot(beginRoot:
|
|
355
|
+
getPathToRoot(beginRoot: KeyOrNodeOrEntry<K, V, N>, isReverse?: boolean): N[];
|
|
299
356
|
/**
|
|
300
357
|
* Time Complexity: O(log n)
|
|
301
|
-
* Space Complexity: O(
|
|
358
|
+
* Space Complexity: O(1)
|
|
302
359
|
*/
|
|
303
360
|
/**
|
|
304
361
|
* Time Complexity: O(log n)
|
|
@@ -314,7 +371,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
314
371
|
* @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
|
|
315
372
|
* is no leftmost node, it returns `null` or `undefined` depending on the input.
|
|
316
373
|
*/
|
|
317
|
-
getLeftMost(beginRoot?:
|
|
374
|
+
getLeftMost(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
|
|
318
375
|
/**
|
|
319
376
|
* Time Complexity: O(log n)
|
|
320
377
|
* Space Complexity: O(1)
|
|
@@ -334,7 +391,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
334
391
|
* @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
|
|
335
392
|
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
|
|
336
393
|
*/
|
|
337
|
-
getRightMost(beginRoot?:
|
|
394
|
+
getRightMost(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): N | null | undefined;
|
|
338
395
|
/**
|
|
339
396
|
* Time Complexity: O(log n)
|
|
340
397
|
* Space Complexity: O(1)
|
|
@@ -351,77 +408,31 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
351
408
|
* possible values:
|
|
352
409
|
* @returns a boolean value.
|
|
353
410
|
*/
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Time Complexity: O(n)
|
|
357
|
-
* Space Complexity: O(1)
|
|
358
|
-
*/
|
|
359
|
-
/**
|
|
360
|
-
* Time Complexity: O(n)
|
|
361
|
-
* Space Complexity: O(1)
|
|
362
|
-
*
|
|
363
|
-
* The function checks if a binary tree is a binary search tree.
|
|
364
|
-
* @param iterationType - The parameter "iterationType" is used to specify the type of iteration to
|
|
365
|
-
* be used when checking if the binary tree is a binary search tree (BST). It is an optional
|
|
366
|
-
* parameter with a default value of "this.iterationType". The value of "this.iterationType" is
|
|
367
|
-
* expected to be
|
|
368
|
-
* @returns a boolean value.
|
|
369
|
-
*/
|
|
370
|
-
isBST(iterationType?: IterationType): boolean;
|
|
371
|
-
/**
|
|
372
|
-
* Time Complexity: O(n)
|
|
373
|
-
* Space Complexity: O(1)
|
|
374
|
-
*/
|
|
375
|
-
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
376
|
-
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
377
|
-
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
411
|
+
isBST(beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType): boolean;
|
|
378
412
|
/**
|
|
379
413
|
* Time complexity: O(n)
|
|
380
414
|
* Space complexity: O(log n)
|
|
381
415
|
*/
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
isRealNode(node: BTNExemplar<K, V, N>): node is N;
|
|
389
|
-
/**
|
|
390
|
-
* The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
|
|
391
|
-
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
392
|
-
* @returns a boolean value.
|
|
393
|
-
*/
|
|
394
|
-
isNIL(node: BTNExemplar<K, V, N>): boolean;
|
|
395
|
-
/**
|
|
396
|
-
* The function checks if a given node is a real node or null.
|
|
397
|
-
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
398
|
-
* @returns a boolean value.
|
|
399
|
-
*/
|
|
400
|
-
isNodeOrNull(node: BTNExemplar<K, V, N>): node is N | null;
|
|
401
|
-
/**
|
|
402
|
-
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
403
|
-
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
404
|
-
* data type.
|
|
405
|
-
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
406
|
-
*/
|
|
407
|
-
isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
|
|
408
|
-
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
409
|
-
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
410
|
-
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
416
|
+
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
417
|
+
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
418
|
+
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
419
|
+
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
420
|
+
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
421
|
+
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
411
422
|
/**
|
|
412
423
|
* Time complexity: O(n)
|
|
413
424
|
* Space complexity: O(n)
|
|
414
425
|
*/
|
|
415
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?:
|
|
416
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?:
|
|
417
|
-
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?:
|
|
426
|
+
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
427
|
+
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
428
|
+
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
418
429
|
/**
|
|
419
430
|
* Time complexity: O(n)
|
|
420
431
|
* Space complexity: O(n)
|
|
421
432
|
*/
|
|
422
|
-
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?:
|
|
423
|
-
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?:
|
|
424
|
-
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?:
|
|
433
|
+
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
434
|
+
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
|
|
435
|
+
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
425
436
|
/**
|
|
426
437
|
* Time Complexity: O(log n)
|
|
427
438
|
* Space Complexity: O(1)
|
|
@@ -445,7 +456,12 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
445
456
|
getSuccessor(x?: K | N | null): N | null | undefined;
|
|
446
457
|
/**
|
|
447
458
|
* Time complexity: O(n)
|
|
448
|
-
* Space complexity: O(
|
|
459
|
+
* Space complexity: O(n)
|
|
460
|
+
*/
|
|
461
|
+
/**
|
|
462
|
+
* Time complexity: O(n)
|
|
463
|
+
* Space complexity: O(n)
|
|
464
|
+
*
|
|
449
465
|
* The `morris` function performs a depth-first traversal on a binary tree using the Morris traversal
|
|
450
466
|
* algorithm.
|
|
451
467
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
@@ -458,10 +474,10 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
458
474
|
* for the traversal. It can be specified as a key, a node object, or `null`/`undefined` to indicate
|
|
459
475
|
* the root of the tree. If no value is provided, the default value is the root of the tree.
|
|
460
476
|
* @returns The function `morris` returns an array of values that are the result of invoking the
|
|
461
|
-
* `callback` function on each node in the binary tree. The type of the array
|
|
477
|
+
* `callback` function on each node in the binary tree. The type of the array nodes is determined
|
|
462
478
|
* by the return type of the `callback` function.
|
|
463
479
|
*/
|
|
464
|
-
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?:
|
|
480
|
+
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, N>): ReturnType<C>[];
|
|
465
481
|
/**
|
|
466
482
|
* Time complexity: O(n)
|
|
467
483
|
* Space complexity: O(n)
|
|
@@ -483,8 +499,8 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
483
499
|
* Time Complexity: O(n)
|
|
484
500
|
* Space Complexity: O(n)
|
|
485
501
|
*
|
|
486
|
-
* The `filter` function creates a new tree by iterating over the
|
|
487
|
-
* adding only the
|
|
502
|
+
* The `filter` function creates a new tree by iterating over the nodes of the current tree and
|
|
503
|
+
* adding only the nodes that satisfy the given predicate function.
|
|
488
504
|
* @param predicate - The `predicate` parameter is a function that takes three arguments: `value`,
|
|
489
505
|
* `key`, and `index`. It should return a boolean value indicating whether the pair should be
|
|
490
506
|
* included in the filtered tree or not.
|
|
@@ -516,13 +532,20 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
516
532
|
*/
|
|
517
533
|
map(callback: EntryCallback<K, V | undefined, V>, thisArg?: any): TREE;
|
|
518
534
|
/**
|
|
535
|
+
* Time Complexity: O(n)
|
|
536
|
+
* Space Complexity: O(n)
|
|
537
|
+
*/
|
|
538
|
+
/**
|
|
539
|
+
* Time Complexity: O(n)
|
|
540
|
+
* Space Complexity: O(n)
|
|
541
|
+
*
|
|
519
542
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
520
543
|
* @param {K | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | N | null |
|
|
521
544
|
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
522
545
|
* following types:
|
|
523
546
|
* @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes.
|
|
524
547
|
*/
|
|
525
|
-
print(beginRoot?:
|
|
548
|
+
print(beginRoot?: KeyOrNodeOrEntry<K, V, N>, options?: BinaryTreePrintOptions): void;
|
|
526
549
|
protected _getIterator(node?: N | null | undefined): IterableIterator<[K, V | undefined]>;
|
|
527
550
|
protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
528
551
|
protected _defaultOneParamCallback: (node: N | null | undefined) => K | undefined;
|
|
@@ -532,7 +555,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
532
555
|
* @param {N} destNode - The destination node to swap.
|
|
533
556
|
* @returns {N} - The destination node after the swap.
|
|
534
557
|
*/
|
|
535
|
-
protected _swapProperties(srcNode:
|
|
558
|
+
protected _swapProperties(srcNode: KeyOrNodeOrEntry<K, V, N>, destNode: KeyOrNodeOrEntry<K, V, N>): N | undefined;
|
|
536
559
|
/**
|
|
537
560
|
* The function replaces an old node with a new node in a binary tree.
|
|
538
561
|
* @param {N} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|