linked-list-typed 1.53.7 → 1.53.9

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 (68) hide show
  1. package/dist/common/index.js +5 -0
  2. package/dist/data-structures/base/iterable-entry-base.js +4 -4
  3. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +36 -17
  4. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +65 -36
  5. package/dist/data-structures/binary-tree/avl-tree.d.ts +12 -8
  6. package/dist/data-structures/binary-tree/avl-tree.js +19 -6
  7. package/dist/data-structures/binary-tree/binary-tree.d.ts +53 -40
  8. package/dist/data-structures/binary-tree/binary-tree.js +76 -72
  9. package/dist/data-structures/binary-tree/bst.d.ts +87 -52
  10. package/dist/data-structures/binary-tree/bst.js +111 -63
  11. package/dist/data-structures/binary-tree/index.d.ts +1 -1
  12. package/dist/data-structures/binary-tree/index.js +1 -1
  13. package/dist/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +83 -10
  14. package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +91 -44
  15. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +34 -18
  16. package/dist/data-structures/binary-tree/tree-multi-map.js +66 -40
  17. package/dist/data-structures/graph/abstract-graph.js +2 -2
  18. package/dist/data-structures/hash/hash-map.d.ts +31 -1
  19. package/dist/data-structures/hash/hash-map.js +35 -5
  20. package/dist/data-structures/heap/heap.d.ts +20 -3
  21. package/dist/data-structures/heap/heap.js +31 -11
  22. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +46 -11
  23. package/dist/data-structures/linked-list/doubly-linked-list.js +68 -21
  24. package/dist/data-structures/linked-list/singly-linked-list.d.ts +44 -11
  25. package/dist/data-structures/linked-list/singly-linked-list.js +70 -26
  26. package/dist/data-structures/queue/deque.d.ts +37 -8
  27. package/dist/data-structures/queue/deque.js +73 -29
  28. package/dist/data-structures/queue/queue.d.ts +41 -1
  29. package/dist/data-structures/queue/queue.js +51 -9
  30. package/dist/data-structures/stack/stack.d.ts +27 -10
  31. package/dist/data-structures/stack/stack.js +39 -20
  32. package/dist/data-structures/trie/trie.d.ts +8 -3
  33. package/dist/data-structures/trie/trie.js +8 -3
  34. package/dist/interfaces/binary-tree.d.ts +3 -4
  35. package/dist/types/data-structures/base/base.d.ts +1 -1
  36. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  37. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  38. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
  39. package/dist/types/data-structures/binary-tree/bst.d.ts +3 -4
  40. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -5
  41. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -5
  42. package/package.json +2 -2
  43. package/src/common/index.ts +7 -1
  44. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  45. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +82 -55
  46. package/src/data-structures/binary-tree/avl-tree.ts +32 -15
  47. package/src/data-structures/binary-tree/binary-tree.ts +89 -84
  48. package/src/data-structures/binary-tree/bst.ts +149 -97
  49. package/src/data-structures/binary-tree/index.ts +1 -1
  50. package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +105 -55
  51. package/src/data-structures/binary-tree/tree-multi-map.ts +81 -51
  52. package/src/data-structures/graph/abstract-graph.ts +2 -2
  53. package/src/data-structures/hash/hash-map.ts +37 -7
  54. package/src/data-structures/heap/heap.ts +33 -10
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +75 -21
  56. package/src/data-structures/linked-list/singly-linked-list.ts +77 -27
  57. package/src/data-structures/queue/deque.ts +72 -28
  58. package/src/data-structures/queue/queue.ts +50 -7
  59. package/src/data-structures/stack/stack.ts +39 -20
  60. package/src/data-structures/trie/trie.ts +8 -3
  61. package/src/interfaces/binary-tree.ts +3 -13
  62. package/src/types/data-structures/base/base.ts +1 -1
  63. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -4
  64. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -4
  65. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -3
  66. package/src/types/data-structures/binary-tree/bst.ts +3 -5
  67. package/src/types/data-structures/binary-tree/rb-tree.ts +4 -6
  68. package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -6
@@ -497,7 +497,7 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
497
497
  * `DoublyLinkedListOptions<E, R>`. It is an optional parameter that allows you to pass additional
498
498
  * configuration options to customize the behavior of the DoublyLinkedList.
499
499
  */
500
- constructor(elements?: Iterable<E> | Iterable<R>, options?: DoublyLinkedListOptions<E, R>);
500
+ constructor(elements?: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>, options?: DoublyLinkedListOptions<E, R>);
501
501
  protected _head: DoublyLinkedListNode<E> | undefined;
502
502
  /**
503
503
  * The `head` function returns the first node of a doubly linked list.
@@ -533,6 +533,16 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
533
533
  * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
534
534
  */
535
535
  get last(): E | undefined;
536
+ /**
537
+ * Time Complexity: O(n)
538
+ * Space Complexity: O(n)
539
+ *
540
+ * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
541
+ * given array.
542
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
543
+ * @returns The `fromArray` function returns a DoublyLinkedList object.
544
+ */
545
+ static fromArray<E>(data: E[]): DoublyLinkedList<E, any>;
536
546
  /**
537
547
  * Time Complexity: O(1)
538
548
  * Space Complexity: O(1)
@@ -585,6 +595,35 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
585
595
  * @returns The `unshift` method is returning a boolean value, specifically `true`.
586
596
  */
587
597
  unshift(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
598
+ /**
599
+ * Time Complexity: O(k)
600
+ * Space Complexity: O(k)
601
+ *
602
+ * The function `pushMany` iterates over elements and pushes them into a data structure, applying a
603
+ * transformation function if provided.
604
+ * @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
605
+ * parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
606
+ * or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and pushes
607
+ * it onto the linked list. If a transformation function `to
608
+ * @returns The `pushMany` function is returning an array of boolean values (`ans`) which indicate
609
+ * the success or failure of pushing each element into the data structure.
610
+ */
611
+ pushMany(elements: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>): boolean[];
612
+ /**
613
+ * Time Complexity: O(k)
614
+ * Space Complexity: O(k)
615
+ *
616
+ * The function `unshiftMany` iterates through a collection of elements and adds them to the
617
+ * beginning of a Doubly Linked List, returning an array of boolean values indicating the success of
618
+ * each insertion.
619
+ * @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
620
+ * parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
621
+ * `R`, or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and
622
+ * performs an `unshift` operation on the doubly linked list
623
+ * @returns The `unshiftMany` function returns an array of boolean values indicating the success of
624
+ * each unshift operation performed on the elements passed as input.
625
+ */
626
+ unshiftMany(elements: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>): boolean[];
588
627
  /**
589
628
  * Time Complexity: O(n)
590
629
  * Space Complexity: O(1)
@@ -830,18 +869,14 @@ export declare class DoublyLinkedList<E = any, R = any> extends IterableElementB
830
869
  * Time Complexity: O(n)
831
870
  * Space Complexity: O(1)
832
871
  *
872
+ * The function `countOccurrences` iterates through a doubly linked list and counts the occurrences
873
+ * of a specified element or nodes that satisfy a given predicate.
874
+ * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementOrNode
875
+ * - The `elementOrNode` parameter in the `countOccurrences` method can accept three types of values:
876
+ * @returns The `countOccurrences` method returns the number of occurrences of the specified element,
877
+ * node, or predicate function in the doubly linked list.
833
878
  */
834
879
  countOccurrences(elementOrNode: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): number;
835
- /**
836
- * Time Complexity: O(n)
837
- * Space Complexity: O(n)
838
- *
839
- * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
840
- * given array.
841
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
842
- * @returns The `fromArray` function returns a DoublyLinkedList object.
843
- */
844
- static fromArray<E>(data: E[]): DoublyLinkedList<E, any>;
845
880
  /**
846
881
  * The function returns an iterator that iterates over the values of a linked list.
847
882
  */
@@ -511,15 +511,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
511
511
  this._head = undefined;
512
512
  this._tail = undefined;
513
513
  this._size = 0;
514
- if (elements) {
515
- for (const el of elements) {
516
- if (this.toElementFn) {
517
- this.push(this.toElementFn(el));
518
- }
519
- else
520
- this.push(el);
521
- }
522
- }
514
+ this.pushMany(elements);
523
515
  }
524
516
  /**
525
517
  * The `head` function returns the first node of a doubly linked list.
@@ -565,6 +557,18 @@ class DoublyLinkedList extends base_1.IterableElementBase {
565
557
  var _a;
566
558
  return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
567
559
  }
560
+ /**
561
+ * Time Complexity: O(n)
562
+ * Space Complexity: O(n)
563
+ *
564
+ * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
565
+ * given array.
566
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
567
+ * @returns The `fromArray` function returns a DoublyLinkedList object.
568
+ */
569
+ static fromArray(data) {
570
+ return new DoublyLinkedList(data);
571
+ }
568
572
  /**
569
573
  * Time Complexity: O(1)
570
574
  * Space Complexity: O(1)
@@ -673,6 +677,55 @@ class DoublyLinkedList extends base_1.IterableElementBase {
673
677
  this._size++;
674
678
  return true;
675
679
  }
680
+ /**
681
+ * Time Complexity: O(k)
682
+ * Space Complexity: O(k)
683
+ *
684
+ * The function `pushMany` iterates over elements and pushes them into a data structure, applying a
685
+ * transformation function if provided.
686
+ * @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
687
+ * parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
688
+ * or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and pushes
689
+ * it onto the linked list. If a transformation function `to
690
+ * @returns The `pushMany` function is returning an array of boolean values (`ans`) which indicate
691
+ * the success or failure of pushing each element into the data structure.
692
+ */
693
+ pushMany(elements) {
694
+ const ans = [];
695
+ for (const el of elements) {
696
+ if (this.toElementFn) {
697
+ ans.push(this.push(this.toElementFn(el)));
698
+ continue;
699
+ }
700
+ ans.push(this.push(el));
701
+ }
702
+ return ans;
703
+ }
704
+ /**
705
+ * Time Complexity: O(k)
706
+ * Space Complexity: O(k)
707
+ *
708
+ * The function `unshiftMany` iterates through a collection of elements and adds them to the
709
+ * beginning of a Doubly Linked List, returning an array of boolean values indicating the success of
710
+ * each insertion.
711
+ * @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
712
+ * parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
713
+ * `R`, or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and
714
+ * performs an `unshift` operation on the doubly linked list
715
+ * @returns The `unshiftMany` function returns an array of boolean values indicating the success of
716
+ * each unshift operation performed on the elements passed as input.
717
+ */
718
+ unshiftMany(elements) {
719
+ const ans = [];
720
+ for (const el of elements) {
721
+ if (this.toElementFn) {
722
+ ans.push(this.unshift(this.toElementFn(el)));
723
+ continue;
724
+ }
725
+ ans.push(this.unshift(el));
726
+ }
727
+ return ans;
728
+ }
676
729
  /**
677
730
  * Time Complexity: O(n)
678
731
  * Space Complexity: O(1)
@@ -1124,6 +1177,12 @@ class DoublyLinkedList extends base_1.IterableElementBase {
1124
1177
  * Time Complexity: O(n)
1125
1178
  * Space Complexity: O(1)
1126
1179
  *
1180
+ * The function `countOccurrences` iterates through a doubly linked list and counts the occurrences
1181
+ * of a specified element or nodes that satisfy a given predicate.
1182
+ * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementOrNode
1183
+ * - The `elementOrNode` parameter in the `countOccurrences` method can accept three types of values:
1184
+ * @returns The `countOccurrences` method returns the number of occurrences of the specified element,
1185
+ * node, or predicate function in the doubly linked list.
1127
1186
  */
1128
1187
  countOccurrences(elementOrNode) {
1129
1188
  const predicate = this._ensurePredicate(elementOrNode);
@@ -1137,18 +1196,6 @@ class DoublyLinkedList extends base_1.IterableElementBase {
1137
1196
  }
1138
1197
  return count;
1139
1198
  }
1140
- /**
1141
- * Time Complexity: O(n)
1142
- * Space Complexity: O(n)
1143
- *
1144
- * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
1145
- * given array.
1146
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
1147
- * @returns The `fromArray` function returns a DoublyLinkedList object.
1148
- */
1149
- static fromArray(data) {
1150
- return new DoublyLinkedList(data);
1151
- }
1152
1199
  /**
1153
1200
  * The function returns an iterator that iterates over the values of a linked list.
1154
1201
  */
@@ -41,7 +41,7 @@ export declare class SinglyLinkedListNode<E = any> {
41
41
  set next(value: SinglyLinkedListNode<E> | undefined);
42
42
  }
43
43
  export declare class SinglyLinkedList<E = any, R = any> extends IterableElementBase<E, R, SinglyLinkedList<E, R>> {
44
- constructor(elements?: Iterable<E> | Iterable<R>, options?: SinglyLinkedListOptions<E, R>);
44
+ constructor(elements?: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>, options?: SinglyLinkedListOptions<E, R>);
45
45
  protected _head: SinglyLinkedListNode<E> | undefined;
46
46
  /**
47
47
  * The `head` function returns the first node of a singly linked list.
@@ -72,6 +72,16 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
72
72
  * @returns The size of the object, which is a number.
73
73
  */
74
74
  get size(): number;
75
+ /**
76
+ * Time Complexity: O(n)
77
+ * Space Complexity: O(n)
78
+ *
79
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
80
+ * array.
81
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
82
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
83
+ */
84
+ static fromArray<E>(data: E[]): SinglyLinkedList<E, any>;
75
85
  /**
76
86
  * Time Complexity: O(1)
77
87
  * Space Complexity: O(1)
@@ -111,6 +121,33 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
111
121
  * @returns The `unshift` method is returning a boolean value, specifically `true`.
112
122
  */
113
123
  unshift(elementOrNode: E | SinglyLinkedListNode<E>): boolean;
124
+ /**
125
+ * Time Complexity: O(k)
126
+ * Space Complexity: O(k)
127
+ *
128
+ * The function `pushMany` iterates over elements and pushes them into a data structure, applying a
129
+ * transformation function if provided.
130
+ * @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
131
+ * parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
132
+ * or `SinglyLinkedListNode<E>`.
133
+ * @returns The `pushMany` function returns an array of boolean values indicating whether each
134
+ * element was successfully pushed into the data structure.
135
+ */
136
+ pushMany(elements: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>): boolean[];
137
+ /**
138
+ * Time Complexity: O(k)
139
+ * Space Complexity: O(k)
140
+ *
141
+ * The function `unshiftMany` iterates over elements and adds them to a data structure, optionally
142
+ * converting them using a provided function.
143
+ * @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
144
+ * parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
145
+ * `R`, or `SinglyLinkedListNode<E>`. The function iterates over each element in the iterable and
146
+ * performs an `unshift` operation on the linked list for each
147
+ * @returns The `unshiftMany` function is returning an array of boolean values, where each value
148
+ * represents the result of calling the `unshift` method on the current instance of the class.
149
+ */
150
+ unshiftMany(elements: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>): boolean[];
114
151
  /**
115
152
  * Time Complexity: O(n)
116
153
  * Space Complexity: O(1)
@@ -199,12 +236,18 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
199
236
  */
200
237
  addAt(index: number, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
201
238
  /**
239
+ * Time Complexity: O(1)
240
+ * Space Complexity: O(1)
241
+ *
202
242
  * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
203
243
  * whether it is empty or not.
204
244
  * @returns A boolean value indicating whether the length of the object is equal to 0.
205
245
  */
206
246
  isEmpty(): boolean;
207
247
  /**
248
+ * Time Complexity: O(1)
249
+ * Space Complexity: O(1)
250
+ *
208
251
  * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
209
252
  */
210
253
  clear(): void;
@@ -351,16 +394,6 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
351
394
  * The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
352
395
  */
353
396
  protected _getIterator(): IterableIterator<E>;
354
- /**
355
- * Time Complexity: O(n)
356
- * Space Complexity: O(n)
357
- *
358
- * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
359
- * array.
360
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
361
- * @returns The `fromArray` function returns a `SinglyLinkedList` object.
362
- */
363
- static fromArray<E>(data: E[]): SinglyLinkedList<E, any>;
364
397
  /**
365
398
  * The _isPredicate function in TypeScript checks if the input is a function that takes a
366
399
  * SinglyLinkedListNode as an argument and returns a boolean.
@@ -49,16 +49,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
49
49
  constructor(elements = [], options) {
50
50
  super(options);
51
51
  this._size = 0;
52
- if (elements) {
53
- for (const el of elements) {
54
- if (this.toElementFn) {
55
- this.push(this.toElementFn(el));
56
- }
57
- else {
58
- this.push(el);
59
- }
60
- }
61
- }
52
+ this.pushMany(elements);
62
53
  }
63
54
  /**
64
55
  * The `head` function returns the first node of a singly linked list.
@@ -99,6 +90,22 @@ class SinglyLinkedList extends base_1.IterableElementBase {
99
90
  get size() {
100
91
  return this._size;
101
92
  }
93
+ /**
94
+ * Time Complexity: O(n)
95
+ * Space Complexity: O(n)
96
+ *
97
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
98
+ * array.
99
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
100
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
101
+ */
102
+ static fromArray(data) {
103
+ const singlyLinkedList = new SinglyLinkedList();
104
+ for (const item of data) {
105
+ singlyLinkedList.push(item);
106
+ }
107
+ return singlyLinkedList;
108
+ }
102
109
  /**
103
110
  * Time Complexity: O(1)
104
111
  * Space Complexity: O(1)
@@ -188,6 +195,53 @@ class SinglyLinkedList extends base_1.IterableElementBase {
188
195
  this._size++;
189
196
  return true;
190
197
  }
198
+ /**
199
+ * Time Complexity: O(k)
200
+ * Space Complexity: O(k)
201
+ *
202
+ * The function `pushMany` iterates over elements and pushes them into a data structure, applying a
203
+ * transformation function if provided.
204
+ * @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
205
+ * parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
206
+ * or `SinglyLinkedListNode<E>`.
207
+ * @returns The `pushMany` function returns an array of boolean values indicating whether each
208
+ * element was successfully pushed into the data structure.
209
+ */
210
+ pushMany(elements) {
211
+ const ans = [];
212
+ for (const el of elements) {
213
+ if (this.toElementFn) {
214
+ ans.push(this.push(this.toElementFn(el)));
215
+ continue;
216
+ }
217
+ ans.push(this.push(el));
218
+ }
219
+ return ans;
220
+ }
221
+ /**
222
+ * Time Complexity: O(k)
223
+ * Space Complexity: O(k)
224
+ *
225
+ * The function `unshiftMany` iterates over elements and adds them to a data structure, optionally
226
+ * converting them using a provided function.
227
+ * @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
228
+ * parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
229
+ * `R`, or `SinglyLinkedListNode<E>`. The function iterates over each element in the iterable and
230
+ * performs an `unshift` operation on the linked list for each
231
+ * @returns The `unshiftMany` function is returning an array of boolean values, where each value
232
+ * represents the result of calling the `unshift` method on the current instance of the class.
233
+ */
234
+ unshiftMany(elements) {
235
+ const ans = [];
236
+ for (const el of elements) {
237
+ if (this.toElementFn) {
238
+ ans.push(this.unshift(this.toElementFn(el)));
239
+ continue;
240
+ }
241
+ ans.push(this.unshift(el));
242
+ }
243
+ return ans;
244
+ }
191
245
  /**
192
246
  * Time Complexity: O(n)
193
247
  * Space Complexity: O(1)
@@ -366,6 +420,9 @@ class SinglyLinkedList extends base_1.IterableElementBase {
366
420
  return true;
367
421
  }
368
422
  /**
423
+ * Time Complexity: O(1)
424
+ * Space Complexity: O(1)
425
+ *
369
426
  * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
370
427
  * whether it is empty or not.
371
428
  * @returns A boolean value indicating whether the length of the object is equal to 0.
@@ -374,6 +431,9 @@ class SinglyLinkedList extends base_1.IterableElementBase {
374
431
  return this._size === 0;
375
432
  }
376
433
  /**
434
+ * Time Complexity: O(1)
435
+ * Space Complexity: O(1)
436
+ *
377
437
  * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
378
438
  */
379
439
  clear() {
@@ -646,22 +706,6 @@ class SinglyLinkedList extends base_1.IterableElementBase {
646
706
  current = current.next;
647
707
  }
648
708
  }
649
- /**
650
- * Time Complexity: O(n)
651
- * Space Complexity: O(n)
652
- *
653
- * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
654
- * array.
655
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
656
- * @returns The `fromArray` function returns a `SinglyLinkedList` object.
657
- */
658
- static fromArray(data) {
659
- const singlyLinkedList = new SinglyLinkedList();
660
- for (const item of data) {
661
- singlyLinkedList.push(item);
662
- }
663
- return singlyLinkedList;
664
- }
665
709
  /**
666
710
  * The _isPredicate function in TypeScript checks if the input is a function that takes a
667
711
  * SinglyLinkedListNode as an argument and returns a boolean.
@@ -115,6 +115,16 @@ export declare class Deque<E = any, R = any> extends IterableElementBase<E, R, D
115
115
  * @returns The element that was removed from the data structure is being returned.
116
116
  */
117
117
  pop(): E | undefined;
118
+ /**
119
+ * Time Complexity: O(1)
120
+ * Space Complexity: O(1)
121
+ *
122
+ * The `shift()` function removes and returns the first element from a data structure, updating the
123
+ * internal state variables accordingly.
124
+ * @returns The element that is being removed from the beginning of the data structure is being
125
+ * returned.
126
+ */
127
+ shift(): E | undefined;
118
128
  /**
119
129
  * Time Complexity: Amortized O(1)
120
130
  * Space Complexity: O(n)
@@ -127,15 +137,34 @@ export declare class Deque<E = any, R = any> extends IterableElementBase<E, R, D
127
137
  */
128
138
  unshift(element: E): boolean;
129
139
  /**
130
- * Time Complexity: O(1)
131
- * Space Complexity: O(1)
140
+ * Time Complexity: O(k)
141
+ * Space Complexity: O(k)
132
142
  *
133
- * The `shift()` function removes and returns the first element from a data structure, updating the
134
- * internal state variables accordingly.
135
- * @returns The element that is being removed from the beginning of the data structure is being
136
- * returned.
137
- */
138
- shift(): E | undefined;
143
+ * The function `pushMany` iterates over elements and pushes them into an array after applying a
144
+ * transformation function if provided.
145
+ * @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
146
+ * parameter in the `pushMany` function is expected to be an iterable containing elements of type `E`
147
+ * or `R`. It can be either an `IterableWithSizeOrLength<E>` or an `IterableWithSizeOrLength<R>`. The
148
+ * function iterates over each element
149
+ * @returns The `pushMany` function is returning an array of boolean values, where each value
150
+ * represents the result of calling the `push` method on the current object instance with the
151
+ * corresponding element from the input `elements` iterable.
152
+ */
153
+ pushMany(elements: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
154
+ /**
155
+ * Time Complexity: O(k)
156
+ * Space Complexity: O(k)
157
+ *
158
+ * The `unshiftMany` function in TypeScript iterates over elements and adds them to the beginning of
159
+ * an array, optionally converting them using a provided function.
160
+ * @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
161
+ * parameter in the `unshiftMany` function is an iterable containing elements of type `E` or `R`. It
162
+ * can be an array or any other iterable data structure that has a known size or length. The function
163
+ * iterates over each element in the `elements` iterable and
164
+ * @returns The `unshiftMany` function returns an array of boolean values indicating whether each
165
+ * element was successfully added to the beginning of the array.
166
+ */
167
+ unshiftMany(elements?: IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>): boolean[];
139
168
  /**
140
169
  * Time Complexity: O(1)
141
170
  * Space Complexity: O(1)
@@ -60,14 +60,7 @@ class Deque extends base_1.IterableElementBase {
60
60
  const needBucketNum = (0, utils_1.calcMinUnitsRequired)(_size, this._bucketSize);
61
61
  this._bucketFirst = this._bucketLast = (this._bucketCount >> 1) - (needBucketNum >> 1);
62
62
  this._firstInBucket = this._lastInBucket = (this._bucketSize - (_size % this._bucketSize)) >> 1;
63
- for (const el of elements) {
64
- if (this.toElementFn) {
65
- this.push(this.toElementFn(el));
66
- }
67
- else {
68
- this.push(el);
69
- }
70
- }
63
+ this.pushMany(elements);
71
64
  }
72
65
  /**
73
66
  * The bucketSize function returns the size of the bucket.
@@ -214,6 +207,35 @@ class Deque extends base_1.IterableElementBase {
214
207
  this._size -= 1;
215
208
  return element;
216
209
  }
210
+ /**
211
+ * Time Complexity: O(1)
212
+ * Space Complexity: O(1)
213
+ *
214
+ * The `shift()` function removes and returns the first element from a data structure, updating the
215
+ * internal state variables accordingly.
216
+ * @returns The element that is being removed from the beginning of the data structure is being
217
+ * returned.
218
+ */
219
+ shift() {
220
+ if (this._size === 0)
221
+ return;
222
+ const element = this._buckets[this._bucketFirst][this._firstInBucket];
223
+ if (this._size !== 1) {
224
+ if (this._firstInBucket < this._bucketSize - 1) {
225
+ this._firstInBucket += 1;
226
+ }
227
+ else if (this._bucketFirst < this._bucketCount - 1) {
228
+ this._bucketFirst += 1;
229
+ this._firstInBucket = 0;
230
+ }
231
+ else {
232
+ this._bucketFirst = 0;
233
+ this._firstInBucket = 0;
234
+ }
235
+ }
236
+ this._size -= 1;
237
+ return element;
238
+ }
217
239
  /**
218
240
  * Time Complexity: Amortized O(1)
219
241
  * Space Complexity: O(n)
@@ -247,33 +269,55 @@ class Deque extends base_1.IterableElementBase {
247
269
  return true;
248
270
  }
249
271
  /**
250
- * Time Complexity: O(1)
251
- * Space Complexity: O(1)
272
+ * Time Complexity: O(k)
273
+ * Space Complexity: O(k)
252
274
  *
253
- * The `shift()` function removes and returns the first element from a data structure, updating the
254
- * internal state variables accordingly.
255
- * @returns The element that is being removed from the beginning of the data structure is being
256
- * returned.
257
- */
258
- shift() {
259
- if (this._size === 0)
260
- return;
261
- const element = this._buckets[this._bucketFirst][this._firstInBucket];
262
- if (this._size !== 1) {
263
- if (this._firstInBucket < this._bucketSize - 1) {
264
- this._firstInBucket += 1;
275
+ * The function `pushMany` iterates over elements and pushes them into an array after applying a
276
+ * transformation function if provided.
277
+ * @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
278
+ * parameter in the `pushMany` function is expected to be an iterable containing elements of type `E`
279
+ * or `R`. It can be either an `IterableWithSizeOrLength<E>` or an `IterableWithSizeOrLength<R>`. The
280
+ * function iterates over each element
281
+ * @returns The `pushMany` function is returning an array of boolean values, where each value
282
+ * represents the result of calling the `push` method on the current object instance with the
283
+ * corresponding element from the input `elements` iterable.
284
+ */
285
+ pushMany(elements) {
286
+ const ans = [];
287
+ for (const el of elements) {
288
+ if (this.toElementFn) {
289
+ ans.push(this.push(this.toElementFn(el)));
265
290
  }
266
- else if (this._bucketFirst < this._bucketCount - 1) {
267
- this._bucketFirst += 1;
268
- this._firstInBucket = 0;
291
+ else {
292
+ ans.push(this.push(el));
293
+ }
294
+ }
295
+ return ans;
296
+ }
297
+ /**
298
+ * Time Complexity: O(k)
299
+ * Space Complexity: O(k)
300
+ *
301
+ * The `unshiftMany` function in TypeScript iterates over elements and adds them to the beginning of
302
+ * an array, optionally converting them using a provided function.
303
+ * @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
304
+ * parameter in the `unshiftMany` function is an iterable containing elements of type `E` or `R`. It
305
+ * can be an array or any other iterable data structure that has a known size or length. The function
306
+ * iterates over each element in the `elements` iterable and
307
+ * @returns The `unshiftMany` function returns an array of boolean values indicating whether each
308
+ * element was successfully added to the beginning of the array.
309
+ */
310
+ unshiftMany(elements = []) {
311
+ const ans = [];
312
+ for (const el of elements) {
313
+ if (this.toElementFn) {
314
+ ans.push(this.unshift(this.toElementFn(el)));
269
315
  }
270
316
  else {
271
- this._bucketFirst = 0;
272
- this._firstInBucket = 0;
317
+ ans.push(this.unshift(el));
273
318
  }
274
319
  }
275
- this._size -= 1;
276
- return element;
320
+ return ans;
277
321
  }
278
322
  /**
279
323
  * Time Complexity: O(1)