data-structure-typed 1.52.5 → 1.52.7

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 (181) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +33 -30
  3. package/benchmark/report.html +13 -13
  4. package/benchmark/report.json +156 -156
  5. package/dist/cjs/constants/index.d.ts +4 -0
  6. package/dist/cjs/constants/index.js +9 -0
  7. package/dist/cjs/constants/index.js.map +1 -0
  8. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +8 -1
  9. package/dist/cjs/data-structures/base/iterable-element-base.js +10 -1
  10. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  11. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +8 -1
  12. package/dist/cjs/data-structures/base/iterable-entry-base.js +10 -10
  13. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
  18. package/dist/cjs/data-structures/binary-tree/avl-tree.js +71 -64
  19. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
  21. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.js +669 -598
  23. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/bst.d.ts +72 -65
  25. package/dist/cjs/data-structures/binary-tree/bst.js +115 -113
  26. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  27. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
  28. package/dist/cjs/data-structures/binary-tree/rb-tree.js +40 -39
  29. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  30. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
  31. package/dist/cjs/data-structures/binary-tree/segment-tree.js +2 -2
  32. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
  33. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +44 -43
  34. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  35. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -2
  36. package/dist/cjs/data-structures/graph/abstract-graph.js +7 -4
  37. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  38. package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
  39. package/dist/cjs/data-structures/graph/directed-graph.js +4 -2
  40. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +2 -2
  42. package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
  43. package/dist/cjs/data-structures/hash/hash-map.js +1 -1
  44. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  45. package/dist/cjs/data-structures/heap/heap.js +3 -3
  46. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  48. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +7 -7
  49. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  51. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +6 -6
  52. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  53. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  54. package/dist/cjs/data-structures/matrix/matrix.d.ts +2 -2
  55. package/dist/cjs/data-structures/matrix/navigator.d.ts +2 -2
  56. package/dist/cjs/data-structures/matrix/navigator.js +4 -2
  57. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
  58. package/dist/cjs/data-structures/queue/deque.d.ts +3 -3
  59. package/dist/cjs/data-structures/queue/deque.js +29 -29
  60. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  61. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  62. package/dist/cjs/data-structures/stack/stack.d.ts +2 -2
  63. package/dist/cjs/data-structures/tree/tree.js +2 -0
  64. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  65. package/dist/cjs/data-structures/trie/trie.d.ts +2 -2
  66. package/dist/cjs/data-structures/trie/trie.js +1 -1
  67. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  68. package/dist/cjs/index.d.ts +1 -0
  69. package/dist/cjs/index.js +1 -0
  70. package/dist/cjs/index.js.map +1 -1
  71. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  72. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
  73. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -6
  74. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
  75. package/dist/mjs/constants/index.d.ts +4 -0
  76. package/dist/mjs/constants/index.js +5 -0
  77. package/dist/mjs/data-structures/base/iterable-element-base.d.ts +8 -1
  78. package/dist/mjs/data-structures/base/iterable-element-base.js +10 -1
  79. package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +8 -1
  80. package/dist/mjs/data-structures/base/iterable-entry-base.js +10 -10
  81. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
  82. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +44 -44
  83. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
  84. package/dist/mjs/data-structures/binary-tree/avl-tree.js +72 -64
  85. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
  86. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
  87. package/dist/mjs/data-structures/binary-tree/binary-tree.js +668 -592
  88. package/dist/mjs/data-structures/binary-tree/bst.d.ts +72 -65
  89. package/dist/mjs/data-structures/binary-tree/bst.js +116 -112
  90. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
  91. package/dist/mjs/data-structures/binary-tree/rb-tree.js +41 -38
  92. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
  93. package/dist/mjs/data-structures/binary-tree/segment-tree.js +2 -2
  94. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
  95. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +45 -42
  96. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -2
  97. package/dist/mjs/data-structures/graph/abstract-graph.js +7 -4
  98. package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
  99. package/dist/mjs/data-structures/graph/directed-graph.js +4 -2
  100. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +2 -2
  101. package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
  102. package/dist/mjs/data-structures/hash/hash-map.js +1 -1
  103. package/dist/mjs/data-structures/heap/heap.js +3 -3
  104. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  105. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +7 -7
  106. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  107. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +6 -6
  108. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  109. package/dist/mjs/data-structures/matrix/matrix.d.ts +2 -2
  110. package/dist/mjs/data-structures/matrix/navigator.d.ts +2 -2
  111. package/dist/mjs/data-structures/matrix/navigator.js +4 -2
  112. package/dist/mjs/data-structures/queue/deque.d.ts +3 -3
  113. package/dist/mjs/data-structures/queue/deque.js +29 -29
  114. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  115. package/dist/mjs/data-structures/stack/stack.d.ts +2 -2
  116. package/dist/mjs/data-structures/tree/tree.js +2 -0
  117. package/dist/mjs/data-structures/trie/trie.d.ts +2 -2
  118. package/dist/mjs/data-structures/trie/trie.js +1 -1
  119. package/dist/mjs/index.d.ts +1 -0
  120. package/dist/mjs/index.js +1 -0
  121. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  122. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
  123. package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -5
  124. package/dist/umd/data-structure-typed.js +1344 -1614
  125. package/dist/umd/data-structure-typed.min.js +10 -3
  126. package/dist/umd/data-structure-typed.min.js.map +1 -1
  127. package/eslint.config.mjs +69 -0
  128. package/package.json +30 -28
  129. package/src/constants/index.ts +4 -0
  130. package/src/data-structures/base/iterable-element-base.ts +11 -1
  131. package/src/data-structures/base/iterable-entry-base.ts +11 -19
  132. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
  133. package/src/data-structures/binary-tree/avl-tree.ts +69 -71
  134. package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
  135. package/src/data-structures/binary-tree/binary-tree.ts +698 -726
  136. package/src/data-structures/binary-tree/bst.ts +123 -129
  137. package/src/data-structures/binary-tree/rb-tree.ts +44 -46
  138. package/src/data-structures/binary-tree/segment-tree.ts +2 -2
  139. package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
  140. package/src/data-structures/graph/abstract-graph.ts +6 -6
  141. package/src/data-structures/graph/directed-graph.ts +4 -4
  142. package/src/data-structures/graph/undirected-graph.ts +2 -2
  143. package/src/data-structures/hash/hash-map.ts +3 -3
  144. package/src/data-structures/heap/heap.ts +3 -3
  145. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
  146. package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
  147. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  148. package/src/data-structures/matrix/matrix.ts +2 -2
  149. package/src/data-structures/matrix/navigator.ts +4 -4
  150. package/src/data-structures/queue/deque.ts +31 -31
  151. package/src/data-structures/queue/queue.ts +1 -1
  152. package/src/data-structures/stack/stack.ts +2 -2
  153. package/src/data-structures/trie/trie.ts +3 -3
  154. package/src/index.ts +1 -0
  155. package/src/interfaces/binary-tree.ts +3 -3
  156. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
  157. package/test/config.ts +1 -7
  158. package/test/integration/all-in-one.test.ts +2 -2
  159. package/test/integration/avl-tree.test.ts +3 -3
  160. package/test/integration/bst.test.ts +19 -18
  161. package/test/integration/heap.test.js +6 -1
  162. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +39 -39
  163. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
  164. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +140 -112
  165. package/test/unit/data-structures/binary-tree/bst.test.ts +41 -13
  166. package/test/unit/data-structures/binary-tree/overall.test.ts +0 -6
  167. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +6 -6
  168. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +88 -34
  169. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +42 -42
  170. package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
  171. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
  172. package/test/unit/data-structures/graph/undirected-graph.test.ts +14 -2
  173. package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
  174. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
  175. package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
  176. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  177. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
  178. package/test/unit/data-structures/stack/stack.test.ts +6 -0
  179. package/test/unit/unrestricted-interconversion.test.ts +24 -24
  180. package/test/utils/big-o.ts +5 -4
  181. package/.eslintrc.js +0 -64
@@ -61,21 +61,21 @@ export class BSTNode extends BinaryTreeNode {
61
61
  export class BST extends BinaryTree {
62
62
  /**
63
63
  * This is the constructor function for a Binary Search Tree class in TypeScript.
64
- * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
64
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
65
65
  * iterable that can contain either keys, nodes, entries, or raw elements. These elements will be
66
66
  * added to the binary search tree during the construction of the object.
67
67
  * @param [options] - An optional object that contains additional options for the Binary Search Tree.
68
68
  * It can include a comparator function that defines the order of the elements in the tree.
69
69
  */
70
- constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
70
+ constructor(keysOrNodesOrEntriesOrRaws = [], options) {
71
71
  super([], options);
72
72
  if (options) {
73
73
  const { comparator } = options;
74
74
  if (comparator)
75
75
  this._comparator = comparator;
76
76
  }
77
- if (keysOrNodesOrEntriesOrRawElements)
78
- this.addMany(keysOrNodesOrEntriesOrRawElements);
77
+ if (keysOrNodesOrEntriesOrRaws)
78
+ this.addMany(keysOrNodesOrEntriesOrRaws);
79
79
  }
80
80
  _root = undefined;
81
81
  /**
@@ -106,21 +106,22 @@ export class BST extends BinaryTree {
106
106
  createTree(options) {
107
107
  return new BST([], {
108
108
  iterationType: this.iterationType,
109
- comparator: this.comparator,
109
+ comparator: this._comparator,
110
+ toEntryFn: this._toEntryFn,
110
111
  ...options
111
112
  });
112
113
  }
113
114
  /**
114
115
  * The function overrides a method and converts a key, value pair or entry or raw element to a node.
115
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
116
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - A variable that can be of
116
117
  * type R or BTNKeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
117
118
  * element.
118
119
  * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
119
120
  * value associated with a key in a key-value pair.
120
121
  * @returns either a NODE object or undefined.
121
122
  */
122
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value) {
123
- return super.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value) ?? undefined;
123
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value) {
124
+ return super.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value) ?? undefined;
124
125
  }
125
126
  /**
126
127
  * Time Complexity: O(log n)
@@ -128,8 +129,8 @@ export class BST extends BinaryTree {
128
129
  *
129
130
  * The function ensures the existence of a node in a data structure and returns it, or undefined if
130
131
  * it doesn't exist.
131
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
132
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
132
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
133
+ * `keyOrNodeOrEntryOrRaw` can accept a value of type `R`, which represents the key, node,
133
134
  * entry, or raw element that needs to be ensured in the tree.
134
135
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
135
136
  * parameter that specifies the type of iteration to be used when ensuring a node. It has a default
@@ -137,19 +138,27 @@ export class BST extends BinaryTree {
137
138
  * @returns The method is returning either the node that was ensured or `undefined` if the node could
138
139
  * not be ensured.
139
140
  */
140
- ensureNode(keyOrNodeOrEntryOrRawElement, iterationType = this.iterationType) {
141
- return super.ensureNode(keyOrNodeOrEntryOrRawElement, iterationType) ?? undefined;
141
+ ensureNode(keyOrNodeOrEntryOrRaw, iterationType = this.iterationType) {
142
+ return super.ensureNode(keyOrNodeOrEntryOrRaw, iterationType) ?? undefined;
142
143
  }
143
144
  /**
144
145
  * The function checks if the input is an instance of the BSTNode class.
145
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
146
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
147
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
146
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
147
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
148
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
148
149
  * an instance of the `BSTNode` class.
149
150
  */
150
- isNode(keyOrNodeOrEntryOrRawElement) {
151
- return keyOrNodeOrEntryOrRawElement instanceof BSTNode;
151
+ isNode(keyOrNodeOrEntryOrRaw) {
152
+ return keyOrNodeOrEntryOrRaw instanceof BSTNode;
152
153
  }
154
+ /**
155
+ * The function "override isKey" checks if a key is comparable based on a given comparator.
156
+ * @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
157
+ * type `K`.
158
+ * @returns The `override isKey(key: any): key is K` function is returning a boolean value based on
159
+ * the result of the `isComparable` function with the condition `this.comparator !==
160
+ * this._DEFAULT_COMPARATOR`.
161
+ */
153
162
  isKey(key) {
154
163
  return isComparable(key, this.comparator !== this._DEFAULT_COMPARATOR);
155
164
  }
@@ -158,22 +167,22 @@ export class BST extends BinaryTree {
158
167
  * Space Complexity: O(1)
159
168
  *
160
169
  * The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
161
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
162
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
170
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
171
+ * `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
163
172
  * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
164
173
  * key in the binary search tree. If provided, it will be stored in the node along with the key.
165
174
  * @returns a boolean value.
166
175
  */
167
- add(keyOrNodeOrEntryOrRawElement, value) {
168
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
176
+ add(keyOrNodeOrEntryOrRaw, value) {
177
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value);
169
178
  if (newNode === undefined)
170
179
  return false;
171
- if (this.root === undefined) {
180
+ if (this._root === undefined) {
172
181
  this._setRoot(newNode);
173
182
  this._size++;
174
183
  return true;
175
184
  }
176
- let current = this.root;
185
+ let current = this._root;
177
186
  while (current !== undefined) {
178
187
  if (this.comparator(current.key, newNode.key) === 0) {
179
188
  this._replaceNode(current, newNode);
@@ -204,7 +213,7 @@ export class BST extends BinaryTree {
204
213
  *
205
214
  * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
206
215
  * an array indicating whether each key or node was successfully inserted.
207
- * @param keysOrNodesOrEntriesOrRawElements - An iterable containing keys, nodes, entries, or raw
216
+ * @param keysOrNodesOrEntriesOrRaws - An iterable containing keys, nodes, entries, or raw
208
217
  * elements to be added to the data structure.
209
218
  * @param [values] - An optional iterable of values to be associated with the keys or nodes being
210
219
  * added. If provided, the values will be assigned to the corresponding keys or nodes in the same
@@ -219,14 +228,14 @@ export class BST extends BinaryTree {
219
228
  * @returns The function `addMany` returns an array of booleans indicating whether each element was
220
229
  * successfully inserted into the data structure.
221
230
  */
222
- addMany(keysOrNodesOrEntriesOrRawElements, values, isBalanceAdd = true, iterationType = this.iterationType) {
231
+ addMany(keysOrNodesOrEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
223
232
  const inserted = [];
224
233
  let valuesIterator;
225
234
  if (values) {
226
235
  valuesIterator = values[Symbol.iterator]();
227
236
  }
228
237
  if (!isBalanceAdd) {
229
- for (const kve of keysOrNodesOrEntriesOrRawElements) {
238
+ for (const kve of keysOrNodesOrEntriesOrRaws) {
230
239
  const value = valuesIterator?.next().value;
231
240
  const nn = this.add(kve, value);
232
241
  inserted.push(nn);
@@ -239,8 +248,9 @@ export class BST extends BinaryTree {
239
248
  return false;
240
249
  return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null));
241
250
  };
242
- for (const kve of keysOrNodesOrEntriesOrRawElements) {
243
- isRealBTNExemplar(kve) && realBTNExemplars.push(kve);
251
+ for (const kve of keysOrNodesOrEntriesOrRaws) {
252
+ if (isRealBTNExemplar(kve))
253
+ realBTNExemplars.push(kve);
244
254
  }
245
255
  let sorted = [];
246
256
  sorted = realBTNExemplars.sort((a, b) => {
@@ -249,8 +259,8 @@ export class BST extends BinaryTree {
249
259
  keyA = a[0];
250
260
  else if (this.isRealNode(a))
251
261
  keyA = a.key;
252
- else if (this.toEntryFn) {
253
- keyA = this.toEntryFn(a)[0];
262
+ else if (this._toEntryFn) {
263
+ keyA = this._toEntryFn(a)[0];
254
264
  }
255
265
  else {
256
266
  keyA = a;
@@ -259,8 +269,8 @@ export class BST extends BinaryTree {
259
269
  keyB = b[0];
260
270
  else if (this.isRealNode(b))
261
271
  keyB = b.key;
262
- else if (this.toEntryFn) {
263
- keyB = this.toEntryFn(b)[0];
272
+ else if (this._toEntryFn) {
273
+ keyB = this._toEntryFn(b)[0];
264
274
  }
265
275
  else {
266
276
  keyB = b;
@@ -308,54 +318,55 @@ export class BST extends BinaryTree {
308
318
  * Time Complexity: O(log n)
309
319
  * Space Complexity: O(k + log n)
310
320
  *
311
- * The `getNodes` function in TypeScript retrieves nodes from a binary tree based on a given
312
- * identifier and callback function.
313
- * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
314
- * want to search for in the binary tree. It can be of any type that is returned by the callback
315
- * function.
316
- * @param {C} callback - The `callback` parameter is a function that takes a node as input and
317
- * returns a value. This value is used to identify the nodes that match the given identifier. The
318
- * `callback` function is optional and defaults to `this._DEFAULT_CALLBACK`.
319
- * @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
320
- * or all matching nodes. If set to true, only the first matching node will be returned. If set to
321
- * false, all matching nodes will be returned. The default value is false.
322
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
323
- * point for the search in the binary tree. It can be either a node object, a key-value pair, or an
324
- * entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
325
- * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
326
- * iteration to be performed. It can have two possible values:
327
- * @returns The method `getNodes` returns an array of `NODE` objects.
321
+ * The function `getNodes` in TypeScript overrides the base class method to retrieve nodes based on a
322
+ * given predicate and iteration type.
323
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
324
+ * parameter in the `getNodes` method is used to filter the nodes that will be returned. It can be a
325
+ * key, a node, an entry, or a custom predicate function that determines whether a node should be
326
+ * included in the result.
327
+ * @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` method is a boolean flag that
328
+ * determines whether to return only the first node that matches the predicate (`true`) or all nodes
329
+ * that match the predicate (`false`). If `onlyOne` is set to `true`, the method will stop iterating
330
+ * and
331
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
332
+ * `getNodes` method is used to specify the starting point for traversing the tree when searching for
333
+ * nodes that match a given predicate. It represents the root node of the subtree where the search
334
+ * should begin. If not explicitly provided, the default value for `begin
335
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `getNodes` method
336
+ * specifies the type of iteration to be performed when traversing the nodes of a binary tree. It can
337
+ * have two possible values:
338
+ * @returns The `getNodes` method returns an array of nodes that satisfy the given predicate.
328
339
  */
329
- getNodes(identifier, callback = this._DEFAULT_CALLBACK, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
330
- if (identifier === undefined)
340
+ getNodes(predicate, onlyOne = false, beginRoot = this._root, iterationType = this.iterationType) {
341
+ if (predicate === undefined)
331
342
  return [];
332
- if (identifier === null)
343
+ if (predicate === null)
333
344
  return [];
334
345
  beginRoot = this.ensureNode(beginRoot);
335
346
  if (!beginRoot)
336
347
  return [];
337
- callback = this._ensureCallback(identifier, callback);
348
+ const callback = this._ensurePredicate(predicate);
338
349
  const ans = [];
339
350
  if (iterationType === 'RECURSIVE') {
340
351
  const dfs = (cur) => {
341
- const callbackResult = callback(cur);
342
- if (callbackResult === identifier) {
352
+ if (callback(cur)) {
343
353
  ans.push(cur);
344
354
  if (onlyOne)
345
355
  return;
346
356
  }
347
357
  if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
348
358
  return;
349
- // TODO potential bug
350
- if (callback === this._DEFAULT_CALLBACK) {
351
- if (this.isRealNode(cur.left) && this.comparator(cur.key, identifier) > 0)
359
+ if (this.isKey(predicate)) {
360
+ if (this.isRealNode(cur.left) && this.comparator(cur.key, predicate) > 0)
352
361
  dfs(cur.left);
353
- if (this.isRealNode(cur.right) && this.comparator(cur.key, identifier) < 0)
362
+ if (this.isRealNode(cur.right) && this.comparator(cur.key, predicate) < 0)
354
363
  dfs(cur.right);
355
364
  }
356
365
  else {
357
- this.isRealNode(cur.left) && dfs(cur.left);
358
- this.isRealNode(cur.right) && dfs(cur.right);
366
+ if (this.isRealNode(cur.left))
367
+ dfs(cur.left);
368
+ if (this.isRealNode(cur.right))
369
+ dfs(cur.right);
359
370
  }
360
371
  };
361
372
  dfs(beginRoot);
@@ -364,28 +375,22 @@ export class BST extends BinaryTree {
364
375
  const stack = [beginRoot];
365
376
  while (stack.length > 0) {
366
377
  const cur = stack.pop();
367
- const callbackResult = callback(cur);
368
- if (callbackResult === identifier) {
378
+ if (callback(cur)) {
369
379
  ans.push(cur);
370
380
  if (onlyOne)
371
381
  return ans;
372
382
  }
373
- // TODO potential bug
374
- if (callback === this._DEFAULT_CALLBACK) {
375
- if (this.isRealNode(cur.right) && this.comparator(cur.key, identifier) < 0)
383
+ if (this.isKey(predicate)) {
384
+ if (this.isRealNode(cur.right) && this.comparator(cur.key, predicate) < 0)
376
385
  stack.push(cur.right);
377
- if (this.isRealNode(cur.left) && this.comparator(cur.key, identifier) > 0)
386
+ if (this.isRealNode(cur.left) && this.comparator(cur.key, predicate) > 0)
378
387
  stack.push(cur.left);
379
- // if (this.isRealNode(cur.right) && this._lt(cur.key, identifier as K)) stack.push(cur.right);
380
- // if (this.isRealNode(cur.left) && this._gt(cur.key, identifier as K)) stack.push(cur.left);
381
- // // @ts-ignore
382
- // if (this.isRealNode(cur.right) && cur.key > identifier) stack.push(cur.right);
383
- // // @ts-ignore
384
- // if (this.isRealNode(cur.left) && cur.key < identifier) stack.push(cur.left);
385
388
  }
386
389
  else {
387
- this.isRealNode(cur.right) && stack.push(cur.right);
388
- this.isRealNode(cur.left) && stack.push(cur.left);
390
+ if (this.isRealNode(cur.right))
391
+ stack.push(cur.right);
392
+ if (this.isRealNode(cur.left))
393
+ stack.push(cur.left);
389
394
  }
390
395
  }
391
396
  }
@@ -395,25 +400,24 @@ export class BST extends BinaryTree {
395
400
  * Time Complexity: O(log n)
396
401
  * Space Complexity: O(1)
397
402
  *
398
- * The function `getNode` returns the first node that matches the given identifier and callback
399
- * function in a binary search tree.
400
- * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
401
- * want to search for in the binary search tree. It can be of any type that is compatible with the
402
- * type returned by the callback function.
403
- * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
404
- * node matches the desired criteria. It should be a function that takes a node as an argument and
405
- * returns a boolean value indicating whether the node matches the criteria or not. If no callback is
406
- * provided, the default callback will be
407
- * @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
408
- * search tree. It can be either a key or a node. If it is a key, the search will start from the node
409
- * with that key. If it is a node, the search will start from that node.
410
- * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
411
- * of iteration to be performed when searching for nodes in the binary search tree. It can have one
412
- * of the following values:
413
- * @returns The method is returning a NODE object or undefined.
403
+ * This function retrieves a node based on a given predicate within a binary search tree structure.
404
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
405
+ * parameter can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, `R`, or `BTNPredicate<NODE>`.
406
+ * @param {R | BSTNKeyOrNode<K, NODE>} beginRoot - The `beginRoot` parameter in the `getNode` method
407
+ * is used to specify the starting point for searching nodes in the binary search tree. If no
408
+ * specific starting point is provided, the default value is set to `this._root`, which is the root
409
+ * node of the binary search tree.
410
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `getNode` method is a
411
+ * parameter that specifies the type of iteration to be used. It has a default value of
412
+ * `this.iterationType`, which means it will use the iteration type defined in the class instance if
413
+ * no value is provided when calling the method.
414
+ * @returns The `getNode` method is returning an optional binary search tree node (`OptBSTN<NODE>`).
415
+ * It is using the `getNodes` method to find the node based on the provided predicate, beginning at
416
+ * the specified root node (`beginRoot`) and using the specified iteration type. The method then
417
+ * returns the first node found or `undefined` if no node is found.
414
418
  */
415
- getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
416
- return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined;
419
+ getNode(predicate, beginRoot = this._root, iterationType = this.iterationType) {
420
+ return this.getNodes(predicate, true, beginRoot, iterationType)[0] ?? undefined;
417
421
  }
418
422
  /**
419
423
  * Time Complexity: O(log n)
@@ -429,7 +433,7 @@ export class BST extends BinaryTree {
429
433
  * @returns The method is returning a NODE object or undefined.
430
434
  */
431
435
  getNodeByKey(key, iterationType = this.iterationType) {
432
- return this.getNode(key, this._DEFAULT_CALLBACK, this.root, iterationType);
436
+ return this.getNode(key, this._root, iterationType);
433
437
  }
434
438
  /**
435
439
  * Time complexity: O(n)
@@ -439,11 +443,11 @@ export class BST extends BinaryTree {
439
443
  * the callback function.
440
444
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
441
445
  * during the depth-first search traversal. It is an optional parameter and defaults to
442
- * `this._DEFAULT_CALLBACK`. The type `C` represents the type of the callback function.
446
+ * `this._DEFAULT_BTN_CALLBACK`. The type `C` represents the type of the callback function.
443
447
  * @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
444
448
  * order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
445
449
  * take one of the following values:
446
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
450
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
447
451
  * point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
448
452
  * node entry. If not specified, the default value is the root of the tree.
449
453
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
@@ -451,7 +455,7 @@ export class BST extends BinaryTree {
451
455
  * following values:
452
456
  * @returns The method is returning an array of the return type of the callback function.
453
457
  */
454
- dfs(callback = this._DEFAULT_CALLBACK, pattern = 'IN', beginRoot = this.root, iterationType = this.iterationType) {
458
+ dfs(callback = this._DEFAULT_BTN_CALLBACK, pattern = 'IN', beginRoot = this._root, iterationType = this.iterationType) {
455
459
  return super.dfs(callback, pattern, beginRoot, iterationType);
456
460
  }
457
461
  /**
@@ -463,7 +467,7 @@ export class BST extends BinaryTree {
463
467
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
464
468
  * visited during the breadth-first search. It should take a single argument, which is the current
465
469
  * node being visited, and it can return a value of any type.
466
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
470
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
467
471
  * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
468
472
  * object. If no value is provided, the default value is the root of the tree.
469
473
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
@@ -471,7 +475,7 @@ export class BST extends BinaryTree {
471
475
  * the following values:
472
476
  * @returns an array of the return type of the callback function.
473
477
  */
474
- bfs(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
478
+ bfs(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType) {
475
479
  return super.bfs(callback, beginRoot, iterationType, false);
476
480
  }
477
481
  /**
@@ -483,7 +487,7 @@ export class BST extends BinaryTree {
483
487
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
484
488
  * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
485
489
  * tree during the iteration process.
486
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
490
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
487
491
  * point for listing the levels of the binary tree. It can be either a root node of the tree, a
488
492
  * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
489
493
  * value is provided, the root of
@@ -492,7 +496,7 @@ export class BST extends BinaryTree {
492
496
  * @returns The method is returning a two-dimensional array of the return type of the callback
493
497
  * function.
494
498
  */
495
- listLevels(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
499
+ listLevels(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType) {
496
500
  return super.listLevels(callback, beginRoot, iterationType, false);
497
501
  }
498
502
  /**
@@ -507,7 +511,7 @@ export class BST extends BinaryTree {
507
511
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
508
512
  * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
509
513
  * 0, or 1, where:
510
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
514
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} targetNode - The `targetNode` parameter is the node in
511
515
  * the binary tree that you want to start traversing from. It can be specified either by providing
512
516
  * the key of the node, the node itself, or an entry containing the key and value of the node. If no
513
517
  * `targetNode` is provided,
@@ -516,12 +520,12 @@ export class BST extends BinaryTree {
516
520
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
517
521
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
518
522
  */
519
- lesserOrGreaterTraverse(callback = this._DEFAULT_CALLBACK, lesserOrGreater = -1, targetNode = this.root, iterationType = this.iterationType) {
523
+ lesserOrGreaterTraverse(callback = this._DEFAULT_BTN_CALLBACK, lesserOrGreater = -1, targetNode = this._root, iterationType = this.iterationType) {
520
524
  const targetNodeEnsured = this.ensureNode(targetNode);
521
525
  const ans = [];
522
- if (!targetNodeEnsured)
526
+ if (!this._root)
523
527
  return ans;
524
- if (!this.root)
528
+ if (!targetNodeEnsured)
525
529
  return ans;
526
530
  const targetKey = targetNodeEnsured.key;
527
531
  if (iterationType === 'RECURSIVE') {
@@ -534,11 +538,11 @@ export class BST extends BinaryTree {
534
538
  if (this.isRealNode(cur.right))
535
539
  dfs(cur.right);
536
540
  };
537
- dfs(this.root);
541
+ dfs(this._root);
538
542
  return ans;
539
543
  }
540
544
  else {
541
- const queue = new Queue([this.root]);
545
+ const queue = new Queue([this._root]);
542
546
  while (queue.size > 0) {
543
547
  const cur = queue.shift();
544
548
  if (this.isRealNode(cur)) {
@@ -615,7 +619,7 @@ export class BST extends BinaryTree {
615
619
  * @returns a boolean value.
616
620
  */
617
621
  isAVLBalanced(iterationType = this.iterationType) {
618
- if (!this.root)
622
+ if (!this._root)
619
623
  return true;
620
624
  let balanced = true;
621
625
  if (iterationType === 'RECURSIVE') {
@@ -627,11 +631,11 @@ export class BST extends BinaryTree {
627
631
  balanced = false;
628
632
  return Math.max(leftHeight, rightHeight) + 1;
629
633
  };
630
- _height(this.root);
634
+ _height(this._root);
631
635
  }
632
636
  else {
633
637
  const stack = [];
634
- let node = this.root, last = undefined;
638
+ let node = this._root, last = undefined;
635
639
  const depths = new Map();
636
640
  while (stack.length > 0 || node) {
637
641
  if (node) {
@@ -643,8 +647,8 @@ export class BST extends BinaryTree {
643
647
  if (!node.right || last === node.right) {
644
648
  node = stack.pop();
645
649
  if (node) {
646
- const left = node.left ? (depths.get(node.left) ?? -1) : -1;
647
- const right = node.right ? (depths.get(node.right) ?? -1) : -1;
650
+ const left = node.left ? depths.get(node.left) : -1;
651
+ const right = node.right ? depths.get(node.right) : -1;
648
652
  if (Math.abs(left - right) > 1)
649
653
  return false;
650
654
  depths.set(node, 1 + Math.max(left, right));
@@ -1,5 +1,4 @@
1
- import type { BinaryTreeDeleteResult, BTNCallback, BTNKeyOrNodeOrEntry, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
2
- import { BTNEntry } from '../../types';
1
+ import type { BinaryTreeDeleteResult, BTNKeyOrNodeOrEntry, BTNPredicate, CRUD, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested, BTNEntry } from '../../types';
3
2
  import { BST, BSTNode } from './bst';
4
3
  import { IBinaryTree } from '../../interfaces';
5
4
  export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
@@ -30,7 +29,7 @@ export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTre
30
29
  export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
31
30
  /**
32
31
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
33
- * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
32
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
34
33
  * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
35
34
  * initialize the RBTree with the provided elements.
36
35
  * @param [options] - The `options` parameter is an optional object that can be passed to the
@@ -38,7 +37,7 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
38
37
  * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
39
38
  * depend on the implementation
40
39
  */
41
- constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K, V, R>);
40
+ constructor(keysOrNodesOrEntriesOrRaws?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K, V, R>);
42
41
  protected _root: NODE | undefined;
43
42
  /**
44
43
  * The function returns the root node of a tree or undefined if there is no root.
@@ -72,12 +71,12 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
72
71
  * Space Complexity: O(1)
73
72
  *
74
73
  * The function checks if the input is an instance of the RedBlackTreeNode class.
75
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
76
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
77
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
74
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
75
+ * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
76
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
78
77
  * an instance of the `RedBlackTreeNode` class.
79
78
  */
80
- isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
79
+ isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
81
80
  /**
82
81
  * Time Complexity: O(1)
83
82
  * Space Complexity: O(1)
@@ -92,8 +91,8 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
92
91
  *
93
92
  * The function adds a new node to a binary search tree and returns true if the node was successfully
94
93
  * added.
95
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
96
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
94
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
95
+ * `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
97
96
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
98
97
  * the key in the data structure. It represents the value that you want to add or update in the data
99
98
  * structure.
@@ -101,24 +100,22 @@ export declare class RedBlackTree<K = any, V = any, R = BTNEntry<K, V>, NODE ext
101
100
  * the method returns true. If the node already exists and its value is updated, the method also
102
101
  * returns true. If the node cannot be added or updated, the method returns false.
103
102
  */
104
- add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
103
+ add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): boolean;
105
104
  /**
106
105
  * Time Complexity: O(log n)
107
106
  * Space Complexity: O(1)
108
107
  *
109
- * The function overrides the delete method of a binary tree data structure, allowing for the
110
- * deletion of a node and maintaining the balance of the tree.
111
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
112
- * that identifies the node to be deleted from the binary tree. It can be of any type that is
113
- * returned by the callback function `C`. It can also be `null` or `undefined` if there is no node to
114
- * delete.
115
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
116
- * equality of nodes in the binary tree. It is optional and has a default value of
117
- * `this._DEFAULT_CALLBACK`. The type of the `callback` parameter is `C`, which is a generic type
118
- * that extends the `BTNCallback
119
- * @returns an array of BinaryTreeDeleteResult<NODE> objects.
120
- */
121
- delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C): BinaryTreeDeleteResult<NODE>[];
108
+ * The function overrides the delete method in a binary tree data structure to remove a node based on
109
+ * a given predicate and maintain the binary search tree properties.
110
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
111
+ * parameter in the `override delete` method is used to specify the condition or key based on which a
112
+ * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
113
+ * function that determines which node(s) should be deleted.
114
+ * @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
115
+ * objects. Each object in the array contains information about the deleted node and whether
116
+ * balancing is needed.
117
+ */
118
+ delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
122
119
  /**
123
120
  * Time Complexity: O(1)
124
121
  * Space Complexity: O(1)