data-structure-typed 1.51.7 → 1.51.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +13 -13
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +156 -156
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +1 -10
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +12 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +5 -12
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +22 -32
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +32 -77
- package/dist/cjs/data-structures/binary-tree/bst.js +68 -136
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +3 -13
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +3 -20
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +1 -3
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/common.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -2
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -2
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +6 -5
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -2
- package/dist/cjs/types/utils/utils.d.ts +10 -1
- package/dist/cjs/utils/utils.d.ts +2 -1
- package/dist/cjs/utils/utils.js +29 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -12
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +1 -10
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +12 -12
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +5 -12
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +22 -32
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +32 -77
- package/dist/mjs/data-structures/binary-tree/bst.js +70 -139
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +3 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +3 -20
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/mjs/data-structures/heap/heap.d.ts +1 -3
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -2
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -2
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +6 -5
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -2
- package/dist/mjs/types/utils/utils.d.ts +10 -1
- package/dist/mjs/utils/utils.d.ts +2 -1
- package/dist/mjs/utils/utils.js +27 -0
- package/dist/umd/data-structure-typed.js +133 -208
- package/dist/umd/data-structure-typed.min.js +4 -4
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +4 -12
- package/src/data-structures/binary-tree/avl-tree.ts +15 -14
- package/src/data-structures/binary-tree/binary-tree.ts +29 -38
- package/src/data-structures/binary-tree/bst.ts +78 -148
- package/src/data-structures/binary-tree/rb-tree.ts +8 -22
- package/src/data-structures/binary-tree/tree-multi-map.ts +4 -3
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/interfaces/binary-tree.ts +4 -3
- package/src/types/common.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -2
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +5 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -2
- package/src/types/utils/utils.ts +14 -1
- package/src/utils/utils.ts +20 -1
- package/test/integration/all-in-one.test.ts +2 -2
- package/test/integration/index.html +70 -0
- package/test/performance/reportor.ts +2 -3
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +7 -7
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/bst.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/overall.test.ts +24 -20
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +6 -6
- package/test/unit/utils/utils.test.ts +5 -0
- package/test/utils/console.ts +1 -1
|
@@ -59,25 +59,25 @@ export class BSTNode extends BinaryTreeNode {
|
|
|
59
59
|
*/
|
|
60
60
|
export class BST extends BinaryTree {
|
|
61
61
|
/**
|
|
62
|
-
* This is the constructor function for a
|
|
63
|
-
*
|
|
64
|
-
* @param keysOrNodesOrEntries -
|
|
65
|
-
* to initialize the binary search tree with the provided
|
|
62
|
+
* This is the constructor function for a Binary Search Tree class in TypeScript, which initializes
|
|
63
|
+
* the tree with keys, nodes, or entries and optional options.
|
|
64
|
+
* @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
|
|
65
|
+
* contain keys, nodes, or entries. It is used to initialize the binary search tree with the provided
|
|
66
|
+
* keys, nodes, or entries.
|
|
66
67
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
67
68
|
* configuration options for the binary search tree. It can have the following properties:
|
|
68
69
|
*/
|
|
69
70
|
constructor(keysOrNodesOrEntries = [], options) {
|
|
70
71
|
super([], options);
|
|
71
72
|
if (options) {
|
|
72
|
-
const {
|
|
73
|
-
if (
|
|
74
|
-
this.
|
|
73
|
+
const { comparator } = options;
|
|
74
|
+
if (comparator)
|
|
75
|
+
this._comparator = comparator;
|
|
75
76
|
}
|
|
76
|
-
this._root = undefined;
|
|
77
77
|
if (keysOrNodesOrEntries)
|
|
78
78
|
this.addMany(keysOrNodesOrEntries);
|
|
79
79
|
}
|
|
80
|
-
_root;
|
|
80
|
+
_root = undefined;
|
|
81
81
|
/**
|
|
82
82
|
* The function returns the root node of a tree structure.
|
|
83
83
|
* @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
|
|
@@ -85,13 +85,19 @@ export class BST extends BinaryTree {
|
|
|
85
85
|
get root() {
|
|
86
86
|
return this._root;
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
_comparator = (a, b) => {
|
|
89
|
+
if (a > b)
|
|
90
|
+
return 1;
|
|
91
|
+
if (a < b)
|
|
92
|
+
return -1;
|
|
93
|
+
return 0;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The function returns the value of the _comparator property.
|
|
97
|
+
* @returns The `_comparator` property is being returned.
|
|
98
|
+
*/
|
|
99
|
+
get comparator() {
|
|
100
|
+
return this._comparator;
|
|
95
101
|
}
|
|
96
102
|
/**
|
|
97
103
|
* The function creates a new BSTNode with the given key and value and returns it.
|
|
@@ -115,7 +121,7 @@ export class BST extends BinaryTree {
|
|
|
115
121
|
createTree(options) {
|
|
116
122
|
return new BST([], {
|
|
117
123
|
iterationType: this.iterationType,
|
|
118
|
-
|
|
124
|
+
comparator: this.comparator,
|
|
119
125
|
...options
|
|
120
126
|
});
|
|
121
127
|
}
|
|
@@ -201,13 +207,11 @@ export class BST extends BinaryTree {
|
|
|
201
207
|
* Time Complexity: O(log n)
|
|
202
208
|
* Space Complexity: O(1)
|
|
203
209
|
*
|
|
204
|
-
* The `add` function adds a new node to a binary tree
|
|
205
|
-
*
|
|
206
|
-
* @param keyOrNodeOrEntry -
|
|
207
|
-
* @param {V} [value] - The
|
|
208
|
-
*
|
|
209
|
-
* @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
|
|
210
|
-
* node was not added.
|
|
210
|
+
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value,
|
|
211
|
+
* updating the value if the key already exists.
|
|
212
|
+
* @param keyOrNodeOrEntry - It is a parameter that can accept three types of values:
|
|
213
|
+
* @param {V} [value] - The value to be added to the binary search tree.
|
|
214
|
+
* @returns The method returns a boolean value.
|
|
211
215
|
*/
|
|
212
216
|
add(keyOrNodeOrEntry, value) {
|
|
213
217
|
const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
|
|
@@ -220,7 +224,7 @@ export class BST extends BinaryTree {
|
|
|
220
224
|
}
|
|
221
225
|
let current = this.root;
|
|
222
226
|
while (current !== undefined) {
|
|
223
|
-
if (this.
|
|
227
|
+
if (this.comparator(current.key, newNode.key) === 0) {
|
|
224
228
|
// if (current !== newNode) {
|
|
225
229
|
// The key value is the same but the reference is different, update the value of the existing node
|
|
226
230
|
this._replaceNode(current, newNode);
|
|
@@ -231,7 +235,7 @@ export class BST extends BinaryTree {
|
|
|
231
235
|
// return;
|
|
232
236
|
// }
|
|
233
237
|
}
|
|
234
|
-
else if (this.
|
|
238
|
+
else if (this.comparator(current.key, newNode.key) > 0) {
|
|
235
239
|
if (current.left === undefined) {
|
|
236
240
|
current.left = newNode;
|
|
237
241
|
this._size++;
|
|
@@ -258,21 +262,24 @@ export class BST extends BinaryTree {
|
|
|
258
262
|
* Time Complexity: O(k log n)
|
|
259
263
|
* Space Complexity: O(k + log n)
|
|
260
264
|
*
|
|
261
|
-
* The `addMany` function in TypeScript adds multiple keys or nodes to a
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
+
* The `addMany` function in TypeScript adds multiple keys or nodes to a data structure, balancing
|
|
266
|
+
* the structure if specified, and returns an array indicating whether each key or node was
|
|
267
|
+
* successfully inserted.
|
|
268
|
+
* @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries to be added to the
|
|
269
|
+
* data structure.
|
|
265
270
|
* @param [values] - An optional iterable of values to be associated with the keys or nodes being
|
|
266
271
|
* added. If provided, the values will be assigned to the corresponding keys or nodes in the same
|
|
267
272
|
* order. If not provided, undefined will be assigned as the value for each key or node.
|
|
268
|
-
* @param [isBalanceAdd=true] - A boolean flag indicating whether the
|
|
269
|
-
*
|
|
270
|
-
* algorithm. If set to false, the
|
|
271
|
-
*
|
|
272
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that
|
|
273
|
-
* type of iteration to use when adding multiple keys or nodes
|
|
274
|
-
* `this.iterationType`, which
|
|
275
|
-
*
|
|
273
|
+
* @param [isBalanceAdd=true] - A boolean flag indicating whether the tree should be balanced after
|
|
274
|
+
* adding the elements. If set to true, the tree will be balanced using a binary search tree
|
|
275
|
+
* algorithm. If set to false, the elements will be added without balancing the tree. The default
|
|
276
|
+
* value is true.
|
|
277
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
278
|
+
* specifies the type of iteration to use when adding multiple keys or nodes to the binary tree. It
|
|
279
|
+
* has a default value of `this.iterationType`, which means it will use the iteration type specified
|
|
280
|
+
* in the binary tree instance.
|
|
281
|
+
* @returns The function `addMany` returns an array of booleans indicating whether each key or node
|
|
282
|
+
* or entry was successfully inserted into the data structure.
|
|
276
283
|
*/
|
|
277
284
|
addMany(keysOrNodesOrEntries, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
278
285
|
const inserted = [];
|
|
@@ -299,20 +306,24 @@ export class BST extends BinaryTree {
|
|
|
299
306
|
}
|
|
300
307
|
let sorted = [];
|
|
301
308
|
sorted = realBTNExemplars.sort((a, b) => {
|
|
302
|
-
let
|
|
303
|
-
if (this.isEntry(a))
|
|
304
|
-
|
|
309
|
+
let keyA, keyB;
|
|
310
|
+
if (this.isEntry(a)) {
|
|
311
|
+
keyA = a[0];
|
|
312
|
+
}
|
|
305
313
|
else if (this.isRealNode(a))
|
|
306
|
-
|
|
314
|
+
keyA = a.key;
|
|
307
315
|
else
|
|
308
|
-
|
|
316
|
+
keyA = a;
|
|
309
317
|
if (this.isEntry(b))
|
|
310
|
-
|
|
318
|
+
keyB = b[0];
|
|
311
319
|
else if (this.isRealNode(b))
|
|
312
|
-
|
|
320
|
+
keyB = b.key;
|
|
313
321
|
else
|
|
314
|
-
|
|
315
|
-
|
|
322
|
+
keyB = b;
|
|
323
|
+
if (keyA !== undefined && keyA !== null && keyB !== undefined && keyB !== null) {
|
|
324
|
+
return this.comparator(keyA, keyB);
|
|
325
|
+
}
|
|
326
|
+
return 0;
|
|
316
327
|
});
|
|
317
328
|
const _dfs = (arr) => {
|
|
318
329
|
if (arr.length === 0)
|
|
@@ -394,9 +405,9 @@ export class BST extends BinaryTree {
|
|
|
394
405
|
return;
|
|
395
406
|
// TODO potential bug
|
|
396
407
|
if (callback === this._DEFAULT_CALLBACK) {
|
|
397
|
-
if (this.isRealNode(cur.left) && this.
|
|
408
|
+
if (this.isRealNode(cur.left) && this.comparator(cur.key, identifier) > 0)
|
|
398
409
|
dfs(cur.left);
|
|
399
|
-
if (this.isRealNode(cur.right) && this.
|
|
410
|
+
if (this.isRealNode(cur.right) && this.comparator(cur.key, identifier) < 0)
|
|
400
411
|
dfs(cur.right);
|
|
401
412
|
}
|
|
402
413
|
else {
|
|
@@ -418,9 +429,9 @@ export class BST extends BinaryTree {
|
|
|
418
429
|
}
|
|
419
430
|
// TODO potential bug
|
|
420
431
|
if (callback === this._DEFAULT_CALLBACK) {
|
|
421
|
-
if (this.isRealNode(cur.right) && this.
|
|
432
|
+
if (this.isRealNode(cur.right) && this.comparator(cur.key, identifier) < 0)
|
|
422
433
|
stack.push(cur.right);
|
|
423
|
-
if (this.isRealNode(cur.left) && this.
|
|
434
|
+
if (this.isRealNode(cur.left) && this.comparator(cur.key, identifier) > 0)
|
|
424
435
|
stack.push(cur.left);
|
|
425
436
|
// if (this.isRealNode(cur.right) && this._lt(cur.key, identifier as K)) stack.push(cur.right);
|
|
426
437
|
// if (this.isRealNode(cur.left) && this._gt(cur.key, identifier as K)) stack.push(cur.left);
|
|
@@ -561,41 +572,6 @@ export class BST extends BinaryTree {
|
|
|
561
572
|
listLevels(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
|
|
562
573
|
return super.listLevels(callback, beginRoot, iterationType, false);
|
|
563
574
|
}
|
|
564
|
-
/**
|
|
565
|
-
* Time Complexity: O(log n)
|
|
566
|
-
* Space Complexity: O(1)
|
|
567
|
-
*/
|
|
568
|
-
/**
|
|
569
|
-
* Time Complexity: O(log n)
|
|
570
|
-
* Space Complexity: O(1)
|
|
571
|
-
*
|
|
572
|
-
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
|
|
573
|
-
* leftmost node if the comparison result is greater than.
|
|
574
|
-
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
|
|
575
|
-
* type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
|
|
576
|
-
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
|
|
577
|
-
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
|
|
578
|
-
* the key of the leftmost node if the comparison result is greater than, and the key of the
|
|
579
|
-
* rightmost node otherwise. If no node is found, it returns 0.
|
|
580
|
-
*/
|
|
581
|
-
lastKey(beginRoot = this.root) {
|
|
582
|
-
let current = this.ensureNode(beginRoot);
|
|
583
|
-
if (!current)
|
|
584
|
-
return undefined;
|
|
585
|
-
if (this._variant === 'STANDARD') {
|
|
586
|
-
// For 'STANDARD', find the rightmost node
|
|
587
|
-
while (current.right !== undefined) {
|
|
588
|
-
current = current.right;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
// For BSTVariant.MAX, find the leftmost node
|
|
593
|
-
while (current.left !== undefined) {
|
|
594
|
-
current = current.left;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
return current.key;
|
|
598
|
-
}
|
|
599
575
|
/**
|
|
600
576
|
* Time Complexity: O(log n)
|
|
601
577
|
* Space Complexity: O(log n)
|
|
@@ -621,18 +597,18 @@ export class BST extends BinaryTree {
|
|
|
621
597
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
622
598
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
623
599
|
*/
|
|
624
|
-
lesserOrGreaterTraverse(callback = this._DEFAULT_CALLBACK, lesserOrGreater =
|
|
625
|
-
|
|
600
|
+
lesserOrGreaterTraverse(callback = this._DEFAULT_CALLBACK, lesserOrGreater = -1, targetNode = this.root, iterationType = this.iterationType) {
|
|
601
|
+
const targetNodeEnsured = this.ensureNode(targetNode);
|
|
626
602
|
const ans = [];
|
|
627
|
-
if (!
|
|
603
|
+
if (!targetNodeEnsured)
|
|
628
604
|
return ans;
|
|
629
605
|
if (!this.root)
|
|
630
606
|
return ans;
|
|
631
|
-
const targetKey =
|
|
607
|
+
const targetKey = targetNodeEnsured.key;
|
|
632
608
|
if (iterationType === 'RECURSIVE') {
|
|
633
609
|
const dfs = (cur) => {
|
|
634
|
-
const compared = this.
|
|
635
|
-
if (compared === lesserOrGreater)
|
|
610
|
+
const compared = this.comparator(cur.key, targetKey);
|
|
611
|
+
if (Math.sign(compared) === lesserOrGreater)
|
|
636
612
|
ans.push(callback(cur));
|
|
637
613
|
if (this.isRealNode(cur.left))
|
|
638
614
|
dfs(cur.left);
|
|
@@ -647,8 +623,8 @@ export class BST extends BinaryTree {
|
|
|
647
623
|
while (queue.size > 0) {
|
|
648
624
|
const cur = queue.shift();
|
|
649
625
|
if (this.isRealNode(cur)) {
|
|
650
|
-
const compared = this.
|
|
651
|
-
if (compared === lesserOrGreater)
|
|
626
|
+
const compared = this.comparator(cur.key, targetKey);
|
|
627
|
+
if (Math.sign(compared) === lesserOrGreater)
|
|
652
628
|
ans.push(callback(cur));
|
|
653
629
|
if (this.isRealNode(cur.left))
|
|
654
630
|
queue.push(cur.left);
|
|
@@ -788,49 +764,4 @@ export class BST extends BinaryTree {
|
|
|
788
764
|
}
|
|
789
765
|
this._root = v;
|
|
790
766
|
}
|
|
791
|
-
/**
|
|
792
|
-
* The function compares two values using a comparator function and returns whether the first value
|
|
793
|
-
* is greater than, less than, or equal to the second value.
|
|
794
|
-
* @param {K} a - The parameter "a" is of type K.
|
|
795
|
-
* @param {K} b - The parameter "b" in the above code represents a K.
|
|
796
|
-
* @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
|
|
797
|
-
* than), 'LT' (less than), or 'EQ' (equal).
|
|
798
|
-
*/
|
|
799
|
-
_compare(a, b) {
|
|
800
|
-
const extractedA = this.extractor(a);
|
|
801
|
-
const extractedB = this.extractor(b);
|
|
802
|
-
const compared = this.variant === 'STANDARD' ? extractedA - extractedB : extractedB - extractedA;
|
|
803
|
-
if (compared > 0)
|
|
804
|
-
return 'GT';
|
|
805
|
-
if (compared < 0)
|
|
806
|
-
return 'LT';
|
|
807
|
-
return 'EQ';
|
|
808
|
-
}
|
|
809
|
-
/**
|
|
810
|
-
* The function `_lt` compares two values `a` and `b` using an extractor function and returns true if
|
|
811
|
-
* `a` is less than `b` based on the specified variant.
|
|
812
|
-
* @param {K} a - The parameter "a" is of type "K", which means it can be any type. It represents the
|
|
813
|
-
* first value to be compared in the function.
|
|
814
|
-
* @param {K} b - The parameter `b` is of type `K`, which means it can be any type. It is used as one
|
|
815
|
-
* of the arguments for the comparison in the `_lt` function.
|
|
816
|
-
* @returns a boolean value.
|
|
817
|
-
*/
|
|
818
|
-
_lt(a, b) {
|
|
819
|
-
const extractedA = this.extractor(a);
|
|
820
|
-
const extractedB = this.extractor(b);
|
|
821
|
-
return this.variant === 'STANDARD' ? extractedA < extractedB : extractedA > extractedB;
|
|
822
|
-
}
|
|
823
|
-
/**
|
|
824
|
-
* The function compares two values using a custom extractor function and returns true if the first
|
|
825
|
-
* value is greater than the second value.
|
|
826
|
-
* @param {K} a - The parameter "a" is of type K, which means it can be any type.
|
|
827
|
-
* @param {K} b - The parameter "b" is of type K, which means it can be any type. It is used as one
|
|
828
|
-
* of the arguments for the comparison in the function.
|
|
829
|
-
* @returns a boolean value.
|
|
830
|
-
*/
|
|
831
|
-
_gt(a, b) {
|
|
832
|
-
const extractedA = this.extractor(a);
|
|
833
|
-
const extractedB = this.extractor(b);
|
|
834
|
-
return this.variant === 'STANDARD' ? extractedA > extractedB : extractedA < extractedB;
|
|
835
|
-
}
|
|
836
767
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { BinaryTreeDeleteResult, BTNCallback, KeyOrNodeOrEntry, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
|
|
2
|
-
import { CP, CRUD, RBTNColor } from '../../types';
|
|
1
|
+
import type { BinaryTreeDeleteResult, BTNCallback, Comparable, CRUD, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
|
|
3
2
|
import { BST, BSTNode } from './bst';
|
|
4
3
|
import { IBinaryTree } from '../../interfaces';
|
|
5
|
-
export declare class RedBlackTreeNode<K
|
|
4
|
+
export declare class RedBlackTreeNode<K extends Comparable, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
|
|
6
5
|
/**
|
|
7
6
|
* The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
|
|
8
7
|
* color.
|
|
@@ -27,7 +26,7 @@ export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTre
|
|
|
27
26
|
*/
|
|
28
27
|
set color(value: RBTNColor);
|
|
29
28
|
}
|
|
30
|
-
export declare class RedBlackTree<K
|
|
29
|
+
export declare class RedBlackTree<K extends Comparable, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, NODE, TREE> = RedBlackTree<K, V, NODE, RedBlackTreeNested<K, V, NODE>>> extends BST<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
|
|
31
30
|
/**
|
|
32
31
|
* This is the constructor function for a Red-Black Tree data structure in TypeScript.
|
|
33
32
|
* @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
|
|
@@ -255,13 +254,4 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
255
254
|
* @returns void, which means it does not return any value.
|
|
256
255
|
*/
|
|
257
256
|
protected _rightRotate(y: NODE | undefined): void;
|
|
258
|
-
/**
|
|
259
|
-
* The function compares two values using a comparator function and returns whether the first value
|
|
260
|
-
* is greater than, less than, or equal to the second value.
|
|
261
|
-
* @param {K} a - The parameter "a" is of type K.
|
|
262
|
-
* @param {K} b - The parameter "b" in the above code represents a K.
|
|
263
|
-
* @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
|
|
264
|
-
* than), 'LT' (less than), or 'EQ' (equal).
|
|
265
|
-
*/
|
|
266
|
-
protected _compare(a: K, b: K): CP;
|
|
267
257
|
}
|
|
@@ -314,10 +314,11 @@ export class RedBlackTree extends BST {
|
|
|
314
314
|
let parent = undefined;
|
|
315
315
|
while (this.isRealNode(current)) {
|
|
316
316
|
parent = current;
|
|
317
|
-
|
|
317
|
+
const compared = this.comparator(node.key, current.key);
|
|
318
|
+
if (compared < 0) {
|
|
318
319
|
current = current.left ?? this.NIL;
|
|
319
320
|
}
|
|
320
|
-
else if (
|
|
321
|
+
else if (compared > 0) {
|
|
321
322
|
current = current.right ?? this.NIL;
|
|
322
323
|
}
|
|
323
324
|
else {
|
|
@@ -597,22 +598,4 @@ export class RedBlackTree extends BST {
|
|
|
597
598
|
x.right = y;
|
|
598
599
|
y.parent = x;
|
|
599
600
|
}
|
|
600
|
-
/**
|
|
601
|
-
* The function compares two values using a comparator function and returns whether the first value
|
|
602
|
-
* is greater than, less than, or equal to the second value.
|
|
603
|
-
* @param {K} a - The parameter "a" is of type K.
|
|
604
|
-
* @param {K} b - The parameter "b" in the above code represents a K.
|
|
605
|
-
* @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
|
|
606
|
-
* than), 'LT' (less than), or 'EQ' (equal).
|
|
607
|
-
*/
|
|
608
|
-
_compare(a, b) {
|
|
609
|
-
const extractedA = this.extractor(a);
|
|
610
|
-
const extractedB = this.extractor(b);
|
|
611
|
-
const compared = extractedA - extractedB;
|
|
612
|
-
if (compared > 0)
|
|
613
|
-
return 'GT';
|
|
614
|
-
if (compared < 0)
|
|
615
|
-
return 'LT';
|
|
616
|
-
return 'EQ';
|
|
617
|
-
}
|
|
618
601
|
}
|
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, IterationType, KeyOrNodeOrEntry, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
|
|
9
|
-
import { RBTNColor } from '../../types';
|
|
8
|
+
import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, Comparable, IterationType, KeyOrNodeOrEntry, RBTNColor, TreeMultiMapNested, TreeMultiMapNodeNested, TreeMultiMapOptions } from '../../types';
|
|
10
9
|
import { IBinaryTree } from '../../interfaces';
|
|
11
10
|
import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
|
|
12
|
-
export declare class TreeMultiMapNode<K
|
|
11
|
+
export declare class TreeMultiMapNode<K extends Comparable, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>> extends RedBlackTreeNode<K, V, NODE> {
|
|
13
12
|
/**
|
|
14
13
|
* The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
|
|
15
14
|
* @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
|
|
@@ -36,7 +35,7 @@ export declare class TreeMultiMapNode<K = any, V = any, NODE extends TreeMultiMa
|
|
|
36
35
|
*/
|
|
37
36
|
set count(value: number);
|
|
38
37
|
}
|
|
39
|
-
export declare class TreeMultiMap<K
|
|
38
|
+
export declare class TreeMultiMap<K extends Comparable, V = any, NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>, TREE extends TreeMultiMap<K, V, NODE, TREE> = TreeMultiMap<K, V, NODE, TreeMultiMapNested<K, V, NODE>>> extends RedBlackTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
|
|
40
39
|
/**
|
|
41
40
|
* The constructor function initializes a new instance of the TreeMultiMap class with optional
|
|
42
41
|
* initial keys, nodes, or entries.
|
|
@@ -57,9 +57,7 @@ export declare class Heap<E = any> extends IterableElementBase<E> {
|
|
|
57
57
|
* @param elements
|
|
58
58
|
* @param options
|
|
59
59
|
*/
|
|
60
|
-
static heapify<E>(elements: Iterable<E>, options:
|
|
61
|
-
comparator: Comparator<E>;
|
|
62
|
-
}): Heap<E>;
|
|
60
|
+
static heapify<E>(elements: Iterable<E>, options: HeapOptions<E>): Heap<E>;
|
|
63
61
|
/**
|
|
64
62
|
* Time Complexity: O(log n)
|
|
65
63
|
* Space Complexity: O(1)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, KeyOrNodeOrEntry } from '../types';
|
|
3
|
-
export interface IBinaryTree<K
|
|
2
|
+
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, Comparable, KeyOrNodeOrEntry } from '../types';
|
|
3
|
+
export interface IBinaryTree<K extends Comparable, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTreeNested<K, V, N>> {
|
|
4
4
|
createNode(key: K, value?: N['value']): N;
|
|
5
|
-
createTree(options?: Partial<BinaryTreeOptions
|
|
5
|
+
createTree(options?: Partial<BinaryTreeOptions>): TREE;
|
|
6
6
|
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): boolean;
|
|
7
7
|
addMany(nodes: Iterable<KeyOrNodeOrEntry<K, V, N>>, values?: Iterable<V | undefined>): boolean[];
|
|
8
8
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<N>[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../data-structures';
|
|
2
2
|
import type { AVLTreeOptions } from './avl-tree';
|
|
3
|
-
|
|
4
|
-
export type
|
|
3
|
+
import { Comparable } from "../../utils";
|
|
4
|
+
export type AVLTreeMultiMapNodeNested<K extends Comparable, V> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type AVLTreeMultiMapNested<K extends Comparable, V, N extends AVLTreeMultiMapNode<K, V, N>> = AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
6
|
export type AVLTreeMultiMapOptions<K> = AVLTreeOptions<K> & {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AVLTree, AVLTreeNode } from '../../../data-structures';
|
|
2
2
|
import { BSTOptions } from './bst';
|
|
3
|
-
|
|
4
|
-
export type
|
|
3
|
+
import { Comparable } from "../../utils";
|
|
4
|
+
export type AVLTreeNodeNested<K extends Comparable, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type AVLTreeNested<K extends Comparable, V, N extends AVLTreeNode<K, V, N>> = AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
6
|
export type AVLTreeOptions<K> = BSTOptions<K> & {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
2
|
import { IterationType } from "../../common";
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
3
|
+
import { Comparable } from "../../utils";
|
|
4
|
+
export type BinaryTreeNodeNested<K extends Comparable, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type BinaryTreeNested<K extends Comparable, V, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type BinaryTreeOptions = {
|
|
6
7
|
iterationType?: IterationType;
|
|
7
|
-
extractor?: (key: K) => number;
|
|
8
8
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BST, BSTNode } from '../../../data-structures';
|
|
2
2
|
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
7
|
-
|
|
3
|
+
import { Comparator } from "../../common";
|
|
4
|
+
import { Comparable } from "../../utils";
|
|
5
|
+
export type BSTNodeNested<K extends Comparable, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type BSTNested<K extends Comparable, V, N extends BSTNode<K, V, N>> = BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
7
|
+
export type BSTOptions<K> = BinaryTreeOptions & {
|
|
8
|
+
comparator?: Comparator<K>;
|
|
8
9
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RedBlackTree, RedBlackTreeNode } from '../../../data-structures';
|
|
2
2
|
import type { BSTOptions } from "./bst";
|
|
3
|
+
import { Comparable } from "../../utils";
|
|
3
4
|
export type RBTNColor = 'RED' | 'BLACK';
|
|
4
|
-
export type RedBlackTreeNodeNested<K, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
-
export type RedBlackTreeNested<K, V, N extends RedBlackTreeNode<K, V, N>> = RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
-
export type RBTreeOptions<K> =
|
|
5
|
+
export type RedBlackTreeNodeNested<K extends Comparable, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type RedBlackTreeNested<K extends Comparable, V, N extends RedBlackTreeNode<K, V, N>> = RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
7
|
+
export type RBTreeOptions<K> = BSTOptions<K> & {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TreeMultiMap, TreeMultiMapNode } from '../../../data-structures';
|
|
2
2
|
import type { RBTreeOptions } from './rb-tree';
|
|
3
|
-
|
|
4
|
-
export type
|
|
3
|
+
import { Comparable } from "../../utils";
|
|
4
|
+
export type TreeMultiMapNodeNested<K extends Comparable, V> = TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
+
export type TreeMultiMapNested<K extends Comparable, V, N extends TreeMultiMapNode<K, V, N>> = TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
6
|
export type TreeMultiMapOptions<K> = RBTreeOptions<K> & {};
|