data-structure-typed 1.49.1 → 1.49.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 (85) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +16 -16
  3. package/README_zh-CN.md +2 -2
  4. package/benchmark/report.html +46 -1
  5. package/benchmark/report.json +457 -22
  6. package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
  7. package/dist/cjs/data-structures/base/iterable-base.js +21 -0
  8. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  9. package/dist/cjs/data-structures/hash/hash-map.d.ts +9 -9
  10. package/dist/cjs/data-structures/hash/hash-map.js +16 -15
  11. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  12. package/dist/cjs/data-structures/heap/heap.d.ts +6 -35
  13. package/dist/cjs/data-structures/heap/heap.js +10 -42
  14. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  15. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +87 -93
  16. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +126 -129
  17. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  18. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +16 -21
  19. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -42
  20. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  21. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  22. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
  23. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  24. package/dist/cjs/data-structures/queue/deque.d.ts +70 -75
  25. package/dist/cjs/data-structures/queue/deque.js +100 -110
  26. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  27. package/dist/cjs/data-structures/queue/queue.d.ts +13 -14
  28. package/dist/cjs/data-structures/queue/queue.js +15 -18
  29. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  30. package/dist/cjs/data-structures/stack/stack.d.ts +2 -3
  31. package/dist/cjs/data-structures/stack/stack.js +2 -5
  32. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  33. package/dist/cjs/data-structures/trie/trie.d.ts +1 -2
  34. package/dist/cjs/data-structures/trie/trie.js +2 -5
  35. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  36. package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
  37. package/dist/mjs/data-structures/base/iterable-base.js +21 -0
  38. package/dist/mjs/data-structures/hash/hash-map.d.ts +9 -9
  39. package/dist/mjs/data-structures/hash/hash-map.js +16 -15
  40. package/dist/mjs/data-structures/heap/heap.d.ts +6 -35
  41. package/dist/mjs/data-structures/heap/heap.js +10 -42
  42. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +87 -93
  43. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +125 -128
  44. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +16 -21
  45. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -43
  46. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  47. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
  48. package/dist/mjs/data-structures/queue/deque.d.ts +70 -75
  49. package/dist/mjs/data-structures/queue/deque.js +100 -110
  50. package/dist/mjs/data-structures/queue/queue.d.ts +13 -14
  51. package/dist/mjs/data-structures/queue/queue.js +15 -18
  52. package/dist/mjs/data-structures/stack/stack.d.ts +2 -3
  53. package/dist/mjs/data-structures/stack/stack.js +2 -5
  54. package/dist/mjs/data-structures/trie/trie.d.ts +1 -2
  55. package/dist/mjs/data-structures/trie/trie.js +2 -5
  56. package/dist/umd/data-structure-typed.js +338 -370
  57. package/dist/umd/data-structure-typed.min.js +2 -2
  58. package/dist/umd/data-structure-typed.min.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/data-structures/base/iterable-base.ts +24 -0
  61. package/src/data-structures/hash/hash-map.ts +27 -28
  62. package/src/data-structures/heap/heap.ts +19 -57
  63. package/src/data-structures/linked-list/doubly-linked-list.ts +138 -142
  64. package/src/data-structures/linked-list/singly-linked-list.ts +49 -49
  65. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  66. package/src/data-structures/queue/deque.ts +122 -135
  67. package/src/data-structures/queue/queue.ts +19 -23
  68. package/src/data-structures/stack/stack.ts +4 -8
  69. package/src/data-structures/trie/trie.ts +5 -9
  70. package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
  71. package/test/performance/data-structures/heap/heap.test.ts +2 -2
  72. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
  73. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
  74. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
  75. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
  76. package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
  77. package/test/unit/data-structures/heap/heap.test.ts +1 -1
  78. package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
  79. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
  80. package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
  81. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
  82. package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
  83. package/test/unit/data-structures/queue/deque.test.ts +5 -5
  84. package/test/unit/data-structures/queue/queue.test.ts +4 -4
  85. package/test/unit/data-structures/trie/trie.test.ts +1 -1
@@ -73,95 +73,6 @@ export class Deque extends IterableElementBase {
73
73
  return;
74
74
  return this._buckets[this._bucketLast][this._lastInBucket];
75
75
  }
76
- /**
77
- * Time Complexity: O(1) - Removes the last element.
78
- * Space Complexity: O(1) - Operates in-place.
79
- */
80
- isEmpty() {
81
- return this.size === 0;
82
- }
83
- /**
84
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
85
- * Space Complexity: O(n) - Due to potential resizing.
86
- */
87
- /**
88
- * Time Complexity: O(1)
89
- * Space Complexity: O(n) - In worst case, resizing doubles the array size.
90
- *
91
- * The addLast function adds an element to the end of an array.
92
- * @param {E} element - The element parameter represents the element that you want to add to the end of the
93
- * data structure.
94
- */
95
- addLast(element) {
96
- this.push(element);
97
- }
98
- /**
99
- * Time Complexity: O(1) - Removes the first element.
100
- * Space Complexity: O(1) - In-place operation.
101
- */
102
- /**
103
- * Time Complexity: O(1) - Removes the last element.
104
- * Space Complexity: O(1) - Operates in-place.
105
- *
106
- * The function "pollLast" removes and returns the last element of an array.
107
- * @returns The last element of the array is being returned.
108
- */
109
- pollLast() {
110
- return this.pop();
111
- }
112
- /**
113
- * Time Complexity: O(1).
114
- * Space Complexity: O(n) - Due to potential resizing.
115
- *
116
- * The "addFirst" function adds an element to the beginning of an array.
117
- * @param {E} element - The parameter "element" represents the element that you want to add to the
118
- * beginning of the data structure.
119
- */
120
- addFirst(element) {
121
- this.unshift(element);
122
- }
123
- /**
124
- * Time Complexity: O(1) - Removes the first element.
125
- * Space Complexity: O(1) - In-place operation.
126
- *
127
- * The function "pollFirst" removes and returns the first element of an array.
128
- * @returns The method `pollFirst()` is returning the first element of the array after removing it
129
- * from the beginning. If the array is empty, it will return `undefined`.
130
- */
131
- pollFirst() {
132
- return this.shift();
133
- }
134
- /**
135
- * The clear() function resets the state of the object by initializing all variables to their default
136
- * values.
137
- */
138
- clear() {
139
- this._buckets = [new Array(this._bucketSize)];
140
- this._bucketCount = 1;
141
- this._bucketFirst = this._bucketLast = this._size = 0;
142
- this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
143
- }
144
- /**
145
- * The below function is a generator that yields elements from a collection one by one.
146
- */
147
- *begin() {
148
- let index = 0;
149
- while (index < this.size) {
150
- yield this.getAt(index);
151
- index++;
152
- }
153
- }
154
- /**
155
- * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
156
- * the last element.
157
- */
158
- *reverseBegin() {
159
- let index = this.size - 1;
160
- while (index >= 0) {
161
- yield this.getAt(index);
162
- index--;
163
- }
164
- }
165
76
  /**
166
77
  * Time Complexity - Amortized O(1) (possible reallocation)
167
78
  * Space Complexity - O(n) (due to potential resizing).
@@ -194,7 +105,7 @@ export class Deque extends IterableElementBase {
194
105
  }
195
106
  this._size += 1;
196
107
  this._buckets[this._bucketLast][this._lastInBucket] = element;
197
- return this.size;
108
+ return true;
198
109
  }
199
110
  /**
200
111
  * Time Complexity: O(1)
@@ -261,7 +172,7 @@ export class Deque extends IterableElementBase {
261
172
  }
262
173
  this._size += 1;
263
174
  this._buckets[this._bucketFirst][this._firstInBucket] = element;
264
- return this.size;
175
+ return true;
265
176
  }
266
177
  /**
267
178
  * Time Complexity: O(1)
@@ -296,6 +207,44 @@ export class Deque extends IterableElementBase {
296
207
  this._size -= 1;
297
208
  return element;
298
209
  }
210
+ /**
211
+ * Time Complexity: O(1) - Removes the last element.
212
+ * Space Complexity: O(1) - Operates in-place.
213
+ */
214
+ isEmpty() {
215
+ return this.size === 0;
216
+ }
217
+ /**
218
+ * The clear() function resets the state of the object by initializing all variables to their default
219
+ * values.
220
+ */
221
+ clear() {
222
+ this._buckets = [new Array(this._bucketSize)];
223
+ this._bucketCount = 1;
224
+ this._bucketFirst = this._bucketLast = this._size = 0;
225
+ this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
226
+ }
227
+ /**
228
+ * The below function is a generator that yields elements from a collection one by one.
229
+ */
230
+ *begin() {
231
+ let index = 0;
232
+ while (index < this.size) {
233
+ yield this.getAt(index);
234
+ index++;
235
+ }
236
+ }
237
+ /**
238
+ * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
239
+ * the last element.
240
+ */
241
+ *reverseBegin() {
242
+ let index = this.size - 1;
243
+ while (index >= 0) {
244
+ yield this.getAt(index);
245
+ index--;
246
+ }
247
+ }
299
248
  /**
300
249
  * Time Complexity: O(1)
301
250
  * Space Complexity: O(1)
@@ -333,6 +282,7 @@ export class Deque extends IterableElementBase {
333
282
  rangeCheck(pos, 0, this.size - 1);
334
283
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
335
284
  this._buckets[bucketIndex][indexInBucket] = element;
285
+ return true;
336
286
  }
337
287
  /**
338
288
  * Time Complexity: O(n)
@@ -342,7 +292,7 @@ export class Deque extends IterableElementBase {
342
292
  * Time Complexity: O(n)
343
293
  * Space Complexity: O(n)
344
294
  *
345
- * The `insertAt` function inserts one or more elements at a specified position in an array-like data
295
+ * The `addAt` function inserts one or more elements at a specified position in an array-like data
346
296
  * structure.
347
297
  * @param {number} pos - The `pos` parameter represents the position at which the element(s) should
348
298
  * be inserted. It is of type `number`.
@@ -353,7 +303,7 @@ export class Deque extends IterableElementBase {
353
303
  * will be inserted once. However, you can provide a different value for `num` if you want
354
304
  * @returns The size of the array after the insertion is being returned.
355
305
  */
356
- insertAt(pos, element, num = 1) {
306
+ addAt(pos, element, num = 1) {
357
307
  const length = this.size;
358
308
  rangeCheck(pos, 0, length);
359
309
  if (pos === 0) {
@@ -375,7 +325,7 @@ export class Deque extends IterableElementBase {
375
325
  for (let i = 0; i < arr.length; ++i)
376
326
  this.push(arr[i]);
377
327
  }
378
- return this.size;
328
+ return true;
379
329
  }
380
330
  /**
381
331
  * Time Complexity: O(1)
@@ -434,7 +384,7 @@ export class Deque extends IterableElementBase {
434
384
  }
435
385
  this.pop();
436
386
  }
437
- return this.size;
387
+ return true;
438
388
  }
439
389
  /**
440
390
  * Time Complexity: O(n)
@@ -453,7 +403,7 @@ export class Deque extends IterableElementBase {
453
403
  delete(element) {
454
404
  const size = this.size;
455
405
  if (size === 0)
456
- return 0;
406
+ return false;
457
407
  let i = 0;
458
408
  let index = 0;
459
409
  while (i < size) {
@@ -465,7 +415,7 @@ export class Deque extends IterableElementBase {
465
415
  i += 1;
466
416
  }
467
417
  this.cut(index - 1);
468
- return this.size;
418
+ return true;
469
419
  }
470
420
  /**
471
421
  * Time Complexity: O(n)
@@ -505,7 +455,7 @@ export class Deque extends IterableElementBase {
505
455
  */
506
456
  unique() {
507
457
  if (this.size <= 1) {
508
- return this.size;
458
+ return this;
509
459
  }
510
460
  let index = 1;
511
461
  let prev = this.getAt(0);
@@ -517,7 +467,7 @@ export class Deque extends IterableElementBase {
517
467
  }
518
468
  }
519
469
  this.cut(index - 1);
520
- return this.size;
470
+ return this;
521
471
  }
522
472
  /**
523
473
  * Time Complexity: O(n log n)
@@ -531,7 +481,7 @@ export class Deque extends IterableElementBase {
531
481
  * @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
532
482
  * `y` of type `E` and returns a number. The comparator function is used to determine the order of
533
483
  * the elements in the sorted array.
534
- * @returns The method is returning the sorted instance of the object on which the method is called.
484
+ * @returns Deque<E>
535
485
  */
536
486
  sort(comparator) {
537
487
  const arr = [];
@@ -602,7 +552,7 @@ export class Deque extends IterableElementBase {
602
552
  return element;
603
553
  }
604
554
  }
605
- return undefined;
555
+ return;
606
556
  }
607
557
  /**
608
558
  * Time Complexity: O(n)
@@ -639,11 +589,7 @@ export class Deque extends IterableElementBase {
639
589
  * @returns The `toArray()` method is returning an array of elements of type `E`.
640
590
  */
641
591
  toArray() {
642
- const arr = [];
643
- for (let i = 0; i < this.size; ++i) {
644
- arr.push(this.getAt(i));
645
- }
646
- return arr;
592
+ return [...this];
647
593
  }
648
594
  /**
649
595
  * Time Complexity: O(n)
@@ -703,11 +649,55 @@ export class Deque extends IterableElementBase {
703
649
  return newDeque;
704
650
  }
705
651
  /**
706
- * Time Complexity: O(n)
707
- * Space Complexity: O(n)
652
+ * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
653
+ * Space Complexity: O(n) - Due to potential resizing.
654
+ */
655
+ /**
656
+ * Time Complexity: O(1)
657
+ * Space Complexity: O(n) - In worst case, resizing doubles the array size.
658
+ *
659
+ * The addLast function adds an element to the end of an array.
660
+ * @param {E} element - The element parameter represents the element that you want to add to the end of the
661
+ * data structure.
662
+ */
663
+ addLast(element) {
664
+ return this.push(element);
665
+ }
666
+ /**
667
+ * Time Complexity: O(1) - Removes the first element.
668
+ * Space Complexity: O(1) - In-place operation.
669
+ */
670
+ /**
671
+ * Time Complexity: O(1) - Removes the last element.
672
+ * Space Complexity: O(1) - Operates in-place.
673
+ *
674
+ * The function "pollLast" removes and returns the last element of an array.
675
+ * @returns The last element of the array is being returned.
708
676
  */
709
- print() {
710
- console.log([...this]);
677
+ pollLast() {
678
+ return this.pop();
679
+ }
680
+ /**
681
+ * Time Complexity: O(1).
682
+ * Space Complexity: O(n) - Due to potential resizing.
683
+ *
684
+ * The "addFirst" function adds an element to the beginning of an array.
685
+ * @param {E} element - The parameter "element" represents the element that you want to add to the
686
+ * beginning of the data structure.
687
+ */
688
+ addFirst(element) {
689
+ return this.unshift(element);
690
+ }
691
+ /**
692
+ * Time Complexity: O(1) - Removes the first element.
693
+ * Space Complexity: O(1) - In-place operation.
694
+ *
695
+ * The function "pollFirst" removes and returns the first element of an array.
696
+ * @returns The method `pollFirst()` is returning the first element of the array after removing it
697
+ * from the beginning. If the array is empty, it will return `undefined`.
698
+ */
699
+ pollFirst() {
700
+ return this.shift();
711
701
  }
712
702
  /**
713
703
  * Time Complexity: O(n)
@@ -53,7 +53,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
53
53
  * @param {E} element - The `element` parameter represents the element that you want to add to the queue.
54
54
  * @returns The `add` method is returning a `Queue<E>` object.
55
55
  */
56
- push(element: E): Queue<E>;
56
+ push(element: E): boolean;
57
57
  /**
58
58
  * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
59
59
  * Space Complexity: O(1) - no additional space is used.
@@ -75,11 +75,11 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
75
75
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
76
76
  * Space Complexity: O(1) - no additional space is used.
77
77
  *
78
- * The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
79
- * @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
78
+ * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
79
+ * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
80
80
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
81
81
  */
82
- getFirst(): E | undefined;
82
+ get first(): E | undefined;
83
83
  /**
84
84
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
85
85
  * Space Complexity: O(1) - no additional space is used.
@@ -101,11 +101,11 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
101
101
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
102
102
  * Space Complexity: O(1) - no additional space is used.
103
103
  *
104
- * The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
105
- * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
104
+ * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
105
+ * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
106
106
  * array is empty, it returns `undefined`.
107
107
  */
108
- getLast(): E | undefined;
108
+ get last(): E | undefined;
109
109
  /**
110
110
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
111
111
  * Space Complexity: O(1) - no additional space is used.
@@ -130,7 +130,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
130
130
  * The enqueue function adds a value to the end of a queue.
131
131
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
132
132
  */
133
- enqueue(value: E): Queue<E>;
133
+ enqueue(value: E): boolean;
134
134
  /**
135
135
  * Time Complexity: O(n) - same as shift().
136
136
  * Space Complexity: O(1) - same as shift().
@@ -194,7 +194,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
194
194
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
195
195
  */
196
196
  clone(): Queue<E>;
197
- print(): void;
198
197
  /**
199
198
  * Time Complexity: O(n)
200
199
  * Space Complexity: O(n)
@@ -239,7 +238,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
239
238
  * Time Complexity: O(n)
240
239
  * Space Complexity: O(n)
241
240
  */
242
- protected _getIterator(): Generator<E, void, unknown>;
241
+ protected _getIterator(): IterableIterator<E>;
243
242
  }
244
243
  /**
245
244
  * 1. First In, First Out (FIFO) Strategy: Like other queue implementations, LinkedListQueue follows the first in, first out principle, meaning the element that is added to the queue first will be the first to be removed.
@@ -252,17 +251,17 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
252
251
  * The enqueue function adds a value to the end of an array.
253
252
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
254
253
  */
255
- enqueue(value: E): void;
254
+ enqueue(value: E): boolean;
256
255
  /**
257
256
  * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
258
257
  * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
259
258
  */
260
259
  dequeue(): E | undefined;
261
260
  /**
262
- * The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
263
- * @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
261
+ * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
262
+ * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
264
263
  */
265
- getFirst(): E | undefined;
264
+ get first(): E | undefined;
266
265
  /**
267
266
  * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
268
267
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
@@ -61,7 +61,7 @@ export class Queue extends IterableElementBase {
61
61
  */
62
62
  push(element) {
63
63
  this.nodes.push(element);
64
- return this;
64
+ return true;
65
65
  }
66
66
  /**
67
67
  * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
@@ -78,7 +78,7 @@ export class Queue extends IterableElementBase {
78
78
  shift() {
79
79
  if (this.size === 0)
80
80
  return undefined;
81
- const first = this.getFirst();
81
+ const first = this.first;
82
82
  this._offset += 1;
83
83
  if (this.offset * 2 < this.nodes.length)
84
84
  return first;
@@ -96,11 +96,11 @@ export class Queue extends IterableElementBase {
96
96
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
97
97
  * Space Complexity: O(1) - no additional space is used.
98
98
  *
99
- * The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
100
- * @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
99
+ * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
100
+ * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
101
101
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
102
102
  */
103
- getFirst() {
103
+ get first() {
104
104
  return this.size > 0 ? this.nodes[this.offset] : undefined;
105
105
  }
106
106
  /**
@@ -116,7 +116,7 @@ export class Queue extends IterableElementBase {
116
116
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
117
117
  */
118
118
  peek() {
119
- return this.getFirst();
119
+ return this.first;
120
120
  }
121
121
  /**
122
122
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
@@ -126,11 +126,11 @@ export class Queue extends IterableElementBase {
126
126
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
127
127
  * Space Complexity: O(1) - no additional space is used.
128
128
  *
129
- * The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
130
- * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
129
+ * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
130
+ * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
131
131
  * array is empty, it returns `undefined`.
132
132
  */
133
- getLast() {
133
+ get last() {
134
134
  return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
135
135
  }
136
136
  /**
@@ -146,7 +146,7 @@ export class Queue extends IterableElementBase {
146
146
  * array is empty, it returns `undefined`.
147
147
  */
148
148
  peekLast() {
149
- return this.getLast();
149
+ return this.last;
150
150
  }
151
151
  /**
152
152
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
@@ -238,9 +238,6 @@ export class Queue extends IterableElementBase {
238
238
  clone() {
239
239
  return new Queue(this.nodes.slice(this.offset));
240
240
  }
241
- print() {
242
- console.log([...this]);
243
- }
244
241
  /**
245
242
  * Time Complexity: O(n)
246
243
  * Space Complexity: O(n)
@@ -321,7 +318,7 @@ export class LinkedListQueue extends SinglyLinkedList {
321
318
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
322
319
  */
323
320
  enqueue(value) {
324
- this.push(value);
321
+ return this.push(value);
325
322
  }
326
323
  /**
327
324
  * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
@@ -331,10 +328,10 @@ export class LinkedListQueue extends SinglyLinkedList {
331
328
  return this.shift();
332
329
  }
333
330
  /**
334
- * The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
335
- * @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
331
+ * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
332
+ * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
336
333
  */
337
- getFirst() {
334
+ get first() {
338
335
  return this.head?.value;
339
336
  }
340
337
  /**
@@ -342,6 +339,6 @@ export class LinkedListQueue extends SinglyLinkedList {
342
339
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
343
340
  */
344
341
  peek() {
345
- return this.getFirst();
342
+ return this.first;
346
343
  }
347
344
  }
@@ -73,7 +73,7 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
73
73
  * @param {E} element - The parameter "element" is of type E, which means it can be any data type.
74
74
  * @returns The `push` method is returning the updated `Stack<E>` object.
75
75
  */
76
- push(element: E): Stack<E>;
76
+ push(element: E): boolean;
77
77
  /**
78
78
  * Time Complexity: O(1), as it only involves accessing the last element of the array.
79
79
  * Space Complexity: O(1), as it does not use any additional space.
@@ -154,10 +154,9 @@ export declare class Stack<E = any> extends IterableElementBase<E> {
154
154
  * @returns The `map` method is returning a new `Stack` object.
155
155
  */
156
156
  map<T>(callback: ElementCallback<E, T>, thisArg?: any): Stack<T>;
157
- print(): void;
158
157
  /**
159
158
  * Custom iterator for the Stack class.
160
159
  * @returns An iterator object.
161
160
  */
162
- protected _getIterator(): Generator<E, void, unknown>;
161
+ protected _getIterator(): IterableIterator<E>;
163
162
  }
@@ -87,7 +87,7 @@ export class Stack extends IterableElementBase {
87
87
  */
88
88
  push(element) {
89
89
  this.elements.push(element);
90
- return this;
90
+ return true;
91
91
  }
92
92
  /**
93
93
  * Time Complexity: O(1), as it only involves accessing the last element of the array.
@@ -103,7 +103,7 @@ export class Stack extends IterableElementBase {
103
103
  */
104
104
  pop() {
105
105
  if (this.isEmpty())
106
- return undefined;
106
+ return;
107
107
  return this.elements.pop();
108
108
  }
109
109
  /**
@@ -197,9 +197,6 @@ export class Stack extends IterableElementBase {
197
197
  }
198
198
  return newStack;
199
199
  }
200
- print() {
201
- console.log([...this]);
202
- }
203
200
  /**
204
201
  * Custom iterator for the Stack class.
205
202
  * @returns An iterator object.
@@ -172,7 +172,7 @@ export declare class Trie extends IterableElementBase<string> {
172
172
  * specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
173
173
  * @returns The `filter` method is returning an array of strings (`string[]`).
174
174
  */
175
- filter(predicate: ElementCallback<string, boolean>, thisArg?: any): string[];
175
+ filter(predicate: ElementCallback<string, boolean>, thisArg?: any): Trie;
176
176
  /**
177
177
  * Time Complexity: O(n)
178
178
  * Space Complexity: O(n)
@@ -191,7 +191,6 @@ export declare class Trie extends IterableElementBase<string> {
191
191
  * @returns The `map` function is returning a new Trie object.
192
192
  */
193
193
  map(callback: ElementCallback<string, string>, thisArg?: any): Trie;
194
- print(): void;
195
194
  protected _getIterator(): IterableIterator<string>;
196
195
  /**
197
196
  * Time Complexity: O(M), where M is the length of the input string.
@@ -343,11 +343,11 @@ export class Trie extends IterableElementBase {
343
343
  * @returns The `filter` method is returning an array of strings (`string[]`).
344
344
  */
345
345
  filter(predicate, thisArg) {
346
- const results = [];
346
+ const results = new Trie();
347
347
  let index = 0;
348
348
  for (const word of this) {
349
349
  if (predicate.call(thisArg, word, index, this)) {
350
- results.push(word);
350
+ results.add(word);
351
351
  }
352
352
  index++;
353
353
  }
@@ -379,9 +379,6 @@ export class Trie extends IterableElementBase {
379
379
  }
380
380
  return newTrie;
381
381
  }
382
- print() {
383
- console.log([...this]);
384
- }
385
382
  *_getIterator() {
386
383
  function* _dfs(node, path) {
387
384
  if (node.isEnd) {