undirected-graph-typed 2.0.5 → 2.1.0

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 (101) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
  2. package/dist/data-structures/base/iterable-element-base.js +149 -107
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
  4. package/dist/data-structures/base/iterable-entry-base.js +59 -116
  5. package/dist/data-structures/base/linear-base.d.ts +250 -192
  6. package/dist/data-structures/base/linear-base.js +137 -274
  7. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  8. package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
  9. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  10. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  11. package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
  12. package/dist/data-structures/binary-tree/avl-tree.js +208 -195
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
  14. package/dist/data-structures/binary-tree/binary-tree.js +598 -869
  15. package/dist/data-structures/binary-tree/bst.d.ts +258 -306
  16. package/dist/data-structures/binary-tree/bst.js +505 -481
  17. package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  18. package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
  19. package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
  20. package/dist/data-structures/binary-tree/tree-counter.js +172 -203
  21. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  22. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
  23. package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
  24. package/dist/data-structures/graph/abstract-graph.js +267 -237
  25. package/dist/data-structures/graph/directed-graph.d.ts +108 -224
  26. package/dist/data-structures/graph/directed-graph.js +146 -233
  27. package/dist/data-structures/graph/map-graph.d.ts +49 -55
  28. package/dist/data-structures/graph/map-graph.js +56 -59
  29. package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
  30. package/dist/data-structures/graph/undirected-graph.js +129 -149
  31. package/dist/data-structures/hash/hash-map.d.ts +164 -338
  32. package/dist/data-structures/hash/hash-map.js +270 -457
  33. package/dist/data-structures/heap/heap.d.ts +214 -289
  34. package/dist/data-structures/heap/heap.js +340 -349
  35. package/dist/data-structures/heap/max-heap.d.ts +11 -47
  36. package/dist/data-structures/heap/max-heap.js +11 -66
  37. package/dist/data-structures/heap/min-heap.d.ts +12 -47
  38. package/dist/data-structures/heap/min-heap.js +11 -66
  39. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  40. package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
  41. package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  42. package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
  43. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  44. package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
  45. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  46. package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
  47. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  48. package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
  49. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
  50. package/dist/data-structures/priority-queue/priority-queue.js +8 -83
  51. package/dist/data-structures/queue/deque.d.ts +227 -254
  52. package/dist/data-structures/queue/deque.js +309 -348
  53. package/dist/data-structures/queue/queue.d.ts +180 -201
  54. package/dist/data-structures/queue/queue.js +265 -248
  55. package/dist/data-structures/stack/stack.d.ts +124 -102
  56. package/dist/data-structures/stack/stack.js +181 -125
  57. package/dist/data-structures/trie/trie.d.ts +164 -165
  58. package/dist/data-structures/trie/trie.js +189 -172
  59. package/dist/interfaces/binary-tree.d.ts +56 -6
  60. package/dist/interfaces/graph.d.ts +16 -0
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
  63. package/dist/types/utils/utils.d.ts +1 -0
  64. package/dist/utils/utils.d.ts +1 -1
  65. package/dist/utils/utils.js +2 -1
  66. package/package.json +2 -2
  67. package/src/data-structures/base/iterable-element-base.ts +238 -115
  68. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  69. package/src/data-structures/base/linear-base.ts +271 -277
  70. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  71. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  72. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  73. package/src/data-structures/binary-tree/binary-tree.ts +664 -893
  74. package/src/data-structures/binary-tree/bst.ts +568 -570
  75. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  76. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  77. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  78. package/src/data-structures/graph/abstract-graph.ts +339 -264
  79. package/src/data-structures/graph/directed-graph.ts +146 -236
  80. package/src/data-structures/graph/map-graph.ts +63 -60
  81. package/src/data-structures/graph/undirected-graph.ts +129 -152
  82. package/src/data-structures/hash/hash-map.ts +274 -496
  83. package/src/data-structures/heap/heap.ts +389 -402
  84. package/src/data-structures/heap/max-heap.ts +12 -76
  85. package/src/data-structures/heap/min-heap.ts +13 -76
  86. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  87. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  88. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  89. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  90. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  91. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  92. package/src/data-structures/queue/deque.ts +381 -357
  93. package/src/data-structures/queue/queue.ts +310 -264
  94. package/src/data-structures/stack/stack.ts +217 -131
  95. package/src/data-structures/trie/trie.ts +240 -175
  96. package/src/interfaces/binary-tree.ts +240 -6
  97. package/src/interfaces/graph.ts +37 -0
  98. package/src/types/data-structures/base/base.ts +5 -5
  99. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  100. package/src/types/utils/utils.ts +2 -0
  101. package/src/utils/utils.ts +9 -14
@@ -5,30 +5,64 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparable, Comparator, CP, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNode } from '../../types';
8
+ import type { BinaryTreeOptions, BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparable, Comparator, CP, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNode } from '../../types';
9
9
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { Range } from '../../common';
12
+ /**
13
+ * Represents a Node in a Binary Search Tree.
14
+ *
15
+ * @template K - The type of the key.
16
+ * @template V - The type of the value.
17
+ */
12
18
  export declare class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
13
19
  parent?: BSTNode<K, V>;
14
20
  /**
15
- * This TypeScript constructor function initializes an instance with a key and an optional value.
16
- * @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
17
- * within a data structure. It serves as a reference or identifier for accessing or manipulating the
18
- * associated value.
19
- * @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
20
- * have to be provided when creating an instance of the class. If a value is not provided, it will
21
- * default to `undefined`.
21
+ * Creates an instance of BSTNode.
22
+ * @remarks Time O(1), Space O(1)
23
+ *
24
+ * @param key - The key of the node.
25
+ * @param [value] - The value associated with the key.
22
26
  */
23
27
  constructor(key: K, value?: V);
24
28
  _left?: BSTNode<K, V> | null | undefined;
29
+ /**
30
+ * Gets the left child of the node.
31
+ * @remarks Time O(1), Space O(1)
32
+ *
33
+ * @returns The left child.
34
+ */
25
35
  get left(): BSTNode<K, V> | null | undefined;
36
+ /**
37
+ * Sets the left child of the node and updates its parent reference.
38
+ * @remarks Time O(1), Space O(1)
39
+ *
40
+ * @param v - The node to set as the left child.
41
+ */
26
42
  set left(v: BSTNode<K, V> | null | undefined);
27
43
  _right?: BSTNode<K, V> | null | undefined;
44
+ /**
45
+ * Gets the right child of the node.
46
+ * @remarks Time O(1), Space O(1)
47
+ *
48
+ * @returns The right child.
49
+ */
28
50
  get right(): BSTNode<K, V> | null | undefined;
51
+ /**
52
+ * Sets the right child of the node and updates its parent reference.
53
+ * @remarks Time O(1), Space O(1)
54
+ *
55
+ * @param v - The node to set as the right child.
56
+ */
29
57
  set right(v: BSTNode<K, V> | null | undefined);
30
58
  }
31
59
  /**
60
+ * Represents a Binary Search Tree (BST).
61
+ * Keys are ordered, allowing for faster search operations compared to a standard Binary Tree.
62
+ * @template K - The type of the key.
63
+ * @template V - The type of the value.
64
+ * @template R - The type of the raw data object (if using `toEntryFn`).
65
+ *
32
66
  * 1. Node Order: Each node's left child has a lesser value, and the right child has a greater value.
33
67
  * 2. Unique Keys: No duplicate keys in a standard BST.
34
68
  * 3. Efficient Search: Enables quick search, minimum, and maximum operations.
@@ -93,369 +127,287 @@ export declare class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
93
127
  * console.log(findLCA(5, 35)); // 15
94
128
  * console.log(findLCA(20, 30)); // 25
95
129
  */
96
- export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends BinaryTree<K, V, R, MK, MV, MR> implements IBinaryTree<K, V, R, MK, MV, MR> {
130
+ export declare class BST<K = any, V = any, R extends object = object> extends BinaryTree<K, V, R> implements IBinaryTree<K, V, R> {
97
131
  /**
98
- * This TypeScript constructor initializes a binary search tree with optional options and adds
99
- * elements if provided.
100
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
101
- * iterable that can contain elements of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It is used to
102
- * initialize the binary search tree with keys, nodes, entries, or raw data.
103
- * @param [options] - The `options` parameter is an optional object that can contain the following
104
- * properties:
132
+ * Creates an instance of BST.
133
+ * @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
134
+ *
135
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
136
+ * @param [options] - Configuration options for the BST, including comparator.
105
137
  */
106
138
  constructor(keysNodesEntriesOrRaws?: Iterable<K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BSTOptions<K, V, R>);
107
139
  protected _root?: BSTNode<K, V>;
140
+ /**
141
+ * Gets the root node of the tree.
142
+ * @remarks Time O(1)
143
+ *
144
+ * @returns The root node.
145
+ */
108
146
  get root(): OptNode<BSTNode<K, V>>;
109
147
  protected _isReverse: boolean;
148
+ /**
149
+ * Gets whether the tree's comparison logic is reversed.
150
+ * @remarks Time O(1)
151
+ *
152
+ * @returns True if the tree is reversed (e.g., a max-heap logic).
153
+ */
110
154
  get isReverse(): boolean;
155
+ /**
156
+ * The default comparator function.
157
+ * @remarks Time O(1) (or O(C) if `specifyComparable` is used, C is complexity of that function).
158
+ */
111
159
  protected _comparator: Comparator<K>;
160
+ /**
161
+ * Gets the comparator function used by the tree.
162
+ * @remarks Time O(1)
163
+ *
164
+ * @returns The comparator function.
165
+ */
112
166
  get comparator(): Comparator<K>;
113
167
  protected _specifyComparable?: (key: K) => Comparable;
114
- get specifyComparable(): ((key: K) => Comparable) | undefined;
115
168
  /**
116
- * Time Complexity: O(1)
117
- * Space Complexity: O(1)
169
+ * Gets the function used to extract a comparable value from a complex key.
170
+ * @remarks Time O(1)
118
171
  *
119
- * The function creates a new BSTNode with the given key and value and returns it.
120
- * @param {K} key - The key parameter is of type K, which represents the type of the key for the node
121
- * being created.
122
- * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
123
- * value associated with the key in the node being created.
124
- * @returns The method is returning a new instance of the BSTNode class, casted as the BSTNode<K, V> type.
172
+ * @returns The key-to-comparable conversion function.
125
173
  */
126
- createNode(key: K, value?: V): BSTNode<K, V>;
174
+ get specifyComparable(): ((key: K) => Comparable) | undefined;
127
175
  /**
128
- * Time Complexity: O(1)
129
- * Space Complexity: O(1)
176
+ * (Protected) Creates a new BST node.
177
+ * @remarks Time O(1), Space O(1)
130
178
  *
131
- * The function creates a new binary search tree with the specified options.
132
- * @param [options] - The `options` parameter is an optional object that allows you to customize the
133
- * behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
134
- * following properties:
135
- * @returns a new instance of the BST class with the provided options.
179
+ * @param key - The key for the new node.
180
+ * @param [value] - The value for the new node (used if not in Map mode).
181
+ * @returns The newly created BSTNode.
136
182
  */
137
- createTree(options?: BSTOptions<K, V, R>): BST<K, V, R, MK, MV, MR>;
183
+ _createNode(key: K, value?: V): BSTNode<K, V>;
138
184
  /**
139
- * Time Complexity: O(log n)
140
- * Space Complexity: O(log n)
185
+ * Ensures the input is a node. If it's a key or entry, it searches for the node.
186
+ * @remarks Time O(log N) (height of the tree), O(N) worst-case.
141
187
  *
142
- * The function ensures the existence of a node in a data structure and returns it, or undefined if
143
- * it doesn't exist.
144
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
145
- * `keyNodeOrEntry` can accept a value of type `R`, which represents the key, node,
146
- * entry, or raw element that needs to be ensured in the tree.
147
- * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
148
- * parameter that specifies the type of iteration to be used when ensuring a node. It has a default
149
- * value of `'ITERATIVE'`.
150
- * @returns The method is returning either the node that was ensured or `undefined` if the node could
151
- * not be ensured.
188
+ * @param keyNodeOrEntry - The item to resolve to a node.
189
+ * @param [iterationType=this.iterationType] - The traversal method to use if searching.
190
+ * @returns The resolved node, or undefined if not found.
152
191
  */
153
192
  ensureNode(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): OptNode<BSTNode<K, V>>;
154
193
  /**
155
- * Time Complexity: O(1)
156
- * Space Complexity: O(1)
194
+ * Checks if the given item is a `BSTNode` instance.
195
+ * @remarks Time O(1), Space O(1)
157
196
  *
158
- * The function checks if the input is an instance of the BSTNode class.
159
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
160
- * `keyNodeOrEntry` can be of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
161
- * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
162
- * an instance of the `BSTNode` class.
197
+ * @param keyNodeOrEntry - The item to check.
198
+ * @returns True if it's a BSTNode, false otherwise.
163
199
  */
164
200
  isNode(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is BSTNode<K, V>;
165
201
  /**
166
- * Time Complexity: O(1)
167
- * Space Complexity: O(1)
202
+ * Checks if the given key is valid (comparable).
203
+ * @remarks Time O(1)
168
204
  *
169
- * The function "override isValidKey" checks if a key is comparable based on a given comparator.
170
- * @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
171
- * type `K`.
172
- * @returns The `override isValidKey(key: any): key is K` function is returning a boolean value based on
173
- * the result of the `isComparable` function with the condition `this._compare !==
174
- * this._DEFAULT_COMPARATOR`.
205
+ * @param key - The key to validate.
206
+ * @returns True if the key is valid, false otherwise.
175
207
  */
176
208
  isValidKey(key: any): key is K;
177
209
  /**
178
- * Time Complexity: O(log n)
179
- * Space Complexity: O(log n)
210
+ * Performs a Depth-First Search (DFS) traversal.
211
+ * @remarks Time O(N), visits every node. Space O(log N) for the call/explicit stack. O(N) worst-case.
180
212
  *
181
- * The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
182
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
183
- * `keyNodeOrEntry` can accept a value of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
184
- * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
185
- * key in the binary search tree. If provided, it will be stored in the node along with the key.
186
- * @returns a boolean value.
213
+ * @template C - The type of the callback function.
214
+ * @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on each node.
215
+ * @param [pattern='IN'] - The traversal order ('IN', 'PRE', 'POST').
216
+ * @param [onlyOne=false] - If true, stops after the first callback.
217
+ * @param [startNode=this._root] - The node to start from.
218
+ * @param [iterationType=this.iterationType] - The traversal method.
219
+ * @returns An array of callback results.
187
220
  */
188
- add(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
221
+ dfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
189
222
  /**
190
- * Time Complexity: O(k log n)
191
- * Space Complexity: O(k + log n)
192
- *
193
- * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
194
- * an array indicating whether each key or node was successfully inserted.
195
- * @param keysNodesEntriesOrRaws - An iterable containing keys, nodes, entries, or raw
196
- * elements to be added to the data structure.
197
- * @param [values] - An optional iterable of values to be associated with the keys or nodes being
198
- * added. If provided, the values will be assigned to the corresponding keys or nodes in the same
199
- * order. If not provided, undefined will be assigned as the value for each key or node.
200
- * @param [isBalanceAdd=true] - A boolean flag indicating whether the tree should be balanced after
201
- * adding the elements. If set to true, the tree will be balanced using a binary search tree
202
- * algorithm. If set to false, the elements will be added without balancing the tree. The default
203
- * value is true.
204
- * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
205
- * specifies the type of iteration to use when adding multiple keys or nodes to the binary search
206
- * tree. It can have two possible values:
207
- * @returns The function `addMany` returns an array of booleans indicating whether each element was
208
- * successfully inserted into the data structure.
223
+ * Performs a Breadth-First Search (BFS) or Level-Order traversal.
224
+ * @remarks Time O(N), visits every node. Space O(N) in the worst case for the queue.
225
+ *
226
+ * @template C - The type of the callback function.
227
+ * @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on each node.
228
+ * @param [startNode=this._root] - The node to start from.
229
+ * @param [iterationType=this.iterationType] - The traversal method.
230
+ * @returns An array of callback results.
209
231
  */
210
- addMany(keysNodesEntriesOrRaws: Iterable<R | BTNRep<K, V, BSTNode<K, V>>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
232
+ bfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
211
233
  /**
212
- * Time Complexity: O(log n)
213
- * Space Complexity: O(k + log n)
214
- *
215
- * The function `search` in TypeScript overrides the search behavior in a binary tree structure based
216
- * on specified criteria.
217
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
218
- * `keyNodeEntryOrPredicate` parameter in the `override search` method can accept one of the
219
- * following types:
220
- * @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
221
- * search should stop after finding the first matching node. If `onlyOne` is set to `true`, the
222
- * search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
223
- * @param {C} callback - The `callback` parameter in the `override search` function is a function
224
- * that will be called on each node that matches the search criteria. It is of type `C`, which
225
- * extends `NodeCallback<BSTNode<K, V> | null>`. The callback function should accept a node of type `BSTNode<K, V>` as its
226
- * argument and
227
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `override search`
228
- * method represents the node from which the search operation will begin. It is the starting point
229
- * for searching within the tree data structure. The method ensures that the `startNode` is a valid
230
- * node before proceeding with the search operation. If the `
231
- * @param {IterationType} iterationType - The `iterationType` parameter in the `override search`
232
- * function determines the type of iteration to be used during the search operation. It can have two
233
- * possible values:
234
- * @returns The `override search` method returns an array of values that match the search criteria
235
- * specified by the input parameters. The method performs a search operation on a binary tree
236
- * structure based on the provided key, predicate, and other options. The search results are
237
- * collected in an array and returned as the output of the method.
234
+ * Returns a 2D array of nodes, grouped by level.
235
+ * @remarks Time O(N), visits every node. Space O(N) for the result array and the queue/stack.
236
+ *
237
+ * @template C - The type of the callback function.
238
+ * @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on each node.
239
+ * @param [startNode=this._root] - The node to start from.
240
+ * @param [iterationType=this.iterationType] - The traversal method.
241
+ * @returns A 2D array of callback results.
238
242
  */
239
- search<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean, callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
243
+ listLevels<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[][];
240
244
  /**
241
- * Time Complexity: O(log n)
242
- * Space Complexity: O(k + log n)
243
- *
244
- * The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
245
- * @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
246
- * either a `Range` object or an array of two elements representing the range boundaries.
247
- * @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
248
- * function that is used to process each node that is found within the specified range during the
249
- * search operation. It is of type `NodeCallback<BSTNode<K, V> | null>`, where `BSTNode<K, V>` is the type of nodes in the
250
- * data structure.
251
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `rangeSearch`
252
- * function represents the node from which the search for nodes within the specified range will
253
- * begin. It is the starting point for the range search operation.
254
- * @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
255
- * is used to specify the type of iteration to be performed during the search operation. It has a
256
- * default value of `this.iterationType`, which suggests that it is likely a property of the class or
257
- * object that the `rangeSearch`
258
- * @returns The `rangeSearch` function is returning the result of calling the `search` method with
259
- * the specified parameters.
245
+ * Gets the first node matching a predicate.
246
+ * @remarks Time O(log N) if searching by key, O(N) if searching by predicate. Space O(log N) or O(N).
247
+ *
248
+ * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
249
+ * @param [startNode=this._root] - The node to start the search from.
250
+ * @param [iterationType=this.iterationType] - The traversal method.
251
+ * @returns The first matching node, or undefined if not found.
260
252
  */
261
- rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
253
+ getNode(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, startNode?: BSTNOptKeyOrNode<K, BSTNode<K, V>>, iterationType?: IterationType): OptNode<BSTNode<K, V>>;
262
254
  /**
263
- * Time Complexity: O(log n)
264
- * Space Complexity: O(log n)
265
- *
266
- * This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
267
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
268
- * parameter can be of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `, `R`, or `NodePredicate<BSTNode<K, V>>`.
269
- * @param {BSTNOptKeyOrNode<K, BSTNode<K, V>>} startNode - The `startNode` parameter in the `getNode` method
270
- * is used to specify the starting point for searching nodes in the binary search tree. If no
271
- * specific starting point is provided, the default value is set to `this._root`, which is the root
272
- * node of the binary search tree.
273
- * @param {IterationType} iterationType - The `iterationType` parameter in the `getNode` method is a
274
- * parameter that specifies the type of iteration to be used. It has a default value of
275
- * `this.iterationType`, which means it will use the iteration type defined in the class instance if
276
- * no value is provided when calling the method.
277
- * @returns The `getNode` method is returning an optional binary search tree node (`OptNode<BSTNode<K, V>>`).
278
- * It is using the `getNodes` method to find the node based on the provided keyNodeEntryOrPredicate, beginning at
279
- * the specified root node (`startNode`) and using the specified iteration type. The method then
280
- * returns the first node found or `undefined` if no node is found.
255
+ * Searches the tree for nodes matching a predicate, key, or range.
256
+ * @remarks This is an optimized search for a BST. If searching by key or range, it prunes branches.
257
+ * Time O(H + M) for key/range search (H=height, M=matches). O(N) for predicate search.
258
+ * Space O(log N) for the stack.
259
+ *
260
+ * @template C - The type of the callback function.
261
+ * @param keyNodeEntryOrPredicate - The key, node, entry, predicate, or range to search for.
262
+ * @param [onlyOne=false] - If true, stops after finding the first match.
263
+ * @param [callback=this._DEFAULT_NODE_CALLBACK] - A function to call on matching nodes.
264
+ * @param [startNode=this._root] - The node to start the search from.
265
+ * @param [iterationType=this.iterationType] - Whether to use 'RECURSIVE' or 'ITERATIVE' search.
266
+ * @returns An array of results from the callback function for each matching node.
281
267
  */
282
- getNode(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, startNode?: BSTNOptKeyOrNode<K, BSTNode<K, V>>, iterationType?: IterationType): OptNode<BSTNode<K, V>>;
268
+ search<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean, callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
283
269
  /**
284
- * Time complexity: O(n)
285
- * Space complexity: O(n)
286
- *
287
- * The function `dfs` in TypeScript overrides the base class method with default parameters and
288
- * returns the result of the super class `dfs` method.
289
- * @param {C} callback - The `callback` parameter is a function that will be called for each node
290
- * visited during the Depth-First Search traversal. It is a generic type `C` that extends the
291
- * `NodeCallback` interface for `BSTNode<K, V>`. The default value for `callback` is `this._
292
- * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `override dfs` method
293
- * specifies the order in which the Depth-First Search (DFS) traversal should be performed on the
294
- * Binary Search Tree (BST). The possible values for the `pattern` parameter are:
295
- * @param {boolean} [onlyOne=false] - The `onlyOne` parameter in the `override dfs` method is a
296
- * boolean flag that indicates whether you want to stop the depth-first search traversal after
297
- * finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set
298
- * to `true`, the traversal will stop after finding
299
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} startNode -
300
- * The `startNode` parameter in the `override dfs` method can be one of the following types:
301
- * @param {IterationType} iterationType - The `iterationType` parameter in the `override dfs` method
302
- * specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
303
- * Binary Search Tree (BST). It is used to determine the order in which nodes are visited during the
304
- * traversal. The possible values for `
305
- * @returns The `override` function is returning the result of calling the `dfs` method from the
306
- * superclass, with the provided arguments `callback`, `pattern`, `onlyOne`, `startNode`, and
307
- * `iterationType`. The return type is an array of the return type of the callback function `C`.
270
+ * Performs an optimized search for nodes within a given key range.
271
+ * @remarks Time O(H + M), where H is tree height and M is the number of matches.
272
+ *
273
+ * @template C - The type of the callback function.
274
+ * @param range - A `Range` object or a `[low, high]` tuple.
275
+ * @param [callback=this._DEFAULT_NODE_CALLBACK] - A function to call on matching nodes.
276
+ * @param [startNode=this._root] - The node to start the search from.
277
+ * @param [iterationType=this.iterationType] - The traversal method.
278
+ * @returns An array of callback results.
308
279
  */
309
- dfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
280
+ rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
310
281
  /**
311
- * Time complexity: O(n)
312
- * Space complexity: O(n)
313
- *
314
- * The function overrides the breadth-first search method and returns an array of the return types of
315
- * the callback function.
316
- * @param {C} callback - The `callback` parameter is a function that will be called for each node
317
- * visited during the breadth-first search. It should take a single argument, which is the current
318
- * node being visited, and it can return a value of any type.
319
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
320
- * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
321
- * object. If no value is provided, the default value is the root of the tree.
322
- * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
323
- * of iteration to be performed during the breadth-first search (BFS) traversal. It can have one of
324
- * the following values:
325
- * @returns an array of the return type of the callback function.
282
+ * Adds a new node to the BST based on key comparison.
283
+ * @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
284
+ *
285
+ * @param keyNodeOrEntry - The key, node, or entry to add.
286
+ * @param [value] - The value, if providing just a key.
287
+ * @returns True if the addition was successful, false otherwise.
326
288
  */
327
- bfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
289
+ add(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
328
290
  /**
329
- * Time complexity: O(n)
330
- * Space complexity: O(n)
331
- *
332
- * The function overrides the listLevels method from the superclass and returns an array of arrays
333
- * containing the results of the callback function applied to each level of the tree.
334
- * @param {C} callback - The `callback` parameter is a generic type `C` that extends
335
- * `NodeCallback<BSTNode<K, V> | null>`. It represents a callback function that will be called for each node in the
336
- * tree during the iteration process.
337
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
338
- * point for listing the levels of the binary tree. It can be either a root node of the tree, a
339
- * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
340
- * value is provided, the root of
341
- * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
342
- * of iteration to be performed on the tree. It can have one of the following values:
343
- * @returns The method is returning a two-dimensional array of the return type of the callback
344
- * function.
291
+ * Adds multiple items to the tree.
292
+ * @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced add).
293
+ * If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
294
+ * Space O(N) for sorting and recursion/iteration stack.
295
+ *
296
+ * @param keysNodesEntriesOrRaws - An iterable of items to add.
297
+ * @param [values] - An optional parallel iterable of values.
298
+ * @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
299
+ * @param [iterationType=this.iterationType] - The traversal method for balanced add (recursive or iterative).
300
+ * @returns An array of booleans indicating the success of each individual `add` operation.
345
301
  */
346
- listLevels<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[][];
302
+ addMany(keysNodesEntriesOrRaws: Iterable<R | BTNRep<K, V, BSTNode<K, V>>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
347
303
  /**
348
- * Time complexity: O(n)
349
- * Space complexity: O(n)
350
- *
351
- * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
352
- * each node that meets a certain condition based on a target node and a comparison value.
353
- * @param {C} callback - The `callback` parameter is a function that will be called for each node
354
- * that meets the condition specified by the `lesserOrGreater` parameter. It takes a single argument,
355
- * which is the current node being traversed, and returns a value of any type.
356
- * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
357
- * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
358
- * 0, or 1, where:
359
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } targetNode - The `targetNode` parameter is the node in
360
- * the binary tree that you want to start traversing from. It can be specified either by providing
361
- * the key of the node, the node itself, or an entry containing the key and value of the node. If no
362
- * `targetNode` is provided,
363
- * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
364
- * traversal to be performed on the binary tree. It can have two possible values:
365
- * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
366
- * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
304
+ * Traverses the tree and returns nodes that are lesser or greater than a target node.
305
+ * @remarks Time O(N), as it performs a full traversal. Space O(log N) or O(N).
306
+ *
307
+ * @template C - The type of the callback function.
308
+ * @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on matching nodes.
309
+ * @param [lesserOrGreater=-1] - -1 for lesser, 1 for greater, 0 for equal.
310
+ * @param [targetNode=this._root] - The node to compare against.
311
+ * @param [iterationType=this.iterationType] - The traversal method.
312
+ * @returns An array of callback results.
367
313
  */
368
314
  lesserOrGreaterTraverse<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, lesserOrGreater?: CP, targetNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
369
315
  /**
370
- * Time complexity: O(n)
371
- * Space complexity: O(n)
316
+ * Rebuilds the tree to be perfectly balanced.
317
+ * @remarks Time O(N) (O(N) for DFS, O(N) for sorted build). Space O(N) for node array and recursion stack.
372
318
  *
373
- * The `perfectlyBalance` function takes an optional `iterationType` parameter and returns `true` if
374
- * the binary search tree is perfectly balanced, otherwise it returns `false`.
375
- * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
376
- * specifies the type of iteration to use when building a balanced binary search tree. It has a
377
- * default value of `this.iterationType`, which means it will use the iteration type specified in the
378
- * current instance of the class.
379
- * @returns The function `perfectlyBalance` returns a boolean value.
319
+ * @param [iterationType=this.iterationType] - The traversal method for the initial node export.
320
+ * @returns True if successful, false if the tree was empty.
380
321
  */
381
322
  perfectlyBalance(iterationType?: IterationType): boolean;
382
323
  /**
383
- * Time Complexity: O(n)
384
- * Space Complexity: O(log n)
324
+ * Checks if the tree meets the AVL balance condition (height difference <= 1).
325
+ * @remarks Time O(N), as it must visit every node to compute height. Space O(log N) for recursion or O(N) for iterative map.
385
326
  *
386
- * The function `isAVLBalanced` checks if a binary tree is AVL balanced using either a recursive or
387
- * iterative approach.
388
- * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
389
- * specifies the type of iteration to use when checking if the AVL tree is balanced. It has a default
390
- * value of `this.iterationType`, which means it will use the iteration type specified in the current
391
- * instance of the AVL tree.
392
- * @returns a boolean value.
327
+ * @param [iterationType=this.iterationType] - The traversal method.
328
+ * @returns True if the tree is AVL balanced, false otherwise.
393
329
  */
394
330
  isAVLBalanced(iterationType?: IterationType): boolean;
395
331
  /**
396
- * Time complexity: O(n)
397
- * Space complexity: O(n)
398
- *
399
- * The `map` function in TypeScript overrides the default map behavior for a binary search tree by
400
- * applying a callback function to each entry and creating a new tree with the results.
401
- * @param callback - A function that will be called for each entry in the BST. It takes four
402
- * arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
403
- * the BST itself.
404
- * @param [options] - The `options` parameter in the `override map` method is of type `BSTOptions<MK,
405
- * MV, MR>`. It is an optional parameter that allows you to specify additional options for the Binary
406
- * Search Tree (BST) being created in the `map` method. These options could include configuration
407
- * @param {any} [thisArg] - The `thisArg` parameter in the `override map` method is used to specify
408
- * the value of `this` that should be used when executing the `callback` function. It allows you to
409
- * set the context or scope in which the callback function will be called. This can be useful when
410
- * you want
411
- * @returns The `map` method is returning a new Binary Search Tree (`BST`) instance with the entries
412
- * transformed by the provided callback function.
413
- */
414
- map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: BSTOptions<MK, MV, MR>, thisArg?: any): BST<MK, MV, MR>;
415
- /**
416
- * Time complexity: O(n)
417
- * Space complexity: O(n)
418
- *
419
- * The function `clone` overrides the default cloning behavior to create a deep copy of a tree
420
- * structure.
421
- * @returns The `cloned` object is being returned.
422
- */
423
- clone(): BST<K, V, R, MK, MV, MR>;
424
- /**
425
- * Time Complexity: O(1)
426
- * Space Complexity: O(1)
427
- *
428
- * The function overrides a method and converts a key, value pair or entry or raw element to a node.
429
- * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - A variable that can be of
430
- * type R or K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined . It represents either a key, a node, an entry, or a raw
431
- * element.
432
- * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
433
- * value associated with a key in a key-value pair.
434
- * @returns either a BSTNode<K, V> object or undefined.
332
+ * Creates a new BST by mapping each [key, value] pair to a new entry.
333
+ * @remarks Time O(N * H), where N is nodes in this tree, and H is height of the new tree during insertion.
334
+ * Space O(N) for the new tree.
335
+ *
336
+ * @template MK - New key type.
337
+ * @template MV - New value type.
338
+ * @template MR - New raw type.
339
+ * @param callback - A function to map each [key, value] pair.
340
+ * @param [options] - Options for the new BST.
341
+ * @param [thisArg] - `this` context for the callback.
342
+ * @returns A new, mapped BST.
343
+ */
344
+ map<MK = K, MV = V, MR extends object = object>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): BST<MK, MV, MR>;
345
+ /**
346
+ * Deletes the first node found that satisfies the predicate.
347
+ * @remarks Performs an in-order traversal. Time O(N) worst-case (O(log N) to find + O(log N) to delete). Space O(log N) for stack.
348
+ *
349
+ * @param predicate - A function to test each [key, value] pair.
350
+ * @returns True if a node was deleted, false otherwise.
351
+ */
352
+ deleteWhere(predicate: (key: K, value: V | undefined, index: number, tree: this) => boolean): boolean;
353
+ /**
354
+ * (Protected) Creates a new, empty instance of the same BST constructor.
355
+ * @remarks Time O(1)
356
+ *
357
+ * @template TK, TV, TR - Generic types for the new instance.
358
+ * @param [options] - Options for the new BST.
359
+ * @returns A new, empty BST.
360
+ */
361
+ protected _createInstance<TK = K, TV = V, TR extends object = R>(options?: Partial<BSTOptions<TK, TV, TR>>): this;
362
+ /**
363
+ * (Protected) Creates a new instance of the same BST constructor, potentially with different generic types.
364
+ * @remarks Time O(N log N) or O(N^2) (from constructor) due to processing the iterable.
365
+ *
366
+ * @template TK, TV, TR - Generic types for the new instance.
367
+ * @param [iter=[]] - An iterable to populate the new BST.
368
+ * @param [options] - Options for the new BST.
369
+ * @returns A new BST.
370
+ */
371
+ protected _createLike<TK = K, TV = V, TR extends object = R>(iter?: Iterable<TK | BSTNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<BSTOptions<TK, TV, TR>>): BST<TK, TV, TR>;
372
+ /**
373
+ * (Protected) Snapshots the current BST's configuration options.
374
+ * @remarks Time O(1)
375
+ *
376
+ * @template TK, TV, TR - Generic types for the options.
377
+ * @returns The options object.
378
+ */
379
+ protected _snapshotOptions<TK = K, TV = V, TR extends object = R>(): BSTOptions<TK, TV, TR>;
380
+ /**
381
+ * (Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
382
+ * @remarks Time O(1)
383
+ *
384
+ * @param keyNodeOrEntry - The input item.
385
+ * @param [value] - An optional value (used if input is just a key).
386
+ * @returns A tuple of [node, value].
435
387
  */
436
388
  protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): [OptNode<BSTNode<K, V>>, V | undefined];
437
389
  /**
438
- * Time Complexity: O(1)
439
- * Space Complexity: O(1)
390
+ * (Protected) Sets the root node and clears its parent reference.
391
+ * @remarks Time O(1)
440
392
  *
441
- * The function sets the root of a tree-like structure and updates the parent property of the new
442
- * root.
443
- * @param {OptNode<BSTNode<K, V>>} v - v is a parameter of type BSTNode<K, V> or undefined.
393
+ * @param v - The node to set as root.
444
394
  */
445
395
  protected _setRoot(v: OptNode<BSTNode<K, V>>): void;
446
396
  /**
447
- * Time Complexity: O(1)
448
- * Space Complexity: O(1)
397
+ * (Protected) Compares two keys using the tree's comparator and reverse setting.
398
+ * @remarks Time O(1) (or O(C) if `specifyComparable` is used).
449
399
  *
450
- * The _compare function compares two values using a specified comparator function and optionally
451
- * reverses the result.
452
- * @param {K} a - The parameter `a` is of type `K`, which is used as an input for comparison in the
453
- * `_compare` method.
454
- * @param {K} b - The parameter `b` in the `_compare` function is of type `K`.
455
- * @returns The `_compare` method is returning the result of the ternary expression. If `_isReverse`
456
- * is true, it returns the negation of the result of calling the `_comparator` function with
457
- * arguments `a` and `b`. If `_isReverse` is false, it returns the result of calling the
458
- * `_comparator` function with arguments `a` and `b`.
400
+ * @param a - The first key.
401
+ * @param b - The second key.
402
+ * @returns A number (1, -1, or 0) representing the comparison.
459
403
  */
460
404
  protected _compare(a: K, b: K): number;
405
+ /**
406
+ * (Private) Deletes a node by its key.
407
+ * @remarks Standard BST deletion algorithm. Time O(log N), O(N) worst-case. Space O(1).
408
+ *
409
+ * @param key - The key of the node to delete.
410
+ * @returns True if the node was found and deleted, false otherwise.
411
+ */
412
+ private _deleteByKey;
461
413
  }