data-structure-typed 1.34.7 → 1.34.9

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 (167) hide show
  1. package/.eslintrc.js +1 -0
  2. package/CHANGELOG.md +1 -1
  3. package/CONTRIBUTING.md +0 -0
  4. package/README.md +8 -8
  5. package/dist/data-structures/binary-tree/aa-tree.js +2 -5
  6. package/dist/data-structures/binary-tree/aa-tree.js.map +1 -1
  7. package/dist/data-structures/binary-tree/abstract-binary-tree.js +314 -457
  8. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  9. package/dist/data-structures/binary-tree/avl-tree.js +64 -90
  10. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/data-structures/binary-tree/b-tree.js +2 -5
  12. package/dist/data-structures/binary-tree/b-tree.js.map +1 -1
  13. package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
  14. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  15. package/dist/data-structures/binary-tree/binary-tree.js +12 -31
  16. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  17. package/dist/data-structures/binary-tree/bst.js +157 -244
  18. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  19. package/dist/data-structures/binary-tree/rb-tree.js +20 -44
  20. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
  21. package/dist/data-structures/binary-tree/segment-tree.js +80 -122
  22. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
  23. package/dist/data-structures/binary-tree/splay-tree.js +2 -5
  24. package/dist/data-structures/binary-tree/splay-tree.js.map +1 -1
  25. package/dist/data-structures/binary-tree/tree-multiset.js +168 -239
  26. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  27. package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
  28. package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -1
  29. package/dist/data-structures/graph/abstract-graph.js +351 -585
  30. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  31. package/dist/data-structures/graph/directed-graph.js +152 -282
  32. package/dist/data-structures/graph/directed-graph.js.map +1 -1
  33. package/dist/data-structures/graph/map-graph.js +47 -88
  34. package/dist/data-structures/graph/map-graph.js.map +1 -1
  35. package/dist/data-structures/graph/undirected-graph.js +91 -180
  36. package/dist/data-structures/graph/undirected-graph.js.map +1 -1
  37. package/dist/data-structures/hash/coordinate-map.js +23 -45
  38. package/dist/data-structures/hash/coordinate-map.js.map +1 -1
  39. package/dist/data-structures/hash/coordinate-set.js +20 -42
  40. package/dist/data-structures/hash/coordinate-set.js.map +1 -1
  41. package/dist/data-structures/hash/hash-map.js +85 -247
  42. package/dist/data-structures/hash/hash-map.js.map +1 -1
  43. package/dist/data-structures/hash/hash-table.js +87 -128
  44. package/dist/data-structures/hash/hash-table.js.map +1 -1
  45. package/dist/data-structures/hash/pair.js +2 -5
  46. package/dist/data-structures/hash/pair.js.map +1 -1
  47. package/dist/data-structures/hash/tree-map.js +2 -5
  48. package/dist/data-structures/hash/tree-map.js.map +1 -1
  49. package/dist/data-structures/hash/tree-set.js +2 -5
  50. package/dist/data-structures/hash/tree-set.js.map +1 -1
  51. package/dist/data-structures/heap/heap.js +56 -80
  52. package/dist/data-structures/heap/heap.js.map +1 -1
  53. package/dist/data-structures/heap/max-heap.js +8 -26
  54. package/dist/data-structures/heap/max-heap.js.map +1 -1
  55. package/dist/data-structures/heap/min-heap.js +8 -26
  56. package/dist/data-structures/heap/min-heap.js.map +1 -1
  57. package/dist/data-structures/linked-list/doubly-linked-list.js +149 -218
  58. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  59. package/dist/data-structures/linked-list/singly-linked-list.js +119 -218
  60. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
  61. package/dist/data-structures/linked-list/skip-linked-list.js +50 -70
  62. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
  63. package/dist/data-structures/matrix/matrix.js +7 -8
  64. package/dist/data-structures/matrix/matrix.js.map +1 -1
  65. package/dist/data-structures/matrix/matrix2d.js +57 -70
  66. package/dist/data-structures/matrix/matrix2d.js.map +1 -1
  67. package/dist/data-structures/matrix/navigator.js +18 -37
  68. package/dist/data-structures/matrix/navigator.js.map +1 -1
  69. package/dist/data-structures/matrix/vector2d.js +63 -84
  70. package/dist/data-structures/matrix/vector2d.js.map +1 -1
  71. package/dist/data-structures/priority-queue/max-priority-queue.js +13 -41
  72. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  73. package/dist/data-structures/priority-queue/min-priority-queue.js +13 -41
  74. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  75. package/dist/data-structures/priority-queue/priority-queue.js +93 -139
  76. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
  77. package/dist/data-structures/queue/deque.js +82 -128
  78. package/dist/data-structures/queue/deque.js.map +1 -1
  79. package/dist/data-structures/queue/queue.js +57 -157
  80. package/dist/data-structures/queue/queue.js.map +1 -1
  81. package/dist/data-structures/stack/stack.js +21 -22
  82. package/dist/data-structures/stack/stack.js.map +1 -1
  83. package/dist/data-structures/tree/tree.js +33 -46
  84. package/dist/data-structures/tree/tree.js.map +1 -1
  85. package/dist/data-structures/trie/trie.js +93 -200
  86. package/dist/data-structures/trie/trie.js.map +1 -1
  87. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
  88. package/dist/utils/utils.js +22 -107
  89. package/dist/utils/utils.js.map +1 -1
  90. package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +124 -123
  91. package/lib/data-structures/binary-tree/abstract-binary-tree.js +136 -216
  92. package/lib/data-structures/binary-tree/avl-tree.d.ts +19 -10
  93. package/lib/data-structures/binary-tree/avl-tree.js +35 -13
  94. package/lib/data-structures/binary-tree/binary-tree.d.ts +6 -6
  95. package/lib/data-structures/binary-tree/binary-tree.js +7 -7
  96. package/lib/data-structures/binary-tree/bst.d.ts +34 -34
  97. package/lib/data-structures/binary-tree/bst.js +86 -89
  98. package/lib/data-structures/binary-tree/rb-tree.d.ts +3 -3
  99. package/lib/data-structures/binary-tree/rb-tree.js +4 -4
  100. package/lib/data-structures/binary-tree/tree-multiset.d.ts +40 -42
  101. package/lib/data-structures/binary-tree/tree-multiset.js +76 -86
  102. package/lib/data-structures/graph/abstract-graph.d.ts +62 -62
  103. package/lib/data-structures/graph/abstract-graph.js +86 -86
  104. package/lib/data-structures/graph/directed-graph.d.ts +51 -51
  105. package/lib/data-structures/graph/directed-graph.js +63 -63
  106. package/lib/data-structures/graph/map-graph.d.ts +13 -13
  107. package/lib/data-structures/graph/map-graph.js +12 -12
  108. package/lib/data-structures/graph/undirected-graph.d.ts +30 -30
  109. package/lib/data-structures/graph/undirected-graph.js +32 -32
  110. package/lib/data-structures/priority-queue/priority-queue.d.ts +3 -3
  111. package/lib/data-structures/priority-queue/priority-queue.js +3 -3
  112. package/lib/data-structures/tree/tree.d.ts +4 -4
  113. package/lib/data-structures/tree/tree.js +6 -6
  114. package/lib/interfaces/abstract-binary-tree.d.ts +37 -42
  115. package/lib/interfaces/abstract-graph.d.ts +13 -13
  116. package/lib/interfaces/avl-tree.d.ts +6 -4
  117. package/lib/interfaces/bst.d.ts +10 -9
  118. package/lib/interfaces/directed-graph.d.ts +5 -5
  119. package/lib/interfaces/rb-tree.d.ts +2 -2
  120. package/lib/interfaces/undirected-graph.d.ts +2 -2
  121. package/lib/types/data-structures/abstract-binary-tree.d.ts +3 -3
  122. package/lib/types/data-structures/abstract-binary-tree.js +0 -1
  123. package/lib/types/data-structures/abstract-graph.d.ts +2 -2
  124. package/lib/types/data-structures/bst.d.ts +2 -2
  125. package/lib/types/data-structures/tree-multiset.d.ts +1 -1
  126. package/lib/types/utils/validate-type.d.ts +8 -8
  127. package/package.json +6 -6
  128. package/scripts/rename_clear_files.sh +29 -0
  129. package/src/data-structures/binary-tree/abstract-binary-tree.ts +241 -293
  130. package/src/data-structures/binary-tree/avl-tree.ts +43 -14
  131. package/src/data-structures/binary-tree/binary-tree.ts +8 -8
  132. package/src/data-structures/binary-tree/bst.ts +101 -96
  133. package/src/data-structures/binary-tree/rb-tree.ts +9 -9
  134. package/src/data-structures/binary-tree/tree-multiset.ts +82 -94
  135. package/src/data-structures/graph/abstract-graph.ts +114 -109
  136. package/src/data-structures/graph/directed-graph.ts +77 -77
  137. package/src/data-structures/graph/map-graph.ts +20 -15
  138. package/src/data-structures/graph/undirected-graph.ts +39 -39
  139. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  140. package/src/data-structures/tree/tree.ts +7 -7
  141. package/src/interfaces/abstract-binary-tree.ts +37 -50
  142. package/src/interfaces/abstract-graph.ts +13 -13
  143. package/src/interfaces/avl-tree.ts +6 -4
  144. package/src/interfaces/bst.ts +9 -9
  145. package/src/interfaces/directed-graph.ts +5 -5
  146. package/src/interfaces/rb-tree.ts +2 -2
  147. package/src/interfaces/undirected-graph.ts +2 -2
  148. package/src/types/data-structures/abstract-binary-tree.ts +3 -4
  149. package/src/types/data-structures/abstract-graph.ts +2 -2
  150. package/src/types/data-structures/bst.ts +2 -2
  151. package/src/types/data-structures/tree-multiset.ts +1 -1
  152. package/src/types/utils/validate-type.ts +10 -10
  153. package/test/integration/avl-tree.test.ts +24 -24
  154. package/test/integration/bst.test.ts +71 -71
  155. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +28 -28
  156. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +4 -12
  157. package/test/unit/data-structures/binary-tree/bst.test.ts +79 -79
  158. package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
  159. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +80 -80
  160. package/test/unit/data-structures/graph/directed-graph.test.ts +8 -8
  161. package/test/unit/data-structures/graph/map-graph.test.ts +4 -4
  162. package/test/unit/data-structures/graph/overall.test.ts +2 -2
  163. package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
  164. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -5
  165. package/test/unit/data-structures/tree/tree.test.ts +2 -2
  166. package/umd/bundle.min.js +1 -1
  167. package/umd/bundle.min.js.map +1 -1
@@ -6,15 +6,18 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import {BST, BSTNode} from './bst';
9
- import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId} from '../../types';
9
+ import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../../types';
10
10
  import {IAVLTree, IAVLTreeNode} from '../../interfaces';
11
11
 
12
12
  export class AVLTreeNode<V = any, NEIGHBOR extends AVLTreeNode<V, NEIGHBOR> = AVLTreeNodeNested<V>>
13
13
  extends BSTNode<V, NEIGHBOR>
14
14
  implements IAVLTreeNode<V, NEIGHBOR>
15
15
  {
16
- constructor(id: BinaryTreeNodeId, val?: V) {
17
- super(id, val);
16
+ height: number;
17
+
18
+ constructor(key: BinaryTreeNodeKey, val?: V) {
19
+ super(key, val);
20
+ this.height = 0;
18
21
  }
19
22
  }
20
23
 
@@ -30,27 +33,53 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends B
30
33
  }
31
34
 
32
35
  /**
33
- * The function creates a new AVL tree node with the given id and value.
34
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
36
+ * The `swapLocation` function swaps the location of two nodes in a binary tree.
37
+ * @param {N} srcNode - The source node that you want to swap with the destination node.
38
+ * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
39
+ * be swapped to.
40
+ * @returns The `destNode` is being returned.
41
+ */
42
+ override swapLocation(srcNode: N, destNode: N): N {
43
+ const {key, val, height} = destNode;
44
+ const tempNode = this.createNode(key, val);
45
+
46
+ if (tempNode) {
47
+ tempNode.height = height;
48
+
49
+ destNode.key = srcNode.key;
50
+ destNode.val = srcNode.val;
51
+ destNode.height = srcNode.height;
52
+
53
+ srcNode.key = tempNode.key;
54
+ srcNode.val = tempNode.val;
55
+ srcNode.height = tempNode.height;
56
+ }
57
+
58
+ return destNode;
59
+ }
60
+
61
+ /**
62
+ * The function creates a new AVL tree node with the given key and value.
63
+ * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
35
64
  * identify each node in the tree.
36
65
  * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
37
66
  * that will be stored in the node.
38
- * @returns a new AVLTreeNode object with the specified id and value.
67
+ * @returns a new AVLTreeNode object with the specified key and value.
39
68
  */
40
- override createNode(id: BinaryTreeNodeId, val?: N['val']): N {
41
- return new AVLTreeNode<N['val'], N>(id, val) as N;
69
+ override createNode(key: BinaryTreeNodeKey, val?: N['val']): N {
70
+ return new AVLTreeNode<N['val'], N>(key, val) as N;
42
71
  }
43
72
 
44
73
  /**
45
74
  * The function overrides the add method of a binary tree node and balances the tree after inserting a new node.
46
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add.
75
+ * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier of the binary tree node that we want to add.
47
76
  * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It is of type
48
77
  * `N['val']`, which means it should be of the same type as the `val` property of the nodes in the binary tree.
49
78
  * @returns The method is returning the inserted node, or null or undefined if the insertion was not successful.
50
79
  */
51
- override add(id: BinaryTreeNodeId, val?: N['val']): N | null | undefined {
80
+ override add(key: BinaryTreeNodeKey, val?: N['val']): N | null | undefined {
52
81
  // TODO support node as a param
53
- const inserted = super.add(id, val);
82
+ const inserted = super.add(key, val);
54
83
  if (inserted) this._balancePath(inserted);
55
84
  return inserted;
56
85
  }
@@ -58,12 +87,12 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends B
58
87
  /**
59
88
  * The function overrides the remove method of a binary tree and performs additional operations to balance the tree after
60
89
  * deletion.
61
- * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
90
+ * @param {BinaryTreeNodeKey} key - The `key` parameter represents the identifier of the binary tree node that needs to be
62
91
  * removed.
63
92
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
64
93
  */
65
- override remove(id: BinaryTreeNodeId): BinaryTreeDeletedResult<N>[] {
66
- const deletedResults = super.remove(id);
94
+ override remove(key: BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[] {
95
+ const deletedResults = super.remove(key);
67
96
  for (const {needBalanced} of deletedResults) {
68
97
  if (needBalanced) {
69
98
  this._balancePath(needBalanced);
@@ -6,7 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
 
9
- import type {BinaryTreeNodeId, BinaryTreeNodeNested, BinaryTreeOptions} from '../../types';
9
+ import type {BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions} from '../../types';
10
10
  import {AbstractBinaryTree, AbstractBinaryTreeNode} from './abstract-binary-tree';
11
11
  import {IBinaryTree, IBinaryTreeNode} from '../../interfaces';
12
12
 
@@ -14,8 +14,8 @@ export class BinaryTreeNode<V = any, NEIGHBOR extends BinaryTreeNode<V, NEIGHBOR
14
14
  extends AbstractBinaryTreeNode<V, NEIGHBOR>
15
15
  implements IBinaryTreeNode<V, NEIGHBOR>
16
16
  {
17
- constructor(id: BinaryTreeNodeId, val?: V) {
18
- super(id, val);
17
+ constructor(key: BinaryTreeNodeKey, val?: V) {
18
+ super(key, val);
19
19
  }
20
20
  }
21
21
 
@@ -35,13 +35,13 @@ export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
35
35
 
36
36
  /**
37
37
  * The function creates a new binary tree node with an optional value.
38
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
39
- * `BinaryTreeNodeId`, which represents the unique identifier for each node in the binary tree.
38
+ * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is of type
39
+ * `BinaryTreeNodeKey`, which represents the unique identifier for each node in the binary tree.
40
40
  * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
41
41
  * stored in the node.
42
- * @returns a new instance of a BinaryTreeNode with the specified id and value.
42
+ * @returns a new instance of a BinaryTreeNode with the specified key and value.
43
43
  */
44
- createNode(id: BinaryTreeNodeId, val?: N['val']): N {
45
- return new BinaryTreeNode<N['val'], N>(id, val) as N;
44
+ createNode(key: BinaryTreeNodeKey, val?: N['val']): N {
45
+ return new BinaryTreeNode<N['val'], N>(key, val) as N;
46
46
  }
47
47
  }
@@ -5,7 +5,13 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type {BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTNodeNested, BSTOptions} from '../../types';
8
+ import type {
9
+ BinaryTreeNodeKey,
10
+ BinaryTreeNodePropertyName,
11
+ BSTComparator,
12
+ BSTNodeNested,
13
+ BSTOptions
14
+ } from '../../types';
9
15
  import {CP, LoopType} from '../../types';
10
16
  import {BinaryTree, BinaryTreeNode} from './binary-tree';
11
17
  import {IBST, IBSTNode} from '../../interfaces';
@@ -14,8 +20,8 @@ export class BSTNode<V = any, NEIGHBOR extends BSTNode<V, NEIGHBOR> = BSTNodeNes
14
20
  extends BinaryTreeNode<V, NEIGHBOR>
15
21
  implements IBSTNode<V, NEIGHBOR>
16
22
  {
17
- constructor(id: BinaryTreeNodeId, val?: V) {
18
- super(id, val);
23
+ constructor(key: BinaryTreeNodeKey, val?: V) {
24
+ super(key, val);
19
25
  }
20
26
  }
21
27
 
@@ -35,35 +41,35 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
35
41
  }
36
42
 
37
43
  /**
38
- * The function creates a new binary search tree node with the given id and value.
39
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
44
+ * The function creates a new binary search tree node with the given key and value.
45
+ * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
40
46
  * identify each node in the binary tree.
41
47
  * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
42
48
  * that will be stored in the node.
43
- * @returns a new instance of the BSTNode class with the specified id and value.
49
+ * @returns a new instance of the BSTNode class with the specified key and value.
44
50
  */
45
- override createNode(id: BinaryTreeNodeId, val?: N['val']): N {
46
- return new BSTNode<N['val'], N>(id, val) as N;
51
+ override createNode(key: BinaryTreeNodeKey, val?: N['val']): N {
52
+ return new BSTNode<N['val'], N>(key, val) as N;
47
53
  }
48
54
 
49
55
  /**
50
56
  * The `add` function adds a new node to a binary search tree, either by creating a new node or by updating an existing
51
57
  * node with the same ID.
52
- * @param {BinaryTreeNodeId | N | null} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId` or a `N`
58
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N`
53
59
  * (which represents a binary tree node) or `null`.
54
60
  * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
55
61
  * being added to the binary search tree.
56
62
  * @returns The function `add` returns the inserted node (`inserted`) which can be of type `N`, `null`, or `undefined`.
57
63
  */
58
- override add(idOrNode: BinaryTreeNodeId | N | null, val?: N['val']): N | null | undefined {
64
+ override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined {
59
65
  // TODO support node as a param
60
66
  let inserted: N | null = null;
61
67
  let newNode: N | null = null;
62
- if (idOrNode instanceof BSTNode) {
63
- newNode = idOrNode;
64
- } else if (typeof idOrNode === 'number') {
65
- newNode = this.createNode(idOrNode, val);
66
- } else if (idOrNode === null) {
68
+ if (keyOrNode instanceof BSTNode) {
69
+ newNode = keyOrNode;
70
+ } else if (typeof keyOrNode === 'number') {
71
+ newNode = this.createNode(keyOrNode, val);
72
+ } else if (keyOrNode === null) {
67
73
  newNode = null;
68
74
  }
69
75
  if (this.root === null) {
@@ -75,14 +81,14 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
75
81
  let traversing = true;
76
82
  while (traversing) {
77
83
  if (cur !== null && newNode !== null) {
78
- if (this._compare(cur.id, newNode.id) === CP.eq) {
84
+ if (this._compare(cur.key, newNode.key) === CP.eq) {
79
85
  if (newNode) {
80
86
  cur.val = newNode.val;
81
87
  }
82
88
  //Duplicates are not accepted.
83
89
  traversing = false;
84
90
  inserted = cur;
85
- } else if (this._compare(cur.id, newNode.id) === CP.gt) {
91
+ } else if (this._compare(cur.key, newNode.key) === CP.gt) {
86
92
  // Traverse left of the node
87
93
  if (cur.left === undefined) {
88
94
  if (newNode) {
@@ -97,7 +103,7 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
97
103
  //Traverse the left of the current node
98
104
  if (cur.left) cur = cur.left;
99
105
  }
100
- } else if (this._compare(cur.id, newNode.id) === CP.lt) {
106
+ } else if (this._compare(cur.key, newNode.key) === CP.lt) {
101
107
  // Traverse right of the node
102
108
  if (cur.right === undefined) {
103
109
  if (newNode) {
@@ -124,48 +130,50 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
124
130
  /**
125
131
  * The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced
126
132
  * manner.
127
- * @param {[BinaryTreeNodeId | N , N['val']][]} idsOrNodes - The `idsOrNodes` parameter in the `addMany` function is an array of
128
- * `BinaryTreeNodeId` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
133
+ * @param {[BinaryTreeNodeKey | N , N['val']][]} keysOrNodes - The `keysOrNodes` parameter in the `addMany` function is an array of
134
+ * `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
129
135
  * to the binary search tree.
130
136
  * @param {N['val'][]} data - The values of tree nodes
131
137
  * @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
132
138
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
133
139
  */
134
140
  override addMany(
135
- idsOrNodes: (BinaryTreeNodeId | null)[] | (N | null)[],
141
+ keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[],
136
142
  data?: N['val'][],
137
143
  isBalanceAdd = false
138
144
  ): (N | null | undefined)[] {
139
- function hasNoNull(arr: (BinaryTreeNodeId | null)[] | (N | null)[]): arr is BinaryTreeNodeId[] | N[] {
145
+ function hasNoNull(arr: (BinaryTreeNodeKey | null)[] | (N | null)[]): arr is BinaryTreeNodeKey[] | N[] {
140
146
  return arr.indexOf(null) === -1;
141
147
  }
142
- if (!isBalanceAdd || !hasNoNull(idsOrNodes)) {
143
- return super.addMany(idsOrNodes, data);
148
+ if (!isBalanceAdd || !hasNoNull(keysOrNodes)) {
149
+ return super.addMany(keysOrNodes, data);
144
150
  }
145
151
  const inserted: (N | null | undefined)[] = [];
146
- const combinedArr: [BinaryTreeNodeId | N, N['val']][] = idsOrNodes.map((value, index) => [value, data?.[index]]);
152
+ const combinedArr: [BinaryTreeNodeKey | N, N['val']][] = keysOrNodes.map((value, index) => [value, data?.[index]]);
147
153
  let sorted = [];
148
- function isNodeOrNullTuple(arr: [BinaryTreeNodeId | N, N['val']][]): arr is [N, N['val']][] {
149
- for (const [idOrNode] of arr) if (idOrNode instanceof BSTNode) return true;
154
+ function isNodeOrNullTuple(arr: [BinaryTreeNodeKey | N, N['val']][]): arr is [N, N['val']][] {
155
+ for (const [keyOrNode] of arr) if (keyOrNode instanceof BSTNode) return true;
150
156
  return false;
151
157
  }
152
- function isBinaryTreeIdOrNullTuple(arr: [BinaryTreeNodeId | N, N['val']][]): arr is [BinaryTreeNodeId, N['val']][] {
153
- for (const [idOrNode] of arr) if (typeof idOrNode === 'number') return true;
158
+ function isBinaryTreeKeyOrNullTuple(
159
+ arr: [BinaryTreeNodeKey | N, N['val']][]
160
+ ): arr is [BinaryTreeNodeKey, N['val']][] {
161
+ for (const [keyOrNode] of arr) if (typeof keyOrNode === 'number') return true;
154
162
  return false;
155
163
  }
156
- let sortedIdsOrNodes: (number | N | null)[] = [],
164
+ let sortedKeysOrNodes: (number | N | null)[] = [],
157
165
  sortedData: (N['val'] | undefined)[] | undefined = [];
158
166
 
159
167
  if (isNodeOrNullTuple(combinedArr)) {
160
- sorted = combinedArr.sort((a, b) => a[0].id - b[0].id);
161
- } else if (isBinaryTreeIdOrNullTuple(combinedArr)) {
168
+ sorted = combinedArr.sort((a, b) => a[0].key - b[0].key);
169
+ } else if (isBinaryTreeKeyOrNullTuple(combinedArr)) {
162
170
  sorted = combinedArr.sort((a, b) => a[0] - b[0]);
163
171
  } else {
164
- throw new Error('Invalid input idsOrNodes');
172
+ throw new Error('Invalid input keysOrNodes');
165
173
  }
166
- sortedIdsOrNodes = sorted.map(([idOrNode]) => idOrNode);
174
+ sortedKeysOrNodes = sorted.map(([keyOrNode]) => keyOrNode);
167
175
  sortedData = sorted.map(([, val]) => val);
168
- const recursive = (arr: (BinaryTreeNodeId | null | N)[], data?: N['val'][]) => {
176
+ const recursive = (arr: (BinaryTreeNodeKey | null | N)[], data?: N['val'][]) => {
169
177
  if (arr.length === 0) return;
170
178
 
171
179
  const mid = Math.floor((arr.length - 1) / 2);
@@ -183,7 +191,7 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
183
191
  const [l, r] = popped;
184
192
  if (l <= r) {
185
193
  const m = l + Math.floor((r - l) / 2);
186
- const newNode = this.add(sortedIdsOrNodes[m], sortedData?.[m]);
194
+ const newNode = this.add(sortedKeysOrNodes[m], sortedData?.[m]);
187
195
  inserted.push(newNode);
188
196
  stack.push([m + 1, r]);
189
197
  stack.push([l, m - 1]);
@@ -192,7 +200,7 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
192
200
  }
193
201
  };
194
202
  if (this.loopType === LoopType.RECURSIVE) {
195
- recursive(sortedIdsOrNodes, sortedData);
203
+ recursive(sortedKeysOrNodes, sortedData);
196
204
  } else {
197
205
  iterative();
198
206
  }
@@ -202,45 +210,44 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
202
210
 
203
211
  /**
204
212
  * The function returns the first node in a binary tree that matches the given property name and value.
205
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
213
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
206
214
  * generic type `N`. It represents the property of the binary tree node that you want to search for.
207
215
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
208
- * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'id'`.
209
- * @returns The method is returning either a BinaryTreeNodeId or N (generic type) or null.
216
+ * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
217
+ * @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
210
218
  */
211
- override get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null {
212
- propertyName = propertyName ?? 'id';
219
+ override get(nodeProperty: BinaryTreeNodeKey | N, propertyName: BinaryTreeNodePropertyName = 'key'): N | null {
213
220
  return this.getNodes(nodeProperty, propertyName, true)[0] ?? null;
214
221
  }
215
222
 
216
223
  /**
217
- * The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
218
- * leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
219
- * @returns The method `lastKey()` returns the id of the rightmost node in the binary tree if the comparison between
220
- * the values at index 0 and 1 is less than, otherwise it returns the id of the leftmost node. If the comparison is
221
- * equal, it returns the id of the rightmost node. If there are no nodes in the tree, it returns 0.
224
+ * The function returns the key of the rightmost node if the comparison between two values is less than, the key of the
225
+ * leftmost node if the comparison is greater than, and the key of the rightmost node otherwise.
226
+ * @returns The method `lastKey()` returns the key of the rightmost node in the binary tree if the comparison between
227
+ * the values at index 0 and 1 is less than, otherwise it returns the key of the leftmost node. If the comparison is
228
+ * equal, it returns the key of the rightmost node. If there are no nodes in the tree, it returns 0.
222
229
  */
223
- lastKey(): BinaryTreeNodeId {
224
- if (this._compare(0, 1) === CP.lt) return this.getRightMost()?.id ?? 0;
225
- else if (this._compare(0, 1) === CP.gt) return this.getLeftMost()?.id ?? 0;
226
- else return this.getRightMost()?.id ?? 0;
230
+ lastKey(): BinaryTreeNodeKey {
231
+ if (this._compare(0, 1) === CP.lt) return this.getRightMost()?.key ?? 0;
232
+ else if (this._compare(0, 1) === CP.gt) return this.getLeftMost()?.key ?? 0;
233
+ else return this.getRightMost()?.key ?? 0;
227
234
  }
228
235
 
229
236
  /**
230
237
  * The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
231
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or an
238
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or an
232
239
  * `N` type. It represents the property of the binary tree node that you want to compare with.
233
240
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
234
- * specifies the property name to use for comparison. If not provided, it defaults to `'id'`.
241
+ * specifies the property name to use for comparison. If not provided, it defaults to `'key'`.
235
242
  * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
236
243
  * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`
237
244
  * is set to `true`, the function will return an array with only one node (if
238
245
  * @returns an array of nodes (type N).
239
246
  */
240
247
  override getNodes(
241
- nodeProperty: BinaryTreeNodeId | N,
242
- propertyName: BinaryTreeNodePropertyName = 'id',
243
- onlyOne?: boolean
248
+ nodeProperty: BinaryTreeNodeKey | N,
249
+ propertyName: BinaryTreeNodePropertyName = 'key',
250
+ onlyOne = false
244
251
  ): N[] {
245
252
  if (!this.root) return [];
246
253
  const result: N[] = [];
@@ -250,9 +257,9 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
250
257
  if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne)) return;
251
258
 
252
259
  if (!cur.left && !cur.right) return;
253
- if (propertyName === 'id') {
254
- if (this._compare(cur.id, nodeProperty as number) === CP.gt) cur.left && _traverse(cur.left);
255
- if (this._compare(cur.id, nodeProperty as number) === CP.lt) cur.right && _traverse(cur.right);
260
+ if (propertyName === 'key') {
261
+ if (this._compare(cur.key, nodeProperty as number) === CP.gt) cur.left && _traverse(cur.left);
262
+ if (this._compare(cur.key, nodeProperty as number) === CP.lt) cur.right && _traverse(cur.right);
256
263
  } else {
257
264
  cur.left && _traverse(cur.left);
258
265
  cur.right && _traverse(cur.right);
@@ -266,9 +273,9 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
266
273
  const cur = queue.shift();
267
274
  if (cur) {
268
275
  if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne)) return result;
269
- if (propertyName === 'id') {
270
- if (this._compare(cur.id, nodeProperty as number) === CP.gt) cur.left && queue.push(cur.left);
271
- if (this._compare(cur.id, nodeProperty as number) === CP.lt) cur.right && queue.push(cur.right);
276
+ if (propertyName === 'key') {
277
+ if (this._compare(cur.key, nodeProperty as number) === CP.gt) cur.left && queue.push(cur.left);
278
+ if (this._compare(cur.key, nodeProperty as number) === CP.lt) cur.right && queue.push(cur.right);
272
279
  } else {
273
280
  cur.left && queue.push(cur.left);
274
281
  cur.right && queue.push(cur.right);
@@ -284,26 +291,25 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
284
291
  /**
285
292
  * The `lesserSum` function calculates the sum of property values in a binary tree for nodes that have a property value
286
293
  * less than a given node.
287
- * @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
294
+ * @param {N | BinaryTreeNodeKey | null} beginNode - The `beginNode` parameter can be one of the following:
288
295
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
289
- * specifies the property name to use for calculating the sum. If not provided, it defaults to `'id'`.
296
+ * specifies the property name to use for calculating the sum. If not provided, it defaults to `'key'`.
290
297
  * @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
291
298
  * binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.
292
299
  */
293
- lesserSum(beginNode: N | BinaryTreeNodeId | null, propertyName?: BinaryTreeNodePropertyName): number {
294
- propertyName = propertyName ?? 'id';
295
- if (typeof beginNode === 'number') beginNode = this.get(beginNode, 'id');
300
+ lesserSum(beginNode: N | BinaryTreeNodeKey | null, propertyName: BinaryTreeNodePropertyName = 'key'): number {
301
+ if (typeof beginNode === 'number') beginNode = this.get(beginNode, 'key');
296
302
  if (!beginNode) return 0;
297
303
  if (!this.root) return 0;
298
- const id = beginNode.id;
304
+ const key = beginNode.key;
299
305
  const getSumByPropertyName = (cur: N) => {
300
306
  let needSum: number;
301
307
  switch (propertyName) {
302
- case 'id':
303
- needSum = cur.id;
308
+ case 'key':
309
+ needSum = cur.key;
304
310
  break;
305
311
  default:
306
- needSum = cur.id;
312
+ needSum = cur.key;
307
313
  break;
308
314
  }
309
315
  return needSum;
@@ -313,7 +319,7 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
313
319
 
314
320
  if (this.loopType === LoopType.RECURSIVE) {
315
321
  const _traverse = (cur: N): void => {
316
- const compared = this._compare(cur.id, id);
322
+ const compared = this._compare(cur.key, key);
317
323
  if (compared === CP.eq) {
318
324
  if (cur.right) sum += this.subTreeSum(cur.right, propertyName);
319
325
  return;
@@ -334,7 +340,7 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
334
340
  while (queue.length > 0) {
335
341
  const cur = queue.shift();
336
342
  if (cur) {
337
- const compared = this._compare(cur.id, id);
343
+ const compared = this._compare(cur.key, key);
338
344
  if (compared === CP.eq) {
339
345
  if (cur.right) sum += this.subTreeSum(cur.right, propertyName);
340
346
  return sum;
@@ -358,44 +364,43 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
358
364
  /**
359
365
  * The `allGreaterNodesAdd` function adds a delta value to the specified property of all nodes in a binary tree that
360
366
  * have a greater value than a given node.
361
- * @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be either of type `N` (a generic type),
362
- * `BinaryTreeNodeId`, or `null`. It represents the node in the binary tree to which the delta value will be added.
367
+ * @param {N | BinaryTreeNodeKey | null} node - The `node` parameter can be either of type `N` (a generic type),
368
+ * `BinaryTreeNodeKey`, or `null`. It represents the node in the binary tree to which the delta value will be added.
363
369
  * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
364
370
  * each greater node should be increased.
365
371
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
366
372
  * specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to
367
- * 'id'.
373
+ * 'key'.
368
374
  * @returns a boolean value.
369
375
  */
370
376
  allGreaterNodesAdd(
371
- node: N | BinaryTreeNodeId | null,
377
+ node: N | BinaryTreeNodeKey | null,
372
378
  delta: number,
373
- propertyName?: BinaryTreeNodePropertyName
379
+ propertyName: BinaryTreeNodePropertyName = 'key'
374
380
  ): boolean {
375
- propertyName = propertyName ?? 'id';
376
- if (typeof node === 'number') node = this.get(node, 'id');
381
+ if (typeof node === 'number') node = this.get(node, 'key');
377
382
  if (!node) return false;
378
- const id = node.id;
383
+ const key = node.key;
379
384
  if (!this.root) return false;
380
385
 
381
386
  const _sumByPropertyName = (cur: N) => {
382
387
  switch (propertyName) {
383
- case 'id':
384
- cur.id += delta;
388
+ case 'key':
389
+ cur.key += delta;
385
390
  break;
386
391
  default:
387
- cur.id += delta;
392
+ cur.key += delta;
388
393
  break;
389
394
  }
390
395
  };
391
396
  if (this.loopType === LoopType.RECURSIVE) {
392
397
  const _traverse = (cur: N) => {
393
- const compared = this._compare(cur.id, id);
398
+ const compared = this._compare(cur.key, key);
394
399
  if (compared === CP.gt) _sumByPropertyName(cur);
395
400
 
396
401
  if (!cur.left && !cur.right) return;
397
- if (cur.left && this._compare(cur.left.id, id) === CP.gt) _traverse(cur.left);
398
- if (cur.right && this._compare(cur.right.id, id) === CP.gt) _traverse(cur.right);
402
+ if (cur.left && this._compare(cur.left.key, key) === CP.gt) _traverse(cur.left);
403
+ if (cur.right && this._compare(cur.right.key, key) === CP.gt) _traverse(cur.right);
399
404
  };
400
405
 
401
406
  _traverse(this.root);
@@ -405,11 +410,11 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
405
410
  while (queue.length > 0) {
406
411
  const cur = queue.shift();
407
412
  if (cur) {
408
- const compared = this._compare(cur.id, id);
413
+ const compared = this._compare(cur.key, key);
409
414
  if (compared === CP.gt) _sumByPropertyName(cur);
410
415
 
411
- if (cur.left && this._compare(cur.left.id, id) === CP.gt) queue.push(cur.left);
412
- if (cur.right && this._compare(cur.right.id, id) === CP.gt) queue.push(cur.right);
416
+ if (cur.left && this._compare(cur.left.key, key) === CP.gt) queue.push(cur.left);
417
+ if (cur.right && this._compare(cur.right.key, key) === CP.gt) queue.push(cur.right);
413
418
  }
414
419
  }
415
420
  return true;
@@ -432,7 +437,7 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
432
437
  * @returns The function `perfectlyBalance()` returns a boolean value.
433
438
  */
434
439
  perfectlyBalance(): boolean {
435
- const sorted = this.DFS('in', 'node'),
440
+ const sorted = this.dfs('in', 'node'),
436
441
  n = sorted.length;
437
442
  this.clear();
438
443
 
@@ -442,7 +447,7 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
442
447
  if (l > r) return;
443
448
  const m = l + Math.floor((r - l) / 2);
444
449
  const midNode = sorted[m];
445
- this.add(midNode.id, midNode.val);
450
+ this.add(midNode.key, midNode.val);
446
451
  buildBalanceBST(l, m - 1);
447
452
  buildBalanceBST(m + 1, r);
448
453
  };
@@ -458,7 +463,7 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
458
463
  if (l <= r) {
459
464
  const m = l + Math.floor((r - l) / 2);
460
465
  const midNode = sorted[m];
461
- this.add(midNode.id, midNode.val);
466
+ this.add(midNode.key, midNode.val);
462
467
  stack.push([m + 1, r]);
463
468
  stack.push([l, m - 1]);
464
469
  }
@@ -521,12 +526,12 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
521
526
  /**
522
527
  * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
523
528
  * greater than, less than, or equal to the second ID.
524
- * @param {BinaryTreeNodeId} a - a is a BinaryTreeNodeId, which represents the identifier of a binary tree node.
525
- * @param {BinaryTreeNodeId} b - The parameter "b" in the above code refers to a BinaryTreeNodeId.
529
+ * @param {BinaryTreeNodeKey} a - "a" is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
530
+ * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
526
531
  * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
527
532
  * than), or CP.eq (equal).
528
533
  */
529
- protected _compare(a: BinaryTreeNodeId, b: BinaryTreeNodeId): CP {
534
+ protected _compare(a: BinaryTreeNodeKey, b: BinaryTreeNodeKey): CP {
530
535
  const compared = this._comparator(a, b);
531
536
  if (compared > 0) return CP.gt;
532
537
  else if (compared < 0) return CP.lt;
@@ -1,4 +1,4 @@
1
- import {BinaryTreeNodeId, RBColor, RBTreeNodeNested, RBTreeOptions} from '../../types';
1
+ import {BinaryTreeNodeKey, RBColor, RBTreeNodeNested, RBTreeOptions} from '../../types';
2
2
  import {IRBTree, IRBTreeNode} from '../../interfaces';
3
3
  import {BST, BSTNode} from './bst';
4
4
 
@@ -8,8 +8,8 @@ export class RBTreeNode<V = any, NEIGHBOR extends RBTreeNode<V, NEIGHBOR> = RBTr
8
8
  {
9
9
  private _color: RBColor;
10
10
 
11
- constructor(id: BinaryTreeNodeId, val?: V) {
12
- super(id, val);
11
+ constructor(key: BinaryTreeNodeKey, val?: V) {
12
+ super(key, val);
13
13
  this._color = RBColor.RED;
14
14
  }
15
15
 
@@ -27,12 +27,12 @@ export class RBTree<N extends RBTreeNode<N['val'], N> = RBTreeNode> extends BST<
27
27
  super(options);
28
28
  }
29
29
 
30
- override createNode(id: BinaryTreeNodeId, val?: N['val']): N {
31
- return new RBTreeNode(id, val) as N;
30
+ override createNode(key: BinaryTreeNodeKey, val?: N['val']): N {
31
+ return new RBTreeNode(key, val) as N;
32
32
  }
33
33
 
34
- // override add(idOrNode: BinaryTreeNodeId | N | null, val?: N['val']): N | null | undefined {
35
- // const inserted = super.add(idOrNode, val);
34
+ // override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined {
35
+ // const inserted = super.add(keyOrNode, val);
36
36
  // if (inserted) this._fixInsertViolation(inserted);
37
37
  // return inserted;
38
38
  // }
@@ -205,8 +205,8 @@ export class RBTree<N extends RBTreeNode<N['val'], N> = RBTreeNode> extends BST<
205
205
  // node.right = null;
206
206
  // }
207
207
  //
208
- // override remove(nodeOrId: BinaryTreeNodeId | N): BinaryTreeDeletedResult<N>[] {
209
- // const node = this.get(nodeOrId);
208
+ // override remove(nodeOrKey: BinaryTreeNodeKey | N): BinaryTreeDeletedResult<N>[] {
209
+ // const node = this.get(nodeOrKey);
210
210
  // const result: BinaryTreeDeletedResult<N>[] = [{deleted: undefined, needBalanced: null}];
211
211
  // if (!node) return result; // Node does not exist
212
212
  //