data-structure-typed 1.47.3 → 1.47.5

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 (69) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/benchmark/report.html +2 -2
  3. package/benchmark/report.json +12 -18
  4. package/dist/cjs/data-structures/hash/hash-map.d.ts +3 -3
  5. package/dist/cjs/data-structures/hash/hash-map.js +10 -4
  6. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  7. package/dist/cjs/data-structures/hash/hash-table.d.ts +9 -4
  8. package/dist/cjs/data-structures/hash/hash-table.js +50 -5
  9. package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
  10. package/dist/cjs/data-structures/heap/heap.d.ts +6 -1
  11. package/dist/cjs/data-structures/heap/heap.js +51 -9
  12. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  13. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +56 -56
  14. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +117 -119
  15. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  16. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +36 -36
  17. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +58 -60
  18. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  19. package/dist/cjs/data-structures/queue/deque.d.ts +49 -49
  20. package/dist/cjs/data-structures/queue/deque.js +79 -72
  21. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  22. package/dist/cjs/data-structures/queue/queue.d.ts +45 -0
  23. package/dist/cjs/data-structures/queue/queue.js +77 -0
  24. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  25. package/dist/cjs/data-structures/stack/stack.d.ts +18 -5
  26. package/dist/cjs/data-structures/stack/stack.js +56 -7
  27. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  28. package/dist/cjs/data-structures/trie/trie.d.ts +5 -0
  29. package/dist/cjs/data-structures/trie/trie.js +47 -0
  30. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  31. package/dist/mjs/data-structures/hash/hash-map.d.ts +3 -3
  32. package/dist/mjs/data-structures/hash/hash-map.js +10 -4
  33. package/dist/mjs/data-structures/hash/hash-table.d.ts +9 -4
  34. package/dist/mjs/data-structures/hash/hash-table.js +50 -5
  35. package/dist/mjs/data-structures/heap/heap.d.ts +6 -1
  36. package/dist/mjs/data-structures/heap/heap.js +51 -9
  37. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +56 -56
  38. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +117 -119
  39. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +36 -36
  40. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +58 -60
  41. package/dist/mjs/data-structures/queue/deque.d.ts +49 -49
  42. package/dist/mjs/data-structures/queue/deque.js +79 -72
  43. package/dist/mjs/data-structures/queue/queue.d.ts +45 -0
  44. package/dist/mjs/data-structures/queue/queue.js +77 -0
  45. package/dist/mjs/data-structures/stack/stack.d.ts +18 -5
  46. package/dist/mjs/data-structures/stack/stack.js +56 -7
  47. package/dist/mjs/data-structures/trie/trie.d.ts +5 -0
  48. package/dist/mjs/data-structures/trie/trie.js +47 -0
  49. package/dist/umd/data-structure-typed.js +545 -276
  50. package/dist/umd/data-structure-typed.min.js +2 -2
  51. package/dist/umd/data-structure-typed.min.js.map +1 -1
  52. package/package.json +1 -1
  53. package/src/data-structures/hash/hash-map.ts +13 -7
  54. package/src/data-structures/hash/hash-table.ts +59 -9
  55. package/src/data-structures/heap/heap.ts +60 -9
  56. package/src/data-structures/linked-list/doubly-linked-list.ts +129 -129
  57. package/src/data-structures/linked-list/singly-linked-list.ts +65 -65
  58. package/src/data-structures/queue/deque.ts +84 -77
  59. package/src/data-structures/queue/queue.ts +84 -0
  60. package/src/data-structures/stack/stack.ts +64 -8
  61. package/src/data-structures/trie/trie.ts +53 -0
  62. package/test/integration/conversion.test.ts +0 -0
  63. package/test/performance/data-structures/heap/heap.test.ts +13 -4
  64. package/test/unit/data-structures/hash/hash-table.test.ts +58 -2
  65. package/test/unit/data-structures/heap/min-heap.test.ts +48 -0
  66. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
  67. package/test/unit/data-structures/queue/queue.test.ts +37 -0
  68. package/test/unit/data-structures/stack/stack.test.ts +55 -5
  69. package/test/unit/data-structures/trie/trie.test.ts +33 -0
@@ -1 +1 @@
1
- {"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH;;;GAGG;AACH,MAAa,QAAQ;IAKnB,YAAY,GAAW;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC9C,CAAC;CACF;AAVD,4BAUC;AAED;;GAEG;AACH,MAAa,IAAI;IACf,YAAY,KAAgB,EAAE,aAAa,GAAG,IAAI;QAChD,IAAI,CAAC,KAAK,GAAG,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,KAAK,EAAE;YACT,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;gBACrB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACb;SACF;IACH,CAAC;IAID,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IAEH;;;;;;;OAOG;IACH,GAAG,CAAC,IAAY;QACd,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC;QACpB,KAA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CAAC;QACd,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;YACvB,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE;gBAChC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACpB;YACD,KAAK,EAAE,CAAC;SACT;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,GAAG,CAAC,QAA6D;QAC/D,MAAM,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;QAC3B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;YACvB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACzC,KAAK,EAAE,CAAC;SACT;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,CAAI,QAAwE,EAAE,YAAe;QACjG,IAAI,WAAW,GAAG,YAAY,CAAC;QAC/B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;YACvB,WAAW,GAAG,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;YACvD,KAAK,EAAE,CAAC;SACT;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;OAGG;IAEH;;;;;;OAMG;IACO,YAAY,CAAC,GAAW;QAChC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,+CAA+C;SACzE;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAlXD,oBAkXC"}
@@ -143,7 +143,7 @@ export declare class HashMap<K = any, V = any> {
143
143
  * @returns a new HashMap object that contains the key-value pairs from the original HashMap that
144
144
  * satisfy the given predicate function.
145
145
  */
146
- filter(predicate: (element: [K, V], map: HashMap<K, V>) => boolean): HashMap<K, V>;
146
+ filter(predicate: (element: [K, V], index: number, map: HashMap<K, V>) => boolean): HashMap<K, V>;
147
147
  /**
148
148
  * The `map` function takes a callback function and returns a new HashMap with the values transformed
149
149
  * by the callback.
@@ -151,7 +151,7 @@ export declare class HashMap<K = any, V = any> {
151
151
  * `map`.
152
152
  * @returns a new HashMap object with the values mapped according to the provided callback function.
153
153
  */
154
- map<NV>(callback: (element: [K, V], map: HashMap<K, V>) => NV): HashMap<K, NV>;
154
+ map<NV>(callback: (element: [K, V], index: number, map: HashMap<K, V>) => NV): HashMap<K, NV>;
155
155
  /**
156
156
  * The `reduce` function iterates over the elements of a HashMap and applies a callback function to
157
157
  * each element, accumulating a single value.
@@ -164,7 +164,7 @@ export declare class HashMap<K = any, V = any> {
164
164
  * @returns The `reduce` function is returning the final value of the accumulator after iterating
165
165
  * over all the elements in the HashMap and applying the callback function to each element.
166
166
  */
167
- reduce<A>(callback: (accumulator: A, element: [K, V], map: HashMap<K, V>) => A, initialValue: A): A;
167
+ reduce<A>(callback: (accumulator: A, element: [K, V], index: number, map: HashMap<K, V>) => A, initialValue: A): A;
168
168
  /**
169
169
  * Time Complexity: O(n), where n is the number of elements in the HashMap.
170
170
  * Space Complexity: O(1)
@@ -289,10 +289,12 @@ export class HashMap {
289
289
  */
290
290
  filter(predicate) {
291
291
  const filteredMap = new HashMap();
292
+ let index = 0;
292
293
  for (const [key, value] of this) {
293
- if (predicate([key, value], this)) {
294
+ if (predicate([key, value], index, this)) {
294
295
  filteredMap.set(key, value);
295
296
  }
297
+ index++;
296
298
  }
297
299
  return filteredMap;
298
300
  }
@@ -305,9 +307,11 @@ export class HashMap {
305
307
  */
306
308
  map(callback) {
307
309
  const mappedMap = new HashMap();
310
+ let index = 0;
308
311
  for (const [key, value] of this) {
309
- const newValue = callback([key, value], this);
312
+ const newValue = callback([key, value], index, this);
310
313
  mappedMap.set(key, newValue);
314
+ index++;
311
315
  }
312
316
  return mappedMap;
313
317
  }
@@ -325,8 +329,10 @@ export class HashMap {
325
329
  */
326
330
  reduce(callback, initialValue) {
327
331
  let accumulator = initialValue;
328
- for (const element of this) {
329
- accumulator = callback(accumulator, element, this);
332
+ let index = 0;
333
+ for (const entry of this) {
334
+ accumulator = callback(accumulator, entry, index, this);
335
+ index++;
330
336
  }
331
337
  return accumulator;
332
338
  }
@@ -8,11 +8,11 @@
8
8
  export declare class HashTableNode<K, V> {
9
9
  key: K;
10
10
  value: V;
11
- next: HashTableNode<K, V> | null;
11
+ next: HashTableNode<K, V> | undefined;
12
12
  constructor(key: K, value: V);
13
13
  }
14
14
  import { HashFunction } from '../../types';
15
- export declare class HashTable<K, V> {
15
+ export declare class HashTable<K = any, V = any> {
16
16
  protected static readonly DEFAULT_CAPACITY = 16;
17
17
  protected static readonly LOAD_FACTOR = 0.75;
18
18
  constructor(capacity?: number, hashFn?: HashFunction<K>);
@@ -20,8 +20,8 @@ export declare class HashTable<K, V> {
20
20
  get capacity(): number;
21
21
  protected _size: number;
22
22
  get size(): number;
23
- protected _buckets: Array<HashTableNode<K, V> | null>;
24
- get buckets(): Array<HashTableNode<K, V> | null>;
23
+ protected _buckets: Array<HashTableNode<K, V> | undefined>;
24
+ get buckets(): Array<HashTableNode<K, V> | undefined>;
25
25
  protected _hashFn: HashFunction<K>;
26
26
  get hashFn(): HashFunction<K>;
27
27
  /**
@@ -50,6 +50,11 @@ export declare class HashTable<K, V> {
50
50
  * any value.
51
51
  */
52
52
  delete(key: K): void;
53
+ [Symbol.iterator](): Generator<[K, V], void, undefined>;
54
+ forEach(callback: (entry: [K, V], index: number, table: HashTable<K, V>) => void): void;
55
+ filter(predicate: (entry: [K, V], index: number, table: HashTable<K, V>) => boolean): HashTable<K, V>;
56
+ map<T>(callback: (entry: [K, V], index: number, table: HashTable<K, V>) => T): HashTable<K, T>;
57
+ reduce<T>(callback: (accumulator: T, entry: [K, V], index: number, table: HashTable<K, V>) => T, initialValue: T): T;
53
58
  /**
54
59
  * The function `_defaultHashFn` calculates the hash value of a given key and returns the remainder when divided by the
55
60
  * capacity of the data structure.
@@ -12,7 +12,7 @@ export class HashTableNode {
12
12
  constructor(key, value) {
13
13
  this.key = key;
14
14
  this.value = value;
15
- this.next = null;
15
+ this.next = undefined;
16
16
  }
17
17
  }
18
18
  export class HashTable {
@@ -22,7 +22,7 @@ export class HashTable {
22
22
  this._hashFn = hashFn || this._defaultHashFn;
23
23
  this._capacity = Math.max(capacity, HashTable.DEFAULT_CAPACITY);
24
24
  this._size = 0;
25
- this._buckets = new Array(this._capacity).fill(null);
25
+ this._buckets = new Array(this._capacity).fill(undefined);
26
26
  }
27
27
  _capacity;
28
28
  get capacity() {
@@ -106,7 +106,7 @@ export class HashTable {
106
106
  delete(key) {
107
107
  const index = this._hash(key);
108
108
  let currentNode = this._buckets[index];
109
- let prevNode = null;
109
+ let prevNode = undefined;
110
110
  while (currentNode) {
111
111
  if (currentNode.key === key) {
112
112
  if (prevNode) {
@@ -116,13 +116,58 @@ export class HashTable {
116
116
  this._buckets[index] = currentNode.next;
117
117
  }
118
118
  this._size--;
119
- currentNode.next = null; // Release memory
119
+ currentNode.next = undefined; // Release memory
120
120
  return;
121
121
  }
122
122
  prevNode = currentNode;
123
123
  currentNode = currentNode.next;
124
124
  }
125
125
  }
126
+ *[Symbol.iterator]() {
127
+ for (const bucket of this._buckets) {
128
+ let currentNode = bucket;
129
+ while (currentNode) {
130
+ yield [currentNode.key, currentNode.value];
131
+ currentNode = currentNode.next;
132
+ }
133
+ }
134
+ }
135
+ forEach(callback) {
136
+ let index = 0;
137
+ for (const entry of this) {
138
+ callback(entry, index, this);
139
+ index++;
140
+ }
141
+ }
142
+ filter(predicate) {
143
+ const newTable = new HashTable();
144
+ let index = 0;
145
+ for (const [key, value] of this) {
146
+ if (predicate([key, value], index, this)) {
147
+ newTable.set(key, value);
148
+ }
149
+ index++;
150
+ }
151
+ return newTable;
152
+ }
153
+ map(callback) {
154
+ const newTable = new HashTable();
155
+ let index = 0;
156
+ for (const [key, value] of this) {
157
+ newTable.set(key, callback([key, value], index, this));
158
+ index++;
159
+ }
160
+ return newTable;
161
+ }
162
+ reduce(callback, initialValue) {
163
+ let accumulator = initialValue;
164
+ let index = 0;
165
+ for (const entry of this) {
166
+ accumulator = callback(accumulator, entry, index, this);
167
+ index++;
168
+ }
169
+ return accumulator;
170
+ }
126
171
  /**
127
172
  * The function `_defaultHashFn` calculates the hash value of a given key and returns the remainder when divided by the
128
173
  * capacity of the data structure.
@@ -213,7 +258,7 @@ export class HashTable {
213
258
  */
214
259
  _expand() {
215
260
  const newCapacity = this._capacity * 2;
216
- const newBuckets = new Array(newCapacity).fill(null);
261
+ const newBuckets = new Array(newCapacity).fill(undefined);
217
262
  for (const bucket of this._buckets) {
218
263
  let currentNode = bucket;
219
264
  while (currentNode) {
@@ -147,7 +147,7 @@ export declare class Heap<E = any> {
147
147
  * @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
148
148
  * @returns An array containing elements traversed in the specified order.
149
149
  */
150
- dfs(order: DFSOrderPattern): E[];
150
+ dfs(order?: DFSOrderPattern): E[];
151
151
  /**
152
152
  * Time Complexity: O(n)
153
153
  * Space Complexity: O(n)
@@ -195,6 +195,11 @@ export declare class Heap<E = any> {
195
195
  * Fix the entire heap to maintain heap properties.
196
196
  */
197
197
  fix(): void;
198
+ [Symbol.iterator](): Generator<E, void, unknown>;
199
+ forEach(callback: (element: E, index: number, heap: this) => void): void;
200
+ filter(predicate: (element: E, index: number, heap: Heap<E>) => boolean): Heap<E>;
201
+ map<T>(callback: (element: E, index: number, heap: Heap<E>) => T, comparator: Comparator<T>): Heap<T>;
202
+ reduce<T>(callback: (accumulator: T, currentValue: E, currentIndex: number, heap: Heap<E>) => T, initialValue: T): T;
198
203
  /**
199
204
  * Time Complexity: O(log n)
200
205
  * Space Complexity: O(1)
@@ -201,29 +201,30 @@ export class Heap {
201
201
  * @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
202
202
  * @returns An array containing elements traversed in the specified order.
203
203
  */
204
- dfs(order) {
204
+ dfs(order = 'pre') {
205
205
  const result = [];
206
206
  // Auxiliary recursive function, traverses the binary heap according to the traversal order
207
- const dfsHelper = (index) => {
207
+ const _dfs = (index) => {
208
+ const left = 2 * index + 1, right = left + 1;
208
209
  if (index < this.size) {
209
210
  if (order === 'in') {
210
- dfsHelper(2 * index + 1);
211
+ _dfs(left);
211
212
  result.push(this.elements[index]);
212
- dfsHelper(2 * index + 2);
213
+ _dfs(right);
213
214
  }
214
215
  else if (order === 'pre') {
215
216
  result.push(this.elements[index]);
216
- dfsHelper(2 * index + 1);
217
- dfsHelper(2 * index + 2);
217
+ _dfs(left);
218
+ _dfs(right);
218
219
  }
219
220
  else if (order === 'post') {
220
- dfsHelper(2 * index + 1);
221
- dfsHelper(2 * index + 2);
221
+ _dfs(left);
222
+ _dfs(right);
222
223
  result.push(this.elements[index]);
223
224
  }
224
225
  }
225
226
  };
226
- dfsHelper(0); // Traverse starting from the root node
227
+ _dfs(0); // Traverse starting from the root node
227
228
  return result;
228
229
  }
229
230
  /**
@@ -291,6 +292,47 @@ export class Heap {
291
292
  for (let i = Math.floor(this.size / 2); i >= 0; i--)
292
293
  this._sinkDown(i, this.elements.length >> 1);
293
294
  }
295
+ *[Symbol.iterator]() {
296
+ for (const element of this.elements) {
297
+ yield element;
298
+ }
299
+ }
300
+ forEach(callback) {
301
+ let index = 0;
302
+ for (const el of this) {
303
+ callback(el, index, this);
304
+ index++;
305
+ }
306
+ }
307
+ filter(predicate) {
308
+ const filteredHeap = new Heap({ comparator: this.comparator });
309
+ let index = 0;
310
+ for (const el of this) {
311
+ if (predicate(el, index, this)) {
312
+ filteredHeap.push(el);
313
+ }
314
+ index++;
315
+ }
316
+ return filteredHeap;
317
+ }
318
+ map(callback, comparator) {
319
+ const mappedHeap = new Heap({ comparator: comparator });
320
+ let index = 0;
321
+ for (const el of this) {
322
+ mappedHeap.add(callback(el, index, this));
323
+ index++;
324
+ }
325
+ return mappedHeap;
326
+ }
327
+ reduce(callback, initialValue) {
328
+ let accumulator = initialValue;
329
+ let index = 0;
330
+ for (const el of this) {
331
+ accumulator = callback(accumulator, el, index, this);
332
+ index++;
333
+ }
334
+ return accumulator;
335
+ }
294
336
  /**
295
337
  * Time Complexity: O(log n)
296
338
  * Space Complexity: O(1)
@@ -249,6 +249,23 @@ export declare class DoublyLinkedList<E = any> {
249
249
  * insertion fails.
250
250
  */
251
251
  insertBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
252
+ /**
253
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
254
+ * Space Complexity: O(1)
255
+ */
256
+ /**
257
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
258
+ * Space Complexity: O(1)
259
+ *
260
+ * The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
261
+ * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
262
+ * after which the new value will be inserted. It can be either the value of the existing node or the existing node
263
+ * itself.
264
+ * @param {E} newValue - The value that you want to insert into the doubly linked list.
265
+ * @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
266
+ * existing value or node is not found in the doubly linked list.
267
+ */
268
+ insertAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
252
269
  /**
253
270
  * Time Complexity: O(n), where n is the number of elements in the linked list.
254
271
  * Space Complexity: O(1)
@@ -279,18 +296,6 @@ export declare class DoublyLinkedList<E = any> {
279
296
  * deleted from the doubly linked list, and `false` if the value or node was not found in the list.
280
297
  */
281
298
  delete(valOrNode: E | DoublyLinkedListNode<E> | null): boolean;
282
- /**
283
- * Time Complexity: O(n), where n is the number of elements in the linked list.
284
- * Space Complexity: O(n)
285
- */
286
- /**
287
- * Time Complexity: O(n), where n is the number of elements in the linked list.
288
- * Space Complexity: O(n)
289
- *
290
- * The `toArray` function converts a linked list into an array.
291
- * @returns The `toArray()` method is returning an array of type `E[]`.
292
- */
293
- toArray(): E[];
294
299
  /**
295
300
  * The function checks if a variable has a length greater than zero and returns a boolean value.
296
301
  * @returns A boolean value is being returned.
@@ -346,6 +351,17 @@ export declare class DoublyLinkedList<E = any> {
346
351
  * the callback function. If no value satisfies the condition, it returns `null`.
347
352
  */
348
353
  findBackward(callback: (value: E) => boolean): E | null;
354
+ /**
355
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
356
+ * Space Complexity: O(1)
357
+ */
358
+ /**
359
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
360
+ * Space Complexity: O(1)
361
+ *
362
+ * The `reverse` function reverses the order of the elements in a doubly linked list.
363
+ */
364
+ reverse(): void;
349
365
  /**
350
366
  * Time Complexity: O(n), where n is the number of elements in the linked list.
351
367
  * Space Complexity: O(n)
@@ -354,21 +370,26 @@ export declare class DoublyLinkedList<E = any> {
354
370
  * Time Complexity: O(n), where n is the number of elements in the linked list.
355
371
  * Space Complexity: O(n)
356
372
  *
357
- * The `toArrayBackward` function converts a doubly linked list into an array in reverse order.
358
- * @returns The `toArrayBackward()` function returns an array of type `E[]`.
373
+ * The `toArray` function converts a linked list into an array.
374
+ * @returns The `toArray()` method is returning an array of type `E[]`.
359
375
  */
360
- toArrayBackward(): E[];
376
+ toArray(): E[];
361
377
  /**
362
378
  * Time Complexity: O(n), where n is the number of elements in the linked list.
363
- * Space Complexity: O(1)
379
+ * Space Complexity: O(n)
364
380
  */
365
381
  /**
366
382
  * Time Complexity: O(n), where n is the number of elements in the linked list.
367
- * Space Complexity: O(1)
383
+ * Space Complexity: O(n)
368
384
  *
369
- * The `reverse` function reverses the order of the elements in a doubly linked list.
385
+ * The `toReversedArray` function converts a doubly linked list into an array in reverse order.
386
+ * @returns The `toReversedArray()` function returns an array of type `E[]`.
370
387
  */
371
- reverse(): void;
388
+ toReversedArray(): E[];
389
+ /**
390
+ * The function returns an iterator that iterates over the values of a linked list.
391
+ */
392
+ [Symbol.iterator](): Generator<E, void, unknown>;
372
393
  /**
373
394
  * Time Complexity: O(n), where n is the number of elements in the linked list.
374
395
  * Space Complexity: O(1)
@@ -382,7 +403,7 @@ export declare class DoublyLinkedList<E = any> {
382
403
  * represents the value of the current node in the linked list, and the index argument represents the index of the
383
404
  * current node in the linked list.
384
405
  */
385
- forEach(callback: (value: E, index: number) => void): void;
406
+ forEach(callback: (value: E, index: number, list: DoublyLinkedList<E>) => void): void;
386
407
  /**
387
408
  * Time Complexity: O(n), where n is the number of elements in the linked list.
388
409
  * Space Complexity: O(n)
@@ -391,14 +412,13 @@ export declare class DoublyLinkedList<E = any> {
391
412
  * Time Complexity: O(n), where n is the number of elements in the linked list.
392
413
  * Space Complexity: O(n)
393
414
  *
394
- * The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
395
- * DoublyLinkedList with the transformed values.
396
- * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
397
- * the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
398
- * DoublyLinkedList).
399
- * @returns The `map` function is returning a new instance of `DoublyLinkedList<U>` that contains the mapped values.
415
+ * The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
416
+ * elements that satisfy the given callback function.
417
+ * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
418
+ * It is used to determine whether a value should be included in the filtered list or not.
419
+ * @returns The filtered list, which is an instance of the DoublyLinkedList class.
400
420
  */
401
- map<U>(callback: (value: E) => U): DoublyLinkedList<U>;
421
+ filter(callback: (value: E, index: number, list: DoublyLinkedList<E>) => boolean): DoublyLinkedList<E>;
402
422
  /**
403
423
  * Time Complexity: O(n), where n is the number of elements in the linked list.
404
424
  * Space Complexity: O(n)
@@ -407,13 +427,14 @@ export declare class DoublyLinkedList<E = any> {
407
427
  * Time Complexity: O(n), where n is the number of elements in the linked list.
408
428
  * Space Complexity: O(n)
409
429
  *
410
- * The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
411
- * elements that satisfy the given callback function.
412
- * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
413
- * It is used to determine whether a value should be included in the filtered list or not.
414
- * @returns The filtered list, which is an instance of the DoublyLinkedList class.
430
+ * The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
431
+ * DoublyLinkedList with the transformed values.
432
+ * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
433
+ * the original DoublyLinkedList) and returns a value of type T (the type of values that will be stored in the mapped
434
+ * DoublyLinkedList).
435
+ * @returns The `map` function is returning a new instance of `DoublyLinkedList<T>` that contains the mapped values.
415
436
  */
416
- filter(callback: (value: E) => boolean): DoublyLinkedList<E>;
437
+ map<T>(callback: (value: E, index: number, list: DoublyLinkedList<E>) => T): DoublyLinkedList<T>;
417
438
  /**
418
439
  * Time Complexity: O(n), where n is the number of elements in the linked list.
419
440
  * Space Complexity: O(n)
@@ -426,31 +447,10 @@ export declare class DoublyLinkedList<E = any> {
426
447
  * single value.
427
448
  * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
428
449
  * used to perform a specific operation on each element of the linked list.
429
- * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
450
+ * @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
430
451
  * point for the reduction operation.
431
452
  * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
432
453
  * elements in the linked list.
433
454
  */
434
- reduce<U>(callback: (accumulator: U, value: E) => U, initialValue: U): U;
435
- /**
436
- * Time Complexity: O(n), where n is the number of elements in the linked list.
437
- * Space Complexity: O(1)
438
- */
439
- /**
440
- * Time Complexity: O(n), where n is the number of elements in the linked list.
441
- * Space Complexity: O(1)
442
- *
443
- * The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
444
- * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
445
- * after which the new value will be inserted. It can be either the value of the existing node or the existing node
446
- * itself.
447
- * @param {E} newValue - The value that you want to insert into the doubly linked list.
448
- * @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
449
- * existing value or node is not found in the doubly linked list.
450
- */
451
- insertAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
452
- /**
453
- * The function returns an iterator that iterates over the values of a linked list.
454
- */
455
- [Symbol.iterator](): Generator<E, void, unknown>;
455
+ reduce<T>(callback: (accumulator: T, value: E, index: number, list: DoublyLinkedList<E>) => T, initialValue: T): T;
456
456
  }