heap-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.
Files changed (42) hide show
  1. package/README.md +72 -80
  2. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -12
  3. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +1 -10
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +3 -3
  5. package/dist/data-structures/binary-tree/avl-tree.js +12 -12
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +5 -12
  7. package/dist/data-structures/binary-tree/binary-tree.js +22 -32
  8. package/dist/data-structures/binary-tree/bst.d.ts +32 -77
  9. package/dist/data-structures/binary-tree/bst.js +68 -136
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -13
  11. package/dist/data-structures/binary-tree/rb-tree.js +3 -20
  12. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  13. package/dist/data-structures/heap/heap.d.ts +1 -3
  14. package/dist/interfaces/binary-tree.d.ts +3 -3
  15. package/dist/types/common.d.ts +1 -1
  16. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -2
  17. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -2
  18. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
  19. package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
  20. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -2
  22. package/dist/types/utils/utils.d.ts +10 -1
  23. package/dist/utils/utils.d.ts +2 -1
  24. package/dist/utils/utils.js +29 -1
  25. package/package.json +2 -2
  26. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +4 -12
  27. package/src/data-structures/binary-tree/avl-tree.ts +15 -14
  28. package/src/data-structures/binary-tree/binary-tree.ts +29 -38
  29. package/src/data-structures/binary-tree/bst.ts +78 -148
  30. package/src/data-structures/binary-tree/rb-tree.ts +8 -22
  31. package/src/data-structures/binary-tree/tree-multi-map.ts +4 -3
  32. package/src/data-structures/heap/heap.ts +1 -1
  33. package/src/interfaces/binary-tree.ts +4 -3
  34. package/src/types/common.ts +1 -1
  35. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -2
  36. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -2
  37. package/src/types/data-structures/binary-tree/binary-tree.ts +5 -5
  38. package/src/types/data-structures/binary-tree/bst.ts +6 -5
  39. package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
  40. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -2
  41. package/src/types/utils/utils.ts +14 -1
  42. package/src/utils/utils.ts +20 -1
@@ -7,22 +7,27 @@
7
7
  */
8
8
  import type {
9
9
  BSTNested,
10
+ BSTNKeyOrNode,
10
11
  BSTNodeNested,
11
12
  BSTOptions,
12
13
  BTNCallback,
13
14
  BTNodePureExemplar,
15
+ Comparable,
16
+ Comparator,
17
+ CP,
18
+ DFSOrderPattern,
19
+ IterationType,
14
20
  KeyOrNodeOrEntry
15
21
  } from '../../types';
16
- import { BSTNKeyOrNode, BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
17
22
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
18
23
  import { IBinaryTree } from '../../interfaces';
19
24
  import { Queue } from '../queue';
20
25
 
21
- export class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<
22
- K,
23
- V,
24
- NODE
25
- > {
26
+ export class BSTNode<
27
+ K extends Comparable,
28
+ V = any,
29
+ NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>
30
+ > extends BinaryTreeNode<K, V, NODE> {
26
31
  override parent?: NODE;
27
32
 
28
33
  constructor(key: K, value?: V) {
@@ -88,7 +93,7 @@ export class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNod
88
93
  * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
89
94
  */
90
95
  export class BST<
91
- K = any,
96
+ K extends Comparable,
92
97
  V = any,
93
98
  NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>,
94
99
  TREE extends BST<K, V, NODE, TREE> = BST<K, V, NODE, BSTNested<K, V, NODE>>
@@ -96,10 +101,11 @@ export class BST<
96
101
  extends BinaryTree<K, V, NODE, TREE>
97
102
  implements IBinaryTree<K, V, NODE, TREE> {
98
103
  /**
99
- * This is the constructor function for a TypeScript class that initializes a binary search tree with
100
- * optional keys or nodes or entries and options.
101
- * @param keysOrNodesOrEntries - An iterable object that contains keys, nodes, or entries. It is used
102
- * to initialize the binary search tree with the provided keys, nodes, or entries.
104
+ * This is the constructor function for a Binary Search Tree class in TypeScript, which initializes
105
+ * the tree with keys, nodes, or entries and optional options.
106
+ * @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
107
+ * contain keys, nodes, or entries. It is used to initialize the binary search tree with the provided
108
+ * keys, nodes, or entries.
103
109
  * @param [options] - The `options` parameter is an optional object that can contain additional
104
110
  * configuration options for the binary search tree. It can have the following properties:
105
111
  */
@@ -107,16 +113,14 @@ export class BST<
107
113
  super([], options);
108
114
 
109
115
  if (options) {
110
- const { variant } = options;
111
- if (variant) this._variant = variant;
116
+ const { comparator } = options;
117
+ if (comparator) this._comparator = comparator;
112
118
  }
113
119
 
114
- this._root = undefined;
115
-
116
120
  if (keysOrNodesOrEntries) this.addMany(keysOrNodesOrEntries);
117
121
  }
118
122
 
119
- protected override _root?: NODE;
123
+ protected override _root?: NODE = undefined;
120
124
 
121
125
  /**
122
126
  * The function returns the root node of a tree structure.
@@ -126,14 +130,18 @@ export class BST<
126
130
  return this._root;
127
131
  }
128
132
 
129
- protected _variant: BSTVariant = 'STANDARD';
133
+ protected _comparator: Comparator<K> = (a: K, b: K): CP => {
134
+ if (a > b) return 1;
135
+ if (a < b) return -1;
136
+ return 0;
137
+ };
130
138
 
131
139
  /**
132
- * The function returns the value of the _variant property.
133
- * @returns The value of the `_variant` property.
140
+ * The function returns the value of the _comparator property.
141
+ * @returns The `_comparator` property is being returned.
134
142
  */
135
- get variant() {
136
- return this._variant;
143
+ get comparator() {
144
+ return this._comparator;
137
145
  }
138
146
 
139
147
  /**
@@ -159,7 +167,7 @@ export class BST<
159
167
  override createTree(options?: Partial<BSTOptions<K>>): TREE {
160
168
  return new BST<K, V, NODE, TREE>([], {
161
169
  iterationType: this.iterationType,
162
- variant: this.variant,
170
+ comparator: this.comparator,
163
171
  ...options
164
172
  }) as TREE;
165
173
  }
@@ -248,13 +256,11 @@ export class BST<
248
256
  * Time Complexity: O(log n)
249
257
  * Space Complexity: O(1)
250
258
  *
251
- * The `add` function adds a new node to a binary tree, updating the value if the key already exists
252
- * or inserting a new node if the key is unique.
253
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can accept three types of values:
254
- * @param {V} [value] - The `value` parameter represents the value associated with the key that is
255
- * being added to the binary tree.
256
- * @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
257
- * node was not added.
259
+ * The `add` function in TypeScript adds a new node to a binary search tree based on the key value,
260
+ * updating the value if the key already exists.
261
+ * @param keyOrNodeOrEntry - It is a parameter that can accept three types of values:
262
+ * @param {V} [value] - The value to be added to the binary search tree.
263
+ * @returns The method returns a boolean value.
258
264
  */
259
265
  override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
260
266
  const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
@@ -268,7 +274,7 @@ export class BST<
268
274
 
269
275
  let current = this.root;
270
276
  while (current !== undefined) {
271
- if (this._compare(current.key, newNode.key) === 'EQ') {
277
+ if (this.comparator(current.key, newNode.key) === 0) {
272
278
  // if (current !== newNode) {
273
279
  // The key value is the same but the reference is different, update the value of the existing node
274
280
  this._replaceNode(current, newNode);
@@ -280,7 +286,7 @@ export class BST<
280
286
 
281
287
  // return;
282
288
  // }
283
- } else if (this._compare(current.key, newNode.key) === 'GT') {
289
+ } else if (this.comparator(current.key, newNode.key) > 0) {
284
290
  if (current.left === undefined) {
285
291
  current.left = newNode;
286
292
  this._size++;
@@ -309,21 +315,24 @@ export class BST<
309
315
  * Time Complexity: O(k log n)
310
316
  * Space Complexity: O(k + log n)
311
317
  *
312
- * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
313
- * balancing the tree after each addition.
314
- * @param keysOrNodesOrEntries - An iterable containing the keys, nodes, or entries to be added to
315
- * the binary tree.
318
+ * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure, balancing
319
+ * the structure if specified, and returns an array indicating whether each key or node was
320
+ * successfully inserted.
321
+ * @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries to be added to the
322
+ * data structure.
316
323
  * @param [values] - An optional iterable of values to be associated with the keys or nodes being
317
324
  * added. If provided, the values will be assigned to the corresponding keys or nodes in the same
318
325
  * order. If not provided, undefined will be assigned as the value for each key or node.
319
- * @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
320
- * balanced or not. If set to true, the add operation will be balanced using a binary search tree
321
- * algorithm. If set to false, the add operation will not be balanced and the nodes will be added
322
- * in the order they appear in the input.
323
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
324
- * type of iteration to use when adding multiple keys or nodes. It has a default value of
325
- * `this.iterationType`, which suggests that it is a property of the current object.
326
- * @returns The function `addMany` returns an array of nodes (`NODE`) or `undefined` values.
326
+ * @param [isBalanceAdd=true] - A boolean flag indicating whether the tree should be balanced after
327
+ * adding the elements. If set to true, the tree will be balanced using a binary search tree
328
+ * algorithm. If set to false, the elements will be added without balancing the tree. The default
329
+ * value is true.
330
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
331
+ * specifies the type of iteration to use when adding multiple keys or nodes to the binary tree. It
332
+ * has a default value of `this.iterationType`, which means it will use the iteration type specified
333
+ * in the binary tree instance.
334
+ * @returns The function `addMany` returns an array of booleans indicating whether each key or node
335
+ * or entry was successfully inserted into the data structure.
327
336
  */
328
337
  override addMany(
329
338
  keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>,
@@ -362,16 +371,20 @@ export class BST<
362
371
  let sorted: BTNodePureExemplar<K, V, NODE>[] = [];
363
372
 
364
373
  sorted = realBTNExemplars.sort((a, b) => {
365
- let aR: number, bR: number;
366
- if (this.isEntry(a)) aR = this.extractor(a[0]);
367
- else if (this.isRealNode(a)) aR = this.extractor(a.key);
368
- else aR = this.extractor(a);
369
-
370
- if (this.isEntry(b)) bR = this.extractor(b[0]);
371
- else if (this.isRealNode(b)) bR = this.extractor(b.key);
372
- else bR = this.extractor(b);
373
-
374
- return aR - bR;
374
+ let keyA: K | undefined | null, keyB: K | undefined | null;
375
+ if (this.isEntry(a)) {
376
+ keyA = a[0];
377
+ } else if (this.isRealNode(a)) keyA = a.key;
378
+ else keyA = a;
379
+
380
+ if (this.isEntry(b)) keyB = b[0];
381
+ else if (this.isRealNode(b)) keyB = b.key;
382
+ else keyB = b;
383
+
384
+ if (keyA !== undefined && keyA !== null && keyB !== undefined && keyB !== null) {
385
+ return this.comparator(keyA, keyB);
386
+ }
387
+ return 0;
375
388
  });
376
389
 
377
390
  const _dfs = (arr: BTNodePureExemplar<K, V, NODE>[]) => {
@@ -462,8 +475,8 @@ export class BST<
462
475
  if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right)) return;
463
476
  // TODO potential bug
464
477
  if (callback === this._DEFAULT_CALLBACK) {
465
- if (this.isRealNode(cur.left) && this._compare(cur.key, identifier as K) === 'GT') dfs(cur.left);
466
- if (this.isRealNode(cur.right) && this._compare(cur.key, identifier as K) === 'LT') dfs(cur.right);
478
+ if (this.isRealNode(cur.left) && this.comparator(cur.key, identifier as K) > 0) dfs(cur.left);
479
+ if (this.isRealNode(cur.right) && this.comparator(cur.key, identifier as K) < 0) dfs(cur.right);
467
480
  } else {
468
481
  this.isRealNode(cur.left) && dfs(cur.left);
469
482
  this.isRealNode(cur.right) && dfs(cur.right);
@@ -482,8 +495,8 @@ export class BST<
482
495
  }
483
496
  // TODO potential bug
484
497
  if (callback === this._DEFAULT_CALLBACK) {
485
- if (this.isRealNode(cur.right) && this._compare(cur.key, identifier as K) === 'LT') stack.push(cur.right);
486
- if (this.isRealNode(cur.left) && this._compare(cur.key, identifier as K) === 'GT') stack.push(cur.left);
498
+ if (this.isRealNode(cur.right) && this.comparator(cur.key, identifier as K) < 0) stack.push(cur.right);
499
+ if (this.isRealNode(cur.left) && this.comparator(cur.key, identifier as K) > 0) stack.push(cur.left);
487
500
 
488
501
  // if (this.isRealNode(cur.right) && this._lt(cur.key, identifier as K)) stack.push(cur.right);
489
502
  // if (this.isRealNode(cur.left) && this._gt(cur.key, identifier as K)) stack.push(cur.left);
@@ -654,42 +667,6 @@ export class BST<
654
667
  return super.listLevels(callback, beginRoot, iterationType, false);
655
668
  }
656
669
 
657
- /**
658
- * Time Complexity: O(log n)
659
- * Space Complexity: O(1)
660
- */
661
-
662
- /**
663
- * Time Complexity: O(log n)
664
- * Space Complexity: O(1)
665
- *
666
- * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
667
- * leftmost node if the comparison result is greater than.
668
- * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
669
- * type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
670
- * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
671
- * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
672
- * the key of the leftmost node if the comparison result is greater than, and the key of the
673
- * rightmost node otherwise. If no node is found, it returns 0.
674
- */
675
- lastKey(beginRoot: KeyOrNodeOrEntry<K, V, NODE> = this.root): K | undefined {
676
- let current = this.ensureNode(beginRoot);
677
- if (!current) return undefined;
678
-
679
- if (this._variant === 'STANDARD') {
680
- // For 'STANDARD', find the rightmost node
681
- while (current.right !== undefined) {
682
- current = current.right;
683
- }
684
- } else {
685
- // For BSTVariant.MAX, find the leftmost node
686
- while (current.left !== undefined) {
687
- current = current.left;
688
- }
689
- }
690
- return current.key;
691
- }
692
-
693
670
  /**
694
671
  * Time Complexity: O(log n)
695
672
  * Space Complexity: O(log n)
@@ -718,21 +695,21 @@ export class BST<
718
695
  */
719
696
  lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(
720
697
  callback: C = this._DEFAULT_CALLBACK as C,
721
- lesserOrGreater: CP = 'LT',
698
+ lesserOrGreater: CP = -1,
722
699
  targetNode: KeyOrNodeOrEntry<K, V, NODE> = this.root,
723
700
  iterationType: IterationType = this.iterationType
724
701
  ): ReturnType<C>[] {
725
- targetNode = this.ensureNode(targetNode);
702
+ const targetNodeEnsured = this.ensureNode(targetNode);
726
703
  const ans: ReturnType<BTNCallback<NODE>>[] = [];
727
- if (!targetNode) return ans;
704
+ if (!targetNodeEnsured) return ans;
728
705
  if (!this.root) return ans;
729
706
 
730
- const targetKey = targetNode.key;
707
+ const targetKey = targetNodeEnsured.key;
731
708
 
732
709
  if (iterationType === 'RECURSIVE') {
733
710
  const dfs = (cur: NODE) => {
734
- const compared = this._compare(cur.key, targetKey);
735
- if (compared === lesserOrGreater) ans.push(callback(cur));
711
+ const compared = this.comparator(cur.key, targetKey);
712
+ if (Math.sign(compared) === lesserOrGreater) ans.push(callback(cur));
736
713
 
737
714
  if (this.isRealNode(cur.left)) dfs(cur.left);
738
715
  if (this.isRealNode(cur.right)) dfs(cur.right);
@@ -745,8 +722,8 @@ export class BST<
745
722
  while (queue.size > 0) {
746
723
  const cur = queue.shift();
747
724
  if (this.isRealNode(cur)) {
748
- const compared = this._compare(cur.key, targetKey);
749
- if (compared === lesserOrGreater) ans.push(callback(cur));
725
+ const compared = this.comparator(cur.key, targetKey);
726
+ if (Math.sign(compared) === lesserOrGreater) ans.push(callback(cur));
750
727
 
751
728
  if (this.isRealNode(cur.left)) queue.push(cur.left);
752
729
  if (this.isRealNode(cur.right)) queue.push(cur.right);
@@ -888,51 +865,4 @@ export class BST<
888
865
  }
889
866
  this._root = v;
890
867
  }
891
-
892
- /**
893
- * The function compares two values using a comparator function and returns whether the first value
894
- * is greater than, less than, or equal to the second value.
895
- * @param {K} a - The parameter "a" is of type K.
896
- * @param {K} b - The parameter "b" in the above code represents a K.
897
- * @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
898
- * than), 'LT' (less than), or 'EQ' (equal).
899
- */
900
- protected _compare(a: K, b: K): CP {
901
- const extractedA = this.extractor(a);
902
- const extractedB = this.extractor(b);
903
- const compared = this.variant === 'STANDARD' ? extractedA - extractedB : extractedB - extractedA;
904
-
905
- if (compared > 0) return 'GT';
906
- if (compared < 0) return 'LT';
907
- return 'EQ';
908
- }
909
-
910
- /**
911
- * The function `_lt` compares two values `a` and `b` using an extractor function and returns true if
912
- * `a` is less than `b` based on the specified variant.
913
- * @param {K} a - The parameter "a" is of type "K", which means it can be any type. It represents the
914
- * first value to be compared in the function.
915
- * @param {K} b - The parameter `b` is of type `K`, which means it can be any type. It is used as one
916
- * of the arguments for the comparison in the `_lt` function.
917
- * @returns a boolean value.
918
- */
919
- protected _lt(a: K, b: K): boolean {
920
- const extractedA = this.extractor(a);
921
- const extractedB = this.extractor(b);
922
- return this.variant === 'STANDARD' ? extractedA < extractedB : extractedA > extractedB;
923
- }
924
-
925
- /**
926
- * The function compares two values using a custom extractor function and returns true if the first
927
- * value is greater than the second value.
928
- * @param {K} a - The parameter "a" is of type K, which means it can be any type.
929
- * @param {K} b - The parameter "b" is of type K, which means it can be any type. It is used as one
930
- * of the arguments for the comparison in the function.
931
- * @returns a boolean value.
932
- */
933
- protected _gt(a: K, b: K): boolean {
934
- const extractedA = this.extractor(a);
935
- const extractedB = this.extractor(b);
936
- return this.variant === 'STANDARD' ? extractedA > extractedB : extractedA < extractedB;
937
- }
938
868
  }
@@ -1,17 +1,19 @@
1
1
  import type {
2
2
  BinaryTreeDeleteResult,
3
3
  BTNCallback,
4
+ Comparable,
5
+ CRUD,
4
6
  KeyOrNodeOrEntry,
7
+ RBTNColor,
5
8
  RBTreeOptions,
6
9
  RedBlackTreeNested,
7
10
  RedBlackTreeNodeNested
8
11
  } from '../../types';
9
- import { CP, CRUD, RBTNColor } from '../../types';
10
12
  import { BST, BSTNode } from './bst';
11
13
  import { IBinaryTree } from '../../interfaces';
12
14
 
13
15
  export class RedBlackTreeNode<
14
- K = any,
16
+ K extends Comparable,
15
17
  V = any,
16
18
  NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>
17
19
  > extends BSTNode<K, V, NODE> {
@@ -51,7 +53,7 @@ export class RedBlackTreeNode<
51
53
  }
52
54
 
53
55
  export class RedBlackTree<
54
- K = any,
56
+ K extends Comparable,
55
57
  V = any,
56
58
  NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>,
57
59
  TREE extends RedBlackTree<K, V, NODE, TREE> = RedBlackTree<K, V, NODE, RedBlackTreeNested<K, V, NODE>>
@@ -363,9 +365,10 @@ export class RedBlackTree<
363
365
 
364
366
  while (this.isRealNode(current)) {
365
367
  parent = current;
366
- if (node.key < current.key) {
368
+ const compared = this.comparator(node.key, current.key);
369
+ if (compared < 0) {
367
370
  current = current.left ?? this.NIL;
368
- } else if (node.key > current.key) {
371
+ } else if (compared > 0) {
369
372
  current = current.right ?? this.NIL;
370
373
  } else {
371
374
  this._replaceNode(current, node);
@@ -656,21 +659,4 @@ export class RedBlackTree<
656
659
  x.right = y;
657
660
  y.parent = x;
658
661
  }
659
-
660
- /**
661
- * The function compares two values using a comparator function and returns whether the first value
662
- * is greater than, less than, or equal to the second value.
663
- * @param {K} a - The parameter "a" is of type K.
664
- * @param {K} b - The parameter "b" in the above code represents a K.
665
- * @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
666
- * than), 'LT' (less than), or 'EQ' (equal).
667
- */
668
- protected override _compare(a: K, b: K): CP {
669
- const extractedA = this.extractor(a);
670
- const extractedB = this.extractor(b);
671
- const compared = extractedA - extractedB;
672
- if (compared > 0) return 'GT';
673
- if (compared < 0) return 'LT';
674
- return 'EQ';
675
- }
676
662
  }
@@ -9,18 +9,19 @@ import type {
9
9
  BinaryTreeDeleteResult,
10
10
  BSTNKeyOrNode,
11
11
  BTNCallback,
12
+ Comparable,
12
13
  IterationType,
13
14
  KeyOrNodeOrEntry,
15
+ RBTNColor,
14
16
  TreeMultiMapNested,
15
17
  TreeMultiMapNodeNested,
16
18
  TreeMultiMapOptions
17
19
  } from '../../types';
18
- import { RBTNColor } from '../../types';
19
20
  import { IBinaryTree } from '../../interfaces';
20
21
  import { RedBlackTree, RedBlackTreeNode } from './rb-tree';
21
22
 
22
23
  export class TreeMultiMapNode<
23
- K = any,
24
+ K extends Comparable,
24
25
  V = any,
25
26
  NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNodeNested<K, V>
26
27
  > extends RedBlackTreeNode<K, V, NODE> {
@@ -62,7 +63,7 @@ export class TreeMultiMapNode<
62
63
  }
63
64
 
64
65
  export class TreeMultiMap<
65
- K = any,
66
+ K extends Comparable,
66
67
  V = any,
67
68
  NODE extends TreeMultiMapNode<K, V, NODE> = TreeMultiMapNode<K, V, TreeMultiMapNodeNested<K, V>>,
68
69
  TREE extends TreeMultiMap<K, V, NODE, TREE> = TreeMultiMap<K, V, NODE, TreeMultiMapNested<K, V, NODE>>
@@ -93,7 +93,7 @@ export class Heap<E = any> extends IterableElementBase<E> {
93
93
  * @param elements
94
94
  * @param options
95
95
  */
96
- static heapify<E>(elements: Iterable<E>, options: { comparator: Comparator<E> }): Heap<E> {
96
+ static heapify<E>(elements: Iterable<E>, options: HeapOptions<E>): Heap<E> {
97
97
  return new Heap<E>(elements, options);
98
98
  }
99
99
 
@@ -1,22 +1,23 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../data-structures';
2
- import {
2
+ import type {
3
3
  BinaryTreeDeleteResult,
4
4
  BinaryTreeNested,
5
5
  BinaryTreeNodeNested,
6
6
  BinaryTreeOptions,
7
7
  BTNCallback,
8
+ Comparable,
8
9
  KeyOrNodeOrEntry
9
10
  } from '../types';
10
11
 
11
12
  export interface IBinaryTree<
12
- K = number,
13
+ K extends Comparable,
13
14
  V = any,
14
15
  N extends BinaryTreeNode<K, V, N> = BinaryTreeNodeNested<K, V>,
15
16
  TREE extends BinaryTree<K, V, N, TREE> = BinaryTreeNested<K, V, N>
16
17
  > {
17
18
  createNode(key: K, value?: N['value']): N;
18
19
 
19
- createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
20
+ createTree(options?: Partial<BinaryTreeOptions>): TREE;
20
21
 
21
22
  add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): boolean;
22
23
 
@@ -1,5 +1,5 @@
1
1
  export type BSTVariant = 'STANDARD' | 'INVERSE';
2
- export type CP = 'LT' | 'EQ' | 'GT';
2
+ export type CP = 1 | -1 | 0;
3
3
 
4
4
  /**
5
5
  * Enum representing different loop types.
@@ -1,8 +1,9 @@
1
1
  import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../data-structures';
2
2
  import type { AVLTreeOptions } from './avl-tree';
3
+ import { Comparable } from "../../utils";
3
4
 
4
- export type AVLTreeMultiMapNodeNested<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, AVLTreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
5
+ 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
6
 
6
- export type AVLTreeMultiMapNested<K, 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
8
 
8
9
  export type AVLTreeMultiMapOptions<K> = AVLTreeOptions<K> & {}
@@ -1,8 +1,9 @@
1
1
  import { AVLTree, AVLTreeNode } from '../../../data-structures';
2
2
  import { BSTOptions } from './bst';
3
+ import { Comparable } from "../../utils";
3
4
 
4
- export type AVLTreeNodeNested<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, AVLTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
5
+ 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
6
 
6
- export type AVLTreeNested<K, 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
8
 
8
9
  export type AVLTreeOptions<K> = BSTOptions<K> & {};
@@ -1,11 +1,11 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
2
2
  import { IterationType } from "../../common";
3
+ import { Comparable } from "../../utils";
3
4
 
4
- export type BinaryTreeNodeNested<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, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
5
+ 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
6
 
6
- export type BinaryTreeNested<K, 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
8
 
8
- export type BinaryTreeOptions<K> = {
9
- iterationType?: IterationType,
10
- extractor?: (key: K) => number
9
+ export type BinaryTreeOptions = {
10
+ iterationType?: IterationType
11
11
  }
@@ -1,11 +1,12 @@
1
1
  import { BST, BSTNode } from '../../../data-structures';
2
2
  import type { BinaryTreeOptions } from './binary-tree';
3
- import { BSTVariant } from "../../common";
3
+ import { Comparator } from "../../common";
4
+ import { Comparable } from "../../utils";
4
5
 
5
- export type BSTNodeNested<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, BSTNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
6
+ 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
7
 
7
- export type BSTNested<K, 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
8
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
8
9
 
9
- export type BSTOptions<K> = BinaryTreeOptions<K> & {
10
- variant?: BSTVariant
10
+ export type BSTOptions<K> = BinaryTreeOptions & {
11
+ comparator?: Comparator<K>
11
12
  }
@@ -1,10 +1,11 @@
1
1
  import { RedBlackTree, RedBlackTreeNode } from '../../../data-structures';
2
2
  import type { BSTOptions } from "./bst";
3
+ import { Comparable } from "../../utils";
3
4
 
4
5
  export type RBTNColor = 'RED' | 'BLACK';
5
6
 
6
- 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7
8
 
8
- 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
9
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
9
10
 
10
- export type RBTreeOptions<K> = Omit<BSTOptions<K>, 'variant'> & {};
11
+ export type RBTreeOptions<K> = BSTOptions<K> & {};