deque-typed 1.49.5 → 1.49.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 (100) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +53 -48
  2. package/dist/data-structures/binary-tree/avl-tree.js +55 -49
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +153 -130
  4. package/dist/data-structures/binary-tree/binary-tree.js +194 -153
  5. package/dist/data-structures/binary-tree/bst.d.ts +83 -71
  6. package/dist/data-structures/binary-tree/bst.js +114 -91
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +37 -35
  8. package/dist/data-structures/binary-tree/rb-tree.js +62 -59
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +46 -39
  10. package/dist/data-structures/binary-tree/tree-multimap.js +58 -51
  11. package/dist/data-structures/hash/hash-map.d.ts +24 -27
  12. package/dist/data-structures/hash/hash-map.js +35 -35
  13. package/dist/data-structures/hash/index.d.ts +0 -1
  14. package/dist/data-structures/hash/index.js +0 -1
  15. package/dist/data-structures/heap/heap.d.ts +2 -1
  16. package/dist/data-structures/heap/heap.js +13 -13
  17. package/dist/data-structures/heap/max-heap.js +1 -1
  18. package/dist/data-structures/heap/min-heap.js +1 -1
  19. package/dist/data-structures/linked-list/doubly-linked-list.js +1 -1
  20. package/dist/data-structures/linked-list/singly-linked-list.js +1 -3
  21. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -8
  22. package/dist/data-structures/linked-list/skip-linked-list.js +15 -18
  23. package/dist/data-structures/matrix/matrix.d.ts +2 -7
  24. package/dist/data-structures/matrix/matrix.js +0 -7
  25. package/dist/data-structures/priority-queue/max-priority-queue.js +1 -1
  26. package/dist/data-structures/priority-queue/min-priority-queue.js +1 -1
  27. package/dist/data-structures/priority-queue/priority-queue.js +1 -1
  28. package/dist/data-structures/queue/deque.d.ts +2 -11
  29. package/dist/data-structures/queue/deque.js +9 -13
  30. package/dist/data-structures/queue/queue.d.ts +13 -13
  31. package/dist/data-structures/queue/queue.js +29 -25
  32. package/dist/data-structures/stack/stack.js +2 -3
  33. package/dist/data-structures/trie/trie.d.ts +2 -2
  34. package/dist/data-structures/trie/trie.js +9 -5
  35. package/dist/interfaces/binary-tree.d.ts +3 -3
  36. package/dist/types/common.d.ts +3 -3
  37. package/dist/types/common.js +2 -2
  38. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
  39. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  40. package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  41. package/dist/types/data-structures/hash/hash-map.d.ts +5 -2
  42. package/dist/types/data-structures/hash/index.d.ts +0 -1
  43. package/dist/types/data-structures/hash/index.js +0 -1
  44. package/dist/types/data-structures/heap/heap.d.ts +1 -1
  45. package/dist/types/data-structures/linked-list/index.d.ts +1 -0
  46. package/dist/types/data-structures/linked-list/index.js +1 -0
  47. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
  48. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  49. package/dist/types/data-structures/matrix/index.js +1 -0
  50. package/dist/types/data-structures/matrix/matrix.d.ts +7 -1
  51. package/dist/types/data-structures/queue/deque.d.ts +3 -1
  52. package/dist/types/data-structures/trie/trie.d.ts +3 -1
  53. package/package.json +2 -2
  54. package/src/data-structures/binary-tree/avl-tree.ts +58 -53
  55. package/src/data-structures/binary-tree/binary-tree.ts +255 -211
  56. package/src/data-structures/binary-tree/bst.ts +126 -107
  57. package/src/data-structures/binary-tree/rb-tree.ts +66 -64
  58. package/src/data-structures/binary-tree/tree-multimap.ts +62 -56
  59. package/src/data-structures/hash/hash-map.ts +46 -50
  60. package/src/data-structures/hash/index.ts +0 -1
  61. package/src/data-structures/heap/heap.ts +20 -19
  62. package/src/data-structures/heap/max-heap.ts +1 -1
  63. package/src/data-structures/heap/min-heap.ts +1 -1
  64. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  65. package/src/data-structures/linked-list/singly-linked-list.ts +2 -5
  66. package/src/data-structures/linked-list/skip-linked-list.ts +15 -16
  67. package/src/data-structures/matrix/matrix.ts +2 -10
  68. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  69. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  70. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  71. package/src/data-structures/queue/deque.ts +11 -15
  72. package/src/data-structures/queue/queue.ts +29 -28
  73. package/src/data-structures/stack/stack.ts +3 -6
  74. package/src/data-structures/trie/trie.ts +10 -11
  75. package/src/interfaces/binary-tree.ts +3 -3
  76. package/src/types/common.ts +3 -3
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
  78. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  79. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
  80. package/src/types/data-structures/hash/hash-map.ts +6 -2
  81. package/src/types/data-structures/hash/index.ts +0 -1
  82. package/src/types/data-structures/heap/heap.ts +1 -1
  83. package/src/types/data-structures/linked-list/index.ts +1 -0
  84. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -1
  85. package/src/types/data-structures/matrix/index.ts +1 -0
  86. package/src/types/data-structures/matrix/matrix.ts +7 -1
  87. package/src/types/data-structures/queue/deque.ts +1 -1
  88. package/src/types/data-structures/trie/trie.ts +1 -1
  89. package/dist/data-structures/hash/hash-table.d.ts +0 -108
  90. package/dist/data-structures/hash/hash-table.js +0 -281
  91. package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
  92. package/dist/types/data-structures/hash/hash-table.js +0 -2
  93. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -1
  94. package/dist/types/data-structures/matrix/matrix2d.js +0 -2
  95. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -1
  96. package/dist/types/data-structures/matrix/vector2d.js +0 -2
  97. package/src/data-structures/hash/hash-table.ts +0 -318
  98. package/src/types/data-structures/hash/hash-table.ts +0 -1
  99. package/src/types/data-structures/matrix/matrix2d.ts +0 -1
  100. package/src/types/data-structures/matrix/vector2d.ts +0 -1
@@ -7,13 +7,11 @@
7
7
  */
8
8
  import type {
9
9
  BSTNested,
10
- BSTNKeyOrNode,
11
10
  BSTNodeNested,
12
11
  BSTOptions,
13
12
  BTNCallback,
14
- BTNExemplar,
15
- BTNKeyOrNode,
16
- BTNodePureExemplar
13
+ BTNodePureExemplar,
14
+ KeyOrNodeOrEntry
17
15
  } from '../../types';
18
16
  import { BSTVariant, CP, IterationType } from '../../types';
19
17
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
@@ -94,25 +92,23 @@ export class BST<
94
92
  implements IBinaryTree<K, V, N, TREE> {
95
93
  /**
96
94
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
97
- * the tree with optional elements and options.
98
- * @param [elements] - An optional iterable of BTNExemplar objects that will be added to the
95
+ * the tree with optional keysOrNodesOrEntries and options.
96
+ * @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects that will be added to the
99
97
  * binary search tree.
100
98
  * @param [options] - The `options` parameter is an optional object that can contain additional
101
99
  * configuration options for the binary search tree. It can have the following properties:
102
100
  */
103
- constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<BSTOptions<K>>) {
101
+ constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>> = [], options?: BSTOptions<K>) {
104
102
  super([], options);
105
103
 
106
104
  if (options) {
107
105
  const { variant } = options;
108
- if (variant) {
109
- this._variant = variant;
110
- }
106
+ if (variant) this._variant = variant;
111
107
  }
112
108
 
113
109
  this._root = undefined;
114
110
 
115
- if (elements) this.addMany(elements);
111
+ if (keysOrNodesOrEntries) this.addMany(keysOrNodesOrEntries);
116
112
  }
117
113
 
118
114
  protected override _root?: N;
@@ -121,7 +117,7 @@ export class BST<
121
117
  return this._root;
122
118
  }
123
119
 
124
- protected _variant = BSTVariant.MIN;
120
+ protected _variant = BSTVariant.STANDARD;
125
121
 
126
122
  get variant() {
127
123
  return this._variant;
@@ -155,37 +151,28 @@ export class BST<
155
151
  }
156
152
 
157
153
  /**
158
- * The function checks if an exemplar is an instance of BSTNode.
159
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V, N>`.
160
- * @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
161
- */
162
- override isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N {
163
- return exemplar instanceof BSTNode;
164
- }
165
-
166
- /**
167
- * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
154
+ * The function `exemplarToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
168
155
  * otherwise it returns undefined.
169
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
156
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
170
157
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
171
- * `exemplarToNode` function. It represents the value associated with the exemplar node.
158
+ * `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
172
159
  * @returns a node of type N or undefined.
173
160
  */
174
- override exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V): N | undefined {
161
+ override exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | undefined {
175
162
  let node: N | undefined;
176
- if (exemplar === null || exemplar === undefined) {
163
+ if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {
177
164
  return;
178
- } else if (this.isNode(exemplar)) {
179
- node = exemplar;
180
- } else if (this.isEntry(exemplar)) {
181
- const [key, value] = exemplar;
165
+ } else if (this.isNode(keyOrNodeOrEntry)) {
166
+ node = keyOrNodeOrEntry;
167
+ } else if (this.isEntry(keyOrNodeOrEntry)) {
168
+ const [key, value] = keyOrNodeOrEntry;
182
169
  if (key === undefined || key === null) {
183
170
  return;
184
171
  } else {
185
172
  node = this.createNode(key, value);
186
173
  }
187
- } else if (this.isNotNodeInstance(exemplar)) {
188
- node = this.createNode(exemplar, value);
174
+ } else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
175
+ node = this.createNode(keyOrNodeOrEntry, value);
189
176
  } else {
190
177
  return;
191
178
  }
@@ -193,13 +180,66 @@ export class BST<
193
180
  }
194
181
 
195
182
  /**
196
- * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
197
- * Space Complexity: O(1) - Constant space is used.
183
+ * Time Complexity: O(log n)
184
+ * Space Complexity: O(log n)
185
+ * Average case for a balanced tree. Space for the recursive call stack in the worst case.
186
+ */
187
+
188
+ /**
189
+ * Time Complexity: O(log n)
190
+ * Space Complexity: O(log n)
191
+ *
192
+ * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
193
+ * otherwise it returns the key itself.
194
+ * @param {K | N | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `N`, or
195
+ * `undefined`.
196
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
197
+ * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
198
+ * @returns either a node object (N) or undefined.
199
+ */
200
+ override ensureNode(
201
+ keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>,
202
+ iterationType = IterationType.ITERATIVE
203
+ ): N | undefined {
204
+ let res: N | undefined;
205
+ if (this.isRealNode(keyOrNodeOrEntry)) {
206
+ res = keyOrNodeOrEntry;
207
+ } else if (this.isEntry(keyOrNodeOrEntry)) {
208
+ if (keyOrNodeOrEntry[0]) res = this.getNodeByKey(keyOrNodeOrEntry[0], iterationType);
209
+ } else {
210
+ if (keyOrNodeOrEntry) res = this.getNodeByKey(keyOrNodeOrEntry, iterationType);
211
+ }
212
+ return res;
213
+ }
214
+
215
+ /**
216
+ * The function "isNotNodeInstance" checks if a potential key is a K.
217
+ * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
218
+ * data type.
219
+ * @returns a boolean value indicating whether the potentialKey is of type number or not.
220
+ */
221
+ override isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K {
222
+ return !(potentialKey instanceof BSTNode);
223
+ }
224
+
225
+ /**
226
+ * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
227
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, N>`.
228
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
229
+ */
230
+ override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N {
231
+ return keyOrNodeOrEntry instanceof BSTNode;
232
+ }
233
+
234
+ /**
235
+ * Time Complexity: O(log n)
236
+ * Space Complexity: O(1)
237
+ * - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
198
238
  */
199
239
 
200
240
  /**
201
- * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
202
- * Space Complexity: O(1) - Constant space is used.
241
+ * Time Complexity: O(log n)
242
+ * Space Complexity: O(1)
203
243
  *
204
244
  * The `add` function adds a new node to a binary tree, updating the value if the key already exists
205
245
  * or inserting a new node if the key is unique.
@@ -209,14 +249,14 @@ export class BST<
209
249
  * @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
210
250
  * node was not added.
211
251
  */
212
- override add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined {
252
+ override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean {
213
253
  const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
214
- if (newNode === undefined) return;
254
+ if (newNode === undefined) return false;
215
255
 
216
256
  if (this.root === undefined) {
217
257
  this._setRoot(newNode);
218
258
  this._size++;
219
- return this.root;
259
+ return true;
220
260
  }
221
261
 
222
262
  let current = this.root;
@@ -225,7 +265,7 @@ export class BST<
225
265
  // if (current !== newNode) {
226
266
  // The key value is the same but the reference is different, update the value of the existing node
227
267
  this._replaceNode(current, newNode);
228
- return newNode;
268
+ return true;
229
269
 
230
270
  // } else {
231
271
  // The key value is the same and the reference is the same, replace the entire node
@@ -238,7 +278,7 @@ export class BST<
238
278
  current.left = newNode;
239
279
  newNode.parent = current;
240
280
  this._size++;
241
- return newNode;
281
+ return true;
242
282
  }
243
283
  current = current.left;
244
284
  } else {
@@ -246,23 +286,24 @@ export class BST<
246
286
  current.right = newNode;
247
287
  newNode.parent = current;
248
288
  this._size++;
249
- return newNode;
289
+ return true;
250
290
  }
251
291
  current = current.right;
252
292
  }
253
293
  }
254
294
 
255
- return undefined;
295
+ return false;
256
296
  }
257
297
 
258
298
  /**
259
- * Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
260
- * Space Complexity: O(k) - Additional space is required for the sorted array.
299
+ * Time Complexity: O(k log n)
300
+ * Space Complexity: O(k)
301
+ * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
261
302
  */
262
303
 
263
304
  /**
264
- * Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
265
- * Space Complexity: O(k) - Additional space is required for the sorted array.
305
+ * Time Complexity: O(k log n)
306
+ * Space Complexity: O(k)
266
307
  *
267
308
  * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
268
309
  * balancing the tree after each addition.
@@ -273,7 +314,7 @@ export class BST<
273
314
  * order. If not provided, undefined will be assigned as the value for each key or node.
274
315
  * @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
275
316
  * balanced or not. If set to true, the add operation will be balanced using a binary search tree
276
- * algorithm. If set to false, the add operation will not be balanced and the elements will be added
317
+ * algorithm. If set to false, the add operation will not be balanced and the nodes will be added
277
318
  * in the order they appear in the input.
278
319
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
279
320
  * type of iteration to use when adding multiple keys or nodes. It has a default value of
@@ -281,12 +322,12 @@ export class BST<
281
322
  * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
282
323
  */
283
324
  override addMany(
284
- keysOrNodesOrEntries: Iterable<BTNExemplar<K, V, N>>,
325
+ keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>,
285
326
  values?: Iterable<V | undefined>,
286
327
  isBalanceAdd = true,
287
328
  iterationType = this.iterationType
288
- ): (N | undefined)[] {
289
- const inserted: (N | undefined)[] = [];
329
+ ): boolean[] {
330
+ const inserted: boolean[] = [];
290
331
 
291
332
  let valuesIterator: Iterator<V | undefined> | undefined;
292
333
 
@@ -305,7 +346,7 @@ export class BST<
305
346
 
306
347
  const realBTNExemplars: BTNodePureExemplar<K, V, N>[] = [];
307
348
 
308
- const isRealBTNExemplar = (kve: BTNExemplar<K, V, N>): kve is BTNodePureExemplar<K, V, N> => {
349
+ const isRealBTNExemplar = (kve: KeyOrNodeOrEntry<K, V, N>): kve is BTNodePureExemplar<K, V, N> => {
309
350
  if (kve === undefined || kve === null) return false;
310
351
  return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null));
311
352
  };
@@ -367,30 +408,29 @@ export class BST<
367
408
  }
368
409
 
369
410
  /**
370
- * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
371
- * Space Complexity: O(n) - Additional space is required for the sorted array.
411
+ * Time Complexity: O(n log n)
412
+ * Space Complexity: O(n)
413
+ * Adding each element individually in a balanced tree. Additional space is required for the sorted array.
372
414
  */
373
415
 
374
416
  /**
375
- * Time Complexity: O(log n) - Average case for a balanced tree.
376
- * Space Complexity: O(1) - Constant space is used.
417
+ * Time Complexity: O(n log n)
418
+ * Space Complexity: O(n)
377
419
  *
378
420
  * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
379
421
  * leftmost node if the comparison result is greater than.
380
422
  * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
381
423
  * type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
382
424
  * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
383
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
384
- * be performed. It can have one of the following values:
385
425
  * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
386
426
  * the key of the leftmost node if the comparison result is greater than, and the key of the
387
427
  * rightmost node otherwise. If no node is found, it returns 0.
388
428
  */
389
- lastKey(beginRoot: BSTNKeyOrNode<K, N> = this.root): K | undefined {
429
+ lastKey(beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root): K | undefined {
390
430
  let current = this.ensureNode(beginRoot);
391
431
  if (!current) return undefined;
392
432
 
393
- if (this._variant === BSTVariant.MIN) {
433
+ if (this._variant === BSTVariant.STANDARD) {
394
434
  // For BSTVariant.MIN, find the rightmost node
395
435
  while (current.right !== undefined) {
396
436
  current = current.right;
@@ -405,13 +445,13 @@ export class BST<
405
445
  }
406
446
 
407
447
  /**
408
- * Time Complexity: O(log n) - Average case for a balanced tree.
409
- * Space Complexity: O(1) - Constant space is used.
448
+ * Time Complexity: O(log n)
449
+ * Space Complexity: O(1)
410
450
  */
411
451
 
412
452
  /**
413
- * Time Complexity: O(log n) - Average case for a balanced tree.
414
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
453
+ * Time Complexity: O(log n)
454
+ * Space Complexity: O(1)
415
455
  *
416
456
  * The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
417
457
  * either recursive or iterative methods.
@@ -449,36 +489,14 @@ export class BST<
449
489
  }
450
490
 
451
491
  /**
452
- * The function "isNotNodeInstance" checks if a potential key is a K.
453
- * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
454
- * data type.
455
- * @returns a boolean value indicating whether the potentialKey is of type number or not.
456
- */
457
- override isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K {
458
- return !(potentialKey instanceof BSTNode);
459
- }
460
-
461
- /**
462
- * Time Complexity: O(log n) - Average case for a balanced tree.
463
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
464
- */
465
-
466
- /**
467
- * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
468
- * otherwise it returns the key itself.
469
- * @param {K | N | undefined} key - The `key` parameter can be of type `K`, `N`, or
470
- * `undefined`.
471
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
472
- * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
473
- * @returns either a node object (N) or undefined.
474
- */
475
- override ensureNode(key: BSTNKeyOrNode<K, N>, iterationType = IterationType.ITERATIVE): N | undefined {
476
- return this.isNotNodeInstance(key) ? this.getNodeByKey(key, iterationType) : key;
477
- }
478
-
479
- /**
480
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
481
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
492
+ * Time Complexity: O(log n)
493
+ * Space Complexity: O(log n)
494
+ * Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
495
+ * /
496
+
497
+ /**
498
+ * Time Complexity: O(log n)
499
+ * Space Complexity: O(log n)
482
500
  *
483
501
  * The function `getNodes` returns an array of nodes that match a given identifier, using either a
484
502
  * recursive or iterative approach.
@@ -503,7 +521,7 @@ export class BST<
503
521
  identifier: ReturnType<C> | undefined,
504
522
  callback: C = this._defaultOneParamCallback as C,
505
523
  onlyOne = false,
506
- beginRoot: BSTNKeyOrNode<K, N> = this.root,
524
+ beginRoot: KeyOrNodeOrEntry<K, V, N> = this.root,
507
525
  iterationType = this.iterationType
508
526
  ): N[] {
509
527
  beginRoot = this.ensureNode(beginRoot);
@@ -556,13 +574,14 @@ export class BST<
556
574
  }
557
575
 
558
576
  /**
559
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
560
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
577
+ * Time Complexity: O(log n)
578
+ * Space Complexity: O(log n)
579
+ * Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key. Space for the recursive call stack in the worst case.
561
580
  */
562
581
 
563
582
  /**
564
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
565
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
583
+ * Time Complexity: O(log n)
584
+ * Space Complexity: O(log n)
566
585
  *
567
586
  * The `lesserOrGreaterTraverse` function traverses a binary tree and returns an array of nodes that
568
587
  * are either lesser or greater than a target node, depending on the specified comparison type.
@@ -584,7 +603,7 @@ export class BST<
584
603
  lesserOrGreaterTraverse<C extends BTNCallback<N>>(
585
604
  callback: C = this._defaultOneParamCallback as C,
586
605
  lesserOrGreater: CP = CP.lt,
587
- targetNode: BSTNKeyOrNode<K, N> = this.root,
606
+ targetNode: KeyOrNodeOrEntry<K, V, N> = this.root,
588
607
  iterationType = this.iterationType
589
608
  ): ReturnType<C>[] {
590
609
  targetNode = this.ensureNode(targetNode);
@@ -623,13 +642,13 @@ export class BST<
623
642
  }
624
643
 
625
644
  /**
626
- * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
627
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
645
+ * Time Complexity: O(log n)
646
+ * Space Complexity: O(log n)
628
647
  */
629
648
 
630
649
  /**
631
- * Time Complexity: O(n) - Building a balanced tree from a sorted array.
632
- * Space Complexity: O(n) - Additional space is required for the sorted array.
650
+ * Time Complexity: O(log n)
651
+ * Space Complexity: O(log n)
633
652
  *
634
653
  * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
635
654
  * ensures the tree is perfectly balanced.
@@ -691,8 +710,8 @@ export class BST<
691
710
  */
692
711
 
693
712
  /**
694
- * Time Complexity: O(n) - Visiting each node once.
695
- * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
713
+ * Time Complexity: O(n)
714
+ * Space Complexity: O(log n)
696
715
  *
697
716
  * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
698
717
  * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
@@ -761,7 +780,7 @@ export class BST<
761
780
  protected _compare(a: K, b: K): CP {
762
781
  const extractedA = this.extractor(a);
763
782
  const extractedB = this.extractor(b);
764
- const compared = this.variant === BSTVariant.MIN ? extractedA - extractedB : extractedB - extractedA;
783
+ const compared = this.variant === BSTVariant.STANDARD ? extractedA - extractedB : extractedB - extractedA;
765
784
 
766
785
  return compared > 0 ? CP.gt : compared < 0 ? CP.lt : CP.eq;
767
786
  }