min-heap-typed 1.50.1 → 1.50.2

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 (67) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +114 -9
  2. package/dist/data-structures/base/iterable-base.js +143 -7
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +43 -46
  4. package/dist/data-structures/binary-tree/avl-tree.js +68 -71
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
  6. package/dist/data-structures/binary-tree/binary-tree.js +484 -376
  7. package/dist/data-structures/binary-tree/bst.d.ts +54 -74
  8. package/dist/data-structures/binary-tree/bst.js +30 -71
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +78 -60
  10. package/dist/data-structures/binary-tree/rb-tree.js +84 -89
  11. package/dist/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  12. package/dist/data-structures/binary-tree/tree-multimap.js +64 -85
  13. package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
  14. package/dist/data-structures/graph/abstract-graph.js +3 -0
  15. package/dist/data-structures/graph/directed-graph.d.ts +14 -0
  16. package/dist/data-structures/graph/directed-graph.js +26 -0
  17. package/dist/data-structures/graph/map-graph.d.ts +8 -0
  18. package/dist/data-structures/graph/map-graph.js +14 -0
  19. package/dist/data-structures/graph/undirected-graph.d.ts +16 -0
  20. package/dist/data-structures/graph/undirected-graph.js +25 -0
  21. package/dist/data-structures/hash/hash-map.d.ts +121 -15
  22. package/dist/data-structures/hash/hash-map.js +160 -25
  23. package/dist/data-structures/heap/heap.d.ts +66 -6
  24. package/dist/data-structures/heap/heap.js +66 -6
  25. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  26. package/dist/data-structures/linked-list/doubly-linked-list.js +70 -64
  27. package/dist/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  28. package/dist/data-structures/linked-list/singly-linked-list.js +130 -112
  29. package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  30. package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
  31. package/dist/data-structures/matrix/matrix.d.ts +35 -4
  32. package/dist/data-structures/matrix/matrix.js +50 -11
  33. package/dist/data-structures/queue/deque.d.ts +49 -19
  34. package/dist/data-structures/queue/deque.js +101 -47
  35. package/dist/data-structures/queue/queue.d.ts +39 -5
  36. package/dist/data-structures/queue/queue.js +47 -5
  37. package/dist/data-structures/stack/stack.d.ts +16 -0
  38. package/dist/data-structures/stack/stack.js +22 -0
  39. package/dist/data-structures/trie/trie.d.ts +38 -1
  40. package/dist/data-structures/trie/trie.js +41 -0
  41. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  42. package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
  43. package/dist/types/utils/utils.d.ts +1 -0
  44. package/package.json +2 -2
  45. package/src/data-structures/base/iterable-base.ts +172 -19
  46. package/src/data-structures/binary-tree/avl-tree.ts +97 -97
  47. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  48. package/src/data-structures/binary-tree/bst.ts +89 -131
  49. package/src/data-structures/binary-tree/rb-tree.ts +127 -155
  50. package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
  51. package/src/data-structures/graph/abstract-graph.ts +4 -0
  52. package/src/data-structures/graph/directed-graph.ts +30 -0
  53. package/src/data-structures/graph/map-graph.ts +15 -0
  54. package/src/data-structures/graph/undirected-graph.ts +28 -0
  55. package/src/data-structures/hash/hash-map.ts +175 -34
  56. package/src/data-structures/heap/heap.ts +66 -6
  57. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
  58. package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
  59. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  60. package/src/data-structures/matrix/matrix.ts +52 -12
  61. package/src/data-structures/queue/deque.ts +108 -49
  62. package/src/data-structures/queue/queue.ts +51 -5
  63. package/src/data-structures/stack/stack.ts +24 -0
  64. package/src/data-structures/trie/trie.ts +45 -1
  65. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  66. package/src/types/data-structures/hash/hash-map.ts +4 -3
  67. package/src/types/utils/utils.ts +2 -0
@@ -11,6 +11,17 @@ const utils_1 = require("../../utils");
11
11
  * 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
12
12
  */
13
13
  class Deque extends base_1.IterableElementBase {
14
+ /**
15
+ * The constructor initializes a Deque object with an optional iterable of elements and options.
16
+ * @param elements - An iterable object (such as an array or a Set) that contains the initial
17
+ * elements to be added to the deque. It can also be an object with a `length` or `size` property
18
+ * that represents the number of elements in the iterable object. If no elements are provided, an
19
+ * empty deque
20
+ * @param {DequeOptions} [options] - The `options` parameter is an optional object that can contain
21
+ * configuration options for the deque. In this code, it is used to set the `bucketSize` option,
22
+ * which determines the size of each bucket in the deque. If the `bucketSize` option is not provided
23
+ * or is not a number
24
+ */
14
25
  constructor(elements = [], options) {
15
26
  super();
16
27
  this._bucketFirst = 0;
@@ -50,9 +61,26 @@ class Deque extends base_1.IterableElementBase {
50
61
  this.push(element);
51
62
  }
52
63
  }
64
+ /**
65
+ * The bucketSize function returns the size of the bucket.
66
+ *
67
+ * @return The size of the bucket
68
+ */
69
+ get bucketSize() {
70
+ return this._bucketSize;
71
+ }
72
+ /**
73
+ * The buckets function returns the buckets property of the object.
74
+ *
75
+ * @return The buckets property
76
+ */
53
77
  get buckets() {
54
78
  return this._buckets;
55
79
  }
80
+ /**
81
+ * The size function returns the number of items in the stack.
82
+ * @return The number of values in the set
83
+ */
56
84
  get size() {
57
85
  return this._size;
58
86
  }
@@ -66,6 +94,10 @@ class Deque extends base_1.IterableElementBase {
66
94
  return;
67
95
  return this._buckets[this._bucketFirst][this._firstInBucket];
68
96
  }
97
+ /**
98
+ * The last function returns the last element in the queue.
99
+ * @return The last element in the array
100
+ */
69
101
  get last() {
70
102
  if (this.size === 0)
71
103
  return;
@@ -226,7 +258,7 @@ class Deque extends base_1.IterableElementBase {
226
258
  *begin() {
227
259
  let index = 0;
228
260
  while (index < this.size) {
229
- yield this.getAt(index);
261
+ yield this.at(index);
230
262
  index++;
231
263
  }
232
264
  }
@@ -237,7 +269,7 @@ class Deque extends base_1.IterableElementBase {
237
269
  *reverseBegin() {
238
270
  let index = this.size - 1;
239
271
  while (index >= 0) {
240
- yield this.getAt(index);
272
+ yield this.at(index);
241
273
  index--;
242
274
  }
243
275
  }
@@ -249,13 +281,13 @@ class Deque extends base_1.IterableElementBase {
249
281
  * Time Complexity: O(1)
250
282
  * Space Complexity: O(1)
251
283
  *
252
- * The `getAt` function retrieves an element at a specified position in an array-like data structure.
284
+ * The `at` function retrieves an element at a specified position in an array-like data structure.
253
285
  * @param {number} pos - The `pos` parameter represents the position of the element that you want to
254
286
  * retrieve from the data structure. It is of type `number` and should be a valid index within the
255
287
  * range of the data structure.
256
288
  * @returns The element at the specified position in the data structure is being returned.
257
289
  */
258
- getAt(pos) {
290
+ at(pos) {
259
291
  (0, utils_1.rangeCheck)(pos, 0, this.size - 1);
260
292
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
261
293
  return this._buckets[bucketIndex][indexInBucket];
@@ -313,9 +345,9 @@ class Deque extends base_1.IterableElementBase {
313
345
  else {
314
346
  const arr = [];
315
347
  for (let i = pos; i < this.size; ++i) {
316
- arr.push(this.getAt(i));
348
+ arr.push(this.at(i));
317
349
  }
318
- this.cut(pos - 1);
350
+ this.cut(pos - 1, true);
319
351
  for (let i = 0; i < num; ++i)
320
352
  this.push(element);
321
353
  for (let i = 0; i < arr.length; ++i)
@@ -335,18 +367,48 @@ class Deque extends base_1.IterableElementBase {
335
367
  * updated size.
336
368
  * @param {number} pos - The `pos` parameter represents the position at which the string should be
337
369
  * cut. It is a number that indicates the index of the character where the cut should be made.
370
+ * @param {boolean} isCutSelf - If true, the original deque will not be cut, and return a new deque
338
371
  * @returns The method is returning the updated size of the data structure.
339
372
  */
340
- cut(pos) {
341
- if (pos < 0) {
342
- this.clear();
343
- return 0;
373
+ cut(pos, isCutSelf = false) {
374
+ if (isCutSelf) {
375
+ if (pos < 0) {
376
+ this.clear();
377
+ return this;
378
+ }
379
+ const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
380
+ this._bucketLast = bucketIndex;
381
+ this._lastInBucket = indexInBucket;
382
+ this._size = pos + 1;
383
+ return this;
384
+ }
385
+ else {
386
+ const newDeque = new Deque([], { bucketSize: this._bucketSize });
387
+ for (let i = 0; i <= pos; i++) {
388
+ newDeque.push(this.at(i));
389
+ }
390
+ return newDeque;
391
+ }
392
+ }
393
+ cutRest(pos, isCutSelf = false) {
394
+ if (isCutSelf) {
395
+ if (pos < 0) {
396
+ this.clear();
397
+ return this;
398
+ }
399
+ const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
400
+ this._bucketFirst = bucketIndex;
401
+ this._firstInBucket = indexInBucket;
402
+ this._size = this._size - pos;
403
+ return this;
404
+ }
405
+ else {
406
+ const newDeque = new Deque([], { bucketSize: this._bucketSize });
407
+ for (let i = pos; i < this.size; i++) {
408
+ newDeque.push(this.at(i));
409
+ }
410
+ return newDeque;
344
411
  }
345
- const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
346
- this._bucketLast = bucketIndex;
347
- this._lastInBucket = indexInBucket;
348
- this._size = pos + 1;
349
- return this.size;
350
412
  }
351
413
  /**
352
414
  * Time Complexity: O(n)
@@ -403,14 +465,14 @@ class Deque extends base_1.IterableElementBase {
403
465
  let i = 0;
404
466
  let index = 0;
405
467
  while (i < size) {
406
- const oldElement = this.getAt(i);
468
+ const oldElement = this.at(i);
407
469
  if (oldElement !== element) {
408
470
  this.setAt(index, oldElement);
409
471
  index += 1;
410
472
  }
411
473
  i += 1;
412
474
  }
413
- this.cut(index - 1);
475
+ this.cut(index - 1, true);
414
476
  return true;
415
477
  }
416
478
  /**
@@ -454,15 +516,15 @@ class Deque extends base_1.IterableElementBase {
454
516
  return this;
455
517
  }
456
518
  let index = 1;
457
- let prev = this.getAt(0);
519
+ let prev = this.at(0);
458
520
  for (let i = 1; i < this.size; ++i) {
459
- const cur = this.getAt(i);
521
+ const cur = this.at(i);
460
522
  if (cur !== prev) {
461
523
  prev = cur;
462
524
  this.setAt(index++, cur);
463
525
  }
464
526
  }
465
- this.cut(index - 1);
527
+ this.cut(index - 1, true);
466
528
  return this;
467
529
  }
468
530
  /**
@@ -482,7 +544,7 @@ class Deque extends base_1.IterableElementBase {
482
544
  sort(comparator) {
483
545
  const arr = [];
484
546
  for (let i = 0; i < this.size; ++i) {
485
- arr.push(this.getAt(i));
547
+ arr.push(this.at(i));
486
548
  }
487
549
  arr.sort(comparator);
488
550
  for (let i = 0; i < this.size; ++i) {
@@ -526,30 +588,6 @@ class Deque extends base_1.IterableElementBase {
526
588
  this._bucketLast = newBuckets.length - 1;
527
589
  this._buckets = newBuckets;
528
590
  }
529
- /**
530
- * Time Complexity: O(n)
531
- * Space Complexity: O(1)
532
- */
533
- /**
534
- * Time Complexity: O(n)
535
- * Space Complexity: O(1)
536
- *
537
- * The `find` function iterates over the elements in a deque and returns the first element for which
538
- * the callback function returns true, or undefined if no such element is found.
539
- * @param callback - A function that takes three parameters: element, index, and deque. It should
540
- * return a boolean value indicating whether the element satisfies a certain condition.
541
- * @returns The method `find` returns the first element in the deque that satisfies the condition
542
- * specified by the callback function. If no element satisfies the condition, it returns `undefined`.
543
- */
544
- find(callback) {
545
- for (let i = 0; i < this.size; ++i) {
546
- const element = this.getAt(i);
547
- if (callback(element, i, this)) {
548
- return element;
549
- }
550
- }
551
- return;
552
- }
553
591
  /**
554
592
  * Time Complexity: O(n)
555
593
  * Space Complexity: O(1)
@@ -567,7 +605,7 @@ class Deque extends base_1.IterableElementBase {
567
605
  */
568
606
  indexOf(element) {
569
607
  for (let i = 0; i < this.size; ++i) {
570
- if (this.getAt(i) === element) {
608
+ if (this.at(i) === element) {
571
609
  return i;
572
610
  }
573
611
  }
@@ -587,6 +625,22 @@ class Deque extends base_1.IterableElementBase {
587
625
  toArray() {
588
626
  return [...this];
589
627
  }
628
+ /**
629
+ * Time Complexity: O(n)
630
+ * Space Complexity: O(n)
631
+ */
632
+ /**
633
+ * Time Complexity: O(n)
634
+ * Space Complexity: O(n)
635
+ *
636
+ * The `clone()` function returns a new instance of the `Deque` class with the same elements and
637
+ * bucket size as the original instance.
638
+ * @returns The `clone()` method is returning a new instance of the `Deque` class with the same
639
+ * elements as the original deque (`this`) and the same bucket size.
640
+ */
641
+ clone() {
642
+ return new Deque([...this], { bucketSize: this.bucketSize });
643
+ }
590
644
  /**
591
645
  * Time Complexity: O(n)
592
646
  * Space Complexity: O(n)
@@ -704,7 +758,7 @@ class Deque extends base_1.IterableElementBase {
704
758
  */
705
759
  *_getIterator() {
706
760
  for (let i = 0; i < this.size; ++i) {
707
- yield this.getAt(i);
761
+ yield this.at(i);
708
762
  }
709
763
  }
710
764
  /**
@@ -24,8 +24,16 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
24
24
  */
25
25
  constructor(elements?: Iterable<E>);
26
26
  protected _elements: E[];
27
+ /**
28
+ * The elements function returns the elements of this set.
29
+ * @return An array of the elements in the stack
30
+ */
27
31
  get elements(): E[];
28
32
  protected _offset: number;
33
+ /**
34
+ * The offset function returns the offset of the current page.
35
+ * @return The value of the private variable _offset
36
+ */
29
37
  get offset(): number;
30
38
  /**
31
39
  * The size function returns the number of elements in an array.
@@ -93,6 +101,18 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
93
101
  * @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
94
102
  */
95
103
  shift(): E | undefined;
104
+ /**
105
+ * The delete function removes an element from the list.
106
+ * @param element: E Specify the element to be deleted
107
+ * @return A boolean value indicating whether the element was successfully deleted or not
108
+ */
109
+ delete(element: E): boolean;
110
+ /**
111
+ * The deleteAt function deletes the element at a given index.
112
+ * @param index: number Determine the index of the element to be deleted
113
+ * @return A boolean value
114
+ */
115
+ deleteAt(index: number): boolean;
96
116
  /**
97
117
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
98
118
  * Space Complexity: O(1) - no additional space is used.
@@ -153,7 +173,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
153
173
  *
154
174
  * @param index
155
175
  */
156
- getAt(index: number): E | undefined;
176
+ at(index: number): E | undefined;
157
177
  /**
158
178
  * Time Complexity: O(1) - constant time as it retrieves the value at the specified index.
159
179
  * Space Complexity: O(1) - no additional space is used.
@@ -183,12 +203,13 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
183
203
  */
184
204
  clear(): void;
185
205
  /**
186
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
187
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
206
+ * Time Complexity: O(n)
207
+ * Space Complexity: O(n)
208
+ * where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
188
209
  */
189
210
  /**
190
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
191
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
211
+ * Time Complexity: O(n)
212
+ * Space Complexity: O(n)
192
213
  *
193
214
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
194
215
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
@@ -267,4 +288,17 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
267
288
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
268
289
  */
269
290
  peek(): E | undefined;
291
+ /**
292
+ * Time Complexity: O(n)
293
+ * Space Complexity: O(n)
294
+ */
295
+ /**
296
+ * Time Complexity: O(n)
297
+ * Space Complexity: O(n)
298
+ * The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
299
+ * the current instance.
300
+ * @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
301
+ * values as the original `LinkedListQueue`.
302
+ */
303
+ clone(): LinkedListQueue<E>;
270
304
  }
@@ -28,9 +28,17 @@ class Queue extends base_1.IterableElementBase {
28
28
  this.push(el);
29
29
  }
30
30
  }
31
+ /**
32
+ * The elements function returns the elements of this set.
33
+ * @return An array of the elements in the stack
34
+ */
31
35
  get elements() {
32
36
  return this._elements;
33
37
  }
38
+ /**
39
+ * The offset function returns the offset of the current page.
40
+ * @return The value of the private variable _offset
41
+ */
34
42
  get offset() {
35
43
  return this._offset;
36
44
  }
@@ -123,6 +131,24 @@ class Queue extends base_1.IterableElementBase {
123
131
  this._offset = 0;
124
132
  return first;
125
133
  }
134
+ /**
135
+ * The delete function removes an element from the list.
136
+ * @param element: E Specify the element to be deleted
137
+ * @return A boolean value indicating whether the element was successfully deleted or not
138
+ */
139
+ delete(element) {
140
+ const index = this.elements.indexOf(element);
141
+ return this.deleteAt(index);
142
+ }
143
+ /**
144
+ * The deleteAt function deletes the element at a given index.
145
+ * @param index: number Determine the index of the element to be deleted
146
+ * @return A boolean value
147
+ */
148
+ deleteAt(index) {
149
+ const spliced = this.elements.splice(index, 1);
150
+ return spliced.length === 1;
151
+ }
126
152
  /**
127
153
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
128
154
  * Space Complexity: O(1) - no additional space is used.
@@ -191,7 +217,7 @@ class Queue extends base_1.IterableElementBase {
191
217
  *
192
218
  * @param index
193
219
  */
194
- getAt(index) {
220
+ at(index) {
195
221
  return this.elements[index];
196
222
  }
197
223
  /**
@@ -230,12 +256,13 @@ class Queue extends base_1.IterableElementBase {
230
256
  this._offset = 0;
231
257
  }
232
258
  /**
233
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
234
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
259
+ * Time Complexity: O(n)
260
+ * Space Complexity: O(n)
261
+ * where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
235
262
  */
236
263
  /**
237
- * Time Complexity: O(n) - where n is the number of elements in the queue. It creates a shallow copy of the internal array.
238
- * Space Complexity: O(n) - the space required is proportional to the number of elements in the queue.
264
+ * Time Complexity: O(n)
265
+ * Space Complexity: O(n)
239
266
  *
240
267
  * The `clone()` function returns a new Queue object with the same elements as the original Queue.
241
268
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
@@ -348,5 +375,20 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
348
375
  peek() {
349
376
  return this.first;
350
377
  }
378
+ /**
379
+ * Time Complexity: O(n)
380
+ * Space Complexity: O(n)
381
+ */
382
+ /**
383
+ * Time Complexity: O(n)
384
+ * Space Complexity: O(n)
385
+ * The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
386
+ * the current instance.
387
+ * @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
388
+ * values as the original `LinkedListQueue`.
389
+ */
390
+ clone() {
391
+ return new LinkedListQueue(this.values());
392
+ }
351
393
  }
352
394
  exports.LinkedListQueue = LinkedListQueue;
@@ -24,6 +24,10 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
24
24
  */
25
25
  constructor(elements?: Iterable<E>);
26
26
  protected _elements: E[];
27
+ /**
28
+ * The elements function returns the elements of this set.
29
+ * @return An array of elements
30
+ */
27
31
  get elements(): E[];
28
32
  /**
29
33
  * Time Complexity: O(n), where n is the number of elements in the input array. Similar to the constructor, it requires iterating through each element.
@@ -87,6 +91,18 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
87
91
  * array is empty, it returns `undefined`.
88
92
  */
89
93
  pop(): E | undefined;
94
+ /**
95
+ * The delete function removes an element from the stack.
96
+ * @param element: E Specify the element to be deleted
97
+ * @return A boolean value indicating whether the element was successfully deleted or not
98
+ */
99
+ delete(element: E): boolean;
100
+ /**
101
+ * The deleteAt function deletes the element at a given index.
102
+ * @param index: number Determine the index of the element to be deleted
103
+ * @return A boolean value
104
+ */
105
+ deleteAt(index: number): boolean;
90
106
  /**
91
107
  * Time Complexity: O(n)
92
108
  * Space Complexity: O(n)
@@ -25,6 +25,10 @@ class Stack extends base_1.IterableElementBase {
25
25
  this.push(el);
26
26
  }
27
27
  }
28
+ /**
29
+ * The elements function returns the elements of this set.
30
+ * @return An array of elements
31
+ */
28
32
  get elements() {
29
33
  return this._elements;
30
34
  }
@@ -107,6 +111,24 @@ class Stack extends base_1.IterableElementBase {
107
111
  return;
108
112
  return this.elements.pop();
109
113
  }
114
+ /**
115
+ * The delete function removes an element from the stack.
116
+ * @param element: E Specify the element to be deleted
117
+ * @return A boolean value indicating whether the element was successfully deleted or not
118
+ */
119
+ delete(element) {
120
+ const index = this.elements.indexOf(element);
121
+ return this.deleteAt(index);
122
+ }
123
+ /**
124
+ * The deleteAt function deletes the element at a given index.
125
+ * @param index: number Determine the index of the element to be deleted
126
+ * @return A boolean value
127
+ */
128
+ deleteAt(index) {
129
+ const spliced = this.elements.splice(index, 1);
130
+ return spliced.length === 1;
131
+ }
110
132
  /**
111
133
  * Time Complexity: O(n)
112
134
  * Space Complexity: O(n)
@@ -30,13 +30,32 @@ export declare class TrieNode {
30
30
  * 10. IP Routing: Used in certain types of IP routing algorithms.
31
31
  * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
32
32
  */
33
- export declare class Trie extends IterableElementBase<string> {
33
+ export declare class Trie extends IterableElementBase<string, Trie> {
34
+ /**
35
+ * The constructor function for the Trie class.
36
+ * @param words: Iterable string Initialize the trie with a set of words
37
+ * @param options?: TrieOptions Allow the user to pass in options for the trie
38
+ * @return This
39
+ */
34
40
  constructor(words?: Iterable<string>, options?: TrieOptions);
35
41
  protected _size: number;
42
+ /**
43
+ * The size function returns the size of the stack.
44
+ * @return The number of elements in the list
45
+ */
36
46
  get size(): number;
37
47
  protected _caseSensitive: boolean;
48
+ /**
49
+ * The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
50
+ *
51
+ * @return The value of the _casesensitive private variable
52
+ */
38
53
  get caseSensitive(): boolean;
39
54
  protected _root: TrieNode;
55
+ /**
56
+ * The root function returns the root node of the tree.
57
+ * @return The root node
58
+ */
40
59
  get root(): TrieNode;
41
60
  /**
42
61
  * Time Complexity: O(M), where M is the length of the word being added.
@@ -64,6 +83,11 @@ export declare class Trie extends IterableElementBase<string> {
64
83
  * @returns {boolean} True if the word is present in the Trie.
65
84
  */
66
85
  has(word: string): boolean;
86
+ /**
87
+ * The isEmpty function checks if the size of the queue is 0.
88
+ * @return True if the size of the queue is 0
89
+ */
90
+ isEmpty(): boolean;
67
91
  /**
68
92
  * Time Complexity: O(M), where M is the length of the word being deleted.
69
93
  * Space Complexity: O(M) - Due to the recursive DFS approach.
@@ -154,6 +178,19 @@ export declare class Trie extends IterableElementBase<string> {
154
178
  * @returns {string[]} an array of strings.
155
179
  */
156
180
  getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
181
+ /**
182
+ * Time Complexity: O(n)
183
+ * Space Complexity: O(n)
184
+ */
185
+ /**
186
+ * Time Complexity: O(n)
187
+ * Space Complexity: O(n)
188
+ *
189
+ * The `clone` function returns a new instance of the Trie class with the same values and case
190
+ * sensitivity as the original Trie.
191
+ * @returns A new instance of the Trie class is being returned.
192
+ */
193
+ clone(): Trie;
157
194
  /**
158
195
  * Time Complexity: O(n)
159
196
  * Space Complexity: O(n)
@@ -28,6 +28,12 @@ exports.TrieNode = TrieNode;
28
28
  * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
29
29
  */
30
30
  class Trie extends base_1.IterableElementBase {
31
+ /**
32
+ * The constructor function for the Trie class.
33
+ * @param words: Iterable string Initialize the trie with a set of words
34
+ * @param options?: TrieOptions Allow the user to pass in options for the trie
35
+ * @return This
36
+ */
31
37
  constructor(words = [], options) {
32
38
  super();
33
39
  this._size = 0;
@@ -43,12 +49,25 @@ class Trie extends base_1.IterableElementBase {
43
49
  this.add(word);
44
50
  }
45
51
  }
52
+ /**
53
+ * The size function returns the size of the stack.
54
+ * @return The number of elements in the list
55
+ */
46
56
  get size() {
47
57
  return this._size;
48
58
  }
59
+ /**
60
+ * The caseSensitive function is a getter that returns the value of the private _caseSensitive property.
61
+ *
62
+ * @return The value of the _casesensitive private variable
63
+ */
49
64
  get caseSensitive() {
50
65
  return this._caseSensitive;
51
66
  }
67
+ /**
68
+ * The root function returns the root node of the tree.
69
+ * @return The root node
70
+ */
52
71
  get root() {
53
72
  return this._root;
54
73
  }
@@ -106,6 +125,13 @@ class Trie extends base_1.IterableElementBase {
106
125
  }
107
126
  return cur.isEnd;
108
127
  }
128
+ /**
129
+ * The isEmpty function checks if the size of the queue is 0.
130
+ * @return True if the size of the queue is 0
131
+ */
132
+ isEmpty() {
133
+ return this.size === 0;
134
+ }
109
135
  /**
110
136
  * Time Complexity: O(M), where M is the length of the word being deleted.
111
137
  * Space Complexity: O(M) - Due to the recursive DFS approach.
@@ -326,6 +352,21 @@ class Trie extends base_1.IterableElementBase {
326
352
  dfs(startNode, prefix);
327
353
  return words;
328
354
  }
355
+ /**
356
+ * Time Complexity: O(n)
357
+ * Space Complexity: O(n)
358
+ */
359
+ /**
360
+ * Time Complexity: O(n)
361
+ * Space Complexity: O(n)
362
+ *
363
+ * The `clone` function returns a new instance of the Trie class with the same values and case
364
+ * sensitivity as the original Trie.
365
+ * @returns A new instance of the Trie class is being returned.
366
+ */
367
+ clone() {
368
+ return new Trie(this.values(), { caseSensitive: this.caseSensitive });
369
+ }
329
370
  /**
330
371
  * Time Complexity: O(n)
331
372
  * Space Complexity: O(n)
@@ -1,7 +1,7 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
2
2
  import { IterationType } from "../../common";
3
3
  export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
- export type BinaryTreeNested<K, V, N extends BinaryTreeNode<K, V, N>> = BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
+ export type BinaryTreeNested<K, V, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
5
  export type BinaryTreeOptions<K> = {
6
6
  iterationType?: IterationType;
7
7
  extractor?: (key: K) => number;
@@ -4,13 +4,14 @@ export type HashMapLinkedNode<K, V> = {
4
4
  next: HashMapLinkedNode<K, V>;
5
5
  prev: HashMapLinkedNode<K, V>;
6
6
  };
7
- export type LinkedHashMapOptions<K> = {
7
+ export type LinkedHashMapOptions<K, V, R> = {
8
8
  hashFn?: (key: K) => string;
9
9
  objHashFn?: (key: K) => object;
10
+ toEntryFn?: (rawElement: R) => [K, V];
10
11
  };
11
- export type HashMapOptions<K, V, T> = {
12
+ export type HashMapOptions<K, V, R> = {
12
13
  hashFn?: (key: K) => string;
13
- toEntryFn?: (rawElement: T) => [K, V];
14
+ toEntryFn?: (rawElement: R) => [K, V];
14
15
  };
15
16
  export type HashMapStoreItem<K, V> = {
16
17
  key: K;