deque-typed 1.52.9 → 1.53.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 (27) hide show
  1. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +21 -21
  2. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +63 -46
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +20 -20
  4. package/dist/data-structures/binary-tree/avl-tree.js +28 -26
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +186 -144
  6. package/dist/data-structures/binary-tree/binary-tree.js +375 -264
  7. package/dist/data-structures/binary-tree/bst.d.ts +56 -56
  8. package/dist/data-structures/binary-tree/bst.js +105 -77
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -13
  10. package/dist/data-structures/binary-tree/rb-tree.js +35 -33
  11. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +21 -21
  12. package/dist/data-structures/binary-tree/tree-multi-map.js +58 -48
  13. package/dist/data-structures/trie/trie.js +3 -3
  14. package/dist/interfaces/binary-tree.d.ts +5 -5
  15. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +13 -13
  16. package/dist/types/data-structures/binary-tree/bst.d.ts +3 -3
  17. package/package.json +2 -2
  18. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +59 -53
  19. package/src/data-structures/binary-tree/avl-tree.ts +31 -34
  20. package/src/data-structures/binary-tree/binary-tree.ts +439 -359
  21. package/src/data-structures/binary-tree/bst.ts +142 -112
  22. package/src/data-structures/binary-tree/rb-tree.ts +37 -41
  23. package/src/data-structures/binary-tree/tree-multi-map.ts +56 -60
  24. package/src/data-structures/trie/trie.ts +3 -3
  25. package/src/interfaces/binary-tree.ts +6 -6
  26. package/src/types/data-structures/binary-tree/binary-tree.ts +14 -15
  27. package/src/types/data-structures/binary-tree/bst.ts +4 -4
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, IterationType, BTNEntry } from '../../types';
8
+ import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNOptKeyOrNode, BTNRep, IterationType } from '../../types';
9
9
  import { IBinaryTree } from '../../interfaces';
10
10
  import { AVLTree, AVLTreeNode } from './avl-tree';
11
11
  export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
@@ -36,16 +36,16 @@ export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeM
36
36
  /**
37
37
  * The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
38
38
  */
39
- export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMapNested<K, V, R, NODE>>> extends AVLTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
39
+ export declare class AVLTreeMultiMap<K = any, V = any, R = object, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMapNested<K, V, R, NODE>>> extends AVLTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
40
40
  /**
41
41
  * The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
42
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
42
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
43
43
  * iterable object that can contain either keys, nodes, entries, or raw elements.
44
44
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
45
45
  * behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
46
46
  * `compareValues` functions to define custom comparison logic for keys and values, respectively.
47
47
  */
48
- constructor(keysOrNodesOrEntriesOrRaws?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K, V, R>);
48
+ constructor(keysNodesEntriesOrRaws?: Iterable<R | BTNRep<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K, V, R>);
49
49
  protected _count: number;
50
50
  /**
51
51
  * The function calculates the sum of the count property of all nodes in a tree using depth-first
@@ -84,17 +84,17 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
84
84
  createTree(options?: AVLTreeMultiMapOptions<K, V, R>): TREE;
85
85
  /**
86
86
  * The function checks if the input is an instance of AVLTreeMultiMapNode.
87
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
88
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
89
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
87
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
88
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
89
+ * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
90
90
  * an instance of the `AVLTreeMultiMapNode` class.
91
91
  */
92
- isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
92
+ isNode(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is NODE;
93
93
  /**
94
- * The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
94
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
95
95
  * a node object.
96
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
97
- * `keyOrNodeOrEntryOrRaw` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
96
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
97
+ * `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
98
98
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
99
99
  * `override` function. It represents the value associated with the key in the data structure. If no
100
100
  * value is provided, it will default to `undefined`.
@@ -102,16 +102,16 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
102
102
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
103
103
  * @returns either a NODE object or undefined.
104
104
  */
105
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): NODE | undefined;
105
+ keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V, count?: number): [NODE | undefined, V | undefined];
106
106
  /**
107
107
  * Time Complexity: O(log n)
108
108
  * Space Complexity: O(1)
109
109
  *
110
110
  * The function overrides the add method of a TypeScript class to add a new node to a data structure
111
111
  * and update the count.
112
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
113
- * `keyOrNodeOrEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
114
- * can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
112
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
113
+ * `keyNodeEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
114
+ * can also accept a value of type `BTNRep<K, V, NODE>`, which represents a key, node,
115
115
  * entry, or raw element
116
116
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
117
117
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -120,14 +120,14 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
120
120
  * be added once. However, you can specify a different value for `count` if you want to add
121
121
  * @returns a boolean value.
122
122
  */
123
- add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): boolean;
123
+ add(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V, count?: number): boolean;
124
124
  /**
125
125
  * Time Complexity: O(log n)
126
126
  * Space Complexity: O(1)
127
127
  *
128
128
  * The function overrides the delete method in a binary tree data structure, handling deletion of
129
129
  * nodes and maintaining balance in the tree.
130
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
130
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `predicate`
131
131
  * parameter in the `delete` method is used to specify the condition for deleting a node from the
132
132
  * binary tree. It can be a key, node, or entry that determines which
133
133
  * node(s) should be deleted.
@@ -140,7 +140,7 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
140
140
  * method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
141
141
  * deleted node and whether balancing is needed in the tree.
142
142
  */
143
- delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
143
+ delete(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
144
144
  /**
145
145
  * Time Complexity: O(1)
146
146
  * Space Complexity: O(1)
@@ -176,14 +176,14 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
176
176
  *
177
177
  * The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
178
178
  * in a binary search tree.
179
- * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
179
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
180
180
  * that will be swapped with the `destNode`.
181
- * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
181
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
182
182
  * node where the properties will be swapped with the source node.
183
183
  * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
184
184
  * If either `srcNode` or `destNode` is undefined, it returns `undefined`.
185
185
  */
186
- protected _swapProperties(srcNode: R | BSTNKeyOrNode<K, NODE>, destNode: R | BSTNKeyOrNode<K, NODE>): NODE | undefined;
186
+ protected _swapProperties(srcNode: R | BSTNOptKeyOrNode<K, NODE>, destNode: R | BSTNOptKeyOrNode<K, NODE>): NODE | undefined;
187
187
  /**
188
188
  * Time Complexity: O(1)
189
189
  * Space Complexity: O(1)
@@ -41,17 +41,17 @@ exports.AVLTreeMultiMapNode = AVLTreeMultiMapNode;
41
41
  class AVLTreeMultiMap extends avl_tree_1.AVLTree {
42
42
  /**
43
43
  * The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
44
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
44
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
45
45
  * iterable object that can contain either keys, nodes, entries, or raw elements.
46
46
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
47
47
  * behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
48
48
  * `compareValues` functions to define custom comparison logic for keys and values, respectively.
49
49
  */
50
- constructor(keysOrNodesOrEntriesOrRaws = [], options) {
50
+ constructor(keysNodesEntriesOrRaws = [], options) {
51
51
  super([], options);
52
52
  this._count = 0;
53
- if (keysOrNodesOrEntriesOrRaws)
54
- this.addMany(keysOrNodesOrEntriesOrRaws);
53
+ if (keysNodesEntriesOrRaws)
54
+ this.addMany(keysNodesEntriesOrRaws);
55
55
  }
56
56
  /**
57
57
  * The function calculates the sum of the count property of all nodes in a tree using depth-first
@@ -96,23 +96,23 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
96
96
  * object.
97
97
  */
98
98
  createTree(options) {
99
- return new AVLTreeMultiMap([], Object.assign({ iterationType: this.iterationType, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
99
+ return new AVLTreeMultiMap([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
100
100
  }
101
101
  /**
102
102
  * The function checks if the input is an instance of AVLTreeMultiMapNode.
103
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
104
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
105
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
103
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
104
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
105
+ * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
106
106
  * an instance of the `AVLTreeMultiMapNode` class.
107
107
  */
108
- isNode(keyOrNodeOrEntryOrRaw) {
109
- return keyOrNodeOrEntryOrRaw instanceof AVLTreeMultiMapNode;
108
+ isNode(keyNodeEntryOrRaw) {
109
+ return keyNodeEntryOrRaw instanceof AVLTreeMultiMapNode;
110
110
  }
111
111
  /**
112
- * The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
112
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
113
113
  * a node object.
114
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
115
- * `keyOrNodeOrEntryOrRaw` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
114
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
115
+ * `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
116
116
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
117
117
  * `override` function. It represents the value associated with the key in the data structure. If no
118
118
  * value is provided, it will default to `undefined`.
@@ -120,26 +120,30 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
120
120
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
121
121
  * @returns either a NODE object or undefined.
122
122
  */
123
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count = 1) {
124
- if (keyOrNodeOrEntryOrRaw === undefined || keyOrNodeOrEntryOrRaw === null)
125
- return;
126
- if (this.isNode(keyOrNodeOrEntryOrRaw))
127
- return keyOrNodeOrEntryOrRaw;
128
- if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
129
- const [key, entryValue] = keyOrNodeOrEntryOrRaw;
123
+ keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
124
+ if (keyNodeEntryOrRaw === undefined || keyNodeEntryOrRaw === null)
125
+ return [undefined, undefined];
126
+ if (this.isNode(keyNodeEntryOrRaw))
127
+ return [keyNodeEntryOrRaw, value];
128
+ if (this.isEntry(keyNodeEntryOrRaw)) {
129
+ const [key, entryValue] = keyNodeEntryOrRaw;
130
130
  if (key === undefined || key === null)
131
- return;
132
- if (this.isKey(key))
133
- return this.createNode(key, value !== null && value !== void 0 ? value : entryValue, count);
131
+ return [undefined, undefined];
132
+ const finalValue = value !== null && value !== void 0 ? value : entryValue;
133
+ return [this.createNode(key, finalValue, count), finalValue];
134
134
  }
135
- if (this._toEntryFn) {
136
- const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
137
- if (this.isKey(key))
138
- return this.createNode(key, value !== null && value !== void 0 ? value : entryValue, count);
135
+ if (this.isKey(keyNodeEntryOrRaw))
136
+ return [this.createNode(keyNodeEntryOrRaw, value, count), value];
137
+ if (this.isRaw(keyNodeEntryOrRaw)) {
138
+ if (this._toEntryFn) {
139
+ const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
140
+ const finalValue = value !== null && value !== void 0 ? value : entryValue;
141
+ if (this.isKey(key))
142
+ return [this.createNode(key, finalValue, count), finalValue];
143
+ }
144
+ return [undefined, undefined];
139
145
  }
140
- if (this.isKey(keyOrNodeOrEntryOrRaw))
141
- return this.createNode(keyOrNodeOrEntryOrRaw, value, count);
142
- return;
146
+ return [undefined, undefined];
143
147
  }
144
148
  /**
145
149
  * Time Complexity: O(log n)
@@ -147,9 +151,9 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
147
151
  *
148
152
  * The function overrides the add method of a TypeScript class to add a new node to a data structure
149
153
  * and update the count.
150
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
151
- * `keyOrNodeOrEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
152
- * can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
154
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
155
+ * `keyNodeEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
156
+ * can also accept a value of type `BTNRep<K, V, NODE>`, which represents a key, node,
153
157
  * entry, or raw element
154
158
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
155
159
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -158,12 +162,12 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
158
162
  * be added once. However, you can specify a different value for `count` if you want to add
159
163
  * @returns a boolean value.
160
164
  */
161
- add(keyOrNodeOrEntryOrRaw, value, count = 1) {
162
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
165
+ add(keyNodeEntryOrRaw, value, count = 1) {
166
+ const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
163
167
  if (newNode === undefined)
164
168
  return false;
165
169
  const orgNodeCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
166
- const inserted = super.add(newNode);
170
+ const inserted = super.add(newNode, newValue);
167
171
  if (inserted) {
168
172
  this._count += orgNodeCount;
169
173
  }
@@ -175,7 +179,7 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
175
179
  *
176
180
  * The function overrides the delete method in a binary tree data structure, handling deletion of
177
181
  * nodes and maintaining balance in the tree.
178
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
182
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `predicate`
179
183
  * parameter in the `delete` method is used to specify the condition for deleting a node from the
180
184
  * binary tree. It can be a key, node, or entry that determines which
181
185
  * node(s) should be deleted.
@@ -188,12 +192,12 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
188
192
  * method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
189
193
  * deleted node and whether balancing is needed in the tree.
190
194
  */
191
- delete(keyOrNodeOrEntryOrRaw, ignoreCount = false) {
195
+ delete(keyNodeEntryOrRaw, ignoreCount = false) {
192
196
  var _a;
193
197
  const deletedResult = [];
194
198
  if (!this.root)
195
199
  return deletedResult;
196
- const curr = (_a = this.getNode(keyOrNodeOrEntryOrRaw)) !== null && _a !== void 0 ? _a : undefined;
200
+ const curr = (_a = this.getNode(keyNodeEntryOrRaw)) !== null && _a !== void 0 ? _a : undefined;
197
201
  if (!curr)
198
202
  return deletedResult;
199
203
  const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : undefined;
@@ -280,7 +284,10 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
280
284
  return;
281
285
  const m = l + Math.floor((r - l) / 2);
282
286
  const midNode = sorted[m];
283
- this.add(midNode.key, midNode.value, midNode.count);
287
+ if (this._isMapMode)
288
+ this.add(midNode.key, undefined, midNode.count);
289
+ else
290
+ this.add(midNode.key, midNode.value, midNode.count);
284
291
  buildBalanceBST(l, m - 1);
285
292
  buildBalanceBST(m + 1, r);
286
293
  };
@@ -296,7 +303,10 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
296
303
  if (l <= r) {
297
304
  const m = l + Math.floor((r - l) / 2);
298
305
  const midNode = sorted[m];
299
- this.add(midNode.key, midNode.value, midNode.count);
306
+ if (this._isMapMode)
307
+ this.add(midNode.key, undefined, midNode.count);
308
+ else
309
+ this.add(midNode.key, midNode.value, midNode.count);
300
310
  stack.push([m + 1, r]);
301
311
  stack.push([l, m - 1]);
302
312
  }
@@ -314,7 +324,12 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
314
324
  */
315
325
  clone() {
316
326
  const cloned = this.createTree();
317
- this.bfs(node => cloned.add(node.key, node.value, node.count));
327
+ if (this._isMapMode)
328
+ this.bfs(node => cloned.add(node.key, undefined, node.count));
329
+ else
330
+ this.bfs(node => cloned.add(node.key, node.value, node.count));
331
+ if (this._isMapMode)
332
+ cloned._store = this._store;
318
333
  return cloned;
319
334
  }
320
335
  /**
@@ -323,9 +338,9 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
323
338
  *
324
339
  * The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
325
340
  * in a binary search tree.
326
- * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
341
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
327
342
  * that will be swapped with the `destNode`.
328
- * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
343
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
329
344
  * node where the properties will be swapped with the source node.
330
345
  * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
331
346
  * If either `srcNode` or `destNode` is undefined, it returns `undefined`.
@@ -339,11 +354,13 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
339
354
  if (tempNode) {
340
355
  tempNode.height = height;
341
356
  destNode.key = srcNode.key;
342
- destNode.value = srcNode.value;
357
+ if (!this._isMapMode)
358
+ destNode.value = srcNode.value;
343
359
  destNode.count = srcNode.count;
344
360
  destNode.height = srcNode.height;
345
361
  srcNode.key = tempNode.key;
346
- srcNode.value = tempNode.value;
362
+ if (!this._isMapMode)
363
+ srcNode.value = tempNode.value;
347
364
  srcNode.count = tempNode.count;
348
365
  srcNode.height = tempNode.height;
349
366
  }
@@ -6,7 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNEntry } from '../../types';
9
+ import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNOptKeyOrNode, BTNRep } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
12
12
  /**
@@ -40,11 +40,11 @@ export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V
40
40
  * 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
41
41
  * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
42
42
  */
43
- export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
43
+ export declare class AVLTree<K = any, V = any, R = object, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, R, NODE, TREE> = AVLTree<K, V, R, NODE, AVLTreeNested<K, V, R, NODE>>> extends BST<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
44
44
  /**
45
45
  * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
46
46
  * entries, or raw elements.
47
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
47
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
48
48
  * iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
49
49
  * be used to initialize the AVLTree.
50
50
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
@@ -52,7 +52,7 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
52
52
  * keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
53
53
  * `nodeBuilder` (
54
54
  */
55
- constructor(keysOrNodesOrEntriesOrRaws?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeOptions<K, V, R>);
55
+ constructor(keysNodesEntriesOrRaws?: Iterable<R | BTNRep<K, V, NODE>>, options?: AVLTreeOptions<K, V, R>);
56
56
  /**
57
57
  * The function creates a new AVL tree node with the given key and value.
58
58
  * @param {K} key - The key parameter is of type K, which represents the key of the node being
@@ -73,54 +73,54 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
73
73
  createTree(options?: AVLTreeOptions<K, V, R>): TREE;
74
74
  /**
75
75
  * The function checks if the input is an instance of AVLTreeNode.
76
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
77
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
78
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
76
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
77
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
78
+ * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
79
79
  * an instance of the `AVLTreeNode` class.
80
80
  */
81
- isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
81
+ isNode(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is NODE;
82
82
  /**
83
83
  * Time Complexity: O(log n)
84
84
  * Space Complexity: O(1)
85
85
  *
86
86
  * The function overrides the add method of a class and inserts a key-value pair into a data
87
87
  * structure, then balances the path.
88
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
89
- * `keyOrNodeOrEntryOrRaw` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
88
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
89
+ * `keyNodeEntryOrRaw` can accept values of type `R`, `BTNRep<K, V, NODE>`, or
90
90
  * `RawElement`.
91
91
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
92
92
  * the key or node being added to the data structure.
93
93
  * @returns The method is returning a boolean value.
94
94
  */
95
- add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): boolean;
95
+ add(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): boolean;
96
96
  /**
97
97
  * Time Complexity: O(log n)
98
98
  * Space Complexity: O(1)
99
99
  *
100
100
  * The function overrides the delete method in a TypeScript class, performs deletion, and then
101
101
  * balances the tree if necessary.
102
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
102
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
103
103
  * parameter in the `override delete` method can be one of the following types:
104
104
  * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
105
105
  * method from the superclass (presumably a parent class) with the provided `predicate`, which could
106
106
  * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
107
107
  * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
108
108
  */
109
- delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
109
+ delete(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
110
110
  /**
111
111
  * Time Complexity: O(1)
112
112
  * Space Complexity: O(1)
113
113
  *
114
114
  * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
115
115
  * binary search tree.
116
- * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
116
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
117
117
  * object (`NODE`) or a key-value pair (`R`) that is being swapped with another node.
118
- * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
119
- * `R` or an instance of `BSTNKeyOrNode<K, NODE>`.
118
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
119
+ * `R` or an instance of `BSTNOptKeyOrNode<K, NODE>`.
120
120
  * @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
121
121
  * `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
122
122
  */
123
- protected _swapProperties(srcNode: R | BSTNKeyOrNode<K, NODE>, destNode: R | BSTNKeyOrNode<K, NODE>): NODE | undefined;
123
+ protected _swapProperties(srcNode: R | BSTNOptKeyOrNode<K, NODE>, destNode: R | BSTNOptKeyOrNode<K, NODE>): NODE | undefined;
124
124
  /**
125
125
  * Time Complexity: O(1)
126
126
  * Space Complexity: O(1)
@@ -179,10 +179,10 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
179
179
  *
180
180
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
181
181
  * to restore balance in an AVL tree after inserting a node.
182
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
183
- * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
182
+ * @param {BTNRep<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
183
+ * `BTNRep<K, V, NODE>`.
184
184
  */
185
- protected _balancePath(node: BTNKeyOrNodeOrEntry<K, V, NODE> | R): void;
185
+ protected _balancePath(node: BTNRep<K, V, NODE> | R): void;
186
186
  /**
187
187
  * Time Complexity: O(1)
188
188
  * Space Complexity: O(1)
@@ -52,7 +52,7 @@ class AVLTree extends bst_1.BST {
52
52
  /**
53
53
  * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
54
54
  * entries, or raw elements.
55
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
55
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
56
56
  * iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
57
57
  * be used to initialize the AVLTree.
58
58
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
@@ -60,10 +60,10 @@ class AVLTree extends bst_1.BST {
60
60
  * keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
61
61
  * `nodeBuilder` (
62
62
  */
63
- constructor(keysOrNodesOrEntriesOrRaws = [], options) {
63
+ constructor(keysNodesEntriesOrRaws = [], options) {
64
64
  super([], options);
65
- if (keysOrNodesOrEntriesOrRaws)
66
- super.addMany(keysOrNodesOrEntriesOrRaws);
65
+ if (keysNodesEntriesOrRaws)
66
+ super.addMany(keysNodesEntriesOrRaws);
67
67
  }
68
68
  /**
69
69
  * The function creates a new AVL tree node with the given key and value.
@@ -85,17 +85,17 @@ class AVLTree extends bst_1.BST {
85
85
  * @returns a new AVLTree object.
86
86
  */
87
87
  createTree(options) {
88
- return new AVLTree([], Object.assign({ iterationType: this.iterationType, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
88
+ return new AVLTree([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
89
89
  }
90
90
  /**
91
91
  * The function checks if the input is an instance of AVLTreeNode.
92
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
93
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
94
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
92
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
93
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
94
+ * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
95
95
  * an instance of the `AVLTreeNode` class.
96
96
  */
97
- isNode(keyOrNodeOrEntryOrRaw) {
98
- return keyOrNodeOrEntryOrRaw instanceof AVLTreeNode;
97
+ isNode(keyNodeEntryOrRaw) {
98
+ return keyNodeEntryOrRaw instanceof AVLTreeNode;
99
99
  }
100
100
  /**
101
101
  * Time Complexity: O(log n)
@@ -103,19 +103,19 @@ class AVLTree extends bst_1.BST {
103
103
  *
104
104
  * The function overrides the add method of a class and inserts a key-value pair into a data
105
105
  * structure, then balances the path.
106
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
107
- * `keyOrNodeOrEntryOrRaw` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
106
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
107
+ * `keyNodeEntryOrRaw` can accept values of type `R`, `BTNRep<K, V, NODE>`, or
108
108
  * `RawElement`.
109
109
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
110
110
  * the key or node being added to the data structure.
111
111
  * @returns The method is returning a boolean value.
112
112
  */
113
- add(keyOrNodeOrEntryOrRaw, value) {
114
- if (keyOrNodeOrEntryOrRaw === null)
113
+ add(keyNodeEntryOrRaw, value) {
114
+ if (keyNodeEntryOrRaw === null)
115
115
  return false;
116
- const inserted = super.add(keyOrNodeOrEntryOrRaw, value);
116
+ const inserted = super.add(keyNodeEntryOrRaw, value);
117
117
  if (inserted)
118
- this._balancePath(keyOrNodeOrEntryOrRaw);
118
+ this._balancePath(keyNodeEntryOrRaw);
119
119
  return inserted;
120
120
  }
121
121
  /**
@@ -124,15 +124,15 @@ class AVLTree extends bst_1.BST {
124
124
  *
125
125
  * The function overrides the delete method in a TypeScript class, performs deletion, and then
126
126
  * balances the tree if necessary.
127
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
127
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
128
128
  * parameter in the `override delete` method can be one of the following types:
129
129
  * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
130
130
  * method from the superclass (presumably a parent class) with the provided `predicate`, which could
131
131
  * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
132
132
  * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
133
133
  */
134
- delete(keyOrNodeOrEntryOrRaw) {
135
- const deletedResults = super.delete(keyOrNodeOrEntryOrRaw);
134
+ delete(keyNodeEntryOrRaw) {
135
+ const deletedResults = super.delete(keyNodeEntryOrRaw);
136
136
  for (const { needBalanced } of deletedResults) {
137
137
  if (needBalanced) {
138
138
  this._balancePath(needBalanced);
@@ -146,10 +146,10 @@ class AVLTree extends bst_1.BST {
146
146
  *
147
147
  * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
148
148
  * binary search tree.
149
- * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
149
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
150
150
  * object (`NODE`) or a key-value pair (`R`) that is being swapped with another node.
151
- * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
152
- * `R` or an instance of `BSTNKeyOrNode<K, NODE>`.
151
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
152
+ * `R` or an instance of `BSTNOptKeyOrNode<K, NODE>`.
153
153
  * @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
154
154
  * `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
155
155
  */
@@ -162,10 +162,12 @@ class AVLTree extends bst_1.BST {
162
162
  if (tempNode) {
163
163
  tempNode.height = height;
164
164
  destNodeEnsured.key = srcNodeEnsured.key;
165
- destNodeEnsured.value = srcNodeEnsured.value;
165
+ if (!this._isMapMode)
166
+ destNodeEnsured.value = srcNodeEnsured.value;
166
167
  destNodeEnsured.height = srcNodeEnsured.height;
167
168
  srcNodeEnsured.key = tempNode.key;
168
- srcNodeEnsured.value = tempNode.value;
169
+ if (!this._isMapMode)
170
+ srcNodeEnsured.value = tempNode.value;
169
171
  srcNodeEnsured.height = tempNode.height;
170
172
  }
171
173
  return destNodeEnsured;
@@ -402,8 +404,8 @@ class AVLTree extends bst_1.BST {
402
404
  *
403
405
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
404
406
  * to restore balance in an AVL tree after inserting a node.
405
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
406
- * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
407
+ * @param {BTNRep<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
408
+ * `BTNRep<K, V, NODE>`.
407
409
  */
408
410
  _balancePath(node) {
409
411
  node = this.ensureNode(node);