min-heap-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 (31) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +11 -0
  2. package/dist/data-structures/base/iterable-base.js +21 -0
  3. package/dist/data-structures/hash/hash-map.d.ts +9 -9
  4. package/dist/data-structures/hash/hash-map.js +16 -15
  5. package/dist/data-structures/heap/heap.d.ts +6 -35
  6. package/dist/data-structures/heap/heap.js +10 -42
  7. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +87 -93
  8. package/dist/data-structures/linked-list/doubly-linked-list.js +126 -129
  9. package/dist/data-structures/linked-list/singly-linked-list.d.ts +16 -21
  10. package/dist/data-structures/linked-list/singly-linked-list.js +42 -42
  11. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  12. package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
  13. package/dist/data-structures/queue/deque.d.ts +70 -75
  14. package/dist/data-structures/queue/deque.js +100 -110
  15. package/dist/data-structures/queue/queue.d.ts +13 -14
  16. package/dist/data-structures/queue/queue.js +15 -18
  17. package/dist/data-structures/stack/stack.d.ts +2 -3
  18. package/dist/data-structures/stack/stack.js +2 -5
  19. package/dist/data-structures/trie/trie.d.ts +1 -2
  20. package/dist/data-structures/trie/trie.js +2 -5
  21. package/package.json +1 -1
  22. package/src/data-structures/base/iterable-base.ts +24 -0
  23. package/src/data-structures/hash/hash-map.ts +27 -28
  24. package/src/data-structures/heap/heap.ts +19 -57
  25. package/src/data-structures/linked-list/doubly-linked-list.ts +138 -142
  26. package/src/data-structures/linked-list/singly-linked-list.ts +49 -49
  27. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  28. package/src/data-structures/queue/deque.ts +122 -135
  29. package/src/data-structures/queue/queue.ts +19 -23
  30. package/src/data-structures/stack/stack.ts +4 -8
  31. package/src/data-structures/trie/trie.ts +5 -9
@@ -75,95 +75,6 @@ class Deque extends base_1.IterableElementBase {
75
75
  return;
76
76
  return this._buckets[this._bucketLast][this._lastInBucket];
77
77
  }
78
- /**
79
- * Time Complexity: O(1) - Removes the last element.
80
- * Space Complexity: O(1) - Operates in-place.
81
- */
82
- isEmpty() {
83
- return this.size === 0;
84
- }
85
- /**
86
- * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
87
- * Space Complexity: O(n) - Due to potential resizing.
88
- */
89
- /**
90
- * Time Complexity: O(1)
91
- * Space Complexity: O(n) - In worst case, resizing doubles the array size.
92
- *
93
- * The addLast function adds an element to the end of an array.
94
- * @param {E} element - The element parameter represents the element that you want to add to the end of the
95
- * data structure.
96
- */
97
- addLast(element) {
98
- this.push(element);
99
- }
100
- /**
101
- * Time Complexity: O(1) - Removes the first element.
102
- * Space Complexity: O(1) - In-place operation.
103
- */
104
- /**
105
- * Time Complexity: O(1) - Removes the last element.
106
- * Space Complexity: O(1) - Operates in-place.
107
- *
108
- * The function "pollLast" removes and returns the last element of an array.
109
- * @returns The last element of the array is being returned.
110
- */
111
- pollLast() {
112
- return this.pop();
113
- }
114
- /**
115
- * Time Complexity: O(1).
116
- * Space Complexity: O(n) - Due to potential resizing.
117
- *
118
- * The "addFirst" function adds an element to the beginning of an array.
119
- * @param {E} element - The parameter "element" represents the element that you want to add to the
120
- * beginning of the data structure.
121
- */
122
- addFirst(element) {
123
- this.unshift(element);
124
- }
125
- /**
126
- * Time Complexity: O(1) - Removes the first element.
127
- * Space Complexity: O(1) - In-place operation.
128
- *
129
- * The function "pollFirst" removes and returns the first element of an array.
130
- * @returns The method `pollFirst()` is returning the first element of the array after removing it
131
- * from the beginning. If the array is empty, it will return `undefined`.
132
- */
133
- pollFirst() {
134
- return this.shift();
135
- }
136
- /**
137
- * The clear() function resets the state of the object by initializing all variables to their default
138
- * values.
139
- */
140
- clear() {
141
- this._buckets = [new Array(this._bucketSize)];
142
- this._bucketCount = 1;
143
- this._bucketFirst = this._bucketLast = this._size = 0;
144
- this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
145
- }
146
- /**
147
- * The below function is a generator that yields elements from a collection one by one.
148
- */
149
- *begin() {
150
- let index = 0;
151
- while (index < this.size) {
152
- yield this.getAt(index);
153
- index++;
154
- }
155
- }
156
- /**
157
- * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
158
- * the last element.
159
- */
160
- *reverseBegin() {
161
- let index = this.size - 1;
162
- while (index >= 0) {
163
- yield this.getAt(index);
164
- index--;
165
- }
166
- }
167
78
  /**
168
79
  * Time Complexity - Amortized O(1) (possible reallocation)
169
80
  * Space Complexity - O(n) (due to potential resizing).
@@ -196,7 +107,7 @@ class Deque extends base_1.IterableElementBase {
196
107
  }
197
108
  this._size += 1;
198
109
  this._buckets[this._bucketLast][this._lastInBucket] = element;
199
- return this.size;
110
+ return true;
200
111
  }
201
112
  /**
202
113
  * Time Complexity: O(1)
@@ -263,7 +174,7 @@ class Deque extends base_1.IterableElementBase {
263
174
  }
264
175
  this._size += 1;
265
176
  this._buckets[this._bucketFirst][this._firstInBucket] = element;
266
- return this.size;
177
+ return true;
267
178
  }
268
179
  /**
269
180
  * Time Complexity: O(1)
@@ -298,6 +209,44 @@ class Deque extends base_1.IterableElementBase {
298
209
  this._size -= 1;
299
210
  return element;
300
211
  }
212
+ /**
213
+ * Time Complexity: O(1) - Removes the last element.
214
+ * Space Complexity: O(1) - Operates in-place.
215
+ */
216
+ isEmpty() {
217
+ return this.size === 0;
218
+ }
219
+ /**
220
+ * The clear() function resets the state of the object by initializing all variables to their default
221
+ * values.
222
+ */
223
+ clear() {
224
+ this._buckets = [new Array(this._bucketSize)];
225
+ this._bucketCount = 1;
226
+ this._bucketFirst = this._bucketLast = this._size = 0;
227
+ this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
228
+ }
229
+ /**
230
+ * The below function is a generator that yields elements from a collection one by one.
231
+ */
232
+ *begin() {
233
+ let index = 0;
234
+ while (index < this.size) {
235
+ yield this.getAt(index);
236
+ index++;
237
+ }
238
+ }
239
+ /**
240
+ * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
241
+ * the last element.
242
+ */
243
+ *reverseBegin() {
244
+ let index = this.size - 1;
245
+ while (index >= 0) {
246
+ yield this.getAt(index);
247
+ index--;
248
+ }
249
+ }
301
250
  /**
302
251
  * Time Complexity: O(1)
303
252
  * Space Complexity: O(1)
@@ -335,6 +284,7 @@ class Deque extends base_1.IterableElementBase {
335
284
  (0, utils_1.rangeCheck)(pos, 0, this.size - 1);
336
285
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
337
286
  this._buckets[bucketIndex][indexInBucket] = element;
287
+ return true;
338
288
  }
339
289
  /**
340
290
  * Time Complexity: O(n)
@@ -344,7 +294,7 @@ class Deque extends base_1.IterableElementBase {
344
294
  * Time Complexity: O(n)
345
295
  * Space Complexity: O(n)
346
296
  *
347
- * The `insertAt` function inserts one or more elements at a specified position in an array-like data
297
+ * The `addAt` function inserts one or more elements at a specified position in an array-like data
348
298
  * structure.
349
299
  * @param {number} pos - The `pos` parameter represents the position at which the element(s) should
350
300
  * be inserted. It is of type `number`.
@@ -355,7 +305,7 @@ class Deque extends base_1.IterableElementBase {
355
305
  * will be inserted once. However, you can provide a different value for `num` if you want
356
306
  * @returns The size of the array after the insertion is being returned.
357
307
  */
358
- insertAt(pos, element, num = 1) {
308
+ addAt(pos, element, num = 1) {
359
309
  const length = this.size;
360
310
  (0, utils_1.rangeCheck)(pos, 0, length);
361
311
  if (pos === 0) {
@@ -377,7 +327,7 @@ class Deque extends base_1.IterableElementBase {
377
327
  for (let i = 0; i < arr.length; ++i)
378
328
  this.push(arr[i]);
379
329
  }
380
- return this.size;
330
+ return true;
381
331
  }
382
332
  /**
383
333
  * Time Complexity: O(1)
@@ -436,7 +386,7 @@ class Deque extends base_1.IterableElementBase {
436
386
  }
437
387
  this.pop();
438
388
  }
439
- return this.size;
389
+ return true;
440
390
  }
441
391
  /**
442
392
  * Time Complexity: O(n)
@@ -455,7 +405,7 @@ class Deque extends base_1.IterableElementBase {
455
405
  delete(element) {
456
406
  const size = this.size;
457
407
  if (size === 0)
458
- return 0;
408
+ return false;
459
409
  let i = 0;
460
410
  let index = 0;
461
411
  while (i < size) {
@@ -467,7 +417,7 @@ class Deque extends base_1.IterableElementBase {
467
417
  i += 1;
468
418
  }
469
419
  this.cut(index - 1);
470
- return this.size;
420
+ return true;
471
421
  }
472
422
  /**
473
423
  * Time Complexity: O(n)
@@ -507,7 +457,7 @@ class Deque extends base_1.IterableElementBase {
507
457
  */
508
458
  unique() {
509
459
  if (this.size <= 1) {
510
- return this.size;
460
+ return this;
511
461
  }
512
462
  let index = 1;
513
463
  let prev = this.getAt(0);
@@ -519,7 +469,7 @@ class Deque extends base_1.IterableElementBase {
519
469
  }
520
470
  }
521
471
  this.cut(index - 1);
522
- return this.size;
472
+ return this;
523
473
  }
524
474
  /**
525
475
  * Time Complexity: O(n log n)
@@ -533,7 +483,7 @@ class Deque extends base_1.IterableElementBase {
533
483
  * @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
534
484
  * `y` of type `E` and returns a number. The comparator function is used to determine the order of
535
485
  * the elements in the sorted array.
536
- * @returns The method is returning the sorted instance of the object on which the method is called.
486
+ * @returns Deque<E>
537
487
  */
538
488
  sort(comparator) {
539
489
  const arr = [];
@@ -604,7 +554,7 @@ class Deque extends base_1.IterableElementBase {
604
554
  return element;
605
555
  }
606
556
  }
607
- return undefined;
557
+ return;
608
558
  }
609
559
  /**
610
560
  * Time Complexity: O(n)
@@ -641,11 +591,7 @@ class Deque extends base_1.IterableElementBase {
641
591
  * @returns The `toArray()` method is returning an array of elements of type `E`.
642
592
  */
643
593
  toArray() {
644
- const arr = [];
645
- for (let i = 0; i < this.size; ++i) {
646
- arr.push(this.getAt(i));
647
- }
648
- return arr;
594
+ return [...this];
649
595
  }
650
596
  /**
651
597
  * Time Complexity: O(n)
@@ -705,11 +651,55 @@ class Deque extends base_1.IterableElementBase {
705
651
  return newDeque;
706
652
  }
707
653
  /**
708
- * Time Complexity: O(n)
709
- * Space Complexity: O(n)
654
+ * Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
655
+ * Space Complexity: O(n) - Due to potential resizing.
656
+ */
657
+ /**
658
+ * Time Complexity: O(1)
659
+ * Space Complexity: O(n) - In worst case, resizing doubles the array size.
660
+ *
661
+ * The addLast function adds an element to the end of an array.
662
+ * @param {E} element - The element parameter represents the element that you want to add to the end of the
663
+ * data structure.
664
+ */
665
+ addLast(element) {
666
+ return this.push(element);
667
+ }
668
+ /**
669
+ * Time Complexity: O(1) - Removes the first element.
670
+ * Space Complexity: O(1) - In-place operation.
671
+ */
672
+ /**
673
+ * Time Complexity: O(1) - Removes the last element.
674
+ * Space Complexity: O(1) - Operates in-place.
675
+ *
676
+ * The function "pollLast" removes and returns the last element of an array.
677
+ * @returns The last element of the array is being returned.
710
678
  */
711
- print() {
712
- console.log([...this]);
679
+ pollLast() {
680
+ return this.pop();
681
+ }
682
+ /**
683
+ * Time Complexity: O(1).
684
+ * Space Complexity: O(n) - Due to potential resizing.
685
+ *
686
+ * The "addFirst" function adds an element to the beginning of an array.
687
+ * @param {E} element - The parameter "element" represents the element that you want to add to the
688
+ * beginning of the data structure.
689
+ */
690
+ addFirst(element) {
691
+ return this.unshift(element);
692
+ }
693
+ /**
694
+ * Time Complexity: O(1) - Removes the first element.
695
+ * Space Complexity: O(1) - In-place operation.
696
+ *
697
+ * The function "pollFirst" removes and returns the first element of an array.
698
+ * @returns The method `pollFirst()` is returning the first element of the array after removing it
699
+ * from the beginning. If the array is empty, it will return `undefined`.
700
+ */
701
+ pollFirst() {
702
+ return this.shift();
713
703
  }
714
704
  /**
715
705
  * 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`.
@@ -62,7 +62,7 @@ class Queue extends base_1.IterableElementBase {
62
62
  */
63
63
  push(element) {
64
64
  this.nodes.push(element);
65
- return this;
65
+ return true;
66
66
  }
67
67
  /**
68
68
  * 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.
@@ -79,7 +79,7 @@ class Queue extends base_1.IterableElementBase {
79
79
  shift() {
80
80
  if (this.size === 0)
81
81
  return undefined;
82
- const first = this.getFirst();
82
+ const first = this.first;
83
83
  this._offset += 1;
84
84
  if (this.offset * 2 < this.nodes.length)
85
85
  return first;
@@ -97,11 +97,11 @@ class Queue extends base_1.IterableElementBase {
97
97
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
98
98
  * Space Complexity: O(1) - no additional space is used.
99
99
  *
100
- * The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
101
- * @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
100
+ * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
101
+ * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
102
102
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
103
103
  */
104
- getFirst() {
104
+ get first() {
105
105
  return this.size > 0 ? this.nodes[this.offset] : undefined;
106
106
  }
107
107
  /**
@@ -117,7 +117,7 @@ class Queue extends base_1.IterableElementBase {
117
117
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
118
118
  */
119
119
  peek() {
120
- return this.getFirst();
120
+ return this.first;
121
121
  }
122
122
  /**
123
123
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
@@ -127,11 +127,11 @@ class Queue extends base_1.IterableElementBase {
127
127
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
128
128
  * Space Complexity: O(1) - no additional space is used.
129
129
  *
130
- * The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
131
- * @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
130
+ * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
131
+ * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
132
132
  * array is empty, it returns `undefined`.
133
133
  */
134
- getLast() {
134
+ get last() {
135
135
  return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
136
136
  }
137
137
  /**
@@ -147,7 +147,7 @@ class Queue extends base_1.IterableElementBase {
147
147
  * array is empty, it returns `undefined`.
148
148
  */
149
149
  peekLast() {
150
- return this.getLast();
150
+ return this.last;
151
151
  }
152
152
  /**
153
153
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
@@ -239,9 +239,6 @@ class Queue extends base_1.IterableElementBase {
239
239
  clone() {
240
240
  return new Queue(this.nodes.slice(this.offset));
241
241
  }
242
- print() {
243
- console.log([...this]);
244
- }
245
242
  /**
246
243
  * Time Complexity: O(n)
247
244
  * Space Complexity: O(n)
@@ -323,7 +320,7 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
323
320
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
324
321
  */
325
322
  enqueue(value) {
326
- this.push(value);
323
+ return this.push(value);
327
324
  }
328
325
  /**
329
326
  * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
@@ -333,10 +330,10 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
333
330
  return this.shift();
334
331
  }
335
332
  /**
336
- * The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
337
- * @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
333
+ * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
334
+ * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
338
335
  */
339
- getFirst() {
336
+ get first() {
340
337
  var _a;
341
338
  return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
342
339
  }
@@ -345,7 +342,7 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
345
342
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
346
343
  */
347
344
  peek() {
348
- return this.getFirst();
345
+ return this.first;
349
346
  }
350
347
  }
351
348
  exports.LinkedListQueue = LinkedListQueue;
@@ -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
  }
@@ -89,7 +89,7 @@ class Stack extends base_1.IterableElementBase {
89
89
  */
90
90
  push(element) {
91
91
  this.elements.push(element);
92
- return this;
92
+ return true;
93
93
  }
94
94
  /**
95
95
  * Time Complexity: O(1), as it only involves accessing the last element of the array.
@@ -105,7 +105,7 @@ class Stack extends base_1.IterableElementBase {
105
105
  */
106
106
  pop() {
107
107
  if (this.isEmpty())
108
- return undefined;
108
+ return;
109
109
  return this.elements.pop();
110
110
  }
111
111
  /**
@@ -199,9 +199,6 @@ class Stack extends base_1.IterableElementBase {
199
199
  }
200
200
  return newStack;
201
201
  }
202
- print() {
203
- console.log([...this]);
204
- }
205
202
  /**
206
203
  * Custom iterator for the Stack class.
207
204
  * @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.
@@ -341,11 +341,11 @@ class Trie extends base_1.IterableElementBase {
341
341
  * @returns The `filter` method is returning an array of strings (`string[]`).
342
342
  */
343
343
  filter(predicate, thisArg) {
344
- const results = [];
344
+ const results = new Trie();
345
345
  let index = 0;
346
346
  for (const word of this) {
347
347
  if (predicate.call(thisArg, word, index, this)) {
348
- results.push(word);
348
+ results.add(word);
349
349
  }
350
350
  index++;
351
351
  }
@@ -377,9 +377,6 @@ class Trie extends base_1.IterableElementBase {
377
377
  }
378
378
  return newTrie;
379
379
  }
380
- print() {
381
- console.log([...this]);
382
- }
383
380
  *_getIterator() {
384
381
  function* _dfs(node, path) {
385
382
  if (node.isEnd) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "min-heap-typed",
3
- "version": "1.49.1",
3
+ "version": "1.49.2",
4
4
  "description": "Min Heap. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -181,6 +181,21 @@ export abstract class IterableEntryBase<K = any, V = any> {
181
181
  return accumulator;
182
182
  }
183
183
 
184
+ hasValue(value: V): boolean {
185
+ for (const [, elementValue] of this) {
186
+ if (elementValue === value) return true;
187
+ }
188
+ return false;
189
+ }
190
+
191
+ /**
192
+ * Time Complexity: O(n)
193
+ * Space Complexity: O(n)
194
+ */
195
+ print(): void {
196
+ console.log([...this])
197
+ }
198
+
184
199
  protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
185
200
  }
186
201
 
@@ -325,5 +340,14 @@ export abstract class IterableElementBase<V> {
325
340
  return accumulator;
326
341
  }
327
342
 
343
+
344
+ /**
345
+ * Time Complexity: O(n)
346
+ * Space Complexity: O(n)
347
+ */
348
+ print(): void {
349
+ console.log([...this])
350
+ }
351
+
328
352
  protected abstract _getIterator(...args: any[]): IterableIterator<V>;
329
353
  }