linked-list-typed 1.51.7 → 1.51.9

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 (55) hide show
  1. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +103 -74
  2. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +116 -93
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
  4. package/dist/data-structures/binary-tree/avl-tree.js +90 -71
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -233
  6. package/dist/data-structures/binary-tree/binary-tree.js +492 -392
  7. package/dist/data-structures/binary-tree/bst.d.ts +204 -251
  8. package/dist/data-structures/binary-tree/bst.js +256 -358
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +74 -85
  10. package/dist/data-structures/binary-tree/rb-tree.js +111 -119
  11. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -76
  12. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
  13. package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
  14. package/dist/data-structures/graph/abstract-graph.js +10 -15
  15. package/dist/data-structures/hash/hash-map.d.ts +31 -38
  16. package/dist/data-structures/hash/hash-map.js +40 -55
  17. package/dist/data-structures/heap/heap.d.ts +1 -3
  18. package/dist/data-structures/queue/deque.d.ts +2 -3
  19. package/dist/data-structures/queue/deque.js +2 -3
  20. package/dist/data-structures/trie/trie.d.ts +1 -1
  21. package/dist/data-structures/trie/trie.js +1 -1
  22. package/dist/interfaces/binary-tree.d.ts +7 -7
  23. package/dist/types/common.d.ts +2 -3
  24. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +4 -3
  25. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -3
  26. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +6 -5
  27. package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
  28. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
  29. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -3
  30. package/dist/types/utils/utils.d.ts +10 -1
  31. package/dist/utils/utils.d.ts +2 -1
  32. package/dist/utils/utils.js +27 -1
  33. package/package.json +2 -2
  34. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -100
  35. package/src/data-structures/binary-tree/avl-tree.ts +109 -80
  36. package/src/data-structures/binary-tree/binary-tree.ts +556 -433
  37. package/src/data-structures/binary-tree/bst.ts +286 -375
  38. package/src/data-structures/binary-tree/rb-tree.ts +132 -125
  39. package/src/data-structures/binary-tree/tree-multi-map.ts +129 -102
  40. package/src/data-structures/graph/abstract-graph.ts +10 -10
  41. package/src/data-structures/hash/hash-map.ts +42 -49
  42. package/src/data-structures/heap/heap.ts +1 -1
  43. package/src/data-structures/queue/deque.ts +2 -2
  44. package/src/data-structures/queue/queue.ts +1 -1
  45. package/src/data-structures/trie/trie.ts +2 -2
  46. package/src/interfaces/binary-tree.ts +11 -9
  47. package/src/types/common.ts +2 -3
  48. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +4 -3
  49. package/src/types/data-structures/binary-tree/avl-tree.ts +4 -3
  50. package/src/types/data-structures/binary-tree/binary-tree.ts +7 -6
  51. package/src/types/data-structures/binary-tree/bst.ts +6 -5
  52. package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
  53. package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -3
  54. package/src/types/utils/utils.ts +14 -1
  55. package/src/utils/utils.ts +20 -1
@@ -60,24 +60,42 @@ exports.BSTNode = BSTNode;
60
60
  */
61
61
  class BST extends binary_tree_1.BinaryTree {
62
62
  /**
63
- * This is the constructor function for a TypeScript class that initializes a binary search tree with
64
- * optional keys or nodes or entries and options.
65
- * @param keysOrNodesOrEntries - An iterable object that contains keys, nodes, or entries. It is used
66
- * to initialize the binary search tree with the provided keys, nodes, or entries.
67
- * @param [options] - The `options` parameter is an optional object that can contain additional
68
- * configuration options for the binary search tree. It can have the following properties:
69
- */
70
- constructor(keysOrNodesOrEntries = [], options) {
63
+ * This is the constructor function for a Binary Search Tree class in TypeScript.
64
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
65
+ * iterable that can contain either keys, nodes, entries, or raw elements. These elements will be
66
+ * added to the binary search tree during the construction of the object.
67
+ * @param [options] - An optional object that contains additional options for the Binary Search Tree.
68
+ * It can include a comparator function that defines the order of the elements in the tree.
69
+ */
70
+ constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
71
71
  super([], options);
72
- this._variant = 'STANDARD';
72
+ this._root = undefined;
73
+ /**
74
+ * Time complexity: O(n)
75
+ * Space complexity: O(n)
76
+ */
77
+ this._DEFAULT_COMPARATOR = (a, b) => {
78
+ if (typeof a === 'object' && typeof b === 'object' && this.comparator === this._DEFAULT_COMPARATOR) {
79
+ throw TypeError('When comparing two object types, it is necessary to customize a [comparator] function of options parameter during the instantiation of the data structure.');
80
+ }
81
+ if (a > b)
82
+ return 1;
83
+ if (a < b)
84
+ return -1;
85
+ return 0;
86
+ };
87
+ /**
88
+ * Time complexity: O(n)
89
+ * Space complexity: O(n)
90
+ */
91
+ this._comparator = this._DEFAULT_COMPARATOR;
73
92
  if (options) {
74
- const { variant } = options;
75
- if (variant)
76
- this._variant = variant;
93
+ const { comparator } = options;
94
+ if (comparator)
95
+ this._comparator = comparator;
77
96
  }
78
- this._root = undefined;
79
- if (keysOrNodesOrEntries)
80
- this.addMany(keysOrNodesOrEntries);
97
+ if (keysOrNodesOrEntriesOrRawElements)
98
+ this.addMany(keysOrNodesOrEntriesOrRawElements);
81
99
  }
82
100
  /**
83
101
  * The function returns the root node of a tree structure.
@@ -86,13 +104,6 @@ class BST extends binary_tree_1.BinaryTree {
86
104
  get root() {
87
105
  return this._root;
88
106
  }
89
- /**
90
- * The function returns the value of the _variant property.
91
- * @returns The value of the `_variant` property.
92
- */
93
- get variant() {
94
- return this._variant;
95
- }
96
107
  /**
97
108
  * The function creates a new BSTNode with the given key and value and returns it.
98
109
  * @param {K} key - The key parameter is of type K, which represents the type of the key for the node
@@ -107,106 +118,68 @@ class BST extends binary_tree_1.BinaryTree {
107
118
  /**
108
119
  * The function creates a new binary search tree with the specified options.
109
120
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
110
- * behavior of the `createTree` method. It is of type `Partial<BSTOptions<K>>`, which means it is a
111
- * partial object of type `BSTOptions<K>`.
112
- * @returns a new instance of the BST class, with the provided options merged with the default
113
- * options. The returned value is casted as TREE.
121
+ * behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
122
+ * following properties:
123
+ * @returns a new instance of the BST class with the provided options.
114
124
  */
115
125
  createTree(options) {
116
- return new BST([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
126
+ return new BST([], Object.assign({ iterationType: this.iterationType, comparator: this.comparator }, options));
117
127
  }
118
128
  /**
119
- * The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
120
- * otherwise it returns undefined.
121
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
122
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
123
- * `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
124
- * @returns a node of type NODE or undefined.
125
- */
126
- keyValueOrEntryToNode(keyOrNodeOrEntry, value) {
127
- let node;
128
- if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {
129
- return;
130
- }
131
- else if (this.isNode(keyOrNodeOrEntry)) {
132
- node = keyOrNodeOrEntry;
133
- }
134
- else if (this.isEntry(keyOrNodeOrEntry)) {
135
- const [key, value] = keyOrNodeOrEntry;
136
- if (key === undefined || key === null) {
137
- return;
138
- }
139
- else {
140
- node = this.createNode(key, value);
141
- }
142
- }
143
- else if (!this.isNode(keyOrNodeOrEntry)) {
144
- node = this.createNode(keyOrNodeOrEntry, value);
145
- }
146
- else {
147
- return;
148
- }
149
- return node;
150
- }
151
- /**
152
- * Time Complexity: O(log n)
153
- * Space Complexity: O(log n)
129
+ * The function overrides a method and converts a key, value pair or entry or raw element to a node.
130
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
131
+ * type R or KeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
132
+ * element.
133
+ * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
134
+ * value associated with a key in a key-value pair.
135
+ * @returns either a NODE object or undefined.
154
136
  */
137
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value) {
138
+ var _a;
139
+ return (_a = super.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value)) !== null && _a !== void 0 ? _a : undefined;
140
+ }
155
141
  /**
156
142
  * Time Complexity: O(log n)
157
143
  * Space Complexity: O(log n)
158
144
  *
159
- * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
160
- * otherwise it returns the key itself.
161
- * @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
162
- * `undefined`.
163
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
164
- * type of iteration to be performed. It has a default value of `'ITERATIVE'`.
165
- * @returns either a node object (NODE) or undefined.
166
- */
167
- ensureNode(keyOrNodeOrEntry, iterationType = 'ITERATIVE') {
168
- if (keyOrNodeOrEntry === this.NIL)
169
- return;
170
- if (this.isRealNode(keyOrNodeOrEntry)) {
171
- return keyOrNodeOrEntry;
172
- }
173
- if (this.isEntry(keyOrNodeOrEntry)) {
174
- const key = keyOrNodeOrEntry[0];
175
- if (key === null || key === undefined)
176
- return;
177
- return this.getNodeByKey(key, iterationType);
178
- }
179
- const key = keyOrNodeOrEntry;
180
- if (key === null || key === undefined)
181
- return;
182
- return this.getNodeByKey(key, iterationType);
145
+ * The function ensures the existence of a node in a data structure and returns it, or undefined if
146
+ * it doesn't exist.
147
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
148
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
149
+ * entry, or raw element that needs to be ensured in the tree.
150
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
151
+ * parameter that specifies the type of iteration to be used when ensuring a node. It has a default
152
+ * value of `'ITERATIVE'`.
153
+ * @returns The method is returning either the node that was ensured or `undefined` if the node could
154
+ * not be ensured.
155
+ */
156
+ ensureNode(keyOrNodeOrEntryOrRawElement, iterationType = 'ITERATIVE') {
157
+ var _a;
158
+ return (_a = super.ensureNode(keyOrNodeOrEntryOrRawElement, iterationType)) !== null && _a !== void 0 ? _a : undefined;
183
159
  }
184
160
  /**
185
- * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
186
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
187
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
161
+ * The function checks if the input is an instance of the BSTNode class.
162
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
163
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
164
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
165
+ * an instance of the `BSTNode` class.
188
166
  */
189
- isNode(keyOrNodeOrEntry) {
190
- return keyOrNodeOrEntry instanceof BSTNode;
167
+ isNode(keyOrNodeOrEntryOrRawElement) {
168
+ return keyOrNodeOrEntryOrRawElement instanceof BSTNode;
191
169
  }
192
- /**
193
- * Time Complexity: O(log n)
194
- * Space Complexity: O(1)
195
- */
196
170
  /**
197
171
  * Time Complexity: O(log n)
198
172
  * Space Complexity: O(1)
199
173
  *
200
- * The `add` function adds a new node to a binary tree, updating the value if the key already exists
201
- * or inserting a new node if the key is unique.
202
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can accept three types of values:
203
- * @param {V} [value] - The `value` parameter represents the value associated with the key that is
204
- * being added to the binary tree.
205
- * @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
206
- * node was not added.
207
- */
208
- add(keyOrNodeOrEntry, value) {
209
- const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
174
+ * The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
175
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
176
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
177
+ * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
178
+ * key in the binary search tree. If provided, it will be stored in the node along with the key.
179
+ * @returns a boolean value.
180
+ */
181
+ add(keyOrNodeOrEntryOrRawElement, value) {
182
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
210
183
  if (newNode === undefined)
211
184
  return false;
212
185
  if (this.root === undefined) {
@@ -216,18 +189,11 @@ class BST extends binary_tree_1.BinaryTree {
216
189
  }
217
190
  let current = this.root;
218
191
  while (current !== undefined) {
219
- if (this._compare(current.key, newNode.key) === 'EQ') {
220
- // if (current !== newNode) {
221
- // The key value is the same but the reference is different, update the value of the existing node
192
+ if (this.comparator(current.key, newNode.key) === 0) {
222
193
  this._replaceNode(current, newNode);
223
194
  return true;
224
- // } else {
225
- // The key value is the same and the reference is the same, replace the entire node
226
- // this._replaceNode(current, newNode);
227
- // return;
228
- // }
229
195
  }
230
- else if (this._compare(current.key, newNode.key) === 'GT') {
196
+ else if (this.comparator(current.key, newNode.key) > 0) {
231
197
  if (current.left === undefined) {
232
198
  current.left = newNode;
233
199
  this._size++;
@@ -247,37 +213,38 @@ class BST extends binary_tree_1.BinaryTree {
247
213
  return false;
248
214
  }
249
215
  /**
250
- * Time Complexity: O(k log n)
251
- * Space Complexity: O(k + log n)
216
+ * Time Complexity: O(log n)
217
+ * Space Complexity: O(log n)
252
218
  */
253
219
  /**
254
220
  * Time Complexity: O(k log n)
255
221
  * Space Complexity: O(k + log n)
256
222
  *
257
- * The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
258
- * balancing the tree after each addition.
259
- * @param keysOrNodesOrEntries - An iterable containing the keys, nodes, or entries to be added to
260
- * the binary tree.
223
+ * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
224
+ * an array indicating whether each key or node was successfully inserted.
225
+ * @param keysOrNodesOrEntriesOrRawElements - An iterable containing keys, nodes, entries, or raw
226
+ * elements to be added to the data structure.
261
227
  * @param [values] - An optional iterable of values to be associated with the keys or nodes being
262
228
  * added. If provided, the values will be assigned to the corresponding keys or nodes in the same
263
229
  * order. If not provided, undefined will be assigned as the value for each key or node.
264
- * @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
265
- * balanced or not. If set to true, the add operation will be balanced using a binary search tree
266
- * algorithm. If set to false, the add operation will not be balanced and the nodes will be added
267
- * in the order they appear in the input.
268
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
269
- * type of iteration to use when adding multiple keys or nodes. It has a default value of
270
- * `this.iterationType`, which suggests that it is a property of the current object.
271
- * @returns The function `addMany` returns an array of nodes (`NODE`) or `undefined` values.
272
- */
273
- addMany(keysOrNodesOrEntries, values, isBalanceAdd = true, iterationType = this.iterationType) {
230
+ * @param [isBalanceAdd=true] - A boolean flag indicating whether the tree should be balanced after
231
+ * adding the elements. If set to true, the tree will be balanced using a binary search tree
232
+ * algorithm. If set to false, the elements will be added without balancing the tree. The default
233
+ * value is true.
234
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
235
+ * specifies the type of iteration to use when adding multiple keys or nodes to the binary search
236
+ * tree. It can have two possible values:
237
+ * @returns The function `addMany` returns an array of booleans indicating whether each element was
238
+ * successfully inserted into the data structure.
239
+ */
240
+ addMany(keysOrNodesOrEntriesOrRawElements, values, isBalanceAdd = true, iterationType = this.iterationType) {
274
241
  const inserted = [];
275
242
  let valuesIterator;
276
243
  if (values) {
277
244
  valuesIterator = values[Symbol.iterator]();
278
245
  }
279
246
  if (!isBalanceAdd) {
280
- for (const kve of keysOrNodesOrEntries) {
247
+ for (const kve of keysOrNodesOrEntriesOrRawElements) {
281
248
  const value = valuesIterator === null || valuesIterator === void 0 ? void 0 : valuesIterator.next().value;
282
249
  const nn = this.add(kve, value);
283
250
  inserted.push(nn);
@@ -290,25 +257,36 @@ class BST extends binary_tree_1.BinaryTree {
290
257
  return false;
291
258
  return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null));
292
259
  };
293
- for (const kve of keysOrNodesOrEntries) {
260
+ for (const kve of keysOrNodesOrEntriesOrRawElements) {
294
261
  isRealBTNExemplar(kve) && realBTNExemplars.push(kve);
295
262
  }
296
263
  let sorted = [];
297
264
  sorted = realBTNExemplars.sort((a, b) => {
298
- let aR, bR;
265
+ let keyA, keyB;
299
266
  if (this.isEntry(a))
300
- aR = this.extractor(a[0]);
267
+ keyA = a[0];
301
268
  else if (this.isRealNode(a))
302
- aR = this.extractor(a.key);
303
- else
304
- aR = this.extractor(a);
269
+ keyA = a.key;
270
+ else if (this.toEntryFn) {
271
+ keyA = this.toEntryFn(a)[0];
272
+ }
273
+ else {
274
+ keyA = a;
275
+ }
305
276
  if (this.isEntry(b))
306
- bR = this.extractor(b[0]);
277
+ keyB = b[0];
307
278
  else if (this.isRealNode(b))
308
- bR = this.extractor(b.key);
309
- else
310
- bR = this.extractor(b);
311
- return aR - bR;
279
+ keyB = b.key;
280
+ else if (this.toEntryFn) {
281
+ keyB = this.toEntryFn(b)[0];
282
+ }
283
+ else {
284
+ keyB = b;
285
+ }
286
+ if (keyA !== undefined && keyA !== null && keyB !== undefined && keyB !== null) {
287
+ return this.comparator(keyA, keyB);
288
+ }
289
+ return 0;
312
290
  });
313
291
  const _dfs = (arr) => {
314
292
  if (arr.length === 0)
@@ -345,32 +323,26 @@ class BST extends binary_tree_1.BinaryTree {
345
323
  return inserted;
346
324
  }
347
325
  /**
348
- * Time Complexity: O(log n)
349
- * Space Complexity: O(k + log n)
350
- * /
351
-
352
- /**
353
326
  * Time Complexity: O(log n)
354
327
  * Space Complexity: O(k + log n)
355
328
  *
356
- * The function `getNodes` returns an array of nodes that match a given identifier, using either a
357
- * recursive or iterative approach.
329
+ * The `getNodes` function in TypeScript retrieves nodes from a binary tree based on a given
330
+ * identifier and callback function.
358
331
  * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
359
- * want to search for in the nodes of the binary tree. It can be of any type that is returned by the
360
- * callback function `C`.
361
- * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
362
- * argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
363
- * function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
364
- * @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the
365
- * first node that matches the identifier. If set to true, the function will return an array
366
- * containing only the first matching node. If set to false (default), the function will continue
367
- * searching for all nodes that match the identifier and return an array containing
368
- * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
369
- * for the traversal. It can be either a key value or a node object. If it is undefined, the
370
- * traversal will start from the root of the tree.
371
- * @param iterationType - The `iterationType` parameter determines the type of iteration to be
372
- * performed on the binary tree. It can have two possible values:
373
- * @returns The method returns an array of nodes (`NODE[]`).
332
+ * want to search for in the binary tree. It can be of any type that is returned by the callback
333
+ * function.
334
+ * @param {C} callback - The `callback` parameter is a function that takes a node as input and
335
+ * returns a value. This value is used to identify the nodes that match the given identifier. The
336
+ * `callback` function is optional and defaults to `this._DEFAULT_CALLBACK`.
337
+ * @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
338
+ * or all matching nodes. If set to true, only the first matching node will be returned. If set to
339
+ * false, all matching nodes will be returned. The default value is false.
340
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
341
+ * point for the search in the binary tree. It can be either a node object, a key-value pair, or an
342
+ * entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
343
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
344
+ * iteration to be performed. It can have two possible values:
345
+ * @returns The method `getNodes` returns an array of `NODE` objects.
374
346
  */
375
347
  getNodes(identifier, callback = this._DEFAULT_CALLBACK, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
376
348
  beginRoot = this.ensureNode(beginRoot);
@@ -390,9 +362,9 @@ class BST extends binary_tree_1.BinaryTree {
390
362
  return;
391
363
  // TODO potential bug
392
364
  if (callback === this._DEFAULT_CALLBACK) {
393
- if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === 'GT')
365
+ if (this.isRealNode(cur.left) && this.comparator(cur.key, identifier) > 0)
394
366
  dfs(cur.left);
395
- if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === 'LT')
367
+ if (this.isRealNode(cur.right) && this.comparator(cur.key, identifier) < 0)
396
368
  dfs(cur.right);
397
369
  }
398
370
  else {
@@ -414,9 +386,9 @@ class BST extends binary_tree_1.BinaryTree {
414
386
  }
415
387
  // TODO potential bug
416
388
  if (callback === this._DEFAULT_CALLBACK) {
417
- if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === 'LT')
389
+ if (this.isRealNode(cur.right) && this.comparator(cur.key, identifier) < 0)
418
390
  stack.push(cur.right);
419
- if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === 'GT')
391
+ if (this.isRealNode(cur.left) && this.comparator(cur.key, identifier) > 0)
420
392
  stack.push(cur.left);
421
393
  // if (this.isRealNode(cur.right) && this._lt(cur.key, identifier as K)) stack.push(cur.right);
422
394
  // if (this.isRealNode(cur.left) && this._gt(cur.key, identifier as K)) stack.push(cur.left);
@@ -441,51 +413,50 @@ class BST extends binary_tree_1.BinaryTree {
441
413
  * Time Complexity: O(log n)
442
414
  * Space Complexity: O(1)
443
415
  *
444
- * The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
445
- * callback function.
446
- * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
447
- * that you want to search for in the binary search tree. It can be of any type that is compatible
448
- * with the type of nodes in the tree.
449
- * @param {C} callback - The `callback` parameter is a function that will be called for each node in
450
- * the tree. It is used to determine whether a node matches the given identifier. The `callback`
451
- * function should take a node as its parameter and return a value that can be compared to the
452
- * `identifier` parameter.
416
+ * The function `getNode` returns the first node that matches the given identifier and callback
417
+ * function in a binary search tree.
418
+ * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
419
+ * want to search for in the binary search tree. It can be of any type that is compatible with the
420
+ * type returned by the callback function.
421
+ * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
422
+ * node matches the desired criteria. It should be a function that takes a node as an argument and
423
+ * returns a boolean value indicating whether the node matches the criteria or not. If no callback is
424
+ * provided, the default callback will be
453
425
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
454
- * search tree. It can be either a key or a node. If it is a key, it will be converted to a node
455
- * using the `ensureNode` method. If it is not provided, the `root`
456
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
457
- * be performed when searching for nodes in the binary search tree. It is an optional parameter and
458
- * its default value is taken from the `iterationType` property of the class.
459
- * @returns The method is returning a value of type `NODE | null | undefined`.
426
+ * search tree. It can be either a key or a node. If it is a key, the search will start from the node
427
+ * with that key. If it is a node, the search will start from that node.
428
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
429
+ * of iteration to be performed when searching for nodes in the binary search tree. It can have one
430
+ * of the following values:
431
+ * @returns The method is returning a NODE object or undefined.
460
432
  */
461
433
  getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
462
434
  var _a;
463
435
  return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : undefined;
464
436
  }
465
437
  /**
466
- * Time Complexity: O(log n)
467
- * Space Complexity: O(1)
438
+ * Time Complexity: O(k log n)
439
+ * Space Complexity: O(k + log n)
468
440
  */
469
441
  /**
470
442
  * Time Complexity: O(log n)
471
443
  * Space Complexity: O(1)
472
444
  *
473
- * The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
474
- * either recursive or iterative methods.
475
- * @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
476
- * It is used to identify the node that we want to retrieve.
477
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
478
- * type of iteration to use when searching for a node in the binary tree. It can have two possible
479
- * values:
480
- * @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
481
- * found in the binary tree. If no node is found, it returns `undefined`.
445
+ * The function `getNodeByKey` returns a node with a specific key from a tree data structure.
446
+ * @param {K} key - The key parameter is the value used to search for a specific node in the tree. It
447
+ * is typically a unique identifier or a value that can be used to determine the position of the node
448
+ * in the tree structure.
449
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
450
+ * parameter that specifies the type of iteration to be used when searching for a node in the tree.
451
+ * It has a default value of `'ITERATIVE'`.
452
+ * @returns The method is returning a NODE object or undefined.
482
453
  */
483
454
  getNodeByKey(key, iterationType = 'ITERATIVE') {
484
455
  return this.getNode(key, this._DEFAULT_CALLBACK, this.root, iterationType);
485
456
  }
486
457
  /**
487
- * Time complexity: O(n)
488
- * Space complexity: O(n)
458
+ * Time Complexity: O(log n)
459
+ * Space Complexity: O(k + log n)
489
460
  */
490
461
  /**
491
462
  * Time complexity: O(n)
@@ -494,15 +465,16 @@ class BST extends binary_tree_1.BinaryTree {
494
465
  * The function overrides the depth-first search method and returns an array of the return types of
495
466
  * the callback function.
496
467
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
497
- * during the depth-first search traversal. It is an optional parameter and if not provided, a
498
- * default callback function will be used.
499
- * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter specifies the order in which the
500
- * nodes are visited during the depth-first search. It can have one of the following values:
501
- * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for the
502
- * Depth-First Search (DFS) traversal. It can be either a key, a node, or an entry in the tree. If no
503
- * value is provided, the DFS traversal will start from the root of the tree.
504
- * @param {IterationType} iterationType - The `iterationType` parameter specifies the type of
505
- * iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
468
+ * during the depth-first search traversal. It is an optional parameter and defaults to
469
+ * `this._DEFAULT_CALLBACK`. The type `C` represents the type of the callback function.
470
+ * @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
471
+ * order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
472
+ * take one of the following values:
473
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
474
+ * point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
475
+ * node entry. If not specified, the default value is the root of the tree.
476
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
477
+ * type of iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
506
478
  * following values:
507
479
  * @returns The method is returning an array of the return type of the callback function.
508
480
  */
@@ -510,8 +482,8 @@ class BST extends binary_tree_1.BinaryTree {
510
482
  return super.dfs(callback, pattern, beginRoot, iterationType, false);
511
483
  }
512
484
  /**
513
- * Time complexity: O(n)
514
- * Space complexity: O(n)
485
+ * Time Complexity: O(log n)
486
+ * Space Complexity: O(1)
515
487
  */
516
488
  /**
517
489
  * Time complexity: O(n)
@@ -520,38 +492,38 @@ class BST extends binary_tree_1.BinaryTree {
520
492
  * The function overrides the breadth-first search method and returns an array of the return types of
521
493
  * the callback function.
522
494
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
523
- * visited during the breadth-first search traversal. It is an optional parameter and if not
524
- * provided, a default callback function will be used.
525
- * @param beginRoot - The `beginRoot` parameter is the starting point for the breadth-first search
526
- * traversal. It can be either a key, a node, or an entry in the tree. If not specified, the root of
527
- * the tree is used as the starting point.
528
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
529
- * be performed during the breadth-first search (BFS) traversal. It determines the order in which the
530
- * nodes are visited.
531
- * @returns The method is returning an array of the return type of the callback function.
495
+ * visited during the breadth-first search. It should take a single argument, which is the current
496
+ * node being visited, and it can return a value of any type.
497
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
498
+ * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
499
+ * object. If no value is provided, the default value is the root of the tree.
500
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
501
+ * of iteration to be performed during the breadth-first search (BFS) traversal. It can have one of
502
+ * the following values:
503
+ * @returns an array of the return type of the callback function.
532
504
  */
533
505
  bfs(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
534
506
  return super.bfs(callback, beginRoot, iterationType, false);
535
507
  }
536
508
  /**
537
- * Time complexity: O(n)
538
- * Space complexity: O(n)
509
+ * Time Complexity: O(log n)
510
+ * Space Complexity: O(1)
539
511
  */
540
512
  /**
541
513
  * Time complexity: O(n)
542
514
  * Space complexity: O(n)
543
515
  *
544
- * The function overrides the listLevels method and returns an array of arrays containing the return
545
- * type of the callback function for each level of the tree.
516
+ * The function overrides the listLevels method from the superclass and returns an array of arrays
517
+ * containing the results of the callback function applied to each level of the tree.
546
518
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
547
- * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
548
- * during the level listing process.
549
- * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
550
- * levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
551
- * provided, the root of the binary tree is used as the starting point.
552
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
553
- * be performed on the tree. It determines the order in which the nodes are visited during the
554
- * iteration.
519
+ * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
520
+ * tree during the iteration process.
521
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
522
+ * point for listing the levels of the binary tree. It can be either a root node of the tree, a
523
+ * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
524
+ * value is provided, the root of
525
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
526
+ * of iteration to be performed on the tree. It can have one of the following values:
555
527
  * @returns The method is returning a two-dimensional array of the return type of the callback
556
528
  * function.
557
529
  */
@@ -559,77 +531,42 @@ class BST extends binary_tree_1.BinaryTree {
559
531
  return super.listLevels(callback, beginRoot, iterationType, false);
560
532
  }
561
533
  /**
562
- * Time Complexity: O(log n)
563
- * Space Complexity: O(1)
564
- */
565
- /**
566
- * Time Complexity: O(log n)
567
- * Space Complexity: O(1)
568
- *
569
- * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
570
- * leftmost node if the comparison result is greater than.
571
- * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
572
- * type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
573
- * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
574
- * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
575
- * the key of the leftmost node if the comparison result is greater than, and the key of the
576
- * rightmost node otherwise. If no node is found, it returns 0.
577
- */
578
- lastKey(beginRoot = this.root) {
579
- let current = this.ensureNode(beginRoot);
580
- if (!current)
581
- return undefined;
582
- if (this._variant === 'STANDARD') {
583
- // For 'STANDARD', find the rightmost node
584
- while (current.right !== undefined) {
585
- current = current.right;
586
- }
587
- }
588
- else {
589
- // For BSTVariant.MAX, find the leftmost node
590
- while (current.left !== undefined) {
591
- current = current.left;
592
- }
593
- }
594
- return current.key;
595
- }
596
- /**
597
- * Time Complexity: O(log n)
598
- * Space Complexity: O(log n)
534
+ * Time complexity: O(n)
535
+ * Space complexity: O(n)
599
536
  */
600
537
  /**
601
- * Time Complexity: O(log n)
602
- * Space Complexity: O(log n)
538
+ * Time complexity: O(n)
539
+ * Space complexity: O(n)
603
540
  *
604
- * The `lesserOrGreaterTraverse` function traverses a binary tree and returns an array of nodes that
605
- * are either lesser or greater than a target node, depending on the specified comparison type.
541
+ * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
542
+ * each node that meets a certain condition based on a target node and a comparison value.
606
543
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
607
- * that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
608
- * parameter of type `NODE` (the node type) and returns a value of any type.
544
+ * that meets the condition specified by the `lesserOrGreater` parameter. It takes a single argument,
545
+ * which is the current node being traversed, and returns a value of any type.
609
546
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
610
- * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
611
- * `CP`, which is a custom type representing the comparison operator. The possible values for
612
- * `lesserOrGreater` are
613
- * @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
614
- * binary tree that you want to traverse from. It can be specified either by its key, by the node
615
- * object itself, or it can be left undefined to start the traversal from the root of the tree.
616
- * @param iterationType - The `iterationType` parameter determines the type of traversal to be
617
- * performed on the binary tree. It can have two possible values:
547
+ * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
548
+ * 0, or 1, where:
549
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
550
+ * the binary tree that you want to start traversing from. It can be specified either by providing
551
+ * the key of the node, the node itself, or an entry containing the key and value of the node. If no
552
+ * `targetNode` is provided,
553
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
554
+ * traversal to be performed on the binary tree. It can have two possible values:
618
555
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
619
556
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
620
557
  */
621
- lesserOrGreaterTraverse(callback = this._DEFAULT_CALLBACK, lesserOrGreater = 'LT', targetNode = this.root, iterationType = this.iterationType) {
622
- targetNode = this.ensureNode(targetNode);
558
+ lesserOrGreaterTraverse(callback = this._DEFAULT_CALLBACK, lesserOrGreater = -1, targetNode = this.root, iterationType = this.iterationType) {
559
+ const targetNodeEnsured = this.ensureNode(targetNode);
623
560
  const ans = [];
624
- if (!targetNode)
561
+ if (!targetNodeEnsured)
625
562
  return ans;
626
563
  if (!this.root)
627
564
  return ans;
628
- const targetKey = targetNode.key;
565
+ const targetKey = targetNodeEnsured.key;
629
566
  if (iterationType === 'RECURSIVE') {
630
567
  const dfs = (cur) => {
631
- const compared = this._compare(cur.key, targetKey);
632
- if (compared === lesserOrGreater)
568
+ const compared = this.comparator(cur.key, targetKey);
569
+ if (Math.sign(compared) === lesserOrGreater)
633
570
  ans.push(callback(cur));
634
571
  if (this.isRealNode(cur.left))
635
572
  dfs(cur.left);
@@ -644,8 +581,8 @@ class BST extends binary_tree_1.BinaryTree {
644
581
  while (queue.size > 0) {
645
582
  const cur = queue.shift();
646
583
  if (this.isRealNode(cur)) {
647
- const compared = this._compare(cur.key, targetKey);
648
- if (compared === lesserOrGreater)
584
+ const compared = this.comparator(cur.key, targetKey);
585
+ if (Math.sign(compared) === lesserOrGreater)
649
586
  ans.push(callback(cur));
650
587
  if (this.isRealNode(cur.left))
651
588
  queue.push(cur.left);
@@ -657,18 +594,19 @@ class BST extends binary_tree_1.BinaryTree {
657
594
  }
658
595
  }
659
596
  /**
660
- * Time Complexity: O(log n)
661
- * Space Complexity: O(log n)
597
+ * Time complexity: O(n)
598
+ * Space complexity: O(n)
662
599
  */
663
600
  /**
664
- * Time Complexity: O(log n)
665
- * Space Complexity: O(log n)
601
+ * Time complexity: O(n)
602
+ * Space complexity: O(n)
666
603
  *
667
- * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
668
- * ensures the tree is perfectly balanced.
669
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
670
- * type of iteration to use when building a balanced binary search tree. It can have two possible
671
- * values:
604
+ * The `perfectlyBalance` function takes an optional `iterationType` parameter and returns `true` if
605
+ * the binary search tree is perfectly balanced, otherwise it returns `false`.
606
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
607
+ * specifies the type of iteration to use when building a balanced binary search tree. It has a
608
+ * default value of `this.iterationType`, which means it will use the iteration type specified in the
609
+ * current instance of the class.
672
610
  * @returns The function `perfectlyBalance` returns a boolean value.
673
611
  */
674
612
  perfectlyBalance(iterationType = this.iterationType) {
@@ -708,25 +646,19 @@ class BST extends binary_tree_1.BinaryTree {
708
646
  }
709
647
  }
710
648
  /**
711
- * Balancing Adjustment:
712
- * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
713
- * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
714
- *
715
- * Use Cases and Efficiency:
716
- * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
717
- * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
718
- */
719
- /**
720
- * Time Complexity: O(n)
721
- * Space Complexity: O(log n)
649
+ * Time complexity: O(n)
650
+ * Space complexity: O(n)
722
651
  */
723
652
  /**
724
653
  * Time Complexity: O(n)
725
654
  * Space Complexity: O(log n)
726
655
  *
727
- * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
728
- * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
729
- * to check if the AVL tree is balanced. It can have two possible values:
656
+ * The function `isAVLBalanced` checks if a binary tree is AVL balanced using either a recursive or
657
+ * iterative approach.
658
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
659
+ * specifies the type of iteration to use when checking if the AVL tree is balanced. It has a default
660
+ * value of `this.iterationType`, which means it will use the iteration type specified in the current
661
+ * instance of the AVL tree.
730
662
  * @returns a boolean value.
731
663
  */
732
664
  isAVLBalanced(iterationType = this.iterationType) {
@@ -776,9 +708,20 @@ class BST extends binary_tree_1.BinaryTree {
776
708
  return balanced;
777
709
  }
778
710
  /**
779
- * The function sets the root property of an object and updates the parent property of the new root.
780
- * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. This means that it
781
- * can either be an object of type `NODE` or it can be `undefined`.
711
+ * Time Complexity: O(n)
712
+ * Space Complexity: O(log n)
713
+ */
714
+ /**
715
+ * The function returns the value of the _comparator property.
716
+ * @returns The `_comparator` property is being returned.
717
+ */
718
+ get comparator() {
719
+ return this._comparator;
720
+ }
721
+ /**
722
+ * The function sets the root of a tree-like structure and updates the parent property of the new
723
+ * root.
724
+ * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
782
725
  */
783
726
  _setRoot(v) {
784
727
  if (v) {
@@ -786,50 +729,5 @@ class BST extends binary_tree_1.BinaryTree {
786
729
  }
787
730
  this._root = v;
788
731
  }
789
- /**
790
- * The function compares two values using a comparator function and returns whether the first value
791
- * is greater than, less than, or equal to the second value.
792
- * @param {K} a - The parameter "a" is of type K.
793
- * @param {K} b - The parameter "b" in the above code represents a K.
794
- * @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
795
- * than), 'LT' (less than), or 'EQ' (equal).
796
- */
797
- _compare(a, b) {
798
- const extractedA = this.extractor(a);
799
- const extractedB = this.extractor(b);
800
- const compared = this.variant === 'STANDARD' ? extractedA - extractedB : extractedB - extractedA;
801
- if (compared > 0)
802
- return 'GT';
803
- if (compared < 0)
804
- return 'LT';
805
- return 'EQ';
806
- }
807
- /**
808
- * The function `_lt` compares two values `a` and `b` using an extractor function and returns true if
809
- * `a` is less than `b` based on the specified variant.
810
- * @param {K} a - The parameter "a" is of type "K", which means it can be any type. It represents the
811
- * first value to be compared in the function.
812
- * @param {K} b - The parameter `b` is of type `K`, which means it can be any type. It is used as one
813
- * of the arguments for the comparison in the `_lt` function.
814
- * @returns a boolean value.
815
- */
816
- _lt(a, b) {
817
- const extractedA = this.extractor(a);
818
- const extractedB = this.extractor(b);
819
- return this.variant === 'STANDARD' ? extractedA < extractedB : extractedA > extractedB;
820
- }
821
- /**
822
- * The function compares two values using a custom extractor function and returns true if the first
823
- * value is greater than the second value.
824
- * @param {K} a - The parameter "a" is of type K, which means it can be any type.
825
- * @param {K} b - The parameter "b" is of type K, which means it can be any type. It is used as one
826
- * of the arguments for the comparison in the function.
827
- * @returns a boolean value.
828
- */
829
- _gt(a, b) {
830
- const extractedA = this.extractor(a);
831
- const extractedB = this.extractor(b);
832
- return this.variant === 'STANDARD' ? extractedA > extractedB : extractedA < extractedB;
833
- }
834
732
  }
835
733
  exports.BST = BST;