red-black-tree-typed 1.53.6 → 1.54.1

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 (121) hide show
  1. package/README.md +52 -0
  2. package/dist/common/index.d.ts +12 -0
  3. package/dist/common/index.js +28 -0
  4. package/dist/data-structures/base/iterable-entry-base.js +4 -4
  5. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
  6. package/dist/data-structures/binary-tree/avl-tree-counter.js +407 -0
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -170
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +133 -331
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +103 -69
  10. package/dist/data-structures/binary-tree/avl-tree.js +131 -71
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.js +3 -0
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +309 -208
  14. package/dist/data-structures/binary-tree/binary-tree.js +382 -300
  15. package/dist/data-structures/binary-tree/bst.d.ts +245 -127
  16. package/dist/data-structures/binary-tree/bst.js +366 -163
  17. package/dist/data-structures/binary-tree/index.d.ts +3 -1
  18. package/dist/data-structures/binary-tree/index.js +3 -1
  19. package/dist/data-structures/binary-tree/red-black-tree.d.ts +286 -0
  20. package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +181 -108
  21. package/dist/data-structures/binary-tree/tree-counter.d.ts +212 -0
  22. package/dist/data-structures/binary-tree/tree-counter.js +444 -0
  23. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +78 -170
  24. package/dist/data-structures/binary-tree/tree-multi-map.js +145 -367
  25. package/dist/data-structures/graph/abstract-graph.js +2 -2
  26. package/dist/data-structures/graph/directed-graph.d.ts +3 -0
  27. package/dist/data-structures/graph/directed-graph.js +3 -0
  28. package/dist/data-structures/graph/map-graph.d.ts +3 -0
  29. package/dist/data-structures/graph/map-graph.js +3 -0
  30. package/dist/data-structures/graph/undirected-graph.d.ts +3 -0
  31. package/dist/data-structures/graph/undirected-graph.js +3 -0
  32. package/dist/data-structures/hash/hash-map.d.ts +31 -1
  33. package/dist/data-structures/hash/hash-map.js +35 -5
  34. package/dist/data-structures/heap/heap.d.ts +26 -9
  35. package/dist/data-structures/heap/heap.js +37 -17
  36. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +64 -19
  37. package/dist/data-structures/linked-list/doubly-linked-list.js +92 -31
  38. package/dist/data-structures/linked-list/singly-linked-list.d.ts +48 -12
  39. package/dist/data-structures/linked-list/singly-linked-list.js +74 -27
  40. package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -0
  41. package/dist/data-structures/linked-list/skip-linked-list.js +3 -0
  42. package/dist/data-structures/matrix/matrix.d.ts +3 -0
  43. package/dist/data-structures/matrix/matrix.js +3 -0
  44. package/dist/data-structures/matrix/navigator.d.ts +3 -0
  45. package/dist/data-structures/matrix/navigator.js +3 -0
  46. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
  47. package/dist/data-structures/priority-queue/max-priority-queue.js +3 -0
  48. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
  49. package/dist/data-structures/priority-queue/min-priority-queue.js +3 -0
  50. package/dist/data-structures/queue/deque.d.ts +37 -8
  51. package/dist/data-structures/queue/deque.js +73 -29
  52. package/dist/data-structures/queue/queue.d.ts +41 -1
  53. package/dist/data-structures/queue/queue.js +51 -9
  54. package/dist/data-structures/stack/stack.d.ts +27 -10
  55. package/dist/data-structures/stack/stack.js +39 -20
  56. package/dist/data-structures/trie/trie.d.ts +111 -10
  57. package/dist/data-structures/trie/trie.js +123 -18
  58. package/dist/index.d.ts +2 -1
  59. package/dist/index.js +2 -1
  60. package/dist/interfaces/binary-tree.d.ts +8 -8
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  63. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
  64. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
  65. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
  66. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -4
  67. package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
  68. package/dist/types/data-structures/binary-tree/index.d.ts +2 -0
  69. package/dist/types/data-structures/binary-tree/index.js +2 -0
  70. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -5
  71. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  72. package/dist/types/data-structures/binary-tree/tree-counter.js +2 -0
  73. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -5
  74. package/dist/types/utils/utils.d.ts +10 -6
  75. package/dist/utils/utils.js +4 -2
  76. package/package.json +2 -2
  77. package/src/common/index.ts +25 -0
  78. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  79. package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
  80. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +152 -373
  81. package/src/data-structures/binary-tree/avl-tree.ts +164 -106
  82. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
  83. package/src/data-structures/binary-tree/binary-tree.ts +563 -447
  84. package/src/data-structures/binary-tree/bst.ts +433 -237
  85. package/src/data-structures/binary-tree/index.ts +3 -1
  86. package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +224 -146
  87. package/src/data-structures/binary-tree/tree-counter.ts +504 -0
  88. package/src/data-structures/binary-tree/tree-multi-map.ts +159 -401
  89. package/src/data-structures/graph/abstract-graph.ts +2 -2
  90. package/src/data-structures/graph/directed-graph.ts +3 -0
  91. package/src/data-structures/graph/map-graph.ts +3 -0
  92. package/src/data-structures/graph/undirected-graph.ts +3 -0
  93. package/src/data-structures/hash/hash-map.ts +37 -7
  94. package/src/data-structures/heap/heap.ts +72 -49
  95. package/src/data-structures/linked-list/doubly-linked-list.ts +186 -118
  96. package/src/data-structures/linked-list/singly-linked-list.ts +81 -28
  97. package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  98. package/src/data-structures/matrix/matrix.ts +3 -0
  99. package/src/data-structures/matrix/navigator.ts +3 -0
  100. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
  101. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
  102. package/src/data-structures/queue/deque.ts +72 -28
  103. package/src/data-structures/queue/queue.ts +50 -7
  104. package/src/data-structures/stack/stack.ts +39 -20
  105. package/src/data-structures/trie/trie.ts +123 -17
  106. package/src/index.ts +4 -3
  107. package/src/interfaces/binary-tree.ts +10 -21
  108. package/src/types/data-structures/base/base.ts +1 -1
  109. package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
  110. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
  111. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
  112. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -6
  113. package/src/types/data-structures/binary-tree/bst.ts +8 -7
  114. package/src/types/data-structures/binary-tree/index.ts +3 -1
  115. package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
  116. package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
  117. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -7
  118. package/src/types/utils/utils.ts +16 -10
  119. package/src/utils/utils.ts +4 -2
  120. package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -205
  121. package/src/types/data-structures/binary-tree/rb-tree.ts +0 -10
@@ -60,14 +60,7 @@ class Deque extends base_1.IterableElementBase {
60
60
  const needBucketNum = (0, utils_1.calcMinUnitsRequired)(_size, this._bucketSize);
61
61
  this._bucketFirst = this._bucketLast = (this._bucketCount >> 1) - (needBucketNum >> 1);
62
62
  this._firstInBucket = this._lastInBucket = (this._bucketSize - (_size % this._bucketSize)) >> 1;
63
- for (const el of elements) {
64
- if (this.toElementFn) {
65
- this.push(this.toElementFn(el));
66
- }
67
- else {
68
- this.push(el);
69
- }
70
- }
63
+ this.pushMany(elements);
71
64
  }
72
65
  /**
73
66
  * The bucketSize function returns the size of the bucket.
@@ -214,6 +207,35 @@ class Deque extends base_1.IterableElementBase {
214
207
  this._size -= 1;
215
208
  return element;
216
209
  }
210
+ /**
211
+ * Time Complexity: O(1)
212
+ * Space Complexity: O(1)
213
+ *
214
+ * The `shift()` function removes and returns the first element from a data structure, updating the
215
+ * internal state variables accordingly.
216
+ * @returns The element that is being removed from the beginning of the data structure is being
217
+ * returned.
218
+ */
219
+ shift() {
220
+ if (this._size === 0)
221
+ return;
222
+ const element = this._buckets[this._bucketFirst][this._firstInBucket];
223
+ if (this._size !== 1) {
224
+ if (this._firstInBucket < this._bucketSize - 1) {
225
+ this._firstInBucket += 1;
226
+ }
227
+ else if (this._bucketFirst < this._bucketCount - 1) {
228
+ this._bucketFirst += 1;
229
+ this._firstInBucket = 0;
230
+ }
231
+ else {
232
+ this._bucketFirst = 0;
233
+ this._firstInBucket = 0;
234
+ }
235
+ }
236
+ this._size -= 1;
237
+ return element;
238
+ }
217
239
  /**
218
240
  * Time Complexity: Amortized O(1)
219
241
  * Space Complexity: O(n)
@@ -247,33 +269,55 @@ class Deque extends base_1.IterableElementBase {
247
269
  return true;
248
270
  }
249
271
  /**
250
- * Time Complexity: O(1)
251
- * Space Complexity: O(1)
272
+ * Time Complexity: O(k)
273
+ * Space Complexity: O(k)
252
274
  *
253
- * The `shift()` function removes and returns the first element from a data structure, updating the
254
- * internal state variables accordingly.
255
- * @returns The element that is being removed from the beginning of the data structure is being
256
- * returned.
257
- */
258
- shift() {
259
- if (this._size === 0)
260
- return;
261
- const element = this._buckets[this._bucketFirst][this._firstInBucket];
262
- if (this._size !== 1) {
263
- if (this._firstInBucket < this._bucketSize - 1) {
264
- this._firstInBucket += 1;
275
+ * The function `pushMany` iterates over elements and pushes them into an array after applying a
276
+ * transformation function if provided.
277
+ * @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
278
+ * parameter in the `pushMany` function is expected to be an iterable containing elements of type `E`
279
+ * or `R`. It can be either an `IterableWithSizeOrLength<E>` or an `IterableWithSizeOrLength<R>`. The
280
+ * function iterates over each element
281
+ * @returns The `pushMany` function is returning an array of boolean values, where each value
282
+ * represents the result of calling the `push` method on the current object instance with the
283
+ * corresponding element from the input `elements` iterable.
284
+ */
285
+ pushMany(elements) {
286
+ const ans = [];
287
+ for (const el of elements) {
288
+ if (this.toElementFn) {
289
+ ans.push(this.push(this.toElementFn(el)));
265
290
  }
266
- else if (this._bucketFirst < this._bucketCount - 1) {
267
- this._bucketFirst += 1;
268
- this._firstInBucket = 0;
291
+ else {
292
+ ans.push(this.push(el));
293
+ }
294
+ }
295
+ return ans;
296
+ }
297
+ /**
298
+ * Time Complexity: O(k)
299
+ * Space Complexity: O(k)
300
+ *
301
+ * The `unshiftMany` function in TypeScript iterates over elements and adds them to the beginning of
302
+ * an array, optionally converting them using a provided function.
303
+ * @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
304
+ * parameter in the `unshiftMany` function is an iterable containing elements of type `E` or `R`. It
305
+ * can be an array or any other iterable data structure that has a known size or length. The function
306
+ * iterates over each element in the `elements` iterable and
307
+ * @returns The `unshiftMany` function returns an array of boolean values indicating whether each
308
+ * element was successfully added to the beginning of the array.
309
+ */
310
+ unshiftMany(elements = []) {
311
+ const ans = [];
312
+ for (const el of elements) {
313
+ if (this.toElementFn) {
314
+ ans.push(this.unshift(this.toElementFn(el)));
269
315
  }
270
316
  else {
271
- this._bucketFirst = 0;
272
- this._firstInBucket = 0;
317
+ ans.push(this.unshift(el));
273
318
  }
274
319
  }
275
- this._size -= 1;
276
- return element;
320
+ return ans;
277
321
  }
278
322
  /**
279
323
  * Time Complexity: O(1)
@@ -84,6 +84,18 @@ export declare class Queue<E = any, R = any> extends IterableElementBase<E, R, Q
84
84
  * @returns Always returns true, indicating the element was successfully added.
85
85
  */
86
86
  push(element: E): boolean;
87
+ /**
88
+ * Time Complexity: O(k)
89
+ * Space Complexity: O(k)
90
+ *
91
+ * The `pushMany` function iterates over elements and pushes them into an array after applying a
92
+ * transformation function if provided.
93
+ * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
94
+ * is an iterable containing elements of type `E` or `R`.
95
+ * @returns The `pushMany` function is returning an array of boolean values indicating whether each
96
+ * element was successfully pushed into the data structure.
97
+ */
98
+ pushMany(elements: Iterable<E> | Iterable<R>): boolean[];
87
99
  /**
88
100
  * Time Complexity: O(1)
89
101
  * Space Complexity: O(1)
@@ -94,12 +106,18 @@ export declare class Queue<E = any, R = any> extends IterableElementBase<E, R, Q
94
106
  */
95
107
  shift(): E | undefined;
96
108
  /**
109
+ * Time Complexity: O(n)
110
+ * Space Complexity: O(1)
111
+ *
97
112
  * The delete function removes an element from the list.
98
113
  * @param {E} element - Specify the element to be deleted
99
114
  * @return A boolean value indicating whether the element was successfully deleted or not
100
115
  */
101
116
  delete(element: E): boolean;
102
117
  /**
118
+ * Time Complexity: O(n)
119
+ * Space Complexity: O(1)
120
+ *
103
121
  * The deleteAt function deletes the element at a given index.
104
122
  * @param {number} index - Determine the index of the element to be deleted
105
123
  * @return A boolean value
@@ -109,7 +127,12 @@ export declare class Queue<E = any, R = any> extends IterableElementBase<E, R, Q
109
127
  * Time Complexity: O(1)
110
128
  * Space Complexity: O(1)
111
129
  *
112
- * @param index
130
+ * The `at` function returns the element at a specified index adjusted by an offset, or `undefined`
131
+ * if the index is out of bounds.
132
+ * @param {number} index - The `index` parameter represents the position of the element you want to
133
+ * retrieve from the data structure.
134
+ * @returns The `at` method is returning the element at the specified index adjusted by the offset
135
+ * `_offset`.
113
136
  */
114
137
  at(index: number): E | undefined;
115
138
  /**
@@ -136,6 +159,9 @@ export declare class Queue<E = any, R = any> extends IterableElementBase<E, R, Q
136
159
  */
137
160
  clear(): void;
138
161
  /**
162
+ * Time Complexity: O(n)
163
+ * Space Complexity: O(1)
164
+ *
139
165
  * The `compact` function in TypeScript slices the elements array based on the offset and resets the
140
166
  * offset to zero.
141
167
  * @returns The `compact()` method is returning a boolean value of `true`.
@@ -169,6 +195,20 @@ export declare class Queue<E = any, R = any> extends IterableElementBase<E, R, Q
169
195
  /**
170
196
  * Time Complexity: O(n)
171
197
  * Space Complexity: O(n)
198
+ *
199
+ * The `map` function in TypeScript creates a new Queue by applying a callback function to each
200
+ * element in the original Queue.
201
+ * @param callback - The `callback` parameter is a function that will be applied to each element in
202
+ * the queue. It takes the current element, its index, and the queue itself as arguments, and returns
203
+ * a new element.
204
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be provided to
205
+ * convert a raw element of type `RM` to a new element of type `EM`. This function is used within the
206
+ * `map` method to transform each raw element before passing it to the `callback` function. If
207
+ * @param {any} [thisArg] - The `thisArg` parameter in the `map` function is used to specify the
208
+ * value of `this` when executing the `callback` function. It allows you to set the context (the
209
+ * value of `this`) within the callback function. If `thisArg` is provided, it will be
210
+ * @returns A new Queue object containing elements of type EM, which are the result of applying the
211
+ * callback function to each element in the original Queue object.
172
212
  */
173
213
  map<EM, RM>(callback: ElementCallback<E, R, EM, Queue<E, R>>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): Queue<EM, RM>;
174
214
  /**
@@ -22,14 +22,7 @@ class Queue extends base_1.IterableElementBase {
22
22
  const { autoCompactRatio = 0.5 } = options;
23
23
  this._autoCompactRatio = autoCompactRatio;
24
24
  }
25
- if (elements) {
26
- for (const el of elements) {
27
- if (this.toElementFn)
28
- this.push(this.toElementFn(el));
29
- else
30
- this.push(el);
31
- }
32
- }
25
+ this.pushMany(elements);
33
26
  }
34
27
  /**
35
28
  * The elements function returns the elements of this set.
@@ -114,6 +107,27 @@ class Queue extends base_1.IterableElementBase {
114
107
  this.elements.push(element);
115
108
  return true;
116
109
  }
110
+ /**
111
+ * Time Complexity: O(k)
112
+ * Space Complexity: O(k)
113
+ *
114
+ * The `pushMany` function iterates over elements and pushes them into an array after applying a
115
+ * transformation function if provided.
116
+ * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
117
+ * is an iterable containing elements of type `E` or `R`.
118
+ * @returns The `pushMany` function is returning an array of boolean values indicating whether each
119
+ * element was successfully pushed into the data structure.
120
+ */
121
+ pushMany(elements) {
122
+ const ans = [];
123
+ for (const el of elements) {
124
+ if (this.toElementFn)
125
+ ans.push(this.push(this.toElementFn(el)));
126
+ else
127
+ ans.push(this.push(el));
128
+ }
129
+ return ans;
130
+ }
117
131
  /**
118
132
  * Time Complexity: O(1)
119
133
  * Space Complexity: O(1)
@@ -132,6 +146,9 @@ class Queue extends base_1.IterableElementBase {
132
146
  return first;
133
147
  }
134
148
  /**
149
+ * Time Complexity: O(n)
150
+ * Space Complexity: O(1)
151
+ *
135
152
  * The delete function removes an element from the list.
136
153
  * @param {E} element - Specify the element to be deleted
137
154
  * @return A boolean value indicating whether the element was successfully deleted or not
@@ -141,6 +158,9 @@ class Queue extends base_1.IterableElementBase {
141
158
  return this.deleteAt(index);
142
159
  }
143
160
  /**
161
+ * Time Complexity: O(n)
162
+ * Space Complexity: O(1)
163
+ *
144
164
  * The deleteAt function deletes the element at a given index.
145
165
  * @param {number} index - Determine the index of the element to be deleted
146
166
  * @return A boolean value
@@ -153,7 +173,12 @@ class Queue extends base_1.IterableElementBase {
153
173
  * Time Complexity: O(1)
154
174
  * Space Complexity: O(1)
155
175
  *
156
- * @param index
176
+ * The `at` function returns the element at a specified index adjusted by an offset, or `undefined`
177
+ * if the index is out of bounds.
178
+ * @param {number} index - The `index` parameter represents the position of the element you want to
179
+ * retrieve from the data structure.
180
+ * @returns The `at` method is returning the element at the specified index adjusted by the offset
181
+ * `_offset`.
157
182
  */
158
183
  at(index) {
159
184
  return this.elements[index + this._offset];
@@ -189,6 +214,9 @@ class Queue extends base_1.IterableElementBase {
189
214
  this._offset = 0;
190
215
  }
191
216
  /**
217
+ * Time Complexity: O(n)
218
+ * Space Complexity: O(1)
219
+ *
192
220
  * The `compact` function in TypeScript slices the elements array based on the offset and resets the
193
221
  * offset to zero.
194
222
  * @returns The `compact()` method is returning a boolean value of `true`.
@@ -238,6 +266,20 @@ class Queue extends base_1.IterableElementBase {
238
266
  /**
239
267
  * Time Complexity: O(n)
240
268
  * Space Complexity: O(n)
269
+ *
270
+ * The `map` function in TypeScript creates a new Queue by applying a callback function to each
271
+ * element in the original Queue.
272
+ * @param callback - The `callback` parameter is a function that will be applied to each element in
273
+ * the queue. It takes the current element, its index, and the queue itself as arguments, and returns
274
+ * a new element.
275
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be provided to
276
+ * convert a raw element of type `RM` to a new element of type `EM`. This function is used within the
277
+ * `map` method to transform each raw element before passing it to the `callback` function. If
278
+ * @param {any} [thisArg] - The `thisArg` parameter in the `map` function is used to specify the
279
+ * value of `this` when executing the `callback` function. It allows you to set the context (the
280
+ * value of `this`) within the callback function. If `thisArg` is provided, it will be
281
+ * @returns A new Queue object containing elements of type EM, which are the result of applying the
282
+ * callback function to each element in the original Queue object.
241
283
  */
242
284
  map(callback, toElementFn, thisArg) {
243
285
  const newDeque = new Queue([], { toElementFn });
@@ -28,10 +28,6 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
28
28
  * @returns The size of the elements array.
29
29
  */
30
30
  get size(): number;
31
- /**
32
- * Time Complexity: O(n)
33
- * Space Complexity: O(n)
34
- */
35
31
  /**
36
32
  * Time Complexity: O(n)
37
33
  * Space Complexity: O(n)
@@ -43,6 +39,9 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
43
39
  */
44
40
  static fromArray<E>(elements: E[]): Stack<E>;
45
41
  /**
42
+ * Time Complexity: O(1)
43
+ * Space Complexity: O(1)
44
+ *
46
45
  * The function checks if an array is empty and returns a boolean value.
47
46
  * @returns A boolean value indicating whether the `_elements` array is empty or not.
48
47
  */
@@ -74,15 +73,33 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
74
73
  */
75
74
  pop(): E | undefined;
76
75
  /**
77
- * The delete function removes an element from the stack.
78
- * @param element: E Specify the element to be deleted
79
- * @return A boolean value indicating whether the element was successfully deleted or not
76
+ * Time Complexity: O(k)
77
+ * Space Complexity: O(1)
78
+ *
79
+ * The function `pushMany` iterates over elements and pushes them into an array after applying a
80
+ * transformation function if provided.
81
+ * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
82
+ * is an iterable containing elements of type `E` or `R`. The function iterates over each element in
83
+ * the iterable and pushes it into the data structure. If a transformation function `toElementFn` is
84
+ * provided, it is used to
85
+ * @returns The `pushMany` function is returning an array of boolean values indicating whether each
86
+ * element was successfully pushed into the data structure.
87
+ */
88
+ pushMany(elements: Iterable<E> | Iterable<R>): boolean[];
89
+ /**
90
+ * Time Complexity: O(n)
91
+ * Space Complexity: O(1)
92
+ *
93
+ * The toArray function returns a copy of the elements in an array.
94
+ * @returns An array of type E.
80
95
  */
81
96
  delete(element: E): boolean;
82
97
  /**
83
- * The deleteAt function deletes the element at a given index.
84
- * @param index: number Determine the index of the element to be deleted
85
- * @return A boolean value
98
+ * Time Complexity: O(n)
99
+ * Space Complexity: O(1)
100
+ *
101
+ * The toArray function returns a copy of the elements in an array.
102
+ * @returns An array of type E.
86
103
  */
87
104
  deleteAt(index: number): boolean;
88
105
  /**
@@ -14,16 +14,7 @@ class Stack extends base_1.IterableElementBase {
14
14
  constructor(elements = [], options) {
15
15
  super(options);
16
16
  this._elements = [];
17
- if (elements) {
18
- for (const el of elements) {
19
- if (this.toElementFn) {
20
- this.push(this.toElementFn(el));
21
- }
22
- else {
23
- this.push(el);
24
- }
25
- }
26
- }
17
+ this.pushMany(elements);
27
18
  }
28
19
  /**
29
20
  * The elements function returns the elements of this set.
@@ -39,10 +30,6 @@ class Stack extends base_1.IterableElementBase {
39
30
  get size() {
40
31
  return this.elements.length;
41
32
  }
42
- /**
43
- * Time Complexity: O(n)
44
- * Space Complexity: O(n)
45
- */
46
33
  /**
47
34
  * Time Complexity: O(n)
48
35
  * Space Complexity: O(n)
@@ -56,6 +43,9 @@ class Stack extends base_1.IterableElementBase {
56
43
  return new Stack(elements);
57
44
  }
58
45
  /**
46
+ * Time Complexity: O(1)
47
+ * Space Complexity: O(1)
48
+ *
59
49
  * The function checks if an array is empty and returns a boolean value.
60
50
  * @returns A boolean value indicating whether the `_elements` array is empty or not.
61
51
  */
@@ -100,18 +90,47 @@ class Stack extends base_1.IterableElementBase {
100
90
  return this.elements.pop();
101
91
  }
102
92
  /**
103
- * The delete function removes an element from the stack.
104
- * @param element: E Specify the element to be deleted
105
- * @return A boolean value indicating whether the element was successfully deleted or not
93
+ * Time Complexity: O(k)
94
+ * Space Complexity: O(1)
95
+ *
96
+ * The function `pushMany` iterates over elements and pushes them into an array after applying a
97
+ * transformation function if provided.
98
+ * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
99
+ * is an iterable containing elements of type `E` or `R`. The function iterates over each element in
100
+ * the iterable and pushes it into the data structure. If a transformation function `toElementFn` is
101
+ * provided, it is used to
102
+ * @returns The `pushMany` function is returning an array of boolean values indicating whether each
103
+ * element was successfully pushed into the data structure.
104
+ */
105
+ pushMany(elements) {
106
+ const ans = [];
107
+ for (const el of elements) {
108
+ if (this.toElementFn) {
109
+ ans.push(this.push(this.toElementFn(el)));
110
+ }
111
+ else {
112
+ ans.push(this.push(el));
113
+ }
114
+ }
115
+ return ans;
116
+ }
117
+ /**
118
+ * Time Complexity: O(n)
119
+ * Space Complexity: O(1)
120
+ *
121
+ * The toArray function returns a copy of the elements in an array.
122
+ * @returns An array of type E.
106
123
  */
107
124
  delete(element) {
108
125
  const index = this.elements.indexOf(element);
109
126
  return this.deleteAt(index);
110
127
  }
111
128
  /**
112
- * The deleteAt function deletes the element at a given index.
113
- * @param index: number Determine the index of the element to be deleted
114
- * @return A boolean value
129
+ * Time Complexity: O(n)
130
+ * Space Complexity: O(1)
131
+ *
132
+ * The toArray function returns a copy of the elements in an array.
133
+ * @returns An array of type E.
115
134
  */
116
135
  deleteAt(index) {
117
136
  const spliced = this.elements.splice(index, 1);
@@ -7,10 +7,6 @@
7
7
  */
8
8
  import type { ElementCallback, TrieOptions } from '../../types';
9
9
  import { IterableElementBase } from '../base';
10
- /**
11
- * TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
12
- * and a flag indicating whether it's the end of a word.
13
- */
14
10
  export declare class TrieNode {
15
11
  constructor(key: string);
16
12
  protected _key: string;
@@ -65,13 +61,100 @@ export declare class TrieNode {
65
61
  * 9. Spell Check: Checking the spelling of words.
66
62
  * 10. IP Routing: Used in certain types of IP routing algorithms.
67
63
  * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data.
64
+ * @example
65
+ * // Autocomplete: Prefix validation and checking
66
+ * const autocomplete = new Trie<string>(['gmail.com', 'gmail.co.nz', 'gmail.co.jp', 'yahoo.com', 'outlook.com']);
67
+ *
68
+ * // Get all completions for a prefix
69
+ * const gmailCompletions = autocomplete.getWords('gmail');
70
+ * console.log(gmailCompletions); // ['gmail.com', 'gmail.co.nz', 'gmail.co.jp']
71
+ * @example
72
+ * // File System Path Operations
73
+ * const fileSystem = new Trie<string>([
74
+ * '/home/user/documents/file1.txt',
75
+ * '/home/user/documents/file2.txt',
76
+ * '/home/user/pictures/photo.jpg',
77
+ * '/home/user/pictures/vacation/',
78
+ * '/home/user/downloads'
79
+ * ]);
80
+ *
81
+ * // Find common directory prefix
82
+ * console.log(fileSystem.getLongestCommonPrefix()); // '/home/user/'
83
+ *
84
+ * // List all files in a directory
85
+ * const documentsFiles = fileSystem.getWords('/home/user/documents/');
86
+ * console.log(documentsFiles); // ['/home/user/documents/file1.txt', '/home/user/documents/file2.txt']
87
+ * @example
88
+ * // Autocomplete: Basic word suggestions
89
+ * // Create a trie for autocomplete
90
+ * const autocomplete = new Trie<string>([
91
+ * 'function',
92
+ * 'functional',
93
+ * 'functions',
94
+ * 'class',
95
+ * 'classes',
96
+ * 'classical',
97
+ * 'closure',
98
+ * 'const',
99
+ * 'constructor'
100
+ * ]);
101
+ *
102
+ * // Test autocomplete with different prefixes
103
+ * console.log(autocomplete.getWords('fun')); // ['functional', 'functions', 'function']
104
+ * console.log(autocomplete.getWords('cla')); // ['classes', 'classical', 'class']
105
+ * console.log(autocomplete.getWords('con')); // ['constructor', 'const']
106
+ *
107
+ * // Test with non-matching prefix
108
+ * console.log(autocomplete.getWords('xyz')); // []
109
+ * @example
110
+ * // Dictionary: Case-insensitive word lookup
111
+ * // Create a case-insensitive dictionary
112
+ * const dictionary = new Trie<string>([], { caseSensitive: false });
113
+ *
114
+ * // Add words with mixed casing
115
+ * dictionary.add('Hello');
116
+ * dictionary.add('WORLD');
117
+ * dictionary.add('JavaScript');
118
+ *
119
+ * // Test lookups with different casings
120
+ * console.log(dictionary.has('hello')); // true
121
+ * console.log(dictionary.has('HELLO')); // true
122
+ * console.log(dictionary.has('Hello')); // true
123
+ * console.log(dictionary.has('javascript')); // true
124
+ * console.log(dictionary.has('JAVASCRIPT')); // true
125
+ * @example
126
+ * // IP Address Routing Table
127
+ * // Add IP address prefixes and their corresponding routes
128
+ * const routes = {
129
+ * '192.168.1': 'LAN_SUBNET_1',
130
+ * '192.168.2': 'LAN_SUBNET_2',
131
+ * '10.0.0': 'PRIVATE_NETWORK_1',
132
+ * '10.0.1': 'PRIVATE_NETWORK_2'
133
+ * };
134
+ *
135
+ * const ipRoutingTable = new Trie<string>(Object.keys(routes));
136
+ *
137
+ * // Check IP address prefix matching
138
+ * console.log(ipRoutingTable.hasPrefix('192.168.1')); // true
139
+ * console.log(ipRoutingTable.hasPrefix('192.168.2')); // true
140
+ *
141
+ * // Validate IP address belongs to subnet
142
+ * const ip = '192.168.1.100';
143
+ * const subnet = ip.split('.').slice(0, 3).join('.');
144
+ * console.log(ipRoutingTable.hasPrefix(subnet)); // true
68
145
  */
69
146
  export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R>> {
70
147
  /**
71
- * The constructor function for the Trie class.
72
- * @param words: Iterable string Initialize the trie with a set of words
73
- * @param options?: TrieOptions Allow the user to pass in options for the trie
74
- * @return This
148
+ * The constructor initializes a Trie data structure with optional options and words provided as
149
+ * input.
150
+ * @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the constructor is an
151
+ * iterable containing either strings or elements of type `R`. It is used to initialize the Trie with
152
+ * a list of words or elements. If no `words` are provided, an empty iterable is used as the default
153
+ * value.
154
+ * @param [options] - The `options` parameter in the constructor is an optional object that can
155
+ * contain configuration options for the Trie data structure. One of the options it can have is
156
+ * `caseSensitive`, which is a boolean value indicating whether the Trie should be case-sensitive or
157
+ * not. If `caseSensitive` is set to `
75
158
  */
76
159
  constructor(words?: Iterable<string> | Iterable<R>, options?: TrieOptions<R>);
77
160
  protected _size: number;
@@ -101,6 +184,19 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
101
184
  * @returns {boolean} True if the word was successfully added.
102
185
  */
103
186
  add(word: string): boolean;
187
+ /**
188
+ * Time Complexity: O(n * l)
189
+ * Space Complexity: O(1)
190
+ *
191
+ * The `addMany` function in TypeScript takes an iterable of strings or elements of type R, converts
192
+ * them using a provided function if available, and adds them to a data structure while returning an
193
+ * array of boolean values indicating success.
194
+ * @param {Iterable<string> | Iterable<R>} words - The `words` parameter in the `addMany` function is
195
+ * an iterable that contains either strings or elements of type `R`.
196
+ * @returns The `addMany` method returns an array of boolean values indicating whether each word in
197
+ * the input iterable was successfully added to the data structure.
198
+ */
199
+ addMany(words: Iterable<string> | Iterable<R>): boolean[];
104
200
  /**
105
201
  * Time Complexity: O(l), where l is the length of the input word.
106
202
  * Space Complexity: O(1) - Constant space.
@@ -135,9 +231,14 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
135
231
  */
136
232
  delete(word: string): boolean;
137
233
  /**
138
- * Time Complexity: O(n), where n is the total number of nodes in the trie.
139
- * Space Complexity: O(1) - Constant space.
234
+ * Time Complexity: O(n)
235
+ * Space Complexity: O(1)
140
236
  *
237
+ * The function `getHeight` calculates the height of a trie data structure starting from the root
238
+ * node.
239
+ * @returns The `getHeight` method returns the maximum depth or height of the trie tree starting from
240
+ * the root node. It calculates the depth using a breadth-first search (BFS) traversal of the trie
241
+ * tree and returns the maximum depth found.
141
242
  */
142
243
  getHeight(): number;
143
244
  /**