deque-typed 1.49.4 → 1.49.6

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 (69) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +1 -1
  2. package/dist/data-structures/binary-tree/avl-tree.d.ts +53 -48
  3. package/dist/data-structures/binary-tree/avl-tree.js +55 -49
  4. package/dist/data-structures/binary-tree/binary-tree.d.ts +154 -143
  5. package/dist/data-structures/binary-tree/binary-tree.js +211 -198
  6. package/dist/data-structures/binary-tree/bst.d.ts +83 -71
  7. package/dist/data-structures/binary-tree/bst.js +113 -89
  8. package/dist/data-structures/binary-tree/rb-tree.d.ts +37 -35
  9. package/dist/data-structures/binary-tree/rb-tree.js +62 -59
  10. package/dist/data-structures/binary-tree/tree-multimap.d.ts +46 -55
  11. package/dist/data-structures/binary-tree/tree-multimap.js +59 -94
  12. package/dist/data-structures/graph/abstract-graph.d.ts +1 -1
  13. package/dist/data-structures/graph/abstract-graph.js +3 -2
  14. package/dist/data-structures/hash/hash-map.d.ts +1 -1
  15. package/dist/data-structures/hash/hash-map.js +2 -2
  16. package/dist/data-structures/heap/heap.js +2 -3
  17. package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  18. package/dist/data-structures/matrix/index.d.ts +0 -2
  19. package/dist/data-structures/matrix/index.js +0 -2
  20. package/dist/data-structures/matrix/matrix.d.ts +128 -10
  21. package/dist/data-structures/matrix/matrix.js +400 -15
  22. package/dist/data-structures/queue/deque.d.ts +2 -2
  23. package/dist/data-structures/queue/deque.js +5 -7
  24. package/dist/data-structures/queue/queue.d.ts +1 -1
  25. package/dist/interfaces/binary-tree.d.ts +3 -3
  26. package/dist/types/common.d.ts +3 -3
  27. package/dist/types/common.js +2 -2
  28. package/dist/types/data-structures/base/base.d.ts +1 -1
  29. package/dist/types/data-structures/heap/heap.d.ts +1 -1
  30. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  31. package/dist/utils/utils.d.ts +1 -0
  32. package/dist/utils/utils.js +6 -1
  33. package/package.json +2 -2
  34. package/src/data-structures/base/index.ts +1 -1
  35. package/src/data-structures/base/iterable-base.ts +7 -10
  36. package/src/data-structures/binary-tree/avl-tree.ts +73 -61
  37. package/src/data-structures/binary-tree/binary-tree.ts +301 -270
  38. package/src/data-structures/binary-tree/bst.ts +139 -115
  39. package/src/data-structures/binary-tree/rb-tree.ts +81 -73
  40. package/src/data-structures/binary-tree/tree-multimap.ts +72 -103
  41. package/src/data-structures/graph/abstract-graph.ts +13 -11
  42. package/src/data-structures/graph/directed-graph.ts +1 -3
  43. package/src/data-structures/graph/map-graph.ts +6 -1
  44. package/src/data-structures/graph/undirected-graph.ts +3 -6
  45. package/src/data-structures/hash/hash-map.ts +18 -16
  46. package/src/data-structures/heap/heap.ts +7 -10
  47. package/src/data-structures/heap/max-heap.ts +2 -1
  48. package/src/data-structures/heap/min-heap.ts +2 -1
  49. package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
  50. package/src/data-structures/matrix/index.ts +0 -2
  51. package/src/data-structures/matrix/matrix.ts +442 -13
  52. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
  53. package/src/data-structures/queue/deque.ts +18 -39
  54. package/src/data-structures/queue/queue.ts +1 -1
  55. package/src/interfaces/binary-tree.ts +9 -4
  56. package/src/types/common.ts +5 -5
  57. package/src/types/data-structures/base/base.ts +14 -3
  58. package/src/types/data-structures/base/index.ts +1 -1
  59. package/src/types/data-structures/graph/abstract-graph.ts +4 -2
  60. package/src/types/data-structures/hash/hash-map.ts +3 -3
  61. package/src/types/data-structures/heap/heap.ts +2 -2
  62. package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
  63. package/src/utils/utils.ts +7 -1
  64. package/dist/data-structures/matrix/matrix2d.d.ts +0 -107
  65. package/dist/data-structures/matrix/matrix2d.js +0 -199
  66. package/dist/data-structures/matrix/vector2d.d.ts +0 -200
  67. package/dist/data-structures/matrix/vector2d.js +0 -290
  68. package/src/data-structures/matrix/matrix2d.ts +0 -211
  69. package/src/data-structures/matrix/vector2d.ts +0 -315
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { BinaryTreeDeleteResult, BTNCallback, BTNExemplar, BTNKeyOrNode, IterationType, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
8
+ import { BinaryTreeDeleteResult, BTNCallback, IterationType, KeyOrNodeOrEntry, RBTNColor, RBTreeOptions, RedBlackTreeNested, RedBlackTreeNodeNested } from '../../types';
9
9
  import { BST, BSTNode } from './bst';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  export declare class RedBlackTreeNode<K = any, V = any, N extends RedBlackTreeNode<K, V, N> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
@@ -23,16 +23,16 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
23
23
  Sentinel: N;
24
24
  /**
25
25
  * This is the constructor function for a Red-Black Tree data structure in TypeScript, which
26
- * initializes the tree with optional elements and options.
27
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
28
- * objects. It represents the initial elements that will be added to the RBTree during its
26
+ * initializes the tree with optional nodes and options.
27
+ * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
28
+ * objects. It represents the initial nodes that will be added to the RBTree during its
29
29
  * construction. If this parameter is provided, the `addMany` method is called to add all the
30
- * elements to the
30
+ * nodes to the
31
31
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
32
32
  * behavior of the RBTree. It is of type `Partial<RBTreeOptions>`, which means that you can provide
33
33
  * only a subset of the properties defined in the `RBTreeOptions` interface.
34
34
  */
35
- constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<RBTreeOptions<K>>);
35
+ constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<RBTreeOptions<K>>);
36
36
  protected _root: N;
37
37
  get root(): N;
38
38
  protected _size: number;
@@ -59,34 +59,40 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
59
59
  */
60
60
  createTree(options?: RBTreeOptions<K>): TREE;
61
61
  /**
62
- * The function checks if an exemplar is an instance of the RedBlackTreeNode class.
63
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
64
- * @returns a boolean value indicating whether the exemplar is an instance of the RedBlackTreeNode
62
+ * The function `exemplarToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
63
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
64
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
65
+ * `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If a value
66
+ * is provided, it will be used when creating the new node. If no value is provided, the new node
67
+ * @returns a node of type N or undefined.
68
+ */
69
+ exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): N | undefined;
70
+ /**
71
+ * The function checks if an keyOrNodeOrEntry is an instance of the RedBlackTreeNode class.
72
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
73
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the RedBlackTreeNode
65
74
  * class.
66
75
  */
67
- isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
76
+ isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
77
+ /**
78
+ * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
79
+ * Space Complexity: O(1)
80
+ */
81
+ isRealNode(node: N | undefined): node is N;
68
82
  /**
69
83
  * The function "isNotNodeInstance" checks if a potential key is a K.
70
84
  * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
71
85
  * data type.
72
86
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
73
87
  */
74
- isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
88
+ isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
75
89
  /**
76
- * The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
77
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
78
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
79
- * `exemplarToNode` function. It represents the value associated with the exemplar node. If a value
80
- * is provided, it will be used when creating the new node. If no value is provided, the new node
81
- * @returns a node of type N or undefined.
82
- */
83
- exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V): N | undefined;
84
- /**
85
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
90
+ * Time Complexity: O(log n)
86
91
  * Space Complexity: O(1)
92
+ * on average (where n is the number of nodes in the tree)
87
93
  */
88
94
  /**
89
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
95
+ * Time Complexity: O(log n)
90
96
  * Space Complexity: O(1)
91
97
  *
92
98
  * The `add` function adds a new node to a binary search tree and performs necessary rotations and
@@ -97,13 +103,14 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
97
103
  * being added to the binary search tree.
98
104
  * @returns The method `add` returns either the newly added node (`N`) or `undefined`.
99
105
  */
100
- add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
106
+ add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
101
107
  /**
102
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
108
+ * Time Complexity: O(log n)
103
109
  * Space Complexity: O(1)
110
+ * on average (where n is the number of nodes in the tree)
104
111
  */
105
112
  /**
106
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
113
+ * Time Complexity: O(log n)
107
114
  * Space Complexity: O(1)
108
115
  *
109
116
  * The `delete` function removes a node from a binary tree based on a given identifier and updates
@@ -118,11 +125,6 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
118
125
  * @returns an array of `BinaryTreeDeleteResult<N>`.
119
126
  */
120
127
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback?: C): BinaryTreeDeleteResult<N>[];
121
- /**
122
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
123
- * Space Complexity: O(1)
124
- */
125
- isRealNode(node: N | undefined): node is N;
126
128
  getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: N | undefined, iterationType?: IterationType): N | undefined;
127
129
  getNode<C extends BTNCallback<N, N>>(identifier: N | undefined, callback?: C, beginRoot?: N | undefined, iterationType?: IterationType): N | undefined;
128
130
  getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: N | undefined, iterationType?: IterationType): N | undefined;
@@ -141,7 +143,7 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
141
143
  */
142
144
  getPredecessor(x: N): N;
143
145
  /**
144
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
146
+ * Time Complexity: O(1)
145
147
  * Space Complexity: O(1)
146
148
  */
147
149
  clear(): void;
@@ -172,11 +174,11 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
172
174
  */
173
175
  protected _rightRotate(x: N): void;
174
176
  /**
175
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
177
+ * Time Complexity: O(log n)
176
178
  * Space Complexity: O(1)
177
179
  */
178
180
  /**
179
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
181
+ * Time Complexity: O(log n)
180
182
  * Space Complexity: O(1)
181
183
  *
182
184
  * The function `_fixDelete` is used to fix the red-black tree after a node deletion.
@@ -197,11 +199,11 @@ export declare class RedBlackTree<K = any, V = any, N extends RedBlackTreeNode<K
197
199
  */
198
200
  protected _rbTransplant(u: N, v: N): void;
199
201
  /**
200
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
202
+ * Time Complexity: O(log n)
201
203
  * Space Complexity: O(1)
202
204
  */
203
205
  /**
204
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
206
+ * Time Complexity: O(log n)
205
207
  * Space Complexity: O(1)
206
208
  *
207
209
  * The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
@@ -27,22 +27,22 @@ exports.RedBlackTreeNode = RedBlackTreeNode;
27
27
  class RedBlackTree extends bst_1.BST {
28
28
  /**
29
29
  * This is the constructor function for a Red-Black Tree data structure in TypeScript, which
30
- * initializes the tree with optional elements and options.
31
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
32
- * objects. It represents the initial elements that will be added to the RBTree during its
30
+ * initializes the tree with optional nodes and options.
31
+ * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
32
+ * objects. It represents the initial nodes that will be added to the RBTree during its
33
33
  * construction. If this parameter is provided, the `addMany` method is called to add all the
34
- * elements to the
34
+ * nodes to the
35
35
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
36
36
  * behavior of the RBTree. It is of type `Partial<RBTreeOptions>`, which means that you can provide
37
37
  * only a subset of the properties defined in the `RBTreeOptions` interface.
38
38
  */
39
- constructor(elements, options) {
39
+ constructor(nodes, options) {
40
40
  super([], options);
41
41
  this.Sentinel = new RedBlackTreeNode(NaN);
42
42
  this._size = 0;
43
43
  this._root = this.Sentinel;
44
- if (elements)
45
- super.addMany(elements);
44
+ if (nodes)
45
+ super.addMany(nodes);
46
46
  }
47
47
  get root() {
48
48
  return this._root;
@@ -76,41 +76,23 @@ class RedBlackTree extends bst_1.BST {
76
76
  return new RedBlackTree([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
77
77
  }
78
78
  /**
79
- * The function checks if an exemplar is an instance of the RedBlackTreeNode class.
80
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
81
- * @returns a boolean value indicating whether the exemplar is an instance of the RedBlackTreeNode
82
- * class.
83
- */
84
- isNode(exemplar) {
85
- return exemplar instanceof RedBlackTreeNode;
86
- }
87
- /**
88
- * The function "isNotNodeInstance" checks if a potential key is a K.
89
- * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
90
- * data type.
91
- * @returns a boolean value indicating whether the potentialKey is of type number or not.
92
- */
93
- isNotNodeInstance(potentialKey) {
94
- return !(potentialKey instanceof RedBlackTreeNode);
95
- }
96
- /**
97
- * The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
98
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
79
+ * The function `exemplarToNode` takes an keyOrNodeOrEntry and converts it into a node object if possible.
80
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, where:
99
81
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
100
- * `exemplarToNode` function. It represents the value associated with the exemplar node. If a value
82
+ * `exemplarToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If a value
101
83
  * is provided, it will be used when creating the new node. If no value is provided, the new node
102
84
  * @returns a node of type N or undefined.
103
85
  */
104
- exemplarToNode(exemplar, value) {
86
+ exemplarToNode(keyOrNodeOrEntry, value) {
105
87
  let node;
106
- if (exemplar === null || exemplar === undefined) {
88
+ if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === undefined) {
107
89
  return;
108
90
  }
109
- else if (this.isNode(exemplar)) {
110
- node = exemplar;
91
+ else if (this.isNode(keyOrNodeOrEntry)) {
92
+ node = keyOrNodeOrEntry;
111
93
  }
112
- else if (this.isEntry(exemplar)) {
113
- const [key, value] = exemplar;
94
+ else if (this.isEntry(keyOrNodeOrEntry)) {
95
+ const [key, value] = keyOrNodeOrEntry;
114
96
  if (key === undefined || key === null) {
115
97
  return;
116
98
  }
@@ -118,20 +100,48 @@ class RedBlackTree extends bst_1.BST {
118
100
  node = this.createNode(key, value, types_1.RBTNColor.RED);
119
101
  }
120
102
  }
121
- else if (this.isNotNodeInstance(exemplar)) {
122
- node = this.createNode(exemplar, value, types_1.RBTNColor.RED);
103
+ else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
104
+ node = this.createNode(keyOrNodeOrEntry, value, types_1.RBTNColor.RED);
123
105
  }
124
106
  else {
125
107
  return;
126
108
  }
127
109
  return node;
128
110
  }
111
+ /**
112
+ * The function checks if an keyOrNodeOrEntry is an instance of the RedBlackTreeNode class.
113
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
114
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the RedBlackTreeNode
115
+ * class.
116
+ */
117
+ isNode(keyOrNodeOrEntry) {
118
+ return keyOrNodeOrEntry instanceof RedBlackTreeNode;
119
+ }
129
120
  /**
130
121
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
131
122
  * Space Complexity: O(1)
132
123
  */
124
+ isRealNode(node) {
125
+ if (node === this.Sentinel || node === undefined)
126
+ return false;
127
+ return node instanceof RedBlackTreeNode;
128
+ }
133
129
  /**
134
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
130
+ * The function "isNotNodeInstance" checks if a potential key is a K.
131
+ * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
132
+ * data type.
133
+ * @returns a boolean value indicating whether the potentialKey is of type number or not.
134
+ */
135
+ isNotNodeInstance(potentialKey) {
136
+ return !(potentialKey instanceof RedBlackTreeNode);
137
+ }
138
+ /**
139
+ * Time Complexity: O(log n)
140
+ * Space Complexity: O(1)
141
+ * on average (where n is the number of nodes in the tree)
142
+ */
143
+ /**
144
+ * Time Complexity: O(log n)
135
145
  * Space Complexity: O(1)
136
146
  *
137
147
  * The `add` function adds a new node to a binary search tree and performs necessary rotations and
@@ -145,7 +155,7 @@ class RedBlackTree extends bst_1.BST {
145
155
  add(keyOrNodeOrEntry, value) {
146
156
  const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
147
157
  if (newNode === undefined)
148
- return;
158
+ return false;
149
159
  newNode.left = this.Sentinel;
150
160
  newNode.right = this.Sentinel;
151
161
  let y = undefined;
@@ -163,7 +173,7 @@ class RedBlackTree extends bst_1.BST {
163
173
  if (newNode !== x) {
164
174
  this._replaceNode(x, newNode);
165
175
  }
166
- return;
176
+ return false;
167
177
  }
168
178
  }
169
179
  }
@@ -180,21 +190,23 @@ class RedBlackTree extends bst_1.BST {
180
190
  if (newNode.parent === undefined) {
181
191
  newNode.color = types_1.RBTNColor.BLACK;
182
192
  this._size++;
183
- return;
193
+ return false;
184
194
  }
185
195
  if (newNode.parent.parent === undefined) {
186
196
  this._size++;
187
- return;
197
+ return false;
188
198
  }
189
199
  this._fixInsert(newNode);
190
200
  this._size++;
201
+ return true;
191
202
  }
192
203
  /**
193
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
204
+ * Time Complexity: O(log n)
194
205
  * Space Complexity: O(1)
206
+ * on average (where n is the number of nodes in the tree)
195
207
  */
196
208
  /**
197
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
209
+ * Time Complexity: O(log n)
198
210
  * Space Complexity: O(1)
199
211
  *
200
212
  * The `delete` function removes a node from a binary tree based on a given identifier and updates
@@ -267,20 +279,11 @@ class RedBlackTree extends bst_1.BST {
267
279
  return ans;
268
280
  }
269
281
  /**
270
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
271
- * Space Complexity: O(1)
272
- */
273
- isRealNode(node) {
274
- if (node === this.Sentinel || node === undefined)
275
- return false;
276
- return node instanceof RedBlackTreeNode;
277
- }
278
- /**
279
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
282
+ * Time Complexity: O(log n)
280
283
  * Space Complexity: O(1)
281
284
  */
282
285
  /**
283
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
286
+ * Time Complexity: O(log n)
284
287
  * Space Complexity: O(1)
285
288
  *
286
289
  * The function `getNode` retrieves a single node from a binary tree based on a given identifier and
@@ -332,7 +335,7 @@ class RedBlackTree extends bst_1.BST {
332
335
  return y;
333
336
  }
334
337
  /**
335
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
338
+ * Time Complexity: O(1)
336
339
  * Space Complexity: O(1)
337
340
  */
338
341
  clear() {
@@ -413,11 +416,11 @@ class RedBlackTree extends bst_1.BST {
413
416
  }
414
417
  }
415
418
  /**
416
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
419
+ * Time Complexity: O(log n)
417
420
  * Space Complexity: O(1)
418
421
  */
419
422
  /**
420
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
423
+ * Time Complexity: O(log n)
421
424
  * Space Complexity: O(1)
422
425
  *
423
426
  * The function `_fixDelete` is used to fix the red-black tree after a node deletion.
@@ -512,11 +515,11 @@ class RedBlackTree extends bst_1.BST {
512
515
  v.parent = u.parent;
513
516
  }
514
517
  /**
515
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
518
+ * Time Complexity: O(log n)
516
519
  * Space Complexity: O(1)
517
520
  */
518
521
  /**
519
- * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
522
+ * Time Complexity: O(log n)
520
523
  * Space Complexity: O(1)
521
524
  *
522
525
  * The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNExemplar, BTNKeyOrNode, TreeMultimapNested, TreeMultimapNodeNested, TreeMultimapOptions } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry, TreeMultimapNested, TreeMultimapNodeNested, TreeMultimapOptions } from '../../types';
9
9
  import { IterationType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
@@ -27,7 +27,7 @@ export declare class TreeMultimapNode<K = any, V = any, N extends TreeMultimapNo
27
27
  * The only distinction between a TreeMultimap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
28
28
  */
29
29
  export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K, V, N> = TreeMultimapNode<K, V, TreeMultimapNodeNested<K, V>>, TREE extends TreeMultimap<K, V, N, TREE> = TreeMultimap<K, V, N, TreeMultimapNested<K, V, N>>> extends AVLTree<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
30
- constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<TreeMultimapOptions<K>>);
30
+ constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<TreeMultimapOptions<K>>);
31
31
  private _count;
32
32
  get count(): number;
33
33
  /**
@@ -42,22 +42,8 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
42
42
  createNode(key: K, value?: V, count?: number): N;
43
43
  createTree(options?: TreeMultimapOptions<K>): TREE;
44
44
  /**
45
- * The function checks if an exemplar is an instance of the TreeMultimapNode class.
46
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
47
- * @returns a boolean value indicating whether the exemplar is an instance of the TreeMultimapNode
48
- * class.
49
- */
50
- isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
51
- /**
52
- * The function "isNotNodeInstance" checks if a potential key is a K.
53
- * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
54
- * data type.
55
- * @returns a boolean value indicating whether the potentialKey is of type number or not.
56
- */
57
- isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
58
- /**
59
- * The function `exemplarToNode` converts an exemplar object into a node object.
60
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, which means it
45
+ * The function `exemplarToNode` converts an keyOrNodeOrEntry object into a node object.
46
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, which means it
61
47
  * can be one of the following:
62
48
  * @param {V} [value] - The `value` parameter is an optional argument that represents the value
63
49
  * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
@@ -66,14 +52,29 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
66
52
  * times the value should be added to the node. If not provided, it defaults to 1.
67
53
  * @returns a node of type `N` or `undefined`.
68
54
  */
69
- exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V, count?: number): N | undefined;
55
+ exemplarToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): N | undefined;
70
56
  /**
71
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
72
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
57
+ * The function checks if an keyOrNodeOrEntry is an instance of the TreeMultimapNode class.
58
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
59
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the TreeMultimapNode
60
+ * class.
73
61
  */
62
+ isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
74
63
  /**
75
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
76
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
64
+ * The function "isNotNodeInstance" checks if a potential key is a K.
65
+ * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
66
+ * data type.
67
+ * @returns a boolean value indicating whether the potentialKey is of type number or not.
68
+ */
69
+ isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
70
+ /**
71
+ * Time Complexity: O(log n)
72
+ * Space Complexity: O(1)
73
+ * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
74
+ */
75
+ /**
76
+ * Time Complexity: O(log n)
77
+ * Space Complexity: O(1)
77
78
  *
78
79
  * The function overrides the add method of a binary tree node and adds a new node to the tree.
79
80
  * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
@@ -87,14 +88,15 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
87
88
  * @returns The method is returning either the newly inserted node or `undefined` if the insertion
88
89
  * was not successful.
89
90
  */
90
- add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V, count?: number): N | undefined;
91
+ add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): boolean;
91
92
  /**
92
- * Time Complexity: O(k log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
93
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
93
+ * Time Complexity: O(k log n)
94
+ * Space Complexity: O(1)
95
+ * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
94
96
  */
95
97
  /**
96
- * Time Complexity: O(k log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
97
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
98
+ * Time Complexity: O(k log n)
99
+ * Space Complexity: O(1)
98
100
  *
99
101
  * The function overrides the addMany method to add multiple keys, nodes, or entries to a data
100
102
  * structure.
@@ -102,14 +104,15 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
102
104
  * either keys, nodes, or entries.
103
105
  * @returns The method is returning an array of type `N | undefined`.
104
106
  */
105
- addMany(keysOrNodesOrEntries: Iterable<BTNExemplar<K, V, N>>): (N | undefined)[];
107
+ addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>>): boolean[];
106
108
  /**
107
- * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
108
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
109
+ * Time Complexity: O(n log n)
110
+ * Space Complexity: O(n)
111
+ * logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node. linear space, as it creates an array to store the sorted nodes.
109
112
  */
110
113
  /**
111
- * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
112
- * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
114
+ * Time Complexity: O(n log n)
115
+ * Space Complexity: O(n)
113
116
  *
114
117
  * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
115
118
  * tree using either a recursive or iterative approach.
@@ -120,12 +123,13 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
120
123
  */
121
124
  perfectlyBalance(iterationType?: IterationType): boolean;
122
125
  /**
123
- * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
124
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
126
+ * Time Complexity: O(k log n)
127
+ * Space Complexity: O(1)
128
+ * logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. constant space, as it doesn't use additional data structures that scale with input size.
125
129
  */
126
130
  /**
127
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
128
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
131
+ * Time Complexity: O(k log n)
132
+ * Space Complexity: O(1)
129
133
  *
130
134
  * The `delete` function in TypeScript is used to remove a node from a binary tree, taking into
131
135
  * account the count of the node and balancing the tree if necessary.
@@ -144,10 +148,13 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
144
148
  */
145
149
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<N>[];
146
150
  /**
147
- * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
148
- * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
151
+ * Time Complexity: O(1)
152
+ * Space Complexity: O(1)
149
153
  */
150
154
  /**
155
+ * Time Complexity: O(1)
156
+ * Space Complexity: O(1)
157
+ *
151
158
  * The clear() function clears the contents of a data structure and sets the count to zero.
152
159
  */
153
160
  clear(): void;
@@ -163,22 +170,6 @@ export declare class TreeMultimap<K = any, V = any, N extends TreeMultimapNode<K
163
170
  * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
164
171
  */
165
172
  clone(): TREE;
166
- /**
167
- * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
168
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
169
- *
170
- * The function adds a new node to a binary tree, either as the left child or the right child of a
171
- * given parent node.
172
- * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
173
- * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
174
- * `undefined` if there is no node to add.
175
- * @param {K | N | undefined} parent - The `parent` parameter represents the parent node to
176
- * which the new node will be added as a child. It can be either a node object (`N`) or a key value
177
- * (`K`).
178
- * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
179
- * added, or `undefined` if no node was added.
180
- */
181
- protected _addTo(newNode: N | undefined, parent: BSTNKeyOrNode<K, N>): N | undefined;
182
173
  /**
183
174
  * The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
184
175
  * @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from