undirected-graph-typed 1.54.2 → 2.0.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 (84) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +14 -40
  2. package/dist/data-structures/base/iterable-element-base.js +14 -11
  3. package/dist/data-structures/base/linear-base.d.ts +277 -0
  4. package/dist/data-structures/base/linear-base.js +552 -0
  5. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
  6. package/dist/data-structures/binary-tree/avl-tree-counter.js +8 -7
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +23 -19
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +51 -38
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +89 -21
  10. package/dist/data-structures/binary-tree/avl-tree.js +76 -8
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +173 -225
  12. package/dist/data-structures/binary-tree/binary-tree.js +244 -149
  13. package/dist/data-structures/binary-tree/bst.d.ts +62 -56
  14. package/dist/data-structures/binary-tree/bst.js +89 -133
  15. package/dist/data-structures/binary-tree/red-black-tree.d.ts +19 -25
  16. package/dist/data-structures/binary-tree/red-black-tree.js +7 -13
  17. package/dist/data-structures/binary-tree/tree-counter.d.ts +19 -19
  18. package/dist/data-structures/binary-tree/tree-counter.js +12 -12
  19. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +186 -25
  20. package/dist/data-structures/binary-tree/tree-multi-map.js +211 -41
  21. package/dist/data-structures/graph/abstract-graph.js +2 -2
  22. package/dist/data-structures/heap/heap.d.ts +3 -11
  23. package/dist/data-structures/heap/heap.js +0 -10
  24. package/dist/data-structures/heap/max-heap.d.ts +2 -2
  25. package/dist/data-structures/heap/min-heap.d.ts +2 -2
  26. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
  27. package/dist/data-structures/linked-list/doubly-linked-list.js +131 -146
  28. package/dist/data-structures/linked-list/singly-linked-list.d.ts +79 -75
  29. package/dist/data-structures/linked-list/singly-linked-list.js +217 -169
  30. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  31. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
  32. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -2
  33. package/dist/data-structures/queue/deque.d.ts +130 -91
  34. package/dist/data-structures/queue/deque.js +269 -169
  35. package/dist/data-structures/queue/queue.d.ts +84 -40
  36. package/dist/data-structures/queue/queue.js +134 -50
  37. package/dist/data-structures/stack/stack.d.ts +3 -11
  38. package/dist/data-structures/stack/stack.js +0 -10
  39. package/dist/data-structures/trie/trie.d.ts +4 -3
  40. package/dist/data-structures/trie/trie.js +3 -0
  41. package/dist/types/data-structures/base/base.d.ts +9 -4
  42. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
  43. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  44. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  45. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  46. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  47. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  48. package/dist/types/data-structures/queue/deque.d.ts +2 -3
  49. package/dist/types/data-structures/queue/queue.d.ts +2 -2
  50. package/dist/utils/utils.d.ts +2 -2
  51. package/package.json +2 -2
  52. package/src/data-structures/base/iterable-element-base.ts +29 -20
  53. package/src/data-structures/base/linear-base.ts +649 -0
  54. package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
  55. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +74 -49
  56. package/src/data-structures/binary-tree/avl-tree.ts +99 -29
  57. package/src/data-structures/binary-tree/binary-tree.ts +474 -257
  58. package/src/data-structures/binary-tree/bst.ts +150 -152
  59. package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
  60. package/src/data-structures/binary-tree/tree-counter.ts +33 -27
  61. package/src/data-structures/binary-tree/tree-multi-map.ts +235 -53
  62. package/src/data-structures/graph/abstract-graph.ts +2 -2
  63. package/src/data-structures/heap/heap.ts +3 -14
  64. package/src/data-structures/heap/max-heap.ts +2 -2
  65. package/src/data-structures/heap/min-heap.ts +2 -2
  66. package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
  67. package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
  68. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
  69. package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
  70. package/src/data-structures/priority-queue/priority-queue.ts +2 -2
  71. package/src/data-structures/queue/deque.ts +286 -183
  72. package/src/data-structures/queue/queue.ts +149 -63
  73. package/src/data-structures/stack/stack.ts +3 -18
  74. package/src/data-structures/trie/trie.ts +7 -3
  75. package/src/types/data-structures/base/base.ts +17 -8
  76. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
  78. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  79. package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
  80. package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
  81. package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
  82. package/src/types/data-structures/queue/deque.ts +2 -3
  83. package/src/types/data-structures/queue/queue.ts +2 -2
  84. package/src/utils/utils.ts +2 -2
@@ -1,17 +1,10 @@
1
- import type {
2
- BinaryTreeDeleteResult,
3
- BTNRep,
4
- CRUD,
5
- EntryCallback,
6
- OptNode,
7
- OptNodeOrNull,
8
- RBTNColor,
9
- RedBlackTreeOptions
10
- } from '../../types';
1
+ import type { BinaryTreeDeleteResult, CRUD, EntryCallback, OptNode, RBTNColor, RedBlackTreeOptions } from '../../types';
11
2
  import { BST, BSTNode } from './bst';
12
3
  import { IBinaryTree } from '../../interfaces';
13
4
 
14
5
  export class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
6
+ override parent?: RedBlackTreeNode<K, V> = undefined;
7
+
15
8
  /**
16
9
  * The constructor initializes a node with a key, value, and color for a Red-Black Tree.
17
10
  * @param {K} key - The `key` parameter is a key of type `K` that is used to identify the node in a
@@ -27,28 +20,26 @@ export class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
27
20
  this._color = color;
28
21
  }
29
22
 
30
- override parent?: RedBlackTreeNode<K, V> = undefined;
23
+ override _left?: RedBlackTreeNode<K, V> | null | undefined = undefined;
31
24
 
32
- override _left?: OptNodeOrNull<RedBlackTreeNode<K, V>> = undefined;
33
-
34
- override get left(): OptNodeOrNull<RedBlackTreeNode<K, V>> {
25
+ override get left(): RedBlackTreeNode<K, V> | null | undefined {
35
26
  return this._left;
36
27
  }
37
28
 
38
- override set left(v: OptNodeOrNull<RedBlackTreeNode<K, V>>) {
29
+ override set left(v: RedBlackTreeNode<K, V> | null | undefined) {
39
30
  if (v) {
40
31
  v.parent = this;
41
32
  }
42
33
  this._left = v;
43
34
  }
44
35
 
45
- override _right?: OptNodeOrNull<RedBlackTreeNode<K, V>> = undefined;
36
+ override _right?: RedBlackTreeNode<K, V> | null | undefined = undefined;
46
37
 
47
- override get right(): OptNodeOrNull<RedBlackTreeNode<K, V>> {
38
+ override get right(): RedBlackTreeNode<K, V> | null | undefined {
48
39
  return this._right;
49
40
  }
50
41
 
51
- override set right(v: OptNodeOrNull<RedBlackTreeNode<K, V>>) {
42
+ override set right(v: RedBlackTreeNode<K, V> | null | undefined) {
52
43
  if (v) {
53
44
  v.parent = this;
54
45
  }
@@ -60,12 +51,6 @@ export class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
60
51
  * 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high but the query efficiency is slightly lower.
61
52
  * 2. It is BST itself. Compared with Heap which is not completely ordered, RedBlackTree is completely ordered.
62
53
  * @example
63
- * // Find elements in a range
64
- * const bst = new RedBlackTree<number>([10, 5, 15, 3, 7, 12, 18]);
65
- * console.log(bst.search(new Range(5, 10))); // [5, 10, 7]
66
- * console.log(bst.search(new Range(4, 12))); // [5, 10, 12, 7]
67
- * console.log(bst.search(new Range(15, 20))); // [15, 18]
68
- * @example
69
54
  * // using Red-Black Tree as a price-based index for stock data
70
55
  * // Define the structure of individual stock records
71
56
  * interface StockRecord {
@@ -107,7 +92,7 @@ export class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
107
92
  * [200, 400], // Price range
108
93
  * node => priceIndex.get(node)?.symbol // Extract stock symbols for the result
109
94
  * );
110
- * console.log(stocksInRange); // ['GOOGL', 'MSFT', 'META']
95
+ * console.log(stocksInRange); // ['GOOGL', 'META', 'MSFT']
111
96
  */
112
97
  export class RedBlackTree<K = any, V = any, R = object, MK = any, MV = any, MR = object>
113
98
  extends BST<K, V, R, MK, MV, MR>
@@ -117,7 +102,7 @@ export class RedBlackTree<K = any, V = any, R = object, MK = any, MV = any, MR =
117
102
  * This TypeScript constructor initializes a Red-Black Tree with optional keys, nodes, entries, or
118
103
  * raw data.
119
104
  * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
120
- * iterable that can contain either `BTNRep<K, V, RedBlackTreeNode<K, V>>` objects or `R` objects. It
105
+ * iterable that can contain either `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined` objects or `R` objects. It
121
106
  * is used to initialize the Red-Black Tree with keys, nodes, entries, or
122
107
  * @param [options] - The `options` parameter in the constructor is of type `RedBlackTreeOptions<K,
123
108
  * V, R>`. It is an optional parameter that allows you to specify additional options for the
@@ -125,7 +110,9 @@ export class RedBlackTree<K = any, V = any, R = object, MK = any, MV = any, MR =
125
110
  * any other parameters that are specific to
126
111
  */
127
112
  constructor(
128
- keysNodesEntriesOrRaws: Iterable<BTNRep<K, V, RedBlackTreeNode<K, V>> | R> = [],
113
+ keysNodesEntriesOrRaws: Iterable<
114
+ K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
115
+ > = [],
129
116
  options?: RedBlackTreeOptions<K, V, R>
130
117
  ) {
131
118
  super([], options);
@@ -188,12 +175,14 @@ export class RedBlackTree<K = any, V = any, R = object, MK = any, MV = any, MR =
188
175
  * Space Complexity: O(1)
189
176
  *
190
177
  * The function checks if the input is an instance of the RedBlackTreeNode class.
191
- * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
192
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
178
+ * @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
179
+ * `keyNodeOrEntry` can be of type `R` or `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
193
180
  * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
194
181
  * an instance of the `RedBlackTreeNode` class.
195
182
  */
196
- override isNode(keyNodeOrEntry: BTNRep<K, V, RedBlackTreeNode<K, V>>): keyNodeOrEntry is RedBlackTreeNode<K, V> {
183
+ override isNode(
184
+ keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
185
+ ): keyNodeOrEntry is RedBlackTreeNode<K, V> {
197
186
  return keyNodeOrEntry instanceof RedBlackTreeNode;
198
187
  }
199
188
 
@@ -215,8 +204,8 @@ export class RedBlackTree<K = any, V = any, R = object, MK = any, MV = any, MR =
215
204
  *
216
205
  * The function adds a new node to a binary search tree and returns true if the node was successfully
217
206
  * added.
218
- * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
219
- * `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
207
+ * @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
208
+ * `keyNodeOrEntry` can accept a value of type `R` or `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
220
209
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
221
210
  * the key in the data structure. It represents the value that you want to add or update in the data
222
211
  * structure.
@@ -224,7 +213,10 @@ export class RedBlackTree<K = any, V = any, R = object, MK = any, MV = any, MR =
224
213
  * the method returns true. If the node already exists and its value is updated, the method also
225
214
  * returns true. If the node cannot be added or updated, the method returns false.
226
215
  */
227
- override add(keyNodeOrEntry: BTNRep<K, V, RedBlackTreeNode<K, V>>, value?: V): boolean {
216
+ override add(
217
+ keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
218
+ value?: V
219
+ ): boolean {
228
220
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
229
221
  if (!this.isRealNode(newNode)) return false;
230
222
 
@@ -254,7 +246,7 @@ export class RedBlackTree<K = any, V = any, R = object, MK = any, MV = any, MR =
254
246
  *
255
247
  * The function overrides the delete method in a binary tree data structure to remove a node based on
256
248
  * a given predicate and maintain the binary search tree properties.
257
- * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
249
+ * @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
258
250
  * parameter in the `override delete` method is used to specify the condition or key based on which a
259
251
  * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
260
252
  * function that determines which node(s) should be deleted.
@@ -263,7 +255,7 @@ export class RedBlackTree<K = any, V = any, R = object, MK = any, MV = any, MR =
263
255
  * balancing is needed.
264
256
  */
265
257
  override delete(
266
- keyNodeOrEntry: BTNRep<K, V, RedBlackTreeNode<K, V>>
258
+ keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
267
259
  ): BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>[] {
268
260
  if (keyNodeOrEntry === null) return [];
269
261
 
@@ -8,11 +8,9 @@
8
8
  import type {
9
9
  BinaryTreeDeleteResult,
10
10
  BSTNOptKeyOrNode,
11
- BTNRep,
12
11
  EntryCallback,
13
12
  IterationType,
14
13
  OptNode,
15
- OptNodeOrNull,
16
14
  RBTNColor,
17
15
  TreeCounterOptions
18
16
  } from '../../types';
@@ -20,6 +18,8 @@ import { IBinaryTree } from '../../interfaces';
20
18
  import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
21
19
 
22
20
  export class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<K, V> {
21
+ override parent?: TreeCounterNode<K, V> = undefined;
22
+
23
23
  /**
24
24
  * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
25
25
  * @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
@@ -37,28 +37,26 @@ export class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<K, V> {
37
37
  this.count = count;
38
38
  }
39
39
 
40
- override parent?: TreeCounterNode<K, V> = undefined;
41
-
42
- override _left?: OptNodeOrNull<TreeCounterNode<K, V>> = undefined;
40
+ override _left?: TreeCounterNode<K, V> | null | undefined = undefined;
43
41
 
44
- override get left(): OptNodeOrNull<TreeCounterNode<K, V>> {
42
+ override get left(): TreeCounterNode<K, V> | null | undefined {
45
43
  return this._left;
46
44
  }
47
45
 
48
- override set left(v: OptNodeOrNull<TreeCounterNode<K, V>>) {
46
+ override set left(v: TreeCounterNode<K, V> | null | undefined) {
49
47
  if (v) {
50
48
  v.parent = this;
51
49
  }
52
50
  this._left = v;
53
51
  }
54
52
 
55
- override _right?: OptNodeOrNull<TreeCounterNode<K, V>> = undefined;
53
+ override _right?: TreeCounterNode<K, V> | null | undefined = undefined;
56
54
 
57
- override get right(): OptNodeOrNull<TreeCounterNode<K, V>> {
55
+ override get right(): TreeCounterNode<K, V> | null | undefined {
58
56
  return this._right;
59
57
  }
60
58
 
61
- override set right(v: OptNodeOrNull<TreeCounterNode<K, V>>) {
59
+ override set right(v: TreeCounterNode<K, V> | null | undefined) {
62
60
  if (v) {
63
61
  v.parent = this;
64
62
  }
@@ -83,7 +81,9 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
83
81
  * `compareValues`, which are functions used to compare keys and values respectively.
84
82
  */
85
83
  constructor(
86
- keysNodesEntriesOrRaws: Iterable<BTNRep<K, V, TreeCounterNode<K, V>> | R> = [],
84
+ keysNodesEntriesOrRaws: Iterable<
85
+ K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
86
+ > = [],
87
87
  options?: TreeCounterOptions<K, V, R>
88
88
  ) {
89
89
  super([], options);
@@ -111,7 +111,7 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
111
111
  */
112
112
  getComputedCount(): number {
113
113
  let sum = 0;
114
- this.dfs(node => (sum += node.count));
114
+ this.dfs(node => (sum += node ? node.count : 0));
115
115
  return sum;
116
116
  }
117
117
 
@@ -152,12 +152,14 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
152
152
 
153
153
  /**
154
154
  * The function checks if the input is an instance of the TreeCounterNode class.
155
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
156
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
155
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
156
+ * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
157
157
  * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
158
158
  * an instance of the `TreeCounterNode` class.
159
159
  */
160
- override isNode(keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>): keyNodeOrEntry is TreeCounterNode<K, V> {
160
+ override isNode(
161
+ keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
162
+ ): keyNodeOrEntry is TreeCounterNode<K, V> {
161
163
  return keyNodeOrEntry instanceof TreeCounterNode;
162
164
  }
163
165
 
@@ -167,7 +169,7 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
167
169
  *
168
170
  * The function overrides the add method of a class and adds a new node to a data structure, updating
169
171
  * the count and returning a boolean indicating success.
170
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The
172
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
171
173
  * `keyNodeOrEntry` parameter can accept one of the following types:
172
174
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
173
175
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -177,7 +179,11 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
177
179
  * @returns The method is returning a boolean value. It returns true if the addition of the new node
178
180
  * was successful, and false otherwise.
179
181
  */
180
- override add(keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>, value?: V, count = 1): boolean {
182
+ override add(
183
+ keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
184
+ value?: V,
185
+ count = 1
186
+ ): boolean {
181
187
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
182
188
  const orgCount = newNode?.count || 0;
183
189
  const isSuccessAdded = super.add(newNode, newValue);
@@ -196,7 +202,7 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
196
202
  *
197
203
  * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
198
204
  * structure, handling cases where nodes have children and maintaining balance in the tree.
199
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
205
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
200
206
  * parameter in the `delete` method is used to specify the condition or key based on which a node
201
207
  * should be deleted from the binary tree. It can be a key, a node, or an entry.
202
208
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
@@ -206,7 +212,7 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
206
212
  * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<TreeCounterNode<K, V>>` objects.
207
213
  */
208
214
  override delete(
209
- keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>,
215
+ keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
210
216
  ignoreCount = false
211
217
  ): BinaryTreeDeleteResult<TreeCounterNode<K, V>>[] {
212
218
  if (keyNodeOrEntry === null) return [];
@@ -340,8 +346,8 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
340
346
  if (l > r) return;
341
347
  const m = l + Math.floor((r - l) / 2);
342
348
  const midNode = sorted[m];
343
- if (this._isMapMode) this.add(midNode.key, undefined, midNode.count);
344
- else this.add(midNode.key, midNode.value, midNode.count);
349
+ if (this._isMapMode && midNode !== null) this.add(midNode.key, undefined, midNode.count);
350
+ else if (midNode !== null) this.add(midNode.key, midNode.value, midNode.count);
345
351
  buildBalanceBST(l, m - 1);
346
352
  buildBalanceBST(m + 1, r);
347
353
  };
@@ -357,8 +363,8 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
357
363
  if (l <= r) {
358
364
  const m = l + Math.floor((r - l) / 2);
359
365
  const midNode = sorted[m];
360
- if (this._isMapMode) this.add(midNode.key, undefined, midNode.count);
361
- else this.add(midNode.key, midNode.value, midNode.count);
366
+ if (this._isMapMode && midNode !== null) this.add(midNode.key, undefined, midNode.count);
367
+ else if (midNode !== null) this.add(midNode.key, midNode.value, midNode.count);
362
368
  stack.push([m + 1, r]);
363
369
  stack.push([l, m - 1]);
364
370
  }
@@ -377,7 +383,7 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
377
383
  */
378
384
  override clone() {
379
385
  const cloned = this.createTree();
380
- this.bfs(node => cloned.add(node.key, undefined, node.count));
386
+ this.bfs(node => cloned.add(node === null ? null : node.key, undefined, node === null ? 0 : node.count));
381
387
  if (this._isMapMode) cloned._store = this._store;
382
388
  return cloned;
383
389
  }
@@ -413,8 +419,8 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
413
419
  /**
414
420
  * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
415
421
  * node based on the input.
416
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
417
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
422
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
423
+ * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
418
424
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
419
425
  * associated with the key in the node. It is used when creating a new node or updating the value of
420
426
  * an existing node.
@@ -423,7 +429,7 @@ export class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR =
423
429
  * @returns either a TreeCounterNode<K, V> object or undefined.
424
430
  */
425
431
  protected override _keyValueNodeOrEntryToNodeAndValue(
426
- keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>,
432
+ keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
427
433
  value?: V,
428
434
  count = 1
429
435
  ): [TreeCounterNode<K, V> | undefined, V | undefined] {