undirected-graph-typed 1.51.9 → 1.52.2

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 (106) hide show
  1. package/dist/data-structures/base/index.d.ts +2 -1
  2. package/dist/data-structures/base/index.js +2 -1
  3. package/dist/data-structures/base/iterable-element-base.d.ts +171 -0
  4. package/dist/data-structures/base/iterable-element-base.js +225 -0
  5. package/dist/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  6. package/dist/data-structures/base/{iterable-base.js → iterable-entry-base.js} +12 -189
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +13 -13
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +13 -13
  10. package/dist/data-structures/binary-tree/avl-tree.js +6 -6
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +99 -99
  12. package/dist/data-structures/binary-tree/binary-tree.js +56 -54
  13. package/dist/data-structures/binary-tree/bst.d.ts +37 -45
  14. package/dist/data-structures/binary-tree/bst.js +19 -27
  15. package/dist/data-structures/binary-tree/rb-tree.d.ts +10 -10
  16. package/dist/data-structures/binary-tree/rb-tree.js +6 -6
  17. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
  18. package/dist/data-structures/binary-tree/tree-multi-map.js +5 -5
  19. package/dist/data-structures/graph/directed-graph.js +2 -1
  20. package/dist/data-structures/hash/hash-map.d.ts +2 -2
  21. package/dist/data-structures/heap/heap.d.ts +43 -114
  22. package/dist/data-structures/heap/heap.js +59 -127
  23. package/dist/data-structures/heap/max-heap.d.ts +50 -4
  24. package/dist/data-structures/heap/max-heap.js +76 -10
  25. package/dist/data-structures/heap/min-heap.d.ts +51 -5
  26. package/dist/data-structures/heap/min-heap.js +68 -11
  27. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  28. package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
  29. package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  30. package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
  31. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  32. package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
  33. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  34. package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
  35. package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
  36. package/dist/data-structures/priority-queue/priority-queue.js +70 -1
  37. package/dist/data-structures/queue/deque.d.ts +27 -18
  38. package/dist/data-structures/queue/deque.js +43 -21
  39. package/dist/data-structures/queue/queue.d.ts +26 -29
  40. package/dist/data-structures/queue/queue.js +47 -38
  41. package/dist/data-structures/stack/stack.d.ts +17 -22
  42. package/dist/data-structures/stack/stack.js +25 -24
  43. package/dist/data-structures/trie/trie.d.ts +18 -13
  44. package/dist/data-structures/trie/trie.js +26 -15
  45. package/dist/interfaces/binary-tree.d.ts +4 -4
  46. package/dist/types/common.d.ts +1 -22
  47. package/dist/types/data-structures/base/base.d.ts +5 -2
  48. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  49. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  50. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +20 -4
  51. package/dist/types/data-structures/binary-tree/bst.d.ts +5 -3
  52. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
  53. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
  54. package/dist/types/data-structures/heap/heap.d.ts +3 -2
  55. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  56. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  57. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  58. package/dist/types/data-structures/queue/deque.d.ts +4 -2
  59. package/dist/types/data-structures/queue/queue.d.ts +4 -1
  60. package/dist/types/data-structures/stack/stack.d.ts +2 -1
  61. package/dist/types/data-structures/trie/trie.d.ts +3 -2
  62. package/package.json +2 -2
  63. package/src/data-structures/base/index.ts +2 -1
  64. package/src/data-structures/base/iterable-element-base.ts +250 -0
  65. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +26 -217
  66. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +26 -26
  67. package/src/data-structures/binary-tree/avl-tree.ts +21 -21
  68. package/src/data-structures/binary-tree/binary-tree.ts +166 -161
  69. package/src/data-structures/binary-tree/bst.ts +61 -68
  70. package/src/data-structures/binary-tree/rb-tree.ts +19 -19
  71. package/src/data-structures/binary-tree/tree-multi-map.ts +19 -19
  72. package/src/data-structures/graph/abstract-graph.ts +15 -14
  73. package/src/data-structures/graph/directed-graph.ts +9 -7
  74. package/src/data-structures/graph/undirected-graph.ts +7 -6
  75. package/src/data-structures/hash/hash-map.ts +8 -8
  76. package/src/data-structures/heap/heap.ts +72 -153
  77. package/src/data-structures/heap/max-heap.ts +88 -13
  78. package/src/data-structures/heap/min-heap.ts +78 -15
  79. package/src/data-structures/linked-list/doubly-linked-list.ts +33 -33
  80. package/src/data-structures/linked-list/singly-linked-list.ts +38 -30
  81. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  82. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  83. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  84. package/src/data-structures/queue/deque.ts +53 -28
  85. package/src/data-structures/queue/queue.ts +61 -44
  86. package/src/data-structures/stack/stack.ts +32 -27
  87. package/src/data-structures/trie/trie.ts +34 -19
  88. package/src/interfaces/binary-tree.ts +4 -5
  89. package/src/types/common.ts +2 -24
  90. package/src/types/data-structures/base/base.ts +14 -6
  91. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
  92. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -3
  93. package/src/types/data-structures/binary-tree/binary-tree.ts +24 -5
  94. package/src/types/data-structures/binary-tree/bst.ts +9 -3
  95. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -3
  96. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -3
  97. package/src/types/data-structures/graph/abstract-graph.ts +8 -8
  98. package/src/types/data-structures/heap/heap.ts +4 -1
  99. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  100. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  101. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  102. package/src/types/data-structures/queue/deque.ts +6 -1
  103. package/src/types/data-structures/queue/queue.ts +5 -1
  104. package/src/types/data-structures/stack/stack.ts +3 -1
  105. package/src/types/data-structures/trie/trie.ts +3 -1
  106. package/src/types/utils/utils.ts +4 -4
@@ -14,13 +14,13 @@ import type {
14
14
  BinaryTreePrintOptions,
15
15
  BTNCallback,
16
16
  BTNEntry,
17
- Comparable,
17
+ BTNKeyOrNodeOrEntry,
18
18
  DFSOrderPattern,
19
19
  EntryCallback,
20
20
  FamilyPosition,
21
21
  IterationType,
22
- KeyOrNodeOrEntry,
23
- NodeDisplayLayout
22
+ NodeDisplayLayout,
23
+ OptBTNOrNull
24
24
  } from '../../types';
25
25
  import { IBinaryTree } from '../../interfaces';
26
26
  import { trampoline } from '../../utils';
@@ -33,7 +33,7 @@ import { IterableEntryBase } from '../base';
33
33
  * @template NODE - The type of the family relationship in the binary tree.
34
34
  */
35
35
  export class BinaryTreeNode<
36
- K extends Comparable,
36
+ K = any,
37
37
  V = any,
38
38
  NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>
39
39
  > {
@@ -63,16 +63,16 @@ export class BinaryTreeNode<
63
63
  * @returns The left node of the current node is being returned. It can be either a NODE object,
64
64
  * null, or undefined.
65
65
  */
66
- get left(): NODE | null | undefined {
66
+ get left(): OptBTNOrNull<NODE> {
67
67
  return this._left;
68
68
  }
69
69
 
70
70
  /**
71
71
  * The function sets the left child of a node and updates its parent reference.
72
- * @param {NODE | null | undefined} v - The parameter `v` can be of type `NODE`, `null`, or
72
+ * @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
73
73
  * `undefined`.
74
74
  */
75
- set left(v: NODE | null | undefined) {
75
+ set left(v: OptBTNOrNull<NODE>) {
76
76
  if (v) {
77
77
  v.parent = this as unknown as NODE;
78
78
  }
@@ -86,16 +86,16 @@ export class BinaryTreeNode<
86
86
  * @returns The method is returning the value of the `_right` property, which can be a `NODE` object,
87
87
  * `null`, or `undefined`.
88
88
  */
89
- get right(): NODE | null | undefined {
89
+ get right(): OptBTNOrNull<NODE> {
90
90
  return this._right;
91
91
  }
92
92
 
93
93
  /**
94
94
  * The function sets the right child of a node and updates its parent.
95
- * @param {NODE | null | undefined} v - The parameter `v` can be of type `NODE`, `null`, or
95
+ * @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
96
96
  * `undefined`.
97
97
  */
98
- set right(v: NODE | null | undefined) {
98
+ set right(v: OptBTNOrNull<NODE>) {
99
99
  if (v) {
100
100
  v.parent = this as unknown as NODE;
101
101
  }
@@ -131,19 +131,20 @@ export class BinaryTreeNode<
131
131
  */
132
132
 
133
133
  export class BinaryTree<
134
- K extends Comparable,
135
- V = any,
136
- R = BTNEntry<K, V>,
137
- NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>,
138
- TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>
139
- >
134
+ K = any,
135
+ V = any,
136
+ R = BTNEntry<K, V>,
137
+ NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>,
138
+ TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>
139
+ >
140
140
  extends IterableEntryBase<K, V | undefined>
141
- implements IBinaryTree<K, V, R, NODE, TREE> {
141
+ implements IBinaryTree<K, V, R, NODE, TREE>
142
+ {
142
143
  iterationType: IterationType = 'ITERATIVE';
143
144
 
144
145
  /**
145
146
  * The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
146
- * @param [keysOrNodesOrEntriesOrRawElements] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
147
+ * @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of BTNKeyOrNodeOrEntry objects. These objects represent the
147
148
  * nodes to be added to the binary tree.
148
149
  * @param [options] - The `options` parameter is an optional object that can contain additional
149
150
  * configuration options for the binary tree. In this case, it is of type
@@ -151,7 +152,7 @@ export class BinaryTree<
151
152
  * required.
152
153
  */
153
154
  constructor(
154
- keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>> = [],
155
+ keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
155
156
  options?: BinaryTreeOptions<K, V, R>
156
157
  ) {
157
158
  super();
@@ -159,19 +160,20 @@ export class BinaryTree<
159
160
  const { iterationType, toEntryFn } = options;
160
161
  if (iterationType) this.iterationType = iterationType;
161
162
  if (typeof toEntryFn === 'function') this._toEntryFn = toEntryFn;
163
+ else if (toEntryFn) throw TypeError('toEntryFn must be a function type');
162
164
  }
163
165
 
164
166
  if (keysOrNodesOrEntriesOrRawElements) this.addMany(keysOrNodesOrEntriesOrRawElements);
165
167
  }
166
168
 
167
- protected _root?: NODE | null;
169
+ protected _root?: OptBTNOrNull<NODE>;
168
170
 
169
171
  /**
170
172
  * The function returns the root node, which can be of type NODE, null, or undefined.
171
173
  * @returns The method is returning the value of the `_root` property, which can be of type `NODE`,
172
174
  * `null`, or `undefined`.
173
175
  */
174
- get root(): NODE | null | undefined {
176
+ get root(): OptBTNOrNull<NODE> {
175
177
  return this._root;
176
178
  }
177
179
 
@@ -229,8 +231,8 @@ export class BinaryTree<
229
231
  /**
230
232
  * The function `keyValueOrEntryOrRawElementToNode` converts a key-value pair, entry, or raw element
231
233
  * into a node object.
232
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
233
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
234
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
235
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
234
236
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
235
237
  * `keyValueOrEntryOrRawElementToNode` function. It represents the value associated with a key in a
236
238
  * key-value pair. If provided, it will be used to create a node with the specified key and value.
@@ -238,9 +240,9 @@ export class BinaryTree<
238
240
  * or `undefined`.
239
241
  */
240
242
  keyValueOrEntryOrRawElementToNode(
241
- keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>,
243
+ keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
242
244
  value?: V
243
- ): NODE | null | undefined {
245
+ ): OptBTNOrNull<NODE> {
244
246
  if (keyOrNodeOrEntryOrRawElement === undefined) return;
245
247
  if (keyOrNodeOrEntryOrRawElement === null) return null;
246
248
 
@@ -275,8 +277,8 @@ export class BinaryTree<
275
277
  *
276
278
  * The `ensureNode` function checks if the input is a valid node and returns it, or converts it to a
277
279
  * node if it is a key or entry.
278
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
279
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `KeyOrNodeOrEntry<K, V, NODE>`, or
280
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
281
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
280
282
  * a raw element.
281
283
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
282
284
  * parameter that specifies the type of iteration to be used when searching for a node. It has a
@@ -284,9 +286,9 @@ export class BinaryTree<
284
286
  * @returns The function `ensureNode` returns either a `NODE` object, `null`, or `undefined`.
285
287
  */
286
288
  ensureNode(
287
- keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>,
289
+ keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
288
290
  iterationType: IterationType = 'ITERATIVE'
289
- ): NODE | null | undefined {
291
+ ): OptBTNOrNull<NODE> {
290
292
  if (keyOrNodeOrEntryOrRawElement === null) return null;
291
293
  if (keyOrNodeOrEntryOrRawElement === undefined) return;
292
294
  if (keyOrNodeOrEntryOrRawElement === this.NIL) return;
@@ -310,55 +312,55 @@ export class BinaryTree<
310
312
 
311
313
  /**
312
314
  * The function checks if the input is an instance of the BinaryTreeNode class.
313
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
314
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
315
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
316
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
315
317
  * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
316
318
  * an instance of the `BinaryTreeNode` class.
317
319
  */
318
- isNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE {
320
+ isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE {
319
321
  return keyOrNodeOrEntryOrRawElement instanceof BinaryTreeNode;
320
322
  }
321
323
 
322
324
  /**
323
325
  * The function checks if a given node is a valid node in a binary search tree.
324
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
325
- * `KeyOrNodeOrEntry<K, V, NODE>`.
326
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
327
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
326
328
  * @returns a boolean value.
327
329
  */
328
- isRealNode(node: R | KeyOrNodeOrEntry<K, V, NODE>): node is NODE {
330
+ isRealNode(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): node is NODE {
329
331
  if (node === this.NIL || node === null || node === undefined) return false;
330
332
  return this.isNode(node);
331
333
  }
332
334
 
333
335
  /**
334
336
  * The function checks if a given node is a real node or null.
335
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
336
- * `KeyOrNodeOrEntry<K, V, NODE>`.
337
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
338
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
337
339
  * @returns a boolean value.
338
340
  */
339
- isNodeOrNull(node: R | KeyOrNodeOrEntry<K, V, NODE>): node is NODE | null {
341
+ isNodeOrNull(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): node is NODE | null {
340
342
  return this.isRealNode(node) || node === null;
341
343
  }
342
344
 
343
345
  /**
344
346
  * The function checks if a given node is equal to the NIL value.
345
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
346
- * `KeyOrNodeOrEntry<K, V, NODE>`.
347
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
348
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
347
349
  * @returns a boolean value.
348
350
  */
349
- isNIL(node: R | KeyOrNodeOrEntry<K, V, NODE>) {
351
+ isNIL(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>) {
350
352
  return node === this.NIL;
351
353
  }
352
354
 
353
355
  /**
354
356
  * The function checks if the input is an array with two elements, indicating it is a binary tree
355
357
  * node entry.
356
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
357
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
358
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
359
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
358
360
  * @returns a boolean value.
359
361
  */
360
362
  isEntry(
361
- keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>
363
+ keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
362
364
  ): keyOrNodeOrEntryOrRawElement is BTNEntry<K, V> {
363
365
  return Array.isArray(keyOrNodeOrEntryOrRawElement) && keyOrNodeOrEntryOrRawElement.length === 2;
364
366
  }
@@ -402,17 +404,17 @@ export class BinaryTree<
402
404
  *
403
405
  * The `add` function is used to insert a new node into a binary tree, checking for duplicate keys
404
406
  * and finding the appropriate insertion position.
405
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
407
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
406
408
  * `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which represents the key,
407
409
  * node, entry, or raw element to be added to the tree. It can also accept a value of type
408
- * `KeyOrNodeOrEntry<K, V, NODE>
410
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>
409
411
  * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
410
412
  * key being added to the tree. It represents the value that will be stored in the tree for the given
411
413
  * key.
412
414
  * @returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
413
415
  * insertion position cannot be found or if there are duplicate keys.
414
416
  */
415
- add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
417
+ add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
416
418
  const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
417
419
  if (newNode === undefined) return false;
418
420
 
@@ -486,7 +488,7 @@ export class BinaryTree<
486
488
  * successfully added to the data structure.
487
489
  */
488
490
  addMany(
489
- keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>,
491
+ keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>,
490
492
  values?: Iterable<V | undefined>
491
493
  ): boolean[] {
492
494
  // TODO not sure addMany not be run multi times
@@ -525,13 +527,13 @@ export class BinaryTree<
525
527
  *
526
528
  * The `refill` function clears the current data and adds new data to the collection.
527
529
  * @param keysOrNodesOrEntriesOrRawElements - An iterable collection of keys, nodes, entries, or raw
528
- * elements. These can be of any type (R) or a specific type (KeyOrNodeOrEntry<K, V, NODE>).
530
+ * elements. These can be of any type (R) or a specific type (BTNKeyOrNodeOrEntry<K, V, NODE>).
529
531
  * @param [values] - The `values` parameter is an optional iterable of values that will be associated
530
532
  * with the keys or nodes being added. If provided, the values will be assigned to the corresponding
531
533
  * keys or nodes. If not provided, the values will be set to `undefined`.
532
534
  */
533
535
  refill(
534
- keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>,
536
+ keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>,
535
537
  values?: Iterable<V | undefined>
536
538
  ): void {
537
539
  this.clear();
@@ -541,7 +543,7 @@ export class BinaryTree<
541
543
  delete<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<NODE>[];
542
544
 
543
545
  delete<C extends BTNCallback<NODE, NODE>>(
544
- identifier: NODE | null | undefined,
546
+ identifier: OptBTNOrNull<NODE>,
545
547
  callback?: C
546
548
  ): BinaryTreeDeleteResult<NODE>[];
547
549
 
@@ -619,15 +621,15 @@ export class BinaryTree<
619
621
  identifier: K,
620
622
  callback?: C,
621
623
  onlyOne?: boolean,
622
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
624
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
623
625
  iterationType?: IterationType
624
626
  ): NODE[];
625
627
 
626
628
  getNodes<C extends BTNCallback<NODE, NODE>>(
627
- identifier: NODE | null | undefined,
629
+ identifier: OptBTNOrNull<NODE>,
628
630
  callback?: C,
629
631
  onlyOne?: boolean,
630
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
632
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
631
633
  iterationType?: IterationType
632
634
  ): NODE[];
633
635
 
@@ -635,7 +637,7 @@ export class BinaryTree<
635
637
  identifier: ReturnType<C>,
636
638
  callback: C,
637
639
  onlyOne?: boolean,
638
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
640
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
639
641
  iterationType?: IterationType
640
642
  ): NODE[];
641
643
 
@@ -661,7 +663,7 @@ export class BinaryTree<
661
663
  * the identifier or all nodes that match the identifier. If set to true, only the first matching
662
664
  * node will be returned. If set to false, all matching nodes will be returned. The default value is
663
665
  * false.
664
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
666
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
665
667
  * point for the search. It can be either a node object, a key-value pair, or a key. If it is not
666
668
  * provided, the `root` of the data structure is used as the starting point.
667
669
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
@@ -672,7 +674,7 @@ export class BinaryTree<
672
674
  identifier: ReturnType<C> | null | undefined,
673
675
  callback: C = this._DEFAULT_CALLBACK as C,
674
676
  onlyOne = false,
675
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
677
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
676
678
  iterationType: IterationType = this.iterationType
677
679
  ): NODE[] {
678
680
  beginRoot = this.ensureNode(beginRoot);
@@ -714,23 +716,23 @@ export class BinaryTree<
714
716
  getNode<C extends BTNCallback<NODE, K>>(
715
717
  identifier: K,
716
718
  callback?: C,
717
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
719
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
718
720
  iterationType?: IterationType
719
- ): NODE | null | undefined;
721
+ ): OptBTNOrNull<NODE>;
720
722
 
721
723
  getNode<C extends BTNCallback<NODE, NODE>>(
722
- identifier: NODE | null | undefined,
724
+ identifier: OptBTNOrNull<NODE>,
723
725
  callback?: C,
724
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
726
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
725
727
  iterationType?: IterationType
726
- ): NODE | null | undefined;
728
+ ): OptBTNOrNull<NODE>;
727
729
 
728
730
  getNode<C extends BTNCallback<NODE>>(
729
731
  identifier: ReturnType<C>,
730
732
  callback: C,
731
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
733
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
732
734
  iterationType?: IterationType
733
- ): NODE | null | undefined;
735
+ ): OptBTNOrNull<NODE>;
734
736
 
735
737
  /**
736
738
  * Time Complexity: O(n)
@@ -748,7 +750,7 @@ export class BinaryTree<
748
750
  * the `C` callback function, or it can be `null` or `undefined`.
749
751
  * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
750
752
  * node matches the desired criteria. It should return a value that can be used to identify the node.
751
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
753
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
752
754
  * point for searching nodes in a tree structure. It can be either a root node, a key-value pair, or
753
755
  * a node entry. If not provided, the search will start from the root of the tree.
754
756
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
@@ -758,9 +760,9 @@ export class BinaryTree<
758
760
  getNode<C extends BTNCallback<NODE>>(
759
761
  identifier: ReturnType<C> | null | undefined,
760
762
  callback: C = this._DEFAULT_CALLBACK as C,
761
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
763
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
762
764
  iterationType: IterationType = this.iterationType
763
- ): NODE | null | undefined {
765
+ ): OptBTNOrNull<NODE> {
764
766
  return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? null;
765
767
  }
766
768
 
@@ -781,28 +783,28 @@ export class BinaryTree<
781
783
  * It has a default value of `'ITERATIVE'`.
782
784
  * @returns a value of type NODE, null, or undefined.
783
785
  */
784
- getNodeByKey(key: K, iterationType: IterationType = 'ITERATIVE'): NODE | null | undefined {
786
+ getNodeByKey(key: K, iterationType: IterationType = 'ITERATIVE'): OptBTNOrNull<NODE> {
785
787
  return this.getNode(key, this._DEFAULT_CALLBACK, this.root, iterationType);
786
788
  }
787
789
 
788
790
  override get<C extends BTNCallback<NODE, K>>(
789
791
  identifier: K,
790
792
  callback?: C,
791
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
793
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
792
794
  iterationType?: IterationType
793
795
  ): V | undefined;
794
796
 
795
797
  override get<C extends BTNCallback<NODE, NODE>>(
796
- identifier: NODE | null | undefined,
798
+ identifier: OptBTNOrNull<NODE>,
797
799
  callback?: C,
798
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
800
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
799
801
  iterationType?: IterationType
800
802
  ): V | undefined;
801
803
 
802
804
  override get<C extends BTNCallback<NODE>>(
803
805
  identifier: ReturnType<C>,
804
806
  callback: C,
805
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
807
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
806
808
  iterationType?: IterationType
807
809
  ): V | undefined;
808
810
 
@@ -822,7 +824,7 @@ export class BinaryTree<
822
824
  * callback function `C`. It can also be `null` or `undefined` if no identifier is provided.
823
825
  * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
824
826
  * node matches the given identifier. It is optional and defaults to `this._DEFAULT_CALLBACK`.
825
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
827
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
826
828
  * point for the search in the binary tree. It can be either a root node of the tree or a key, node,
827
829
  * or entry object that exists in the tree. If no specific starting point is provided, the search
828
830
  * will begin from the root of the
@@ -835,7 +837,7 @@ export class BinaryTree<
835
837
  override get<C extends BTNCallback<NODE>>(
836
838
  identifier: ReturnType<C> | null | undefined,
837
839
  callback: C = this._DEFAULT_CALLBACK as C,
838
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
840
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
839
841
  iterationType: IterationType = this.iterationType
840
842
  ): V | undefined {
841
843
  return this.getNode(identifier, callback, beginRoot, iterationType)?.value;
@@ -844,21 +846,21 @@ export class BinaryTree<
844
846
  override has<C extends BTNCallback<NODE, K>>(
845
847
  identifier: K,
846
848
  callback?: C,
847
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
849
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
848
850
  iterationType?: IterationType
849
851
  ): boolean;
850
852
 
851
853
  override has<C extends BTNCallback<NODE, NODE>>(
852
- identifier: NODE | null | undefined,
854
+ identifier: OptBTNOrNull<NODE>,
853
855
  callback?: C,
854
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
856
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
855
857
  iterationType?: IterationType
856
858
  ): boolean;
857
859
 
858
860
  override has<C extends BTNCallback<NODE>>(
859
861
  identifier: ReturnType<C> | null | undefined,
860
862
  callback: C,
861
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
863
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
862
864
  iterationType?: IterationType
863
865
  ): boolean;
864
866
 
@@ -880,7 +882,7 @@ export class BinaryTree<
880
882
  * @param {C} callback - The `callback` parameter is a function that will be used to determine
881
883
  * whether a node should be included in the result or not. It is of type `C`, which extends the
882
884
  * `BTNCallback<NODE>` type.
883
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
885
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
884
886
  * point for the iteration in the data structure. It can be either a root node, a key-value pair, or
885
887
  * a node entry. If not specified, it defaults to the root of the data structure.
886
888
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
@@ -890,7 +892,7 @@ export class BinaryTree<
890
892
  override has<C extends BTNCallback<NODE>>(
891
893
  identifier: ReturnType<C> | null | undefined,
892
894
  callback: C = this._DEFAULT_CALLBACK as C,
893
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
895
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
894
896
  iterationType: IterationType = this.iterationType
895
897
  ): boolean {
896
898
  callback = this._ensureCallback(identifier, callback);
@@ -941,13 +943,13 @@ export class BinaryTree<
941
943
  *
942
944
  * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
943
945
  * height of the tree.
944
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The parameter `beginRoot` is optional and
946
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The parameter `beginRoot` is optional and
945
947
  * has a default value of `this.root`. It represents the starting point for checking if the tree is
946
948
  * perfectly balanced. It can be either a root node (`R`), a key or node or entry
947
- * (`KeyOrNodeOrEntry<K, V, NODE
949
+ * (`BTNKeyOrNodeOrEntry<K, V, NODE
948
950
  * @returns a boolean value.
949
951
  */
950
- isPerfectlyBalanced(beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root): boolean {
952
+ isPerfectlyBalanced(beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root): boolean {
951
953
  return this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot);
952
954
  }
953
955
 
@@ -961,7 +963,7 @@ export class BinaryTree<
961
963
  * Space Complexity: O(1)
962
964
  *
963
965
  * The function `isBST` checks if a binary search tree is valid, either recursively or iteratively.
964
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
966
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
965
967
  * starting point for checking if a binary search tree (BST) is valid. It can be either a root node
966
968
  * of the BST, a key value of a node in the BST, or an entry object containing both the key and value
967
969
  * of a node in the BST
@@ -971,7 +973,7 @@ export class BinaryTree<
971
973
  * @returns a boolean value.
972
974
  */
973
975
  isBST(
974
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
976
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
975
977
  iterationType: IterationType = this.iterationType
976
978
  ): boolean {
977
979
  // TODO there is a bug
@@ -979,7 +981,7 @@ export class BinaryTree<
979
981
  if (!beginRoot) return true;
980
982
 
981
983
  if (iterationType === 'RECURSIVE') {
982
- const dfs = (cur: NODE | null | undefined, min: number, max: number): boolean => {
984
+ const dfs = (cur: OptBTNOrNull<NODE>, min: number, max: number): boolean => {
983
985
  if (!this.isRealNode(cur)) return true;
984
986
  const numKey = Number(cur.key);
985
987
  if (numKey <= min || numKey >= max) return false;
@@ -994,7 +996,7 @@ export class BinaryTree<
994
996
  const stack = [];
995
997
  let prev = checkMax ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER;
996
998
  // @ts-ignore
997
- let curr: NODE | null | undefined = beginRoot;
999
+ let curr: OptBTNOrNull<NODE> = beginRoot;
998
1000
  while (this.isRealNode(curr) || stack.length > 0) {
999
1001
  while (this.isRealNode(curr)) {
1000
1002
  stack.push(curr);
@@ -1024,16 +1026,19 @@ export class BinaryTree<
1024
1026
  * Space Complexity: O(1)
1025
1027
  *
1026
1028
  * The function calculates the depth of a given node or key in a tree-like data structure.
1027
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} dist - The `dist` parameter can be either a `R`
1028
- * (representing a root node), or a `KeyOrNodeOrEntry<K, V, NODE>` (representing a key, node, or
1029
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} dist - The `dist` parameter can be either a `R`
1030
+ * (representing a root node), or a `BTNKeyOrNodeOrEntry<K, V, NODE>` (representing a key, node, or
1029
1031
  * entry).
1030
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is optional and
1032
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is optional and
1031
1033
  * represents the starting point from which to calculate the depth. It can be either a reference to a
1032
1034
  * node in the tree or a key-value pair or an entry object. If not provided, the default value is
1033
1035
  * `this.root`, which refers to the root node
1034
1036
  * @returns the depth of a node in a tree structure.
1035
1037
  */
1036
- getDepth(dist: R | KeyOrNodeOrEntry<K, V, NODE>, beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root): number {
1038
+ getDepth(
1039
+ dist: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
1040
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root
1041
+ ): number {
1037
1042
  let distEnsured = this.ensureNode(dist);
1038
1043
  const beginRootEnsured = this.ensureNode(beginRoot);
1039
1044
  let depth = 0;
@@ -1058,22 +1063,22 @@ export class BinaryTree<
1058
1063
  *
1059
1064
  * The `getHeight` function calculates the maximum height of a binary tree using either a recursive
1060
1065
  * or iterative approach.
1061
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1066
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1062
1067
  * starting point for calculating the height of a tree. It can be either a root node (`R`), a key or
1063
- * node or entry (`KeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current tree.
1068
+ * node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current tree.
1064
1069
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
1065
1070
  * iteration used to calculate the height of the tree. It can have two possible values:
1066
1071
  * @returns the maximum height of the binary tree.
1067
1072
  */
1068
1073
  getHeight(
1069
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
1074
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
1070
1075
  iterationType: IterationType = this.iterationType
1071
1076
  ): number {
1072
1077
  beginRoot = this.ensureNode(beginRoot);
1073
1078
  if (!this.isRealNode(beginRoot)) return -1;
1074
1079
 
1075
1080
  if (iterationType === 'RECURSIVE') {
1076
- const _getMaxHeight = (cur: NODE | null | undefined): number => {
1081
+ const _getMaxHeight = (cur: OptBTNOrNull<NODE>): number => {
1077
1082
  if (!this.isRealNode(cur)) return -1;
1078
1083
  const leftHeight = _getMaxHeight(cur.left);
1079
1084
  const rightHeight = _getMaxHeight(cur.right);
@@ -1109,9 +1114,9 @@ export class BinaryTree<
1109
1114
  *
1110
1115
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
1111
1116
  * recursive or iterative approach.
1112
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1117
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1113
1118
  * starting point for calculating the minimum height of a tree. It can be either a root node (`R`), a
1114
- * key or node or entry (`KeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current
1119
+ * key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current
1115
1120
  * tree.
1116
1121
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
1117
1122
  * iteration to be used when calculating the minimum height of the tree. It can have two possible
@@ -1120,14 +1125,14 @@ export class BinaryTree<
1120
1125
  * binary tree.
1121
1126
  */
1122
1127
  getMinHeight(
1123
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
1128
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
1124
1129
  iterationType: IterationType = this.iterationType
1125
1130
  ): number {
1126
1131
  beginRoot = this.ensureNode(beginRoot);
1127
1132
  if (!beginRoot) return -1;
1128
1133
 
1129
1134
  if (iterationType === 'RECURSIVE') {
1130
- const _getMinHeight = (cur: NODE | null | undefined): number => {
1135
+ const _getMinHeight = (cur: OptBTNOrNull<NODE>): number => {
1131
1136
  if (!this.isRealNode(cur)) return 0;
1132
1137
  if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right)) return 0;
1133
1138
  const leftMinHeight = _getMinHeight(cur.left);
@@ -1138,8 +1143,8 @@ export class BinaryTree<
1138
1143
  return _getMinHeight(beginRoot);
1139
1144
  } else {
1140
1145
  const stack: NODE[] = [];
1141
- let node: NODE | null | undefined = beginRoot,
1142
- last: NODE | null | undefined = null;
1146
+ let node: OptBTNOrNull<NODE> = beginRoot,
1147
+ last: OptBTNOrNull<NODE> = null;
1143
1148
  const depths: Map<NODE, number> = new Map();
1144
1149
 
1145
1150
  while (stack.length > 0 || node) {
@@ -1151,8 +1156,8 @@ export class BinaryTree<
1151
1156
  if (!this.isRealNode(node.right) || last === node.right) {
1152
1157
  node = stack.pop();
1153
1158
  if (this.isRealNode(node)) {
1154
- const leftMinHeight = this.isRealNode(node.left) ? depths.get(node.left) ?? -1 : -1;
1155
- const rightMinHeight = this.isRealNode(node.right) ? depths.get(node.right) ?? -1 : -1;
1159
+ const leftMinHeight = this.isRealNode(node.left) ? (depths.get(node.left) ?? -1) : -1;
1160
+ const rightMinHeight = this.isRealNode(node.right) ? (depths.get(node.right) ?? -1) : -1;
1156
1161
  depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
1157
1162
  last = node;
1158
1163
  node = null;
@@ -1176,14 +1181,14 @@ export class BinaryTree<
1176
1181
  *
1177
1182
  * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
1178
1183
  * up to the root node, with an option to reverse the order of the nodes.
1179
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginNode - The `beginNode` parameter can be either of
1180
- * type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
1184
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginNode - The `beginNode` parameter can be either of
1185
+ * type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
1181
1186
  * @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
1182
1187
  * resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
1183
1188
  * reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
1184
1189
  * @returns The function `getPathToRoot` returns an array of `NODE` objects.
1185
1190
  */
1186
- getPathToRoot(beginNode: R | KeyOrNodeOrEntry<K, V, NODE>, isReverse = true): NODE[] {
1191
+ getPathToRoot(beginNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>, isReverse = true): NODE[] {
1187
1192
  const result: NODE[] = [];
1188
1193
  let beginNodeEnsured = this.ensureNode(beginNode);
1189
1194
 
@@ -1209,17 +1214,17 @@ export class BinaryTree<
1209
1214
  *
1210
1215
  * The `getLeftMost` function returns the leftmost node in a binary tree, either using recursive or
1211
1216
  * iterative traversal.
1212
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1217
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1213
1218
  * starting point for finding the leftmost node in a binary tree. It can be either a root node (`R`),
1214
- * a key or node or entry (`KeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
1219
+ * a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
1215
1220
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
1216
1221
  * of iteration to be performed. It can have two possible values:
1217
1222
  * @returns The function `getLeftMost` returns the leftmost node in a binary tree.
1218
1223
  */
1219
1224
  getLeftMost(
1220
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
1225
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
1221
1226
  iterationType: IterationType = this.iterationType
1222
- ): NODE | null | undefined {
1227
+ ): OptBTNOrNull<NODE> {
1223
1228
  if (this.isNIL(beginRoot)) return beginRoot as NODE;
1224
1229
  beginRoot = this.ensureNode(beginRoot);
1225
1230
 
@@ -1254,18 +1259,18 @@ export class BinaryTree<
1254
1259
  *
1255
1260
  * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or
1256
1261
  * iteratively.
1257
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1262
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1258
1263
  * starting point for finding the rightmost node in a binary tree. It can be either a root node
1259
- * (`R`), a key or node or entry (`KeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
1264
+ * (`R`), a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
1260
1265
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
1261
1266
  * of iteration to be performed when finding the rightmost node in a binary tree. It can have two
1262
1267
  * possible values:
1263
1268
  * @returns The function `getRightMost` returns a NODE object, `null`, or `undefined`.
1264
1269
  */
1265
1270
  getRightMost(
1266
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
1271
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
1267
1272
  iterationType: IterationType = this.iterationType
1268
- ): NODE | null | undefined {
1273
+ ): OptBTNOrNull<NODE> {
1269
1274
  if (this.isNIL(beginRoot)) return beginRoot as NODE;
1270
1275
  // TODO support get right most by passing key in
1271
1276
  beginRoot = this.ensureNode(beginRoot);
@@ -1305,7 +1310,7 @@ export class BinaryTree<
1305
1310
  */
1306
1311
  getPredecessor(node: NODE): NODE {
1307
1312
  if (this.isRealNode(node.left)) {
1308
- let predecessor: NODE | null | undefined = node.left;
1313
+ let predecessor: OptBTNOrNull<NODE> = node.left;
1309
1314
  while (!this.isRealNode(predecessor) || (this.isRealNode(predecessor.right) && predecessor.right !== node)) {
1310
1315
  if (this.isRealNode(predecessor)) {
1311
1316
  predecessor = predecessor.right;
@@ -1331,7 +1336,7 @@ export class BinaryTree<
1331
1336
  * @returns The function `getSuccessor` returns a `NODE` object if a successor exists, `null` if
1332
1337
  * there is no successor, and `undefined` if the input `x` is not a valid node.
1333
1338
  */
1334
- getSuccessor(x?: K | NODE | null): NODE | null | undefined {
1339
+ getSuccessor(x?: K | NODE | null): OptBTNOrNull<NODE> {
1335
1340
  x = this.ensureNode(x);
1336
1341
  if (!this.isRealNode(x)) return undefined;
1337
1342
 
@@ -1339,7 +1344,7 @@ export class BinaryTree<
1339
1344
  return this.getLeftMost(x.right);
1340
1345
  }
1341
1346
 
1342
- let y: NODE | null | undefined = x.parent;
1347
+ let y: OptBTNOrNull<NODE> = x.parent;
1343
1348
  while (this.isRealNode(y) && x === y.right) {
1344
1349
  x = y;
1345
1350
  y = y.parent;
@@ -1350,7 +1355,7 @@ export class BinaryTree<
1350
1355
  dfs<C extends BTNCallback<NODE>>(
1351
1356
  callback?: C,
1352
1357
  pattern?: DFSOrderPattern,
1353
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
1358
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
1354
1359
  iterationType?: IterationType,
1355
1360
  includeNull?: false
1356
1361
  ): ReturnType<C>[];
@@ -1358,7 +1363,7 @@ export class BinaryTree<
1358
1363
  dfs<C extends BTNCallback<NODE | null>>(
1359
1364
  callback?: C,
1360
1365
  pattern?: DFSOrderPattern,
1361
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
1366
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
1362
1367
  iterationType?: IterationType,
1363
1368
  includeNull?: true
1364
1369
  ): ReturnType<C>[];
@@ -1379,7 +1384,7 @@ export class BinaryTree<
1379
1384
  * return type of the callback function is determined by the generic type `C`.
1380
1385
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter determines the order in which the
1381
1386
  * nodes are visited during the depth-first search. It can have one of the following values:
1382
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
1387
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
1383
1388
  * point of the depth-first search. It can be either a node object, a key-value pair, or a key. If it
1384
1389
  * is a key or key-value pair, the method will find the corresponding node in the tree and start the
1385
1390
  * search from there.
@@ -1391,10 +1396,10 @@ export class BinaryTree<
1391
1396
  * values will
1392
1397
  * @returns an array of the return types of the callback function.
1393
1398
  */
1394
- dfs<C extends BTNCallback<NODE | null | undefined>>(
1399
+ dfs<C extends BTNCallback<OptBTNOrNull<NODE>>>(
1395
1400
  callback: C = this._DEFAULT_CALLBACK as C,
1396
1401
  pattern: DFSOrderPattern = 'IN',
1397
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
1402
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
1398
1403
  iterationType: IterationType = 'ITERATIVE',
1399
1404
  includeNull = false
1400
1405
  ): ReturnType<C>[] {
@@ -1402,7 +1407,7 @@ export class BinaryTree<
1402
1407
  if (!beginRoot) return [];
1403
1408
  const ans: ReturnType<C>[] = [];
1404
1409
  if (iterationType === 'RECURSIVE') {
1405
- const dfs = (node: NODE | null | undefined) => {
1410
+ const dfs = (node: OptBTNOrNull<NODE>) => {
1406
1411
  switch (pattern) {
1407
1412
  case 'IN':
1408
1413
  if (includeNull) {
@@ -1444,7 +1449,7 @@ export class BinaryTree<
1444
1449
  dfs(beginRoot);
1445
1450
  } else {
1446
1451
  // 0: visit, 1: print
1447
- const stack: { opt: 0 | 1; node: NODE | null | undefined }[] = [{ opt: 0, node: beginRoot }];
1452
+ const stack: { opt: 0 | 1; node: OptBTNOrNull<NODE> }[] = [{ opt: 0, node: beginRoot }];
1448
1453
 
1449
1454
  while (stack.length > 0) {
1450
1455
  const cur = stack.pop();
@@ -1488,14 +1493,14 @@ export class BinaryTree<
1488
1493
 
1489
1494
  bfs<C extends BTNCallback<NODE>>(
1490
1495
  callback?: C,
1491
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
1496
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
1492
1497
  iterationType?: IterationType,
1493
1498
  includeNull?: false
1494
1499
  ): ReturnType<C>[];
1495
1500
 
1496
1501
  bfs<C extends BTNCallback<NODE | null>>(
1497
1502
  callback?: C,
1498
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
1503
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
1499
1504
  iterationType?: IterationType,
1500
1505
  includeNull?: true
1501
1506
  ): ReturnType<C>[];
@@ -1514,7 +1519,7 @@ export class BinaryTree<
1514
1519
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
1515
1520
  * the breadth-first search traversal. It takes a single argument, which is the current node being
1516
1521
  * visited, and returns a value of any type.
1517
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1522
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1518
1523
  * starting point of the breadth-first search. It can be either a root node of a tree or a key, node,
1519
1524
  * or entry object. If no value is provided, the `root` property of the class is used as the default
1520
1525
  * starting point.
@@ -1529,7 +1534,7 @@ export class BinaryTree<
1529
1534
  */
1530
1535
  bfs<C extends BTNCallback<NODE | null>>(
1531
1536
  callback: C = this._DEFAULT_CALLBACK as C,
1532
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
1537
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
1533
1538
  iterationType: IterationType = this.iterationType,
1534
1539
  includeNull = false
1535
1540
  ): ReturnType<C>[] {
@@ -1539,7 +1544,7 @@ export class BinaryTree<
1539
1544
  const ans: ReturnType<BTNCallback<NODE>>[] = [];
1540
1545
 
1541
1546
  if (iterationType === 'RECURSIVE') {
1542
- const queue: Queue<NODE | null | undefined> = new Queue<NODE | null | undefined>([beginRoot]);
1547
+ const queue: Queue<OptBTNOrNull<NODE>> = new Queue<OptBTNOrNull<NODE>>([beginRoot]);
1543
1548
 
1544
1549
  const dfs = (level: number) => {
1545
1550
  if (queue.size === 0) return;
@@ -1560,7 +1565,7 @@ export class BinaryTree<
1560
1565
 
1561
1566
  dfs(0);
1562
1567
  } else {
1563
- const queue = new Queue<NODE | null | undefined>([beginRoot]);
1568
+ const queue = new Queue<OptBTNOrNull<NODE>>([beginRoot]);
1564
1569
  while (queue.size > 0) {
1565
1570
  const levelSize = queue.size;
1566
1571
 
@@ -1583,14 +1588,14 @@ export class BinaryTree<
1583
1588
 
1584
1589
  listLevels<C extends BTNCallback<NODE>>(
1585
1590
  callback?: C,
1586
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
1591
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
1587
1592
  iterationType?: IterationType,
1588
1593
  includeNull?: false
1589
1594
  ): ReturnType<C>[][];
1590
1595
 
1591
1596
  listLevels<C extends BTNCallback<NODE | null>>(
1592
1597
  callback?: C,
1593
- beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>,
1598
+ beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
1594
1599
  iterationType?: IterationType,
1595
1600
  includeNull?: true
1596
1601
  ): ReturnType<C>[][];
@@ -1609,7 +1614,7 @@ export class BinaryTree<
1609
1614
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
1610
1615
  * the tree. It takes a node as an argument and returns a value. The return type of the callback
1611
1616
  * function is determined by the generic type `C` which extends `BTNCallback<NODE | null>`.
1612
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1617
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
1613
1618
  * starting point for traversing the tree. It can be either a root node, a key-value pair, or a node
1614
1619
  * entry. If no value is provided, the `root` property of the class is used as the default starting
1615
1620
  * point.
@@ -1623,7 +1628,7 @@ export class BinaryTree<
1623
1628
  */
1624
1629
  listLevels<C extends BTNCallback<NODE | null>>(
1625
1630
  callback: C = this._DEFAULT_CALLBACK as C,
1626
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root,
1631
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root,
1627
1632
  iterationType: IterationType = this.iterationType,
1628
1633
  includeNull = false
1629
1634
  ): ReturnType<C>[][] {
@@ -1686,7 +1691,7 @@ export class BinaryTree<
1686
1691
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function is used
1687
1692
  * to specify the order in which the nodes of a binary tree are traversed. It can take one of the
1688
1693
  * following values:
1689
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
1694
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
1690
1695
  * point for the traversal. It can be either a node object, a key, or an entry object. If no value is
1691
1696
  * provided, the `root` of the tree is used as the starting point.
1692
1697
  * @returns The function `morris` returns an array of values that are the return values of the
@@ -1695,16 +1700,16 @@ export class BinaryTree<
1695
1700
  morris<C extends BTNCallback<NODE>>(
1696
1701
  callback: C = this._DEFAULT_CALLBACK as C,
1697
1702
  pattern: DFSOrderPattern = 'IN',
1698
- beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root
1703
+ beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root
1699
1704
  ): ReturnType<C>[] {
1700
1705
  beginRoot = this.ensureNode(beginRoot);
1701
1706
  if (beginRoot === null) return [];
1702
1707
  const ans: ReturnType<BTNCallback<NODE>>[] = [];
1703
1708
 
1704
- let cur: NODE | null | undefined = beginRoot;
1705
- const _reverseEdge = (node: NODE | null | undefined) => {
1706
- let pre: NODE | null | undefined = null;
1707
- let next: NODE | null | undefined = null;
1709
+ let cur: OptBTNOrNull<NODE> = beginRoot;
1710
+ const _reverseEdge = (node: OptBTNOrNull<NODE>) => {
1711
+ let pre: OptBTNOrNull<NODE> = null;
1712
+ let next: OptBTNOrNull<NODE> = null;
1708
1713
  while (node) {
1709
1714
  next = node.right;
1710
1715
  node.right = pre;
@@ -1713,9 +1718,9 @@ export class BinaryTree<
1713
1718
  }
1714
1719
  return pre;
1715
1720
  };
1716
- const _printEdge = (node: NODE | null | undefined) => {
1717
- const tail: NODE | null | undefined = _reverseEdge(node);
1718
- let cur: NODE | null | undefined = tail;
1721
+ const _printEdge = (node: OptBTNOrNull<NODE>) => {
1722
+ const tail: OptBTNOrNull<NODE> = _reverseEdge(node);
1723
+ let cur: OptBTNOrNull<NODE> = tail;
1719
1724
  while (cur) {
1720
1725
  ans.push(callback(cur));
1721
1726
  cur = cur.right;
@@ -1884,7 +1889,7 @@ export class BinaryTree<
1884
1889
  * Space Complexity: O(n)
1885
1890
  *
1886
1891
  * The `print` function in TypeScript prints the binary tree structure with customizable options.
1887
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
1892
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
1888
1893
  * point for printing the binary tree. It can be either a node of the binary tree or a key or entry
1889
1894
  * that exists in the binary tree. If no value is provided, the root of the binary tree will be used
1890
1895
  * as the starting point.
@@ -1893,7 +1898,7 @@ export class BinaryTree<
1893
1898
  * @returns Nothing is being returned. The function has a return type of `void`, which means it does
1894
1899
  * not return any value.
1895
1900
  */
1896
- override print(beginRoot: R | KeyOrNodeOrEntry<K, V, NODE> = this.root, options?: BinaryTreePrintOptions): void {
1901
+ override print(beginRoot: R | BTNKeyOrNodeOrEntry<K, V, NODE> = this.root, options?: BinaryTreePrintOptions): void {
1897
1902
  const opts = { isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false, ...options };
1898
1903
  beginRoot = this.ensureNode(beginRoot);
1899
1904
  if (!beginRoot) return;
@@ -1908,7 +1913,7 @@ export class BinaryTree<
1908
1913
  console.log(`S for Sentinel Node(NIL)
1909
1914
  `);
1910
1915
 
1911
- const display = (root: NODE | null | undefined): void => {
1916
+ const display = (root: OptBTNOrNull<NODE>): void => {
1912
1917
  const [lines, , ,] = this._displayAux(root, opts);
1913
1918
  for (const line of lines) {
1914
1919
  console.log(line);
@@ -1933,12 +1938,12 @@ export class BinaryTree<
1933
1938
  * initially set to the root node of the tree.
1934
1939
  * @returns an IterableIterator<[K, V | undefined]>.
1935
1940
  */
1936
- protected* _getIterator(node = this.root): IterableIterator<[K, V | undefined]> {
1941
+ protected *_getIterator(node = this.root): IterableIterator<[K, V | undefined]> {
1937
1942
  if (!node) return;
1938
1943
 
1939
1944
  if (this.iterationType === 'ITERATIVE') {
1940
- const stack: (NODE | null | undefined)[] = [];
1941
- let current: NODE | null | undefined = node;
1945
+ const stack: OptBTNOrNull<NODE>[] = [];
1946
+ let current: OptBTNOrNull<NODE> = node;
1942
1947
 
1943
1948
  while (current || stack.length > 0) {
1944
1949
  while (this.isRealNode(current)) {
@@ -1975,7 +1980,7 @@ export class BinaryTree<
1975
1980
  *
1976
1981
  * The `_displayAux` function is responsible for generating the display layout of a binary tree node,
1977
1982
  * taking into account various options such as whether to show null, undefined, or NaN nodes.
1978
- * @param {NODE | null | undefined} node - The `node` parameter represents a node in a binary tree.
1983
+ * @param {OptBTNOrNull<NODE>} node - The `node` parameter represents a node in a binary tree.
1979
1984
  * It can be of type `NODE`, `null`, or `undefined`.
1980
1985
  * @param {BinaryTreePrintOptions} options - The `options` parameter is an object that contains the
1981
1986
  * following properties:
@@ -1986,7 +1991,7 @@ export class BinaryTree<
1986
1991
  * 3. `totalHeight`: The total height of the node display.
1987
1992
  * 4. `middleIndex`: The index of the middle character
1988
1993
  */
1989
- protected _displayAux(node: NODE | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout {
1994
+ protected _displayAux(node: OptBTNOrNull<NODE>, options: BinaryTreePrintOptions): NodeDisplayLayout {
1990
1995
  const { isShowNull, isShowUndefined, isShowRedBlackNIL } = options;
1991
1996
  const emptyDisplayLayout = <NodeDisplayLayout>[['─'], 1, 0, 0];
1992
1997
 
@@ -2001,7 +2006,7 @@ export class BinaryTree<
2001
2006
  // Display logic of normal nodes
2002
2007
 
2003
2008
  const key = node.key,
2004
- line = this.isNIL(node) ? 'S' : key.toString(),
2009
+ line = this.isNIL(node) ? 'S' : String(key),
2005
2010
  width = line.length;
2006
2011
 
2007
2012
  return _buildNodeDisplay(
@@ -2012,7 +2017,7 @@ export class BinaryTree<
2012
2017
  );
2013
2018
  } else {
2014
2019
  // For cases where none of the conditions are met, null, undefined, and NaN nodes are not displayed
2015
- const line = node === undefined ? 'U' : 'NODE',
2020
+ const line = node === undefined ? 'U' : 'N',
2016
2021
  width = line.length;
2017
2022
 
2018
2023
  return _buildNodeDisplay(line, width, [[''], 1, 0, 0], [[''], 1, 0, 0]);
@@ -2054,7 +2059,7 @@ export class BinaryTree<
2054
2059
  }
2055
2060
  }
2056
2061
 
2057
- protected _DEFAULT_CALLBACK = (node: NODE | null | undefined) => (node ? node.key : undefined);
2062
+ protected _DEFAULT_CALLBACK = (node: OptBTNOrNull<NODE>) => (node ? node.key : undefined);
2058
2063
 
2059
2064
  /**
2060
2065
  * Time Complexity: O(1)
@@ -2066,17 +2071,17 @@ export class BinaryTree<
2066
2071
  * Space Complexity: O(1)
2067
2072
  *
2068
2073
  * The function `_swapProperties` swaps the key-value properties between two nodes.
2069
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} srcNode - The source node that will be swapped with the
2074
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} srcNode - The source node that will be swapped with the
2070
2075
  * destination node. It can be either an instance of the class `R`, or an object of type
2071
- * `KeyOrNodeOrEntry<K, V, NODE>`.
2072
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} destNode - The `destNode` parameter is the node where
2076
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
2077
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} destNode - The `destNode` parameter is the node where
2073
2078
  * the properties will be swapped with the `srcNode`.
2074
2079
  * @returns either the `destNode` object with its properties swapped with the `srcNode` object's
2075
2080
  * properties, or `undefined` if either `srcNode` or `destNode` is falsy.
2076
2081
  */
2077
2082
  protected _swapProperties(
2078
- srcNode: R | KeyOrNodeOrEntry<K, V, NODE>,
2079
- destNode: R | KeyOrNodeOrEntry<K, V, NODE>
2083
+ srcNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>,
2084
+ destNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>
2080
2085
  ): NODE | undefined {
2081
2086
  srcNode = this.ensureNode(srcNode);
2082
2087
  destNode = this.ensureNode(destNode);
@@ -2144,10 +2149,10 @@ export class BinaryTree<
2144
2149
  *
2145
2150
  * The function sets the root property of an object to the provided value, and also updates the
2146
2151
  * parent property of the new root.
2147
- * @param {NODE | null | undefined} v - The parameter `v` is of type `NODE | null | undefined`. This
2152
+ * @param {OptBTNOrNull<NODE>} v - The parameter `v` is of type `OptBTNOrNull<NODE>`. This
2148
2153
  * means that it can accept a value of type `NODE`, `null`, or `undefined`.
2149
2154
  */
2150
- protected _setRoot(v: NODE | null | undefined) {
2155
+ protected _setRoot(v: OptBTNOrNull<NODE>) {
2151
2156
  if (v) {
2152
2157
  v.parent = undefined;
2153
2158
  }