data-structure-typed 1.48.9 → 1.49.1

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 (163) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +16 -11
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.js +12 -4
  4. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +70 -61
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js +25 -21
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/bst.d.ts +20 -13
  9. package/dist/cjs/data-structures/binary-tree/bst.js +12 -3
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +19 -25
  12. package/dist/cjs/data-structures/binary-tree/rb-tree.js +21 -35
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +20 -13
  15. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +12 -3
  16. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  17. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +9 -3
  18. package/dist/cjs/data-structures/graph/abstract-graph.js +27 -31
  19. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/directed-graph.d.ts +8 -1
  21. package/dist/cjs/data-structures/graph/directed-graph.js +1 -8
  22. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
  24. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +8 -1
  25. package/dist/cjs/data-structures/graph/undirected-graph.js +1 -8
  26. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  27. package/dist/cjs/data-structures/hash/hash-map.d.ts +14 -2
  28. package/dist/cjs/data-structures/hash/hash-map.js +19 -8
  29. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  30. package/dist/cjs/data-structures/hash/hash-table.d.ts +2 -2
  31. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
  32. package/dist/cjs/data-structures/heap/heap.d.ts +14 -3
  33. package/dist/cjs/data-structures/heap/heap.js +12 -0
  34. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  35. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -1
  36. package/dist/cjs/data-structures/heap/max-heap.js +10 -7
  37. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  38. package/dist/cjs/data-structures/heap/min-heap.d.ts +11 -1
  39. package/dist/cjs/data-structures/heap/min-heap.js +10 -7
  40. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  41. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +8 -2
  42. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +6 -7
  43. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  44. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  45. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +0 -7
  46. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  47. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
  48. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -7
  49. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  50. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
  51. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -7
  52. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  53. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
  54. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -7
  55. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  56. package/dist/cjs/data-structures/queue/deque.d.ts +6 -5
  57. package/dist/cjs/data-structures/queue/deque.js +6 -12
  58. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  59. package/dist/cjs/data-structures/queue/queue.d.ts +18 -3
  60. package/dist/cjs/data-structures/queue/queue.js +16 -6
  61. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  62. package/dist/cjs/data-structures/stack/stack.d.ts +15 -5
  63. package/dist/cjs/data-structures/stack/stack.js +7 -4
  64. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  65. package/dist/cjs/data-structures/trie/trie.d.ts +13 -3
  66. package/dist/cjs/data-structures/trie/trie.js +11 -8
  67. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  68. package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
  69. package/dist/cjs/types/common.d.ts +32 -8
  70. package/dist/cjs/types/common.js +22 -1
  71. package/dist/cjs/types/common.js.map +1 -1
  72. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
  73. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -22
  74. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
  75. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  76. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  77. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +16 -11
  78. package/dist/mjs/data-structures/binary-tree/avl-tree.js +12 -4
  79. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +70 -61
  80. package/dist/mjs/data-structures/binary-tree/binary-tree.js +25 -21
  81. package/dist/mjs/data-structures/binary-tree/bst.d.ts +20 -13
  82. package/dist/mjs/data-structures/binary-tree/bst.js +12 -3
  83. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +19 -25
  84. package/dist/mjs/data-structures/binary-tree/rb-tree.js +21 -34
  85. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +20 -13
  86. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +12 -3
  87. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +9 -3
  88. package/dist/mjs/data-structures/graph/abstract-graph.js +27 -31
  89. package/dist/mjs/data-structures/graph/directed-graph.d.ts +8 -1
  90. package/dist/mjs/data-structures/graph/directed-graph.js +1 -8
  91. package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
  92. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +8 -1
  93. package/dist/mjs/data-structures/graph/undirected-graph.js +1 -8
  94. package/dist/mjs/data-structures/hash/hash-map.d.ts +14 -2
  95. package/dist/mjs/data-structures/hash/hash-map.js +18 -7
  96. package/dist/mjs/data-structures/hash/hash-table.d.ts +2 -2
  97. package/dist/mjs/data-structures/heap/heap.d.ts +14 -3
  98. package/dist/mjs/data-structures/heap/heap.js +13 -1
  99. package/dist/mjs/data-structures/heap/max-heap.d.ts +11 -1
  100. package/dist/mjs/data-structures/heap/max-heap.js +9 -6
  101. package/dist/mjs/data-structures/heap/min-heap.d.ts +11 -1
  102. package/dist/mjs/data-structures/heap/min-heap.js +9 -6
  103. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +8 -2
  104. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +7 -8
  105. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  106. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +0 -7
  107. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
  108. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +0 -7
  109. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
  110. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +0 -7
  111. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
  112. package/dist/mjs/data-structures/priority-queue/priority-queue.js +7 -6
  113. package/dist/mjs/data-structures/queue/deque.d.ts +6 -5
  114. package/dist/mjs/data-structures/queue/deque.js +6 -12
  115. package/dist/mjs/data-structures/queue/queue.d.ts +18 -3
  116. package/dist/mjs/data-structures/queue/queue.js +16 -6
  117. package/dist/mjs/data-structures/stack/stack.d.ts +15 -5
  118. package/dist/mjs/data-structures/stack/stack.js +8 -5
  119. package/dist/mjs/data-structures/trie/trie.d.ts +13 -3
  120. package/dist/mjs/data-structures/trie/trie.js +12 -9
  121. package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
  122. package/dist/mjs/types/common.d.ts +32 -8
  123. package/dist/mjs/types/common.js +21 -0
  124. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
  125. package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -21
  126. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
  127. package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  128. package/dist/umd/data-structure-typed.js +241 -216
  129. package/dist/umd/data-structure-typed.min.js +2 -2
  130. package/dist/umd/data-structure-typed.min.js.map +1 -1
  131. package/package.json +1 -1
  132. package/src/data-structures/binary-tree/avl-tree.ts +23 -13
  133. package/src/data-structures/binary-tree/binary-tree.ts +93 -97
  134. package/src/data-structures/binary-tree/bst.ts +26 -15
  135. package/src/data-structures/binary-tree/rb-tree.ts +33 -48
  136. package/src/data-structures/binary-tree/tree-multimap.ts +32 -14
  137. package/src/data-structures/graph/abstract-graph.ts +35 -25
  138. package/src/data-structures/graph/directed-graph.ts +2 -2
  139. package/src/data-structures/graph/map-graph.ts +1 -1
  140. package/src/data-structures/graph/undirected-graph.ts +2 -2
  141. package/src/data-structures/hash/hash-map.ts +20 -3
  142. package/src/data-structures/hash/hash-table.ts +3 -3
  143. package/src/data-structures/heap/heap.ts +14 -3
  144. package/src/data-structures/heap/max-heap.ts +11 -2
  145. package/src/data-structures/heap/min-heap.ts +11 -2
  146. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -3
  147. package/src/data-structures/linked-list/singly-linked-list.ts +3 -3
  148. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  149. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  150. package/src/data-structures/priority-queue/priority-queue.ts +9 -2
  151. package/src/data-structures/queue/deque.ts +7 -9
  152. package/src/data-structures/queue/queue.ts +18 -3
  153. package/src/data-structures/stack/stack.ts +16 -6
  154. package/src/data-structures/trie/trie.ts +13 -4
  155. package/src/interfaces/binary-tree.ts +5 -5
  156. package/src/types/common.ts +37 -12
  157. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
  158. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
  159. package/src/types/data-structures/binary-tree/bst.ts +0 -1
  160. package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
  161. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
  162. package/test/unit/data-structures/graph/directed-graph.test.ts +21 -1
  163. package/test/unit/data-structures/graph/undirected-graph.test.ts +39 -1
@@ -5,8 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNodeEntry, BTNodeExemplar, BTNodeKeyOrNode } from '../../types';
9
- import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeDisplayLayout } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, BTNExemplar, BTNKeyOrNode, DFSOrderPattern, EntryCallback, NodeDisplayLayout } from '../../types';
9
+ import { FamilyPosition, IterationType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { IterableEntryBase } from "../base";
12
12
  /**
@@ -42,14 +42,14 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
42
42
  iterationType: IterationType;
43
43
  /**
44
44
  * The constructor function initializes a binary tree object with optional elements and options.
45
- * @param [elements] - An optional iterable of BTNodeExemplar objects. These objects represent the
45
+ * @param [elements] - An optional iterable of BTNExemplar objects. These objects represent the
46
46
  * elements to be added to the binary tree.
47
47
  * @param [options] - The `options` parameter is an optional object that can contain additional
48
48
  * configuration options for the binary tree. In this case, it is of type
49
49
  * `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
50
50
  * required.
51
51
  */
52
- constructor(elements?: Iterable<BTNodeExemplar<K, V, N>>, options?: Partial<BinaryTreeOptions<K>>);
52
+ constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<BinaryTreeOptions<K>>);
53
53
  protected _extractor: (key: K) => number;
54
54
  get extractor(): (key: K) => number;
55
55
  protected _root?: N | null;
@@ -73,26 +73,26 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
73
73
  createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
74
74
  /**
75
75
  * The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
76
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V,N>`.
76
+ * @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V,N>`.
77
77
  * @returns a boolean value indicating whether the exemplar is an instance of the class N.
78
78
  */
79
- isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
79
+ isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
80
80
  /**
81
81
  * The function `exemplarToNode` converts an exemplar object into a node object.
82
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
82
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
83
83
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
84
84
  * `exemplarToNode` function. It represents the value associated with the exemplar node. If no value
85
85
  * is provided, it will be `undefined`.
86
86
  * @returns a value of type N (node), or null, or undefined.
87
87
  */
88
- exemplarToNode(exemplar: BTNodeExemplar<K, V, N>, value?: V): N | null | undefined;
88
+ exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V): N | null | undefined;
89
89
  /**
90
90
  * The function checks if a given value is an entry in a binary tree node.
91
- * @param kne - BTNodeExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
91
+ * @param kne - BTNExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
92
92
  * two type parameters V and N, representing the value and node type respectively.
93
93
  * @returns a boolean value.
94
94
  */
95
- isEntry(kne: BTNodeExemplar<K, V, N>): kne is BTNodeEntry<K, V>;
95
+ isEntry(kne: BTNExemplar<K, V, N>): kne is BTNEntry<K, V>;
96
96
  /**
97
97
  * Time Complexity O(log n) - O(n)
98
98
  * Space Complexity O(1)
@@ -107,7 +107,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
107
107
  * @param {V} [value] - The value to be inserted into the binary tree.
108
108
  * @returns The function `add` returns either a node (`N`), `null`, or `undefined`.
109
109
  */
110
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V): N | null | undefined;
110
+ add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | null | undefined;
111
111
  /**
112
112
  * Time Complexity: O(k log n) - O(k * n)
113
113
  * Space Complexity: O(1)
@@ -119,23 +119,23 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
119
119
  *
120
120
  * The `addMany` function takes in a collection of nodes and an optional collection of values, and
121
121
  * adds each node with its corresponding value to the data structure.
122
- * @param nodes - An iterable collection of BTNodeExemplar objects.
122
+ * @param nodes - An iterable collection of BTNExemplar objects.
123
123
  * @param [values] - An optional iterable of values that will be assigned to each node being added.
124
124
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
125
125
  */
126
- addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
126
+ addMany(nodes: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
127
127
  /**
128
128
  * Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
129
129
  * Space Complexity: O(1)
130
130
  */
131
- refill(nodesOrKeysOrEntries: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): void;
131
+ refill(nodesOrKeysOrEntries: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>): void;
132
132
  /**
133
133
  * Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
134
134
  * Space Complexity: O(1)
135
135
  */
136
- delete<C extends BTNCallback<N, K>>(identifier: K, callback?: C): BiTreeDeleteResult<N>[];
137
- delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BiTreeDeleteResult<N>[];
138
- delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BiTreeDeleteResult<N>[];
136
+ delete<C extends BTNCallback<N, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<N>[];
137
+ delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BinaryTreeDeleteResult<N>[];
138
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeleteResult<N>[];
139
139
  /**
140
140
  * Time Complexity: O(n)
141
141
  * Space Complexity: O(1)
@@ -153,7 +153,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
153
153
  * `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
154
154
  * @returns the depth of the `distNode` relative to the `beginRoot`.
155
155
  */
156
- getDepth(distNode: BTNodeKeyOrNode<K, N>, beginRoot?: BTNodeKeyOrNode<K, N>): number;
156
+ getDepth(distNode: BTNKeyOrNode<K, N>, beginRoot?: BTNKeyOrNode<K, N>): number;
157
157
  /**
158
158
  * Time Complexity: O(n)
159
159
  * Space Complexity: O(1)
@@ -172,7 +172,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
172
172
  * values:
173
173
  * @returns the height of the binary tree.
174
174
  */
175
- getHeight(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): number;
175
+ getHeight(beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): number;
176
176
  /**
177
177
  * Time Complexity: O(n)
178
178
  * Space Complexity: O(log n)
@@ -191,7 +191,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
191
191
  * to calculate the minimum height of a binary tree. It can have two possible values:
192
192
  * @returns The function `getMinHeight` returns the minimum height of a binary tree.
193
193
  */
194
- getMinHeight(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): number;
194
+ getMinHeight(beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): number;
195
195
  /**
196
196
  * Time Complexity: O(n)
197
197
  * Space Complexity: O(log n)
@@ -208,28 +208,28 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
208
208
  * value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
209
209
  * @returns a boolean value.
210
210
  */
211
- isPerfectlyBalanced(beginRoot?: BTNodeKeyOrNode<K, N>): boolean;
211
+ isPerfectlyBalanced(beginRoot?: BTNKeyOrNode<K, N>): boolean;
212
212
  /**
213
213
  * Time Complexity: O(n)
214
214
  * Space Complexity: O(log n)
215
215
  */
216
- getNodes<C extends BTNCallback<N, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
217
- getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
218
- getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
216
+ getNodes<C extends BTNCallback<N, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N[];
217
+ getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N[];
218
+ getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N[];
219
219
  /**
220
220
  * Time Complexity: O(n)
221
221
  * Space Complexity: O(log n).
222
222
  */
223
- has<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
224
- has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
225
- has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
223
+ has<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): boolean;
224
+ has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): boolean;
225
+ has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): boolean;
226
226
  /**
227
227
  * Time Complexity: O(n)
228
228
  * Space Complexity: O(log n).
229
229
  */
230
- getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
231
- getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
232
- getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
230
+ getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
231
+ getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
232
+ getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
233
233
  /**
234
234
  * Time Complexity: O(n)
235
235
  * Space Complexity: O(log n)
@@ -264,10 +264,10 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
264
264
  * @returns either the node corresponding to the given key if it is a valid node key, or the key
265
265
  * itself if it is not a valid node key.
266
266
  */
267
- ensureNode(key: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
268
- get<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
269
- get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
270
- get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
267
+ ensureNode(key: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
268
+ get<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
269
+ get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
270
+ get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
271
271
  /**
272
272
  * Time Complexity: O(n)
273
273
  * Space Complexity: O(log n)
@@ -295,7 +295,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
295
295
  * reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
296
296
  * @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
297
297
  */
298
- getPathToRoot(beginRoot: BTNodeKeyOrNode<K, N>, isReverse?: boolean): N[];
298
+ getPathToRoot(beginRoot: BTNKeyOrNode<K, N>, isReverse?: boolean): N[];
299
299
  /**
300
300
  * Time Complexity: O(log n)
301
301
  * Space Complexity: O(log n)
@@ -314,7 +314,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
314
314
  * @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
315
315
  * is no leftmost node, it returns `null` or `undefined` depending on the input.
316
316
  */
317
- getLeftMost(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
317
+ getLeftMost(beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
318
318
  /**
319
319
  * Time Complexity: O(log n)
320
320
  * Space Complexity: O(1)
@@ -334,7 +334,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
334
334
  * @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
335
335
  * is no rightmost node, it returns `null` or `undefined`, depending on the input.
336
336
  */
337
- getRightMost(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
337
+ getRightMost(beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
338
338
  /**
339
339
  * Time Complexity: O(log n)
340
340
  * Space Complexity: O(1)
@@ -351,7 +351,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
351
351
  * possible values:
352
352
  * @returns a boolean value.
353
353
  */
354
- isSubtreeBST(beginRoot: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
354
+ isSubtreeBST(beginRoot: BTNKeyOrNode<K, N>, iterationType?: IterationType): boolean;
355
355
  /**
356
356
  * Time Complexity: O(n)
357
357
  * Space Complexity: O(1)
@@ -372,9 +372,9 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
372
372
  * Time Complexity: O(n)
373
373
  * Space Complexity: O(1)
374
374
  */
375
- subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
376
- subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
377
- subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
375
+ subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
376
+ subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
377
+ subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
378
378
  /**
379
379
  * Time complexity: O(n)
380
380
  * Space complexity: O(log n)
@@ -385,46 +385,55 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
385
385
  * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
386
386
  * @returns a boolean value.
387
387
  */
388
- isRealNode(node: any): node is N;
388
+ isRealNode(node: BTNExemplar<K, V, N>): node is N;
389
389
  /**
390
390
  * The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
391
391
  * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
392
392
  * @returns a boolean value.
393
393
  */
394
- isNIL(node: any): boolean;
394
+ isNIL(node: BTNExemplar<K, V, N>): boolean;
395
395
  /**
396
396
  * The function checks if a given node is a real node or null.
397
397
  * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
398
398
  * @returns a boolean value.
399
399
  */
400
- isNodeOrNull(node: any): node is N | null;
400
+ isNodeOrNull(node: BTNExemplar<K, V, N>): node is N | null;
401
401
  /**
402
- * The function "isNotNodeInstance" checks if a potential key is a number.
402
+ * The function "isNotNodeInstance" checks if a potential key is a K.
403
403
  * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
404
404
  * data type.
405
405
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
406
406
  */
407
- isNotNodeInstance(potentialKey: BTNodeKeyOrNode<K, N>): potentialKey is K;
408
- dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
409
- dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
410
- dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
407
+ isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
408
+ dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
409
+ dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
410
+ dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
411
411
  /**
412
412
  * Time complexity: O(n)
413
413
  * Space complexity: O(n)
414
414
  */
415
- bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
416
- bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
417
- bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
415
+ bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
416
+ bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
417
+ bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
418
418
  /**
419
419
  * Time complexity: O(n)
420
420
  * Space complexity: O(n)
421
421
  */
422
- listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
423
- listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
424
- listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
422
+ listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
423
+ listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
424
+ listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
425
425
  /**
426
- * Time complexity: O(n)
427
- * Space complexity: O(n)
426
+ * Time Complexity: O(log n)
427
+ * Space Complexity: O(1)
428
+ */
429
+ /**
430
+ * Time Complexity: O(log n)
431
+ * Space Complexity: O(1)
432
+ *
433
+ * The function returns the predecessor of a given node in a tree.
434
+ * @param {N} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
435
+ * tree.
436
+ * @returns the predecessor of the given 'node'.
428
437
  */
429
438
  getPredecessor(node: N): N;
430
439
  /**
@@ -452,7 +461,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
452
461
  * `callback` function on each node in the binary tree. The type of the array elements is determined
453
462
  * by the return type of the `callback` function.
454
463
  */
455
- morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>): ReturnType<C>[];
464
+ morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>): ReturnType<C>[];
456
465
  /**
457
466
  * Time complexity: O(n)
458
467
  * Space complexity: O(n)
@@ -513,7 +522,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
513
522
  * following types:
514
523
  * @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes.
515
524
  */
516
- print(beginRoot?: BTNodeKeyOrNode<K, N>, options?: BinaryTreePrintOptions): void;
525
+ print(beginRoot?: BTNKeyOrNode<K, N>, options?: BinaryTreePrintOptions): void;
517
526
  protected _getIterator(node?: N | null | undefined): IterableIterator<[K, V | undefined]>;
518
527
  protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
519
528
  protected _defaultOneParamCallback: (node: N) => K;
@@ -523,7 +532,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
523
532
  * @param {N} destNode - The destination node to swap.
524
533
  * @returns {N} - The destination node after the swap.
525
534
  */
526
- protected _swapProperties(srcNode: BTNodeKeyOrNode<K, N>, destNode: BTNodeKeyOrNode<K, N>): N | undefined;
535
+ protected _swapProperties(srcNode: BTNKeyOrNode<K, N>, destNode: BTNKeyOrNode<K, N>): N | undefined;
527
536
  /**
528
537
  * The function replaces an old node with a new node in a binary tree.
529
538
  * @param {N} oldNode - The oldNode parameter represents the node that needs to be replaced in the
@@ -544,7 +553,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
544
553
  * the binary tree. If neither the left nor right child is available, the function returns undefined.
545
554
  * If the parent node is null, the function also returns undefined.
546
555
  */
547
- protected _addTo(newNode: N | null | undefined, parent: BTNodeKeyOrNode<K, N>): N | null | undefined;
556
+ protected _addTo(newNode: N | null | undefined, parent: BTNKeyOrNode<K, N>): N | null | undefined;
548
557
  /**
549
558
  * The function sets the root property of an object to a given value, and if the value is not null,
550
559
  * it also sets the parent property of the value to undefined.
@@ -71,7 +71,7 @@ export class BinaryTree extends IterableEntryBase {
71
71
  iterationType = IterationType.ITERATIVE;
72
72
  /**
73
73
  * The constructor function initializes a binary tree object with optional elements and options.
74
- * @param [elements] - An optional iterable of BTNodeExemplar objects. These objects represent the
74
+ * @param [elements] - An optional iterable of BTNExemplar objects. These objects represent the
75
75
  * elements to be added to the binary tree.
76
76
  * @param [options] - The `options` parameter is an optional object that can contain additional
77
77
  * configuration options for the binary tree. In this case, it is of type
@@ -126,7 +126,7 @@ export class BinaryTree extends IterableEntryBase {
126
126
  }
127
127
  /**
128
128
  * The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
129
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V,N>`.
129
+ * @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V,N>`.
130
130
  * @returns a boolean value indicating whether the exemplar is an instance of the class N.
131
131
  */
132
132
  isNode(exemplar) {
@@ -134,7 +134,7 @@ export class BinaryTree extends IterableEntryBase {
134
134
  }
135
135
  /**
136
136
  * The function `exemplarToNode` converts an exemplar object into a node object.
137
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
137
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
138
138
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
139
139
  * `exemplarToNode` function. It represents the value associated with the exemplar node. If no value
140
140
  * is provided, it will be `undefined`.
@@ -172,7 +172,7 @@ export class BinaryTree extends IterableEntryBase {
172
172
  }
173
173
  /**
174
174
  * The function checks if a given value is an entry in a binary tree node.
175
- * @param kne - BTNodeExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
175
+ * @param kne - BTNExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
176
176
  * two type parameters V and N, representing the value and node type respectively.
177
177
  * @returns a boolean value.
178
178
  */
@@ -250,7 +250,7 @@ export class BinaryTree extends IterableEntryBase {
250
250
  *
251
251
  * The `addMany` function takes in a collection of nodes and an optional collection of values, and
252
252
  * adds each node with its corresponding value to the data structure.
253
- * @param nodes - An iterable collection of BTNodeExemplar objects.
253
+ * @param nodes - An iterable collection of BTNExemplar objects.
254
254
  * @param [values] - An optional iterable of values that will be assigned to each node being added.
255
255
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
256
256
  */
@@ -294,7 +294,7 @@ export class BinaryTree extends IterableEntryBase {
294
294
  * @param {C} callback - The `callback` parameter is a function that is used to determine the
295
295
  * identifier of the node to be deleted. It is optional and has a default value of
296
296
  * `this._defaultOneParamCallback`. The `callback` function should return the identifier of the node.
297
- * @returns an array of `BiTreeDeleteResult<N>`.
297
+ * @returns an array of `BinaryTreeDeleteResult<N>`.
298
298
  */
299
299
  delete(identifier, callback = this._defaultOneParamCallback) {
300
300
  const deletedResult = [];
@@ -979,7 +979,7 @@ export class BinaryTree extends IterableEntryBase {
979
979
  * @returns a boolean value.
980
980
  */
981
981
  isRealNode(node) {
982
- return node instanceof BinaryTreeNode && node.key.toString() !== 'NaN';
982
+ return node instanceof BinaryTreeNode && String(node.key) !== 'NaN';
983
983
  }
984
984
  /**
985
985
  * The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
@@ -987,7 +987,7 @@ export class BinaryTree extends IterableEntryBase {
987
987
  * @returns a boolean value.
988
988
  */
989
989
  isNIL(node) {
990
- return node instanceof BinaryTreeNode && node.key.toString() === 'NaN';
990
+ return node instanceof BinaryTreeNode && String(node.key) === 'NaN';
991
991
  }
992
992
  /**
993
993
  * The function checks if a given node is a real node or null.
@@ -998,7 +998,7 @@ export class BinaryTree extends IterableEntryBase {
998
998
  return this.isRealNode(node) || node === null;
999
999
  }
1000
1000
  /**
1001
- * The function "isNotNodeInstance" checks if a potential key is a number.
1001
+ * The function "isNotNodeInstance" checks if a potential key is a K.
1002
1002
  * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
1003
1003
  * data type.
1004
1004
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
@@ -1279,19 +1279,23 @@ export class BinaryTree extends IterableEntryBase {
1279
1279
  return levelsNodes;
1280
1280
  }
1281
1281
  /**
1282
- * The function `getPredecessor` returns the predecessor node of a given node in a binary tree.
1283
- * @param {K | N | null | undefined} node - The `node` parameter can be of type `K`, `N`,
1284
- * `null`, or `undefined`.
1285
- * @returns The function `getPredecessor` returns a value of type `N | undefined`.
1282
+ * Time Complexity: O(log n)
1283
+ * Space Complexity: O(1)
1284
+ */
1285
+ /**
1286
+ * Time Complexity: O(log n)
1287
+ * Space Complexity: O(1)
1288
+ *
1289
+ * The function returns the predecessor of a given node in a tree.
1290
+ * @param {N} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
1291
+ * tree.
1292
+ * @returns the predecessor of the given 'node'.
1286
1293
  */
1287
1294
  getPredecessor(node) {
1288
- node = this.ensureNode(node);
1289
- if (!this.isRealNode(node))
1290
- return undefined;
1291
- if (node.left) {
1295
+ if (this.isRealNode(node.left)) {
1292
1296
  let predecessor = node.left;
1293
1297
  while (!this.isRealNode(predecessor) || (this.isRealNode(predecessor.right) && predecessor.right !== node)) {
1294
- if (predecessor) {
1298
+ if (this.isRealNode(predecessor)) {
1295
1299
  predecessor = predecessor.right;
1296
1300
  }
1297
1301
  }
@@ -1309,13 +1313,13 @@ export class BinaryTree extends IterableEntryBase {
1309
1313
  */
1310
1314
  getSuccessor(x) {
1311
1315
  x = this.ensureNode(x);
1312
- if (!x)
1316
+ if (!this.isRealNode(x))
1313
1317
  return undefined;
1314
- if (x.right) {
1318
+ if (this.isRealNode(x.right)) {
1315
1319
  return this.getLeftMost(x.right);
1316
1320
  }
1317
1321
  let y = x.parent;
1318
- while (y && y && x === y.right) {
1322
+ while (this.isRealNode(y) && x === y.right) {
1319
1323
  x = y;
1320
1324
  y = y.parent;
1321
1325
  }
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BSTNested, BSTNodeKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, BTNodeExemplar } from '../../types';
8
+ import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, BTNExemplar, BTNKeyOrNode } from '../../types';
9
9
  import { BSTVariant, CP, IterationType } from '../../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBinaryTree } from '../../interfaces';
@@ -46,12 +46,12 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
46
46
  /**
47
47
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
48
48
  * the tree with optional elements and options.
49
- * @param [elements] - An optional iterable of BTNodeExemplar objects that will be added to the
49
+ * @param [elements] - An optional iterable of BTNExemplar objects that will be added to the
50
50
  * binary search tree.
51
51
  * @param [options] - The `options` parameter is an optional object that can contain additional
52
52
  * configuration options for the binary search tree. It can have the following properties:
53
53
  */
54
- constructor(elements?: Iterable<BTNodeExemplar<K, V, N>>, options?: Partial<BSTOptions<K>>);
54
+ constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<BSTOptions<K>>);
55
55
  protected _root?: N;
56
56
  get root(): N | undefined;
57
57
  protected _variant: BSTVariant;
@@ -75,19 +75,19 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
75
75
  createTree(options?: Partial<BSTOptions<K>>): TREE;
76
76
  /**
77
77
  * The function checks if an exemplar is an instance of BSTNode.
78
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V, N>`.
78
+ * @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V, N>`.
79
79
  * @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
80
80
  */
81
- isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
81
+ isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
82
82
  /**
83
83
  * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
84
84
  * otherwise it returns undefined.
85
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
85
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
86
86
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
87
87
  * `exemplarToNode` function. It represents the value associated with the exemplar node.
88
88
  * @returns a node of type N or undefined.
89
89
  */
90
- exemplarToNode(exemplar: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
90
+ exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V): N | undefined;
91
91
  /**
92
92
  * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
93
93
  * Space Complexity: O(1) - Constant space is used.
@@ -104,7 +104,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
104
104
  * @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
105
105
  * node was not added.
106
106
  */
107
- add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V): N | undefined;
107
+ add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
108
108
  /**
109
109
  * Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
110
110
  * Space Complexity: O(k) - Additional space is required for the sorted array.
@@ -129,7 +129,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
129
129
  * `this.iterationType`, which suggests that it is a property of the current object.
130
130
  * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
131
131
  */
132
- addMany(keysOrNodesOrEntries: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): (N | undefined)[];
132
+ addMany(keysOrNodesOrEntries: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): (N | undefined)[];
133
133
  /**
134
134
  * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
135
135
  * Space Complexity: O(n) - Additional space is required for the sorted array.
@@ -149,7 +149,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
149
149
  * the key of the leftmost node if the comparison result is greater than, and the key of the
150
150
  * rightmost node otherwise. If no node is found, it returns 0.
151
151
  */
152
- lastKey(beginRoot?: BSTNodeKeyOrNode<K, N>): K | undefined;
152
+ lastKey(beginRoot?: BSTNKeyOrNode<K, N>): K | undefined;
153
153
  /**
154
154
  * Time Complexity: O(log n) - Average case for a balanced tree.
155
155
  * Space Complexity: O(1) - Constant space is used.
@@ -169,6 +169,13 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
169
169
  * found in the binary tree. If no node is found, it returns `undefined`.
170
170
  */
171
171
  getNodeByKey(key: K, iterationType?: IterationType): N | undefined;
172
+ /**
173
+ * The function "isNotNodeInstance" checks if a potential key is a K.
174
+ * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
175
+ * data type.
176
+ * @returns a boolean value indicating whether the potentialKey is of type number or not.
177
+ */
178
+ isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
172
179
  /**
173
180
  * Time Complexity: O(log n) - Average case for a balanced tree.
174
181
  * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
@@ -182,7 +189,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
182
189
  * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
183
190
  * @returns either a node object (N) or undefined.
184
191
  */
185
- ensureNode(key: BSTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | undefined;
192
+ ensureNode(key: BSTNKeyOrNode<K, N>, iterationType?: IterationType): N | undefined;
186
193
  /**
187
194
  * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
188
195
  * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
@@ -206,7 +213,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
206
213
  * performed on the binary tree. It can have two possible values:
207
214
  * @returns The method returns an array of nodes (`N[]`).
208
215
  */
209
- getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BSTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
216
+ getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BSTNKeyOrNode<K, N>, iterationType?: IterationType): N[];
210
217
  /**
211
218
  * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
212
219
  * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
@@ -232,7 +239,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
232
239
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
233
240
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
234
241
  */
235
- lesserOrGreaterTraverse<C extends BTNCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BSTNodeKeyOrNode<K, N>, iterationType?: IterationType): ReturnType<C>[];
242
+ lesserOrGreaterTraverse<C extends BTNCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BSTNKeyOrNode<K, N>, iterationType?: IterationType): ReturnType<C>[];
236
243
  /**
237
244
  * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
238
245
  * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
@@ -57,7 +57,7 @@ export class BST extends BinaryTree {
57
57
  /**
58
58
  * This is the constructor function for a binary search tree class in TypeScript, which initializes
59
59
  * the tree with optional elements and options.
60
- * @param [elements] - An optional iterable of BTNodeExemplar objects that will be added to the
60
+ * @param [elements] - An optional iterable of BTNExemplar objects that will be added to the
61
61
  * binary search tree.
62
62
  * @param [options] - The `options` parameter is an optional object that can contain additional
63
63
  * configuration options for the binary search tree. It can have the following properties:
@@ -108,7 +108,7 @@ export class BST extends BinaryTree {
108
108
  }
109
109
  /**
110
110
  * The function checks if an exemplar is an instance of BSTNode.
111
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V, N>`.
111
+ * @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V, N>`.
112
112
  * @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
113
113
  */
114
114
  isNode(exemplar) {
@@ -117,7 +117,7 @@ export class BST extends BinaryTree {
117
117
  /**
118
118
  * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
119
119
  * otherwise it returns undefined.
120
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
120
+ * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
121
121
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
122
122
  * `exemplarToNode` function. It represents the value associated with the exemplar node.
123
123
  * @returns a node of type N or undefined.
@@ -390,6 +390,15 @@ export class BST extends BinaryTree {
390
390
  }
391
391
  }
392
392
  }
393
+ /**
394
+ * The function "isNotNodeInstance" checks if a potential key is a K.
395
+ * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
396
+ * data type.
397
+ * @returns a boolean value indicating whether the potentialKey is of type number or not.
398
+ */
399
+ isNotNodeInstance(potentialKey) {
400
+ return !(potentialKey instanceof BSTNode);
401
+ }
393
402
  /**
394
403
  * Time Complexity: O(log n) - Average case for a balanced tree.
395
404
  * Space Complexity: O(log n) - Space for the recursive call stack in the worst case.