min-heap-typed 1.50.1 → 1.50.3
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/base/iterable-base.d.ts +120 -9
- package/dist/data-structures/base/iterable-base.js +143 -7
- package/dist/data-structures/binary-tree/avl-tree.d.ts +72 -47
- package/dist/data-structures/binary-tree/avl-tree.js +101 -72
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/data-structures/binary-tree/binary-tree.js +484 -376
- package/dist/data-structures/binary-tree/bst.d.ts +92 -79
- package/dist/data-structures/binary-tree/bst.js +68 -76
- package/dist/data-structures/binary-tree/rb-tree.d.ts +127 -57
- package/dist/data-structures/binary-tree/rb-tree.js +152 -99
- package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +72 -58
- package/dist/data-structures/binary-tree/tree-multimap.js +102 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +1 -78
- package/dist/data-structures/graph/abstract-graph.js +3 -189
- package/dist/data-structures/graph/directed-graph.d.ts +73 -0
- package/dist/data-structures/graph/directed-graph.js +131 -0
- package/dist/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/data-structures/graph/map-graph.js +14 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +76 -7
- package/dist/data-structures/graph/undirected-graph.js +151 -18
- package/dist/data-structures/hash/hash-map.d.ts +254 -28
- package/dist/data-structures/hash/hash-map.js +347 -78
- package/dist/data-structures/heap/heap.d.ts +95 -25
- package/dist/data-structures/heap/heap.js +95 -26
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
- package/dist/data-structures/linked-list/doubly-linked-list.js +141 -77
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +154 -106
- package/dist/data-structures/linked-list/singly-linked-list.js +164 -115
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/data-structures/matrix/matrix.js +50 -11
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/data-structures/queue/deque.d.ts +139 -35
- package/dist/data-structures/queue/deque.js +200 -62
- package/dist/data-structures/queue/queue.d.ts +103 -49
- package/dist/data-structures/queue/queue.js +111 -49
- package/dist/data-structures/stack/stack.d.ts +51 -21
- package/dist/data-structures/stack/stack.js +58 -22
- package/dist/data-structures/tree/tree.d.ts +57 -3
- package/dist/data-structures/tree/tree.js +77 -11
- package/dist/data-structures/trie/trie.d.ts +135 -34
- package/dist/data-structures/trie/trie.js +153 -33
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/types/utils/utils.d.ts +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +184 -19
- package/src/data-structures/binary-tree/avl-tree.ts +134 -100
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +674 -671
- package/src/data-structures/binary-tree/bst.ts +127 -136
- package/src/data-structures/binary-tree/rb-tree.ts +199 -166
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multimap.ts +138 -115
- package/src/data-structures/graph/abstract-graph.ts +4 -211
- package/src/data-structures/graph/directed-graph.ts +152 -0
- package/src/data-structures/graph/map-graph.ts +15 -0
- package/src/data-structures/graph/undirected-graph.ts +171 -19
- package/src/data-structures/hash/hash-map.ts +389 -96
- package/src/data-structures/heap/heap.ts +97 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +156 -83
- package/src/data-structures/linked-list/singly-linked-list.ts +174 -120
- package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
- package/src/data-structures/matrix/matrix.ts +52 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +225 -70
- package/src/data-structures/queue/queue.ts +118 -49
- package/src/data-structures/stack/stack.ts +63 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +173 -38
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +4 -3
- package/src/types/utils/utils.ts +2 -0
|
@@ -9,29 +9,34 @@ import type { BSTNested, BSTNodeNested, BSTOptions, BTNCallback, KeyOrNodeOrEntr
|
|
|
9
9
|
import { BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
|
|
10
10
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
|
-
export declare class BSTNode<K = any, V = any,
|
|
13
|
-
parent?:
|
|
12
|
+
export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
|
|
13
|
+
parent?: NODE;
|
|
14
14
|
constructor(key: K, value?: V);
|
|
15
|
-
protected _left?:
|
|
15
|
+
protected _left?: NODE;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* The function returns the value of the `_left` property.
|
|
18
|
+
* @returns The `_left` property of the current object is being returned.
|
|
18
19
|
*/
|
|
19
|
-
get left():
|
|
20
|
+
get left(): NODE | undefined;
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @param {
|
|
22
|
+
* The function sets the left child of a node and updates the parent reference of the child.
|
|
23
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be an
|
|
24
|
+
* instance of the `NODE` class or `undefined`.
|
|
23
25
|
*/
|
|
24
|
-
set left(v:
|
|
25
|
-
protected _right?:
|
|
26
|
+
set left(v: NODE | undefined);
|
|
27
|
+
protected _right?: NODE;
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
29
|
+
* The function returns the right node of a binary tree or undefined if there is no right node.
|
|
30
|
+
* @returns The method is returning the value of the `_right` property, which is of type `NODE` or
|
|
31
|
+
* `undefined`.
|
|
28
32
|
*/
|
|
29
|
-
get right():
|
|
33
|
+
get right(): NODE | undefined;
|
|
30
34
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @param {
|
|
35
|
+
* The function sets the right child of a node and updates the parent reference of the child.
|
|
36
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be a
|
|
37
|
+
* `NODE` object or `undefined`.
|
|
33
38
|
*/
|
|
34
|
-
set right(v:
|
|
39
|
+
set right(v: NODE | undefined);
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
37
42
|
* 1. Node Order: Each node's left child has a lesser value, and the right child has a greater value.
|
|
@@ -42,50 +47,58 @@ export declare class BSTNode<K = any, V = any, N extends BSTNode<K, V, N> = BSTN
|
|
|
42
47
|
* 6. Balance Variability: Can become unbalanced; special types maintain balance.
|
|
43
48
|
* 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
|
|
44
49
|
*/
|
|
45
|
-
export declare class BST<K = any, V = any,
|
|
50
|
+
export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, NODE, TREE> = BST<K, V, NODE, BSTNested<K, V, NODE>>> extends BinaryTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
|
|
46
51
|
/**
|
|
47
|
-
* This is the constructor function for a
|
|
48
|
-
*
|
|
49
|
-
* @param
|
|
50
|
-
* binary search tree.
|
|
52
|
+
* This is the constructor function for a TypeScript class that initializes a binary search tree with
|
|
53
|
+
* optional keys or nodes or entries and options.
|
|
54
|
+
* @param keysOrNodesOrEntries - An iterable object that contains keys, nodes, or entries. It is used
|
|
55
|
+
* to initialize the binary search tree with the provided keys, nodes, or entries.
|
|
51
56
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
52
57
|
* configuration options for the binary search tree. It can have the following properties:
|
|
53
58
|
*/
|
|
54
|
-
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V,
|
|
55
|
-
protected _root?:
|
|
56
|
-
|
|
59
|
+
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: BSTOptions<K>);
|
|
60
|
+
protected _root?: NODE;
|
|
61
|
+
/**
|
|
62
|
+
* The function returns the root node of a tree structure.
|
|
63
|
+
* @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
|
|
64
|
+
*/
|
|
65
|
+
get root(): NODE | undefined;
|
|
57
66
|
protected _variant: BSTVariant;
|
|
67
|
+
/**
|
|
68
|
+
* The function returns the value of the _variant property.
|
|
69
|
+
* @returns The value of the `_variant` property.
|
|
70
|
+
*/
|
|
58
71
|
get variant(): BSTVariant;
|
|
59
72
|
/**
|
|
60
|
-
* The function creates a new
|
|
61
|
-
* @param {K} key - The key parameter is the
|
|
62
|
-
*
|
|
63
|
-
* @param [value] - The parameter
|
|
64
|
-
*
|
|
65
|
-
* @returns a new instance of the BSTNode class
|
|
73
|
+
* The function creates a new BSTNode with the given key and value and returns it.
|
|
74
|
+
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
75
|
+
* being created.
|
|
76
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
77
|
+
* value associated with the key in the node being created.
|
|
78
|
+
* @returns The method is returning a new instance of the BSTNode class, casted as the NODE type.
|
|
66
79
|
*/
|
|
67
|
-
createNode(key: K, value?: V):
|
|
80
|
+
createNode(key: K, value?: V): NODE;
|
|
68
81
|
/**
|
|
69
82
|
* The function creates a new binary search tree with the specified options.
|
|
70
83
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
71
|
-
* behavior of the `createTree` method. It
|
|
72
|
-
*
|
|
73
|
-
* @returns a new instance of the BST class with the
|
|
84
|
+
* behavior of the `createTree` method. It is of type `Partial<BSTOptions<K>>`, which means it is a
|
|
85
|
+
* partial object of type `BSTOptions<K>`.
|
|
86
|
+
* @returns a new instance of the BST class, with the provided options merged with the default
|
|
87
|
+
* options. The returned value is casted as TREE.
|
|
74
88
|
*/
|
|
75
89
|
createTree(options?: Partial<BSTOptions<K>>): TREE;
|
|
76
90
|
/**
|
|
77
|
-
* The function `
|
|
91
|
+
* The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
|
|
78
92
|
* otherwise it returns undefined.
|
|
79
|
-
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V,
|
|
93
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
|
|
80
94
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
81
|
-
* `
|
|
82
|
-
* @returns a node of type
|
|
95
|
+
* `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
|
|
96
|
+
* @returns a node of type NODE or undefined.
|
|
83
97
|
*/
|
|
84
|
-
|
|
98
|
+
keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
|
|
85
99
|
/**
|
|
86
100
|
* Time Complexity: O(log n)
|
|
87
101
|
* Space Complexity: O(log n)
|
|
88
|
-
* Average case for a balanced tree. Space for the recursive call stack in the worst case.
|
|
89
102
|
*/
|
|
90
103
|
/**
|
|
91
104
|
* Time Complexity: O(log n)
|
|
@@ -93,23 +106,22 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
93
106
|
*
|
|
94
107
|
* The function `ensureNode` returns the node corresponding to the given key if it is a node key,
|
|
95
108
|
* otherwise it returns the key itself.
|
|
96
|
-
* @param {K |
|
|
109
|
+
* @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
|
|
97
110
|
* `undefined`.
|
|
98
111
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
99
112
|
* type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
|
|
100
|
-
* @returns either a node object (
|
|
113
|
+
* @returns either a node object (NODE) or undefined.
|
|
101
114
|
*/
|
|
102
|
-
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V,
|
|
115
|
+
ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | undefined;
|
|
103
116
|
/**
|
|
104
117
|
* The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
|
|
105
|
-
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,
|
|
118
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
106
119
|
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
|
|
107
120
|
*/
|
|
108
|
-
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V,
|
|
121
|
+
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
|
|
109
122
|
/**
|
|
110
123
|
* Time Complexity: O(log n)
|
|
111
124
|
* Space Complexity: O(1)
|
|
112
|
-
* - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
|
|
113
125
|
*/
|
|
114
126
|
/**
|
|
115
127
|
* Time Complexity: O(log n)
|
|
@@ -123,15 +135,14 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
123
135
|
* @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
|
|
124
136
|
* node was not added.
|
|
125
137
|
*/
|
|
126
|
-
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V,
|
|
138
|
+
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
127
139
|
/**
|
|
128
140
|
* Time Complexity: O(k log n)
|
|
129
|
-
* Space Complexity: O(k)
|
|
130
|
-
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
|
|
141
|
+
* Space Complexity: O(k + log n)
|
|
131
142
|
*/
|
|
132
143
|
/**
|
|
133
144
|
* Time Complexity: O(k log n)
|
|
134
|
-
* Space Complexity: O(k)
|
|
145
|
+
* Space Complexity: O(k + log n)
|
|
135
146
|
*
|
|
136
147
|
* The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
|
|
137
148
|
* balancing the tree after each addition.
|
|
@@ -147,9 +158,9 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
147
158
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
148
159
|
* type of iteration to use when adding multiple keys or nodes. It has a default value of
|
|
149
160
|
* `this.iterationType`, which suggests that it is a property of the current object.
|
|
150
|
-
* @returns The function `addMany` returns an array of nodes (`
|
|
161
|
+
* @returns The function `addMany` returns an array of nodes (`NODE`) or `undefined` values.
|
|
151
162
|
*/
|
|
152
|
-
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V,
|
|
163
|
+
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
|
|
153
164
|
/**
|
|
154
165
|
* Time Complexity: O(log n)
|
|
155
166
|
* Space Complexity: O(1)
|
|
@@ -165,40 +176,39 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
165
176
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
166
177
|
* type of iteration to use when searching for a node in the binary tree. It can have two possible
|
|
167
178
|
* values:
|
|
168
|
-
* @returns The function `getNodeByKey` returns a node (`
|
|
179
|
+
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
169
180
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
170
181
|
*/
|
|
171
|
-
getNodeByKey(key: K, iterationType?: IterationType):
|
|
182
|
+
getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
|
|
172
183
|
/**
|
|
173
184
|
* Time Complexity: O(log n)
|
|
174
|
-
* Space Complexity: O(log n)
|
|
175
|
-
* Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
|
|
185
|
+
* Space Complexity: O(k + log n)
|
|
176
186
|
* /
|
|
177
187
|
|
|
178
188
|
/**
|
|
179
189
|
* Time Complexity: O(log n)
|
|
180
|
-
* Space Complexity: O(log n)
|
|
190
|
+
* Space Complexity: O(k + log n)
|
|
181
191
|
*
|
|
182
192
|
* The function `getNodes` returns an array of nodes that match a given identifier, using either a
|
|
183
193
|
* recursive or iterative approach.
|
|
184
194
|
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
|
|
185
195
|
* want to search for in the nodes of the binary tree. It can be of any type that is returned by the
|
|
186
196
|
* callback function `C`.
|
|
187
|
-
* @param {C} callback - The `callback` parameter is a function that takes a node of type `
|
|
197
|
+
* @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
|
|
188
198
|
* argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
|
|
189
|
-
* function type that extends the `BTNCallback<
|
|
199
|
+
* function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
|
|
190
200
|
* @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the
|
|
191
201
|
* first node that matches the identifier. If set to true, the function will return an array
|
|
192
202
|
* containing only the first matching node. If set to false (default), the function will continue
|
|
193
203
|
* searching for all nodes that match the identifier and return an array containing
|
|
194
|
-
* @param {K |
|
|
204
|
+
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
|
|
195
205
|
* for the traversal. It can be either a key value or a node object. If it is undefined, the
|
|
196
206
|
* traversal will start from the root of the tree.
|
|
197
207
|
* @param iterationType - The `iterationType` parameter determines the type of iteration to be
|
|
198
208
|
* performed on the binary tree. It can have two possible values:
|
|
199
|
-
* @returns The method returns an array of nodes (`
|
|
209
|
+
* @returns The method returns an array of nodes (`NODE[]`).
|
|
200
210
|
*/
|
|
201
|
-
getNodes<C extends BTNCallback<
|
|
211
|
+
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
202
212
|
/**
|
|
203
213
|
* Time complexity: O(n)
|
|
204
214
|
* Space complexity: O(n)
|
|
@@ -222,7 +232,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
222
232
|
* following values:
|
|
223
233
|
* @returns The method is returning an array of the return type of the callback function.
|
|
224
234
|
*/
|
|
225
|
-
dfs<C extends BTNCallback<
|
|
235
|
+
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
226
236
|
/**
|
|
227
237
|
* Time complexity: O(n)
|
|
228
238
|
* Space complexity: O(n)
|
|
@@ -244,7 +254,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
244
254
|
* nodes are visited.
|
|
245
255
|
* @returns The method is returning an array of the return type of the callback function.
|
|
246
256
|
*/
|
|
247
|
-
bfs<C extends BTNCallback<
|
|
257
|
+
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
248
258
|
/**
|
|
249
259
|
* Time complexity: O(n)
|
|
250
260
|
* Space complexity: O(n)
|
|
@@ -256,7 +266,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
256
266
|
* The function overrides the listLevels method and returns an array of arrays containing the return
|
|
257
267
|
* type of the callback function for each level of the tree.
|
|
258
268
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
259
|
-
* `BTNCallback<
|
|
269
|
+
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
|
|
260
270
|
* during the level listing process.
|
|
261
271
|
* @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
|
|
262
272
|
* levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
|
|
@@ -267,30 +277,28 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
267
277
|
* @returns The method is returning a two-dimensional array of the return type of the callback
|
|
268
278
|
* function.
|
|
269
279
|
*/
|
|
270
|
-
listLevels<C extends BTNCallback<
|
|
280
|
+
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
|
|
271
281
|
/**
|
|
272
|
-
* Time Complexity: O(
|
|
273
|
-
* Space Complexity: O(
|
|
274
|
-
* Adding each element individually in a balanced tree. Additional space is required for the sorted array.
|
|
282
|
+
* Time Complexity: O(log n)
|
|
283
|
+
* Space Complexity: O(1)
|
|
275
284
|
*/
|
|
276
285
|
/**
|
|
277
|
-
* Time Complexity: O(
|
|
278
|
-
* Space Complexity: O(
|
|
286
|
+
* Time Complexity: O(log n)
|
|
287
|
+
* Space Complexity: O(1)
|
|
279
288
|
*
|
|
280
289
|
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
|
|
281
290
|
* leftmost node if the comparison result is greater than.
|
|
282
|
-
* @param {K |
|
|
283
|
-
* type `K`, `
|
|
291
|
+
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
|
|
292
|
+
* type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
|
|
284
293
|
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
|
|
285
294
|
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
|
|
286
295
|
* the key of the leftmost node if the comparison result is greater than, and the key of the
|
|
287
296
|
* rightmost node otherwise. If no node is found, it returns 0.
|
|
288
297
|
*/
|
|
289
|
-
lastKey(beginRoot?: KeyOrNodeOrEntry<K, V,
|
|
298
|
+
lastKey(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): K | undefined;
|
|
290
299
|
/**
|
|
291
300
|
* Time Complexity: O(log n)
|
|
292
301
|
* Space Complexity: O(log n)
|
|
293
|
-
* Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
|
|
294
302
|
*/
|
|
295
303
|
/**
|
|
296
304
|
* Time Complexity: O(log n)
|
|
@@ -300,12 +308,12 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
300
308
|
* are either lesser or greater than a target node, depending on the specified comparison type.
|
|
301
309
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
302
310
|
* that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
|
|
303
|
-
* parameter of type `
|
|
311
|
+
* parameter of type `NODE` (the node type) and returns a value of any type.
|
|
304
312
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
305
313
|
* traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
|
|
306
314
|
* `CP`, which is a custom type representing the comparison operator. The possible values for
|
|
307
315
|
* `lesserOrGreater` are
|
|
308
|
-
* @param {K |
|
|
316
|
+
* @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
|
|
309
317
|
* binary tree that you want to traverse from. It can be specified either by its key, by the node
|
|
310
318
|
* object itself, or it can be left undefined to start the traversal from the root of the tree.
|
|
311
319
|
* @param iterationType - The `iterationType` parameter determines the type of traversal to be
|
|
@@ -313,7 +321,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
313
321
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
314
322
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
315
323
|
*/
|
|
316
|
-
lesserOrGreaterTraverse<C extends BTNCallback<
|
|
324
|
+
lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
317
325
|
/**
|
|
318
326
|
* Time Complexity: O(log n)
|
|
319
327
|
* Space Complexity: O(log n)
|
|
@@ -340,8 +348,8 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
340
348
|
* AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
|
|
341
349
|
*/
|
|
342
350
|
/**
|
|
343
|
-
* Time Complexity: O(n)
|
|
344
|
-
* Space Complexity: O(n)
|
|
351
|
+
* Time Complexity: O(n)
|
|
352
|
+
* Space Complexity: O(log n)
|
|
345
353
|
*/
|
|
346
354
|
/**
|
|
347
355
|
* Time Complexity: O(n)
|
|
@@ -353,7 +361,12 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
353
361
|
* @returns a boolean value.
|
|
354
362
|
*/
|
|
355
363
|
isAVLBalanced(iterationType?: IterationType): boolean;
|
|
356
|
-
|
|
364
|
+
/**
|
|
365
|
+
* The function sets the root property of an object and updates the parent property of the new root.
|
|
366
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. This means that it
|
|
367
|
+
* can either be an object of type `NODE` or it can be `undefined`.
|
|
368
|
+
*/
|
|
369
|
+
protected _setRoot(v: NODE | undefined): void;
|
|
357
370
|
/**
|
|
358
371
|
* The function compares two values using a comparator function and returns whether the first value
|
|
359
372
|
* is greater than, less than, or equal to the second value.
|