queue-typed 1.48.5 → 1.48.6
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/binary-tree.d.ts +7 -8
- package/dist/data-structures/binary-tree/binary-tree.js +19 -9
- package/dist/data-structures/binary-tree/bst.d.ts +15 -11
- package/dist/data-structures/binary-tree/bst.js +21 -13
- package/dist/interfaces/binary-tree.d.ts +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +26 -10
- package/src/data-structures/binary-tree/bst.ts +35 -20
- package/src/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/data-structures/binary-tree/tree-multimap.ts +1 -1
- package/src/interfaces/binary-tree.ts +1 -1
|
@@ -121,14 +121,13 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
121
121
|
* Time Complexity: O(k log n) - O(k * n)
|
|
122
122
|
* Space Complexity: O(1)
|
|
123
123
|
*
|
|
124
|
-
* The
|
|
125
|
-
*
|
|
126
|
-
* @param nodes -
|
|
127
|
-
*
|
|
128
|
-
* @returns The function `addMany` returns an array of
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>): (N | null | undefined)[];
|
|
124
|
+
* The `addMany` function takes in a collection of nodes and an optional collection of values, and
|
|
125
|
+
* adds each node with its corresponding value to the data structure.
|
|
126
|
+
* @param nodes - An iterable collection of BTNodeExemplar objects.
|
|
127
|
+
* @param [values] - An optional iterable of values that will be assigned to each node being added.
|
|
128
|
+
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
129
|
+
*/
|
|
130
|
+
addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
|
|
132
131
|
/**
|
|
133
132
|
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
134
133
|
* Space Complexity: O(1)
|
|
@@ -241,18 +241,28 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
241
241
|
* Time Complexity: O(k log n) - O(k * n)
|
|
242
242
|
* Space Complexity: O(1)
|
|
243
243
|
*
|
|
244
|
-
* The
|
|
245
|
-
*
|
|
246
|
-
* @param nodes -
|
|
247
|
-
*
|
|
248
|
-
* @returns The function `addMany` returns an array of
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
addMany(nodes) {
|
|
244
|
+
* The `addMany` function takes in a collection of nodes and an optional collection of values, and
|
|
245
|
+
* adds each node with its corresponding value to the data structure.
|
|
246
|
+
* @param nodes - An iterable collection of BTNodeExemplar objects.
|
|
247
|
+
* @param [values] - An optional iterable of values that will be assigned to each node being added.
|
|
248
|
+
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
249
|
+
*/
|
|
250
|
+
addMany(nodes, values) {
|
|
252
251
|
// TODO not sure addMany not be run multi times
|
|
253
252
|
const inserted = [];
|
|
253
|
+
let valuesIterator;
|
|
254
|
+
if (values) {
|
|
255
|
+
valuesIterator = values[Symbol.iterator]();
|
|
256
|
+
}
|
|
254
257
|
for (const kne of nodes) {
|
|
255
|
-
|
|
258
|
+
let value = undefined;
|
|
259
|
+
if (valuesIterator) {
|
|
260
|
+
const valueResult = valuesIterator.next();
|
|
261
|
+
if (!valueResult.done) {
|
|
262
|
+
value = valueResult.value;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
inserted.push(this.add(kne, value));
|
|
256
266
|
}
|
|
257
267
|
return inserted;
|
|
258
268
|
}
|
|
@@ -113,19 +113,23 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
113
113
|
* Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
|
|
114
114
|
* Space Complexity: O(k) - Additional space is required for the sorted array.
|
|
115
115
|
*
|
|
116
|
-
* The `addMany` function in TypeScript adds multiple nodes to a binary tree,
|
|
117
|
-
*
|
|
118
|
-
* @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries to be added to
|
|
119
|
-
* binary tree.
|
|
120
|
-
* @param [
|
|
121
|
-
*
|
|
116
|
+
* The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
|
|
117
|
+
* balancing the tree after each addition.
|
|
118
|
+
* @param keysOrNodesOrEntries - An iterable containing the keys, nodes, or entries to be added to
|
|
119
|
+
* the binary tree.
|
|
120
|
+
* @param [values] - An optional iterable of values to be associated with the keys or nodes being
|
|
121
|
+
* added. If provided, the values will be assigned to the corresponding keys or nodes in the same
|
|
122
|
+
* order. If not provided, undefined will be assigned as the value for each key or node.
|
|
123
|
+
* @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
|
|
124
|
+
* balanced or not. If set to true, the add operation will be balanced using a binary search tree
|
|
125
|
+
* algorithm. If set to false, the add operation will not be balanced and the elements will be added
|
|
126
|
+
* in the order they appear in the input.
|
|
122
127
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
123
|
-
* type of iteration to use when adding multiple keys or nodes
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @returns The `addMany` function returns an array of `N` or `undefined` values.
|
|
128
|
+
* type of iteration to use when adding multiple keys or nodes. It has a default value of
|
|
129
|
+
* `this.iterationType`, which suggests that it is a property of the current object.
|
|
130
|
+
* @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
|
|
127
131
|
*/
|
|
128
|
-
addMany(keysOrNodesOrEntries: Iterable<BTNodeExemplar<K, V, N>>, isBalanceAdd?: boolean, iterationType?: IterationType): (N | undefined)[];
|
|
132
|
+
addMany(keysOrNodesOrEntries: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): (N | undefined)[];
|
|
129
133
|
/**
|
|
130
134
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
131
135
|
* Space Complexity: O(1) - Constant space is used.
|
|
@@ -211,23 +211,32 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
211
211
|
* Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
|
|
212
212
|
* Space Complexity: O(k) - Additional space is required for the sorted array.
|
|
213
213
|
*
|
|
214
|
-
* The `addMany` function in TypeScript adds multiple nodes to a binary tree,
|
|
215
|
-
*
|
|
216
|
-
* @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries to be added to
|
|
217
|
-
* binary tree.
|
|
218
|
-
* @param [
|
|
219
|
-
*
|
|
214
|
+
* The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
|
|
215
|
+
* balancing the tree after each addition.
|
|
216
|
+
* @param keysOrNodesOrEntries - An iterable containing the keys, nodes, or entries to be added to
|
|
217
|
+
* the binary tree.
|
|
218
|
+
* @param [values] - An optional iterable of values to be associated with the keys or nodes being
|
|
219
|
+
* added. If provided, the values will be assigned to the corresponding keys or nodes in the same
|
|
220
|
+
* order. If not provided, undefined will be assigned as the value for each key or node.
|
|
221
|
+
* @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
|
|
222
|
+
* balanced or not. If set to true, the add operation will be balanced using a binary search tree
|
|
223
|
+
* algorithm. If set to false, the add operation will not be balanced and the elements will be added
|
|
224
|
+
* in the order they appear in the input.
|
|
220
225
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
221
|
-
* type of iteration to use when adding multiple keys or nodes
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* @returns The `addMany` function returns an array of `N` or `undefined` values.
|
|
226
|
+
* type of iteration to use when adding multiple keys or nodes. It has a default value of
|
|
227
|
+
* `this.iterationType`, which suggests that it is a property of the current object.
|
|
228
|
+
* @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
|
|
225
229
|
*/
|
|
226
|
-
addMany(keysOrNodesOrEntries, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
230
|
+
addMany(keysOrNodesOrEntries, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
227
231
|
const inserted = [];
|
|
232
|
+
let valuesIterator;
|
|
233
|
+
if (values) {
|
|
234
|
+
valuesIterator = values[Symbol.iterator]();
|
|
235
|
+
}
|
|
228
236
|
if (!isBalanceAdd) {
|
|
229
237
|
for (const kve of keysOrNodesOrEntries) {
|
|
230
|
-
const
|
|
238
|
+
const value = valuesIterator === null || valuesIterator === void 0 ? void 0 : valuesIterator.next().value;
|
|
239
|
+
const nn = this.add(kve, value);
|
|
231
240
|
inserted.push(nn);
|
|
232
241
|
}
|
|
233
242
|
return inserted;
|
|
@@ -241,7 +250,6 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
241
250
|
for (const kve of keysOrNodesOrEntries) {
|
|
242
251
|
isRealBTNExemplar(kve) && realBTNExemplars.push(kve);
|
|
243
252
|
}
|
|
244
|
-
// TODO this addMany function is inefficient, it should be optimized
|
|
245
253
|
let sorted = [];
|
|
246
254
|
sorted = realBTNExemplars.sort((a, b) => {
|
|
247
255
|
let aR, bR;
|
|
@@ -4,6 +4,6 @@ export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V,
|
|
|
4
4
|
createNode(key: K, value?: N['value']): N;
|
|
5
5
|
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
6
6
|
add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
|
|
7
|
-
addMany(nodes: Iterable<BTNodeExemplar<K, V, N
|
|
7
|
+
addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
|
|
8
8
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "queue-typed",
|
|
3
|
-
"version": "1.48.
|
|
3
|
+
"version": "1.48.6",
|
|
4
4
|
"description": "Queue, ArrayQueue. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -115,6 +115,6 @@
|
|
|
115
115
|
"typescript": "^4.9.5"
|
|
116
116
|
},
|
|
117
117
|
"dependencies": {
|
|
118
|
-
"data-structure-typed": "^1.48.
|
|
118
|
+
"data-structure-typed": "^1.48.6"
|
|
119
119
|
}
|
|
120
120
|
}
|
|
@@ -99,7 +99,7 @@ export class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeN
|
|
|
99
99
|
/**
|
|
100
100
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
101
101
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
102
|
-
*
|
|
102
|
+
*
|
|
103
103
|
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
104
104
|
* a new node.
|
|
105
105
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
|
|
@@ -235,7 +235,7 @@ export class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = Bi
|
|
|
235
235
|
/**
|
|
236
236
|
* Time Complexity O(log n) - O(n)
|
|
237
237
|
* Space Complexity O(1)
|
|
238
|
-
*
|
|
238
|
+
*
|
|
239
239
|
* The `add` function adds a new node to a binary tree, either by creating a new node or replacing an
|
|
240
240
|
* existing node with the same key.
|
|
241
241
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
|
|
@@ -288,22 +288,38 @@ export class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = Bi
|
|
|
288
288
|
* Time Complexity: O(k log n) - O(k * n)
|
|
289
289
|
* Space Complexity: O(1)
|
|
290
290
|
*
|
|
291
|
-
* The
|
|
292
|
-
*
|
|
293
|
-
* @param nodes -
|
|
294
|
-
*
|
|
295
|
-
* @returns The function `addMany` returns an array of
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>): (N | null | undefined)[] {
|
|
291
|
+
* The `addMany` function takes in a collection of nodes and an optional collection of values, and
|
|
292
|
+
* adds each node with its corresponding value to the data structure.
|
|
293
|
+
* @param nodes - An iterable collection of BTNodeExemplar objects.
|
|
294
|
+
* @param [values] - An optional iterable of values that will be assigned to each node being added.
|
|
295
|
+
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
296
|
+
*/
|
|
297
|
+
addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[] {
|
|
299
298
|
// TODO not sure addMany not be run multi times
|
|
300
299
|
const inserted: (N | null | undefined)[] = [];
|
|
300
|
+
|
|
301
|
+
let valuesIterator: Iterator<V | undefined> | undefined;
|
|
302
|
+
if (values) {
|
|
303
|
+
valuesIterator = values[Symbol.iterator]();
|
|
304
|
+
}
|
|
305
|
+
|
|
301
306
|
for (const kne of nodes) {
|
|
302
|
-
|
|
307
|
+
let value: V | undefined | null = undefined;
|
|
308
|
+
|
|
309
|
+
if (valuesIterator) {
|
|
310
|
+
const valueResult = valuesIterator.next();
|
|
311
|
+
if (!valueResult.done) {
|
|
312
|
+
value = valueResult.value;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
inserted.push(this.add(kne, value));
|
|
303
317
|
}
|
|
318
|
+
|
|
304
319
|
return inserted;
|
|
305
320
|
}
|
|
306
321
|
|
|
322
|
+
|
|
307
323
|
/**
|
|
308
324
|
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
309
325
|
* Space Complexity: O(1)
|
|
@@ -192,7 +192,7 @@ export class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<K, V, BS
|
|
|
192
192
|
/**
|
|
193
193
|
* Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
|
|
194
194
|
* Space Complexity: O(1) - Constant space is used.
|
|
195
|
-
*
|
|
195
|
+
*
|
|
196
196
|
* The `add` function adds a new node to a binary tree, updating the value if the key already exists
|
|
197
197
|
* or inserting a new node if the key is unique.
|
|
198
198
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can accept three types of values:
|
|
@@ -256,31 +256,45 @@ export class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<K, V, BS
|
|
|
256
256
|
* Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
|
|
257
257
|
* Space Complexity: O(k) - Additional space is required for the sorted array.
|
|
258
258
|
*
|
|
259
|
-
* The `addMany` function in TypeScript adds multiple nodes to a binary tree,
|
|
260
|
-
*
|
|
261
|
-
* @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries to be added to
|
|
262
|
-
* binary tree.
|
|
263
|
-
* @param [
|
|
264
|
-
*
|
|
259
|
+
* The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
|
|
260
|
+
* balancing the tree after each addition.
|
|
261
|
+
* @param keysOrNodesOrEntries - An iterable containing the keys, nodes, or entries to be added to
|
|
262
|
+
* the binary tree.
|
|
263
|
+
* @param [values] - An optional iterable of values to be associated with the keys or nodes being
|
|
264
|
+
* added. If provided, the values will be assigned to the corresponding keys or nodes in the same
|
|
265
|
+
* order. If not provided, undefined will be assigned as the value for each key or node.
|
|
266
|
+
* @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
|
|
267
|
+
* balanced or not. If set to true, the add operation will be balanced using a binary search tree
|
|
268
|
+
* algorithm. If set to false, the add operation will not be balanced and the elements will be added
|
|
269
|
+
* in the order they appear in the input.
|
|
265
270
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
266
|
-
* type of iteration to use when adding multiple keys or nodes
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* @returns The `addMany` function returns an array of `N` or `undefined` values.
|
|
271
|
+
* type of iteration to use when adding multiple keys or nodes. It has a default value of
|
|
272
|
+
* `this.iterationType`, which suggests that it is a property of the current object.
|
|
273
|
+
* @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
|
|
270
274
|
*/
|
|
271
275
|
override addMany(
|
|
272
276
|
keysOrNodesOrEntries: Iterable<BTNodeExemplar<K, V, N>>,
|
|
277
|
+
values?: Iterable<V | undefined>,
|
|
273
278
|
isBalanceAdd = true,
|
|
274
279
|
iterationType = this.iterationType
|
|
275
280
|
): (N | undefined)[] {
|
|
276
|
-
const inserted: (N | undefined)[] = []
|
|
281
|
+
const inserted: (N | undefined)[] = [];
|
|
282
|
+
|
|
283
|
+
let valuesIterator: Iterator<V | undefined> | undefined;
|
|
284
|
+
|
|
285
|
+
if (values) {
|
|
286
|
+
valuesIterator = values[Symbol.iterator]();
|
|
287
|
+
}
|
|
288
|
+
|
|
277
289
|
if (!isBalanceAdd) {
|
|
278
290
|
for (const kve of keysOrNodesOrEntries) {
|
|
279
|
-
const
|
|
291
|
+
const value = valuesIterator?.next().value;
|
|
292
|
+
const nn = this.add(kve, value);
|
|
280
293
|
inserted.push(nn);
|
|
281
294
|
}
|
|
282
295
|
return inserted;
|
|
283
296
|
}
|
|
297
|
+
|
|
284
298
|
const realBTNExemplars: BTNodePureExemplar<K, V, N>[] = [];
|
|
285
299
|
|
|
286
300
|
const isRealBTNExemplar = (kve: BTNodeExemplar<K, V, N>): kve is BTNodePureExemplar<K, V, N> => {
|
|
@@ -292,22 +306,20 @@ export class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<K, V, BS
|
|
|
292
306
|
isRealBTNExemplar(kve) && realBTNExemplars.push(kve);
|
|
293
307
|
}
|
|
294
308
|
|
|
295
|
-
// TODO this addMany function is inefficient, it should be optimized
|
|
296
309
|
let sorted: BTNodePureExemplar<K, V, N>[] = [];
|
|
297
310
|
|
|
298
311
|
sorted = realBTNExemplars.sort((a, b) => {
|
|
299
312
|
let aR: number, bR: number;
|
|
300
|
-
if (this.isEntry(a)) aR = this.extractor(a[0])
|
|
301
|
-
else if (this.isRealNode(a)) aR = this.extractor(a.key)
|
|
313
|
+
if (this.isEntry(a)) aR = this.extractor(a[0]);
|
|
314
|
+
else if (this.isRealNode(a)) aR = this.extractor(a.key);
|
|
302
315
|
else aR = this.extractor(a);
|
|
303
316
|
|
|
304
|
-
if (this.isEntry(b)) bR = this.extractor(b[0])
|
|
305
|
-
else if (this.isRealNode(b)) bR = this.extractor(b.key)
|
|
317
|
+
if (this.isEntry(b)) bR = this.extractor(b[0]);
|
|
318
|
+
else if (this.isRealNode(b)) bR = this.extractor(b.key);
|
|
306
319
|
else bR = this.extractor(b);
|
|
307
320
|
|
|
308
321
|
return aR - bR;
|
|
309
|
-
})
|
|
310
|
-
|
|
322
|
+
});
|
|
311
323
|
|
|
312
324
|
const _dfs = (arr: BTNodePureExemplar<K, V, N>[]) => {
|
|
313
325
|
if (arr.length === 0) return;
|
|
@@ -318,6 +330,7 @@ export class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<K, V, BS
|
|
|
318
330
|
_dfs(arr.slice(0, mid));
|
|
319
331
|
_dfs(arr.slice(mid + 1));
|
|
320
332
|
};
|
|
333
|
+
|
|
321
334
|
const _iterate = () => {
|
|
322
335
|
const n = sorted.length;
|
|
323
336
|
const stack: [[number, number]] = [[0, n - 1]];
|
|
@@ -335,6 +348,7 @@ export class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<K, V, BS
|
|
|
335
348
|
}
|
|
336
349
|
}
|
|
337
350
|
};
|
|
351
|
+
|
|
338
352
|
if (iterationType === IterationType.RECURSIVE) {
|
|
339
353
|
_dfs(sorted);
|
|
340
354
|
} else {
|
|
@@ -344,6 +358,7 @@ export class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<K, V, BS
|
|
|
344
358
|
return inserted;
|
|
345
359
|
}
|
|
346
360
|
|
|
361
|
+
|
|
347
362
|
// /**
|
|
348
363
|
// * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
|
|
349
364
|
// * Space Complexity: O(n) - Additional space is required for the sorted array.
|
|
@@ -153,7 +153,7 @@ export class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K, V, N>
|
|
|
153
153
|
/**
|
|
154
154
|
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
|
|
155
155
|
* Space Complexity: O(1)
|
|
156
|
-
*
|
|
156
|
+
*
|
|
157
157
|
* The `add` function adds a new node to a binary search tree and performs necessary rotations and
|
|
158
158
|
* color changes to maintain the red-black tree properties.
|
|
159
159
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
|
|
@@ -126,7 +126,7 @@ export class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K, V, N>
|
|
|
126
126
|
/**
|
|
127
127
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
|
|
128
128
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
129
|
-
*
|
|
129
|
+
*
|
|
130
130
|
* The function overrides the add method of a binary tree node and adds a new node to the tree.
|
|
131
131
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
|
|
132
132
|
* entry. It represents the key, node, or entry that you want to add to the binary tree.
|
|
@@ -15,7 +15,7 @@ export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V,
|
|
|
15
15
|
|
|
16
16
|
add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
|
|
17
17
|
|
|
18
|
-
addMany(nodes: Iterable<BTNodeExemplar<K, V, N
|
|
18
|
+
addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
|
|
19
19
|
|
|
20
20
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
|
|
21
21
|
}
|