heap-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 (56) hide show
  1. package/README.md +72 -80
  2. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +103 -74
  3. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +116 -93
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
  5. package/dist/data-structures/binary-tree/avl-tree.js +90 -71
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -233
  7. package/dist/data-structures/binary-tree/binary-tree.js +492 -392
  8. package/dist/data-structures/binary-tree/bst.d.ts +204 -251
  9. package/dist/data-structures/binary-tree/bst.js +256 -358
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +74 -85
  11. package/dist/data-structures/binary-tree/rb-tree.js +111 -119
  12. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -76
  13. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
  14. package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
  15. package/dist/data-structures/graph/abstract-graph.js +10 -15
  16. package/dist/data-structures/hash/hash-map.d.ts +31 -38
  17. package/dist/data-structures/hash/hash-map.js +40 -55
  18. package/dist/data-structures/heap/heap.d.ts +1 -3
  19. package/dist/data-structures/queue/deque.d.ts +2 -3
  20. package/dist/data-structures/queue/deque.js +2 -3
  21. package/dist/data-structures/trie/trie.d.ts +1 -1
  22. package/dist/data-structures/trie/trie.js +1 -1
  23. package/dist/interfaces/binary-tree.d.ts +7 -7
  24. package/dist/types/common.d.ts +2 -3
  25. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +4 -3
  26. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -3
  27. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +6 -5
  28. package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
  29. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
  30. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -3
  31. package/dist/types/utils/utils.d.ts +10 -1
  32. package/dist/utils/utils.d.ts +2 -1
  33. package/dist/utils/utils.js +27 -1
  34. package/package.json +2 -2
  35. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -100
  36. package/src/data-structures/binary-tree/avl-tree.ts +109 -80
  37. package/src/data-structures/binary-tree/binary-tree.ts +556 -433
  38. package/src/data-structures/binary-tree/bst.ts +286 -375
  39. package/src/data-structures/binary-tree/rb-tree.ts +132 -125
  40. package/src/data-structures/binary-tree/tree-multi-map.ts +129 -102
  41. package/src/data-structures/graph/abstract-graph.ts +10 -10
  42. package/src/data-structures/hash/hash-map.ts +42 -49
  43. package/src/data-structures/heap/heap.ts +1 -1
  44. package/src/data-structures/queue/deque.ts +2 -2
  45. package/src/data-structures/queue/queue.ts +1 -1
  46. package/src/data-structures/trie/trie.ts +2 -2
  47. package/src/interfaces/binary-tree.ts +11 -9
  48. package/src/types/common.ts +2 -3
  49. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +4 -3
  50. package/src/types/data-structures/binary-tree/avl-tree.ts +4 -3
  51. package/src/types/data-structures/binary-tree/binary-tree.ts +7 -6
  52. package/src/types/data-structures/binary-tree/bst.ts +6 -5
  53. package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
  54. package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -3
  55. package/src/types/utils/utils.ts +14 -1
  56. package/src/utils/utils.ts +20 -1
@@ -1,17 +1,20 @@
1
1
  import type {
2
2
  BinaryTreeDeleteResult,
3
3
  BTNCallback,
4
+ Comparable,
5
+ CRUD,
4
6
  KeyOrNodeOrEntry,
7
+ RBTNColor,
5
8
  RBTreeOptions,
6
9
  RedBlackTreeNested,
7
10
  RedBlackTreeNodeNested
8
11
  } from '../../types';
9
- import { CP, CRUD, RBTNColor } from '../../types';
12
+ import { BTNEntry } from '../../types';
10
13
  import { BST, BSTNode } from './bst';
11
14
  import { IBinaryTree } from '../../interfaces';
12
15
 
13
16
  export class RedBlackTreeNode<
14
- K = any,
17
+ K extends Comparable,
15
18
  V = any,
16
19
  NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>
17
20
  > extends BSTNode<K, V, NODE> {
@@ -51,30 +54,34 @@ export class RedBlackTreeNode<
51
54
  }
52
55
 
53
56
  export class RedBlackTree<
54
- K = any,
57
+ K extends Comparable,
55
58
  V = any,
59
+ R = BTNEntry<K, V>,
56
60
  NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>,
57
- TREE extends RedBlackTree<K, V, NODE, TREE> = RedBlackTree<K, V, NODE, RedBlackTreeNested<K, V, NODE>>
61
+ TREE extends RedBlackTree<K, V, R, NODE, TREE> = RedBlackTree<K, V, R, NODE, RedBlackTreeNested<K, V, R, NODE>>
58
62
  >
59
- extends BST<K, V, NODE, TREE>
60
- implements IBinaryTree<K, V, NODE, TREE> {
63
+ extends BST<K, V, R, NODE, TREE>
64
+ implements IBinaryTree<K, V, R, NODE, TREE> {
61
65
  /**
62
66
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
63
- * @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
64
- * contain keys, nodes, or entries. It is used to initialize the RBTree with the provided keys,
65
- * nodes, or entries.
67
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
68
+ * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
69
+ * initialize the RBTree with the provided elements.
66
70
  * @param [options] - The `options` parameter is an optional object that can be passed to the
67
- * constructor. It allows you to customize the behavior of the RBTree. It can include properties such
68
- * as `compareKeys`, `compareValues`, `allowDuplicates`, etc. These properties define how the RBTree
69
- * should compare keys and
70
- */
71
- constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>> = [], options?: RBTreeOptions<K>) {
71
+ * constructor. It is of type `RBTreeOptions<K, V, R>`. This object can contain various options for
72
+ * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
73
+ * depend on the implementation
74
+ */
75
+ constructor(
76
+ keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>> = [],
77
+ options?: RBTreeOptions<K, V, R>
78
+ ) {
72
79
  super([], options);
73
80
 
74
81
  this._root = this.NIL;
75
82
 
76
- if (keysOrNodesOrEntries) {
77
- this.addMany(keysOrNodesOrEntries);
83
+ if (keysOrNodesOrEntriesOrRawElements) {
84
+ this.addMany(keysOrNodesOrEntriesOrRawElements);
78
85
  }
79
86
  }
80
87
 
@@ -90,29 +97,30 @@ export class RedBlackTree<
90
97
 
91
98
  /**
92
99
  * The function creates a new Red-Black Tree node with the specified key, value, and color.
93
- * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
94
- * which is a generic type representing the key's data type.
100
+ * @param {K} key - The key parameter represents the key value of the node being created. It is of
101
+ * type K, which is a generic type that can be replaced with any specific type when using the
102
+ * function.
95
103
  * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
96
- * associated with the key in the node. It is not required and can be omitted if not needed.
97
- * @param {RBTNColor} color - The "color" parameter is used to specify the color of the node in a
98
- * Red-Black Tree. It is an optional parameter with a default value of "'BLACK'". The color
99
- * can be either "'RED'" or "'BLACK'".
100
- * @returns The method is returning a new instance of a RedBlackTreeNode with the specified key,
101
- * value, and color.
104
+ * associated with the key in the node. It is not required and can be omitted if you only need to
105
+ * create a node with a key.
106
+ * @param {RBTNColor} [color=BLACK] - The "color" parameter is used to specify the color of the node
107
+ * in a Red-Black Tree. It can have two possible values: "RED" or "BLACK". By default, the color is
108
+ * set to "BLACK" if not specified.
109
+ * @returns A new instance of a RedBlackTreeNode with the specified key, value, and color is being
110
+ * returned.
102
111
  */
103
112
  override createNode(key: K, value?: V, color: RBTNColor = 'BLACK'): NODE {
104
113
  return new RedBlackTreeNode<K, V, NODE>(key, value, color) as NODE;
105
114
  }
106
115
 
107
116
  /**
108
- * The function creates a Red-Black Tree with the given options and returns it.
109
- * @param [options] - The `options` parameter is an optional object that contains configuration
110
- * options for creating the Red-Black Tree. It is of type `RBTreeOptions<K>`, where `K` represents
111
- * the type of keys in the tree.
117
+ * The function creates a new Red-Black Tree with the specified options.
118
+ * @param [options] - The `options` parameter is an optional object that contains additional
119
+ * configuration options for creating the Red-Black Tree. It has the following properties:
112
120
  * @returns a new instance of a RedBlackTree object.
113
121
  */
114
- override createTree(options?: RBTreeOptions<K>): TREE {
115
- return new RedBlackTree<K, V, NODE, TREE>([], {
122
+ override createTree(options?: RBTreeOptions<K, V, R>): TREE {
123
+ return new RedBlackTree<K, V, R, NODE, TREE>([], {
116
124
  iterationType: this.iterationType,
117
125
  ...options
118
126
  }) as TREE;
@@ -124,54 +132,57 @@ export class RedBlackTree<
124
132
  */
125
133
 
126
134
  /**
127
- * Time Complexity: O(1)
128
- * Space Complexity: O(1)
129
- *
130
- * The function `keyValueOrEntryToNode` takes a key, value, or entry and returns a node if it is
131
- * valid, otherwise it returns undefined.
132
- * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntry - The key, value, or entry to convert.
133
- * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntry` is a key).
134
- * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
135
- */
136
- override keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
137
- let node: NODE | undefined;
138
-
139
- if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {
140
- return;
141
- } else if (this.isNode(keyOrNodeOrEntry)) {
142
- node = keyOrNodeOrEntry;
143
- } else if (this.isEntry(keyOrNodeOrEntry)) {
144
- const [key, value] = keyOrNodeOrEntry;
145
- if (key === undefined || key === null) {
146
- return;
147
- } else {
148
- node = this.createNode(key, value, 'RED');
149
- }
150
- } else if (!this.isNode(keyOrNodeOrEntry)) {
151
- node = this.createNode(keyOrNodeOrEntry, value, 'RED');
152
- } else {
153
- return;
154
- }
155
- return node;
156
- }
157
-
158
- /**
159
- * Time Complexity: O(1)
160
- * Space Complexity: O(1)
161
- * /
162
-
163
- /**
164
135
  * Time Complexity: O(1)
165
136
  * Space Complexity: O(1)
166
137
  *
167
138
  * The function checks if the input is an instance of the RedBlackTreeNode class.
168
- * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntry - The object to check.
169
- * @returns {boolean} - `true` if the object is a Red-Black Tree node, `false` otherwise.
170
- */
171
- override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE {
172
- return keyOrNodeOrEntry instanceof RedBlackTreeNode;
139
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
140
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
141
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
142
+ * an instance of the `RedBlackTreeNode` class.
143
+ */
144
+ override isNode(
145
+ keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>
146
+ ): keyOrNodeOrEntryOrRawElement is NODE {
147
+ return keyOrNodeOrEntryOrRawElement instanceof RedBlackTreeNode;
173
148
  }
174
149
 
150
+ // /**
151
+ // * Time Complexity: O(1)
152
+ // * Space Complexity: O(1)
153
+ // */
154
+ //
155
+ // /**
156
+ // * Time Complexity: O(1)
157
+ // * Space Complexity: O(1)
158
+ // *
159
+ // * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
160
+ // * valid, otherwise it returns undefined.
161
+ // * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
162
+ // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
163
+ // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
164
+ // */
165
+ // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
166
+ //
167
+ // if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
168
+ // if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
169
+ //
170
+ // if (this.toEntryFn) {
171
+ // const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
172
+ // if (key) return this.createNode(key, entryValue ?? value, 'RED');
173
+ // }
174
+ //
175
+ // if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
176
+ // const [key, value] = keyOrNodeOrEntryOrRawElement;
177
+ // if (key === undefined || key === null) return;
178
+ // else return this.createNode(key, value, 'RED');
179
+ // }
180
+ //
181
+ // if (this.isKey(keyOrNodeOrEntryOrRawElement)) return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'RED');
182
+ //
183
+ // return ;
184
+ // }
185
+
175
186
  /**
176
187
  * Time Complexity: O(1)
177
188
  * Space Complexity: O(1)
@@ -198,17 +209,19 @@ export class RedBlackTree<
198
209
  * Time Complexity: O(log n)
199
210
  * Space Complexity: O(1)
200
211
  *
201
- * The function adds a new node to a Red-Black Tree data structure and returns a boolean indicating
202
- * whether the operation was successful.
203
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
204
- * entry.
205
- * @param {V} [value] - The `value` parameter is the value associated with the key that is being
206
- * added to the tree.
207
- * @returns The method is returning a boolean value. It returns true if the node was successfully
208
- * added or updated, and false otherwise.
209
- */
210
- override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
211
- const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
212
+ * The function adds a new node to a binary search tree and returns true if the node was successfully
213
+ * added.
214
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
215
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
216
+ * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
217
+ * the key in the data structure. It represents the value that you want to add or update in the data
218
+ * structure.
219
+ * @returns The method is returning a boolean value. If a new node is successfully added to the tree,
220
+ * the method returns true. If the node already exists and its value is updated, the method also
221
+ * returns true. If the node cannot be added or updated, the method returns false.
222
+ */
223
+ override add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
224
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
212
225
  if (!this.isRealNode(newNode)) return false;
213
226
 
214
227
  const insertStatus = this._insert(newNode);
@@ -234,16 +247,16 @@ export class RedBlackTree<
234
247
  * Time Complexity: O(log n)
235
248
  * Space Complexity: O(1)
236
249
  *
237
- * The function `delete` in a binary tree class deletes a node from the tree and fixes the tree if
238
- * necessary.
239
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the
240
- * identifier of the node that needs to be deleted from the binary tree. It can be of any type that
241
- * is returned by the callback function `C`. It can also be `null` or `undefined` if the node to be
242
- * deleted is not found.
243
- * @param {C} callback - The `callback` parameter is a function that is used to retrieve a node from
244
- * the binary tree based on its identifier. It is an optional parameter and if not provided, the
245
- * `_DEFAULT_CALLBACK` function is used as the default callback. The callback function should
246
- * return the identifier of the node to
250
+ * The function overrides the delete method of a binary tree data structure, allowing for the
251
+ * deletion of a node and maintaining the balance of the tree.
252
+ * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
253
+ * that identifies the node to be deleted from the binary tree. It can be of any type that is
254
+ * returned by the callback function `C`. It can also be `null` or `undefined` if there is no node to
255
+ * delete.
256
+ * @param {C} callback - The `callback` parameter is a function that is used to determine the
257
+ * equality of nodes in the binary tree. It is optional and has a default value of
258
+ * `this._DEFAULT_CALLBACK`. The type of the `callback` parameter is `C`, which is a generic type
259
+ * that extends the `BTNCallback
247
260
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
248
261
  */
249
262
  override delete<C extends BTNCallback<NODE>>(
@@ -307,6 +320,14 @@ export class RedBlackTree<
307
320
  }
308
321
 
309
322
  /**
323
+ * Time Complexity: O(1)
324
+ * Space Complexity: O(1)
325
+ */
326
+
327
+ /**
328
+ * Time Complexity: O(1)
329
+ * Space Complexity: O(1)
330
+ *
310
331
  * The function sets the root of a tree-like structure and updates the parent property of the new
311
332
  * root.
312
333
  * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
@@ -330,8 +351,8 @@ export class RedBlackTree<
330
351
  * The function replaces an old node with a new node while preserving the color of the old node.
331
352
  * @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
332
353
  * the data structure.
333
- * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the old node in
334
- * the data structure.
354
+ * @param {NODE} newNode - The `newNode` parameter is of type `NODE`, which represents a node in a
355
+ * data structure.
335
356
  * @returns The method is returning the result of calling the `_replaceNode` method from the
336
357
  * superclass, with the `oldNode` and `newNode` parameters.
337
358
  */
@@ -350,12 +371,13 @@ export class RedBlackTree<
350
371
  * Time Complexity: O(log n)
351
372
  * Space Complexity: O(1)
352
373
  *
353
- * The `_insert` function inserts or updates a node in a binary search tree and performs necessary
354
- * fix-ups to maintain the red-black tree properties.
355
- * @param {NODE} node - The `node` parameter represents the node that needs to be inserted into a
356
- * binary search tree. It contains a `key` property that is used to determine the position of the
357
- * node in the tree.
358
- * @returns {'inserted' | 'updated'} - The result of the insertion.
374
+ * The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
375
+ * maintain the red-black tree properties.
376
+ * @param {NODE} node - The `node` parameter represents the node that needs to be inserted into the
377
+ * binary search tree.
378
+ * @returns a string value indicating the result of the insertion operation. It can return either
379
+ * 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
380
+ * was created and inserted into the tree.
359
381
  */
360
382
  protected _insert(node: NODE): CRUD {
361
383
  let current = this.root;
@@ -363,9 +385,10 @@ export class RedBlackTree<
363
385
 
364
386
  while (this.isRealNode(current)) {
365
387
  parent = current;
366
- if (node.key < current.key) {
388
+ const compared = this.comparator(node.key, current.key);
389
+ if (compared < 0) {
367
390
  current = current.left ?? this.NIL;
368
- } else if (node.key > current.key) {
391
+ } else if (compared > 0) {
369
392
  current = current.right ?? this.NIL;
370
393
  } else {
371
394
  this._replaceNode(current, node);
@@ -429,8 +452,8 @@ export class RedBlackTree<
429
452
  * Space Complexity: O(1)
430
453
  *
431
454
  * The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
432
- * @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree. It can
433
- * either be a valid node object or `undefined`.
455
+ * @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
456
+ * structure. It can either be a valid node or `undefined`.
434
457
  */
435
458
  protected _insertFixup(z: NODE | undefined): void {
436
459
  // Continue fixing the tree as long as the parent of z is red
@@ -501,9 +524,10 @@ export class RedBlackTree<
501
524
  *
502
525
  * The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
503
526
  * the colors and performing rotations.
504
- * @param {NODE | undefined} node - The `node` parameter represents a node in a Red-Black Tree data
505
- * structure. It can be either a valid node object or `undefined`.
506
- * @returns The function does not return any value. It has a return type of `void`.
527
+ * @param {NODE | undefined} node - The `node` parameter represents a node in a binary tree. It can
528
+ * be either a valid node object or `undefined`.
529
+ * @returns The function does not return any value. It has a return type of `void`, which means it
530
+ * does not return anything.
507
531
  */
508
532
  protected _deleteFixup(node: NODE | undefined): void {
509
533
  // Early exit condition
@@ -656,21 +680,4 @@ export class RedBlackTree<
656
680
  x.right = y;
657
681
  y.parent = x;
658
682
  }
659
-
660
- /**
661
- * The function compares two values using a comparator function and returns whether the first value
662
- * is greater than, less than, or equal to the second value.
663
- * @param {K} a - The parameter "a" is of type K.
664
- * @param {K} b - The parameter "b" in the above code represents a K.
665
- * @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
666
- * than), 'LT' (less than), or 'EQ' (equal).
667
- */
668
- protected override _compare(a: K, b: K): CP {
669
- const extractedA = this.extractor(a);
670
- const extractedB = this.extractor(b);
671
- const compared = extractedA - extractedB;
672
- if (compared > 0) return 'GT';
673
- if (compared < 0) return 'LT';
674
- return 'EQ';
675
- }
676
683
  }