undirected-graph-typed 1.48.1 → 1.48.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 (49) hide show
  1. package/dist/data-structures/base/index.d.ts +1 -0
  2. package/dist/data-structures/base/index.js +17 -0
  3. package/dist/data-structures/base/iterable-base.d.ts +232 -0
  4. package/dist/data-structures/base/iterable-base.js +312 -0
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +36 -69
  6. package/dist/data-structures/binary-tree/binary-tree.js +78 -129
  7. package/dist/data-structures/graph/abstract-graph.d.ts +44 -6
  8. package/dist/data-structures/graph/abstract-graph.js +50 -27
  9. package/dist/data-structures/hash/hash-map.d.ts +59 -100
  10. package/dist/data-structures/hash/hash-map.js +69 -173
  11. package/dist/data-structures/heap/heap.d.ts +50 -7
  12. package/dist/data-structures/heap/heap.js +60 -30
  13. package/dist/data-structures/index.d.ts +1 -0
  14. package/dist/data-structures/index.js +1 -0
  15. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
  16. package/dist/data-structures/linked-list/doubly-linked-list.js +46 -73
  17. package/dist/data-structures/linked-list/singly-linked-list.d.ts +32 -51
  18. package/dist/data-structures/linked-list/singly-linked-list.js +40 -73
  19. package/dist/data-structures/queue/deque.d.ts +29 -51
  20. package/dist/data-structures/queue/deque.js +36 -71
  21. package/dist/data-structures/queue/queue.d.ts +49 -48
  22. package/dist/data-structures/queue/queue.js +69 -82
  23. package/dist/data-structures/stack/stack.d.ts +43 -10
  24. package/dist/data-structures/stack/stack.js +50 -31
  25. package/dist/data-structures/trie/trie.d.ts +41 -6
  26. package/dist/data-structures/trie/trie.js +53 -32
  27. package/dist/types/data-structures/base/base.d.ts +5 -0
  28. package/dist/types/data-structures/base/base.js +2 -0
  29. package/dist/types/data-structures/base/index.d.ts +1 -0
  30. package/dist/types/data-structures/base/index.js +17 -0
  31. package/dist/types/data-structures/index.d.ts +1 -0
  32. package/dist/types/data-structures/index.js +1 -0
  33. package/package.json +2 -2
  34. package/src/data-structures/base/index.ts +1 -0
  35. package/src/data-structures/base/iterable-base.ts +329 -0
  36. package/src/data-structures/binary-tree/binary-tree.ts +82 -138
  37. package/src/data-structures/graph/abstract-graph.ts +55 -28
  38. package/src/data-structures/hash/hash-map.ts +76 -185
  39. package/src/data-structures/heap/heap.ts +63 -36
  40. package/src/data-structures/index.ts +1 -0
  41. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -79
  42. package/src/data-structures/linked-list/singly-linked-list.ts +45 -80
  43. package/src/data-structures/queue/deque.ts +40 -82
  44. package/src/data-structures/queue/queue.ts +72 -87
  45. package/src/data-structures/stack/stack.ts +53 -34
  46. package/src/data-structures/trie/trie.ts +58 -35
  47. package/src/types/data-structures/base/base.ts +6 -0
  48. package/src/types/data-structures/base/index.ts +1 -0
  49. package/src/types/data-structures/index.ts +1 -0
@@ -7,8 +7,10 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.FibonacciHeap = exports.FibonacciHeapNode = exports.Heap = void 0;
10
- class Heap {
10
+ const base_1 = require("../base");
11
+ class Heap extends base_1.IterableElementBase {
11
12
  constructor(elements, options) {
13
+ super();
12
14
  this._elements = [];
13
15
  const defaultComparator = (a, b) => {
14
16
  if (!(typeof a === 'number' && typeof b === 'number')) {
@@ -310,47 +312,70 @@ class Heap {
310
312
  for (let i = Math.floor(this.size / 2); i >= 0; i--)
311
313
  this._sinkDown(i, this.elements.length >> 1);
312
314
  }
313
- *[Symbol.iterator]() {
314
- for (const element of this.elements) {
315
- yield element;
316
- }
317
- }
318
- forEach(callback) {
319
- let index = 0;
320
- for (const el of this) {
321
- callback(el, index, this);
322
- index++;
323
- }
324
- }
325
- filter(predicate) {
326
- const filteredHeap = new Heap([], this.options);
315
+ /**
316
+ * Time Complexity: O(n)
317
+ * Space Complexity: O(n)
318
+ */
319
+ /**
320
+ * Time Complexity: O(n)
321
+ * Space Complexity: O(n)
322
+ *
323
+ * The `filter` function creates a new Heap object containing elements that pass a given callback
324
+ * function.
325
+ * @param callback - The `callback` parameter is a function that will be called for each element in
326
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
327
+ * heap itself. The callback function should return a boolean value indicating whether the current
328
+ * element should be included in the filtered list
329
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
330
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
331
+ * passed as the `this` value to the `callback` function. If `thisArg` is
332
+ * @returns The `filter` method is returning a new `Heap` object that contains the elements that pass
333
+ * the filter condition specified by the `callback` function.
334
+ */
335
+ filter(callback, thisArg) {
336
+ const filteredList = new Heap();
327
337
  let index = 0;
328
- for (const el of this) {
329
- if (predicate(el, index, this)) {
330
- filteredHeap.push(el);
338
+ for (const current of this) {
339
+ if (callback.call(thisArg, current, index, this)) {
340
+ filteredList.push(current);
331
341
  }
332
342
  index++;
333
343
  }
334
- return filteredHeap;
344
+ return filteredList;
335
345
  }
336
- map(callback, comparator) {
346
+ /**
347
+ * Time Complexity: O(n)
348
+ * Space Complexity: O(n)
349
+ */
350
+ /**
351
+ * Time Complexity: O(n)
352
+ * Space Complexity: O(n)
353
+ *
354
+ * The `map` function creates a new heap by applying a callback function to each element of the
355
+ * original heap.
356
+ * @param callback - The callback parameter is a function that will be called for each element in the
357
+ * original heap. It takes three arguments: the current element, the index of the current element,
358
+ * and the original heap itself. The callback function should return a value of type T, which will be
359
+ * added to the mapped heap.
360
+ * @param comparator - The `comparator` parameter is a function that is used to compare elements in
361
+ * the heap. It takes two arguments, `a` and `b`, and returns a negative number if `a` is less than
362
+ * `b`, a positive number if `a` is greater than `b`, or
363
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
364
+ * specify the value of `this` within the callback function. It is used when you want to bind a
365
+ * specific object as the context for the callback function. If `thisArg` is not provided,
366
+ * `undefined` is used as
367
+ * @returns a new instance of the Heap class, which is created using the mapped elements from the
368
+ * original Heap.
369
+ */
370
+ map(callback, comparator, thisArg) {
337
371
  const mappedHeap = new Heap([], { comparator: comparator });
338
372
  let index = 0;
339
373
  for (const el of this) {
340
- mappedHeap.add(callback(el, index, this));
374
+ mappedHeap.add(callback.call(thisArg, el, index, this));
341
375
  index++;
342
376
  }
343
377
  return mappedHeap;
344
378
  }
345
- reduce(callback, initialValue) {
346
- let accumulator = initialValue;
347
- let index = 0;
348
- for (const el of this) {
349
- accumulator = callback(accumulator, el, index, this);
350
- index++;
351
- }
352
- return accumulator;
353
- }
354
379
  /**
355
380
  * Time Complexity: O(log n)
356
381
  * Space Complexity: O(1)
@@ -358,6 +383,11 @@ class Heap {
358
383
  print() {
359
384
  console.log([...this]);
360
385
  }
386
+ *_getIterator() {
387
+ for (const element of this.elements) {
388
+ yield element;
389
+ }
390
+ }
361
391
  /**
362
392
  * Time Complexity: O(n)
363
393
  * Space Complexity: O(1)
@@ -9,3 +9,4 @@ export * from './heap';
9
9
  export * from './priority-queue';
10
10
  export * from './matrix';
11
11
  export * from './trie';
12
+ export * from './base';
@@ -25,3 +25,4 @@ __exportStar(require("./heap"), exports);
25
25
  __exportStar(require("./priority-queue"), exports);
26
26
  __exportStar(require("./matrix"), exports);
27
27
  __exportStar(require("./trie"), exports);
28
+ __exportStar(require("./base"), exports);
@@ -1,3 +1,5 @@
1
+ import { IterableElementBase } from "../base";
2
+ import { ElementCallback } from "../../types";
1
3
  /**
2
4
  * data-structure-typed
3
5
  *
@@ -16,7 +18,7 @@ export declare class DoublyLinkedListNode<E = any> {
16
18
  */
17
19
  constructor(value: E);
18
20
  }
19
- export declare class DoublyLinkedList<E = any> {
21
+ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
20
22
  /**
21
23
  * The constructor initializes the linked list with an empty head, tail, and length.
22
24
  */
@@ -387,71 +389,56 @@ export declare class DoublyLinkedList<E = any> {
387
389
  */
388
390
  toReversedArray(): E[];
389
391
  /**
390
- * The function returns an iterator that iterates over the values of a linked list.
391
- */
392
- [Symbol.iterator](): Generator<E, void, unknown>;
393
- /**
394
- * Time Complexity: O(n), where n is the number of elements in the linked list.
395
- * Space Complexity: O(1)
396
- */
397
- /**
398
- * Time Complexity: O(n), where n is the number of elements in the linked list.
399
- * Space Complexity: O(1)
400
- *
401
- * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
402
- * @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
403
- * represents the value of the current node in the linked list, and the index argument represents the index of the
404
- * current node in the linked list.
405
- */
406
- forEach(callback: (value: E, index: number, list: DoublyLinkedList<E>) => void): void;
407
- /**
408
- * Time Complexity: O(n), where n is the number of elements in the linked list.
392
+ * Time Complexity: O(n)
409
393
  * Space Complexity: O(n)
410
394
  */
411
395
  /**
412
- * Time Complexity: O(n), where n is the number of elements in the linked list.
396
+ * Time Complexity: O(n)
413
397
  * Space Complexity: O(n)
414
398
  *
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.
420
- */
421
- filter(callback: (value: E, index: number, list: DoublyLinkedList<E>) => boolean): DoublyLinkedList<E>;
399
+ * The `filter` function creates a new DoublyLinkedList by iterating over the elements of the current
400
+ * list and applying a callback function to each element, returning only the elements for which the
401
+ * callback function returns true.
402
+ * @param callback - The `callback` parameter is a function that will be called for each element in
403
+ * the DoublyLinkedList. It takes three arguments: the current element, the index of the current
404
+ * element, and the DoublyLinkedList itself. The callback function should return a boolean value
405
+ * indicating whether the current element should be included
406
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
407
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
408
+ * passed as the `this` value to the `callback` function. If `thisArg` is
409
+ * @returns The `filter` method is returning a new `DoublyLinkedList` object that contains the
410
+ * elements that pass the filter condition specified by the `callback` function.
411
+ */
412
+ filter(callback: ElementCallback<E, boolean>, thisArg?: any): DoublyLinkedList<E>;
422
413
  /**
423
414
  * Time Complexity: O(n), where n is the number of elements in the linked list.
424
415
  * Space Complexity: O(n)
425
416
  */
426
417
  /**
427
- * Time Complexity: O(n), where n is the number of elements in the linked list.
418
+ * Time Complexity: O(n)
428
419
  * Space Complexity: O(n)
429
420
  *
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.
436
- */
437
- map<T>(callback: (value: E, index: number, list: DoublyLinkedList<E>) => T): DoublyLinkedList<T>;
421
+ * The `map` function creates a new DoublyLinkedList by applying a callback function to each element
422
+ * in the original list.
423
+ * @param callback - The callback parameter is a function that will be called for each element in the
424
+ * DoublyLinkedList. It takes three arguments: the current element, the index of the current element,
425
+ * and the DoublyLinkedList itself. The callback function should return a value that will be added to
426
+ * the new DoublyLinkedList that
427
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
428
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
429
+ * passed as the `this` value to the `callback` function. If `thisArg` is
430
+ * @returns The `map` function is returning a new `DoublyLinkedList` object that contains the results
431
+ * of applying the provided `callback` function to each element in the original `DoublyLinkedList`
432
+ * object.
433
+ */
434
+ map<T>(callback: ElementCallback<E, T>, thisArg?: any): DoublyLinkedList<T>;
438
435
  /**
439
436
  * Time Complexity: O(n), where n is the number of elements in the linked list.
440
437
  * Space Complexity: O(n)
441
438
  */
442
- /**
443
- * Time Complexity: O(n), where n is the number of elements in the linked list.
444
- * Space Complexity: O(n)
445
- *
446
- * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
447
- * single value.
448
- * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
449
- * used to perform a specific operation on each element of the linked list.
450
- * @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
451
- * point for the reduction operation.
452
- * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
453
- * elements in the linked list.
454
- */
455
- reduce<T>(callback: (accumulator: T, value: E, index: number, list: DoublyLinkedList<E>) => T, initialValue: T): T;
456
439
  print(): void;
440
+ /**
441
+ * The function returns an iterator that iterates over the values of a linked list.
442
+ */
443
+ protected _getIterator(): IterableIterator<E>;
457
444
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DoublyLinkedList = exports.DoublyLinkedListNode = void 0;
4
+ const base_1 = require("../base");
4
5
  /**
5
6
  * data-structure-typed
6
7
  *
@@ -21,11 +22,12 @@ class DoublyLinkedListNode {
21
22
  }
22
23
  }
23
24
  exports.DoublyLinkedListNode = DoublyLinkedListNode;
24
- class DoublyLinkedList {
25
+ class DoublyLinkedList extends base_1.IterableElementBase {
25
26
  /**
26
27
  * The constructor initializes the linked list with an empty head, tail, and length.
27
28
  */
28
29
  constructor(elements) {
30
+ super();
29
31
  this._head = undefined;
30
32
  this._tail = undefined;
31
33
  this._length = 0;
@@ -667,54 +669,31 @@ class DoublyLinkedList {
667
669
  return array;
668
670
  }
669
671
  /**
670
- * The function returns an iterator that iterates over the values of a linked list.
671
- */
672
- *[Symbol.iterator]() {
673
- let current = this.head;
674
- while (current) {
675
- yield current.value;
676
- current = current.next;
677
- }
678
- }
679
- /**
680
- * Time Complexity: O(n), where n is the number of elements in the linked list.
681
- * Space Complexity: O(1)
682
- */
683
- /**
684
- * Time Complexity: O(n), where n is the number of elements in the linked list.
685
- * Space Complexity: O(1)
686
- *
687
- * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
688
- * @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
689
- * represents the value of the current node in the linked list, and the index argument represents the index of the
690
- * current node in the linked list.
691
- */
692
- forEach(callback) {
693
- let index = 0;
694
- for (const el of this) {
695
- callback(el, index, this);
696
- index++;
697
- }
698
- }
699
- /**
700
- * Time Complexity: O(n), where n is the number of elements in the linked list.
672
+ * Time Complexity: O(n)
701
673
  * Space Complexity: O(n)
702
674
  */
703
675
  /**
704
- * Time Complexity: O(n), where n is the number of elements in the linked list.
676
+ * Time Complexity: O(n)
705
677
  * Space Complexity: O(n)
706
678
  *
707
- * The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
708
- * elements that satisfy the given callback function.
709
- * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
710
- * It is used to determine whether a value should be included in the filtered list or not.
711
- * @returns The filtered list, which is an instance of the DoublyLinkedList class.
712
- */
713
- filter(callback) {
679
+ * The `filter` function creates a new DoublyLinkedList by iterating over the elements of the current
680
+ * list and applying a callback function to each element, returning only the elements for which the
681
+ * callback function returns true.
682
+ * @param callback - The `callback` parameter is a function that will be called for each element in
683
+ * the DoublyLinkedList. It takes three arguments: the current element, the index of the current
684
+ * element, and the DoublyLinkedList itself. The callback function should return a boolean value
685
+ * indicating whether the current element should be included
686
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
687
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
688
+ * passed as the `this` value to the `callback` function. If `thisArg` is
689
+ * @returns The `filter` method is returning a new `DoublyLinkedList` object that contains the
690
+ * elements that pass the filter condition specified by the `callback` function.
691
+ */
692
+ filter(callback, thisArg) {
714
693
  const filteredList = new DoublyLinkedList();
715
694
  let index = 0;
716
695
  for (const current of this) {
717
- if (callback(current, index, this)) {
696
+ if (callback.call(thisArg, current, index, this)) {
718
697
  filteredList.push(current);
719
698
  }
720
699
  index++;
@@ -726,21 +705,27 @@ class DoublyLinkedList {
726
705
  * Space Complexity: O(n)
727
706
  */
728
707
  /**
729
- * Time Complexity: O(n), where n is the number of elements in the linked list.
708
+ * Time Complexity: O(n)
730
709
  * Space Complexity: O(n)
731
710
  *
732
- * The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
733
- * DoublyLinkedList with the transformed values.
734
- * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
735
- * the original DoublyLinkedList) and returns a value of type T (the type of values that will be stored in the mapped
736
- * DoublyLinkedList).
737
- * @returns The `map` function is returning a new instance of `DoublyLinkedList<T>` that contains the mapped values.
738
- */
739
- map(callback) {
711
+ * The `map` function creates a new DoublyLinkedList by applying a callback function to each element
712
+ * in the original list.
713
+ * @param callback - The callback parameter is a function that will be called for each element in the
714
+ * DoublyLinkedList. It takes three arguments: the current element, the index of the current element,
715
+ * and the DoublyLinkedList itself. The callback function should return a value that will be added to
716
+ * the new DoublyLinkedList that
717
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
718
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
719
+ * passed as the `this` value to the `callback` function. If `thisArg` is
720
+ * @returns The `map` function is returning a new `DoublyLinkedList` object that contains the results
721
+ * of applying the provided `callback` function to each element in the original `DoublyLinkedList`
722
+ * object.
723
+ */
724
+ map(callback, thisArg) {
740
725
  const mappedList = new DoublyLinkedList();
741
726
  let index = 0;
742
727
  for (const current of this) {
743
- mappedList.push(callback(current, index, this));
728
+ mappedList.push(callback.call(thisArg, current, index, this));
744
729
  index++;
745
730
  }
746
731
  return mappedList;
@@ -749,30 +734,18 @@ class DoublyLinkedList {
749
734
  * Time Complexity: O(n), where n is the number of elements in the linked list.
750
735
  * Space Complexity: O(n)
751
736
  */
752
- /**
753
- * Time Complexity: O(n), where n is the number of elements in the linked list.
754
- * Space Complexity: O(n)
755
- *
756
- * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
757
- * single value.
758
- * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
759
- * used to perform a specific operation on each element of the linked list.
760
- * @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
761
- * point for the reduction operation.
762
- * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
763
- * elements in the linked list.
764
- */
765
- reduce(callback, initialValue) {
766
- let accumulator = initialValue;
767
- let index = 0;
768
- for (const current of this) {
769
- accumulator = callback(accumulator, current, index, this);
770
- index++;
771
- }
772
- return accumulator;
773
- }
774
737
  print() {
775
738
  console.log([...this]);
776
739
  }
740
+ /**
741
+ * The function returns an iterator that iterates over the values of a linked list.
742
+ */
743
+ *_getIterator() {
744
+ let current = this.head;
745
+ while (current) {
746
+ yield current.value;
747
+ current = current.next;
748
+ }
749
+ }
777
750
  }
778
751
  exports.DoublyLinkedList = DoublyLinkedList;
@@ -1,3 +1,5 @@
1
+ import { IterableElementBase } from "../base";
2
+ import { ElementCallback } from "../../types";
1
3
  /**
2
4
  * data-structure-typed
3
5
  *
@@ -15,7 +17,7 @@ export declare class SinglyLinkedListNode<E = any> {
15
17
  */
16
18
  constructor(value: E);
17
19
  }
18
- export declare class SinglyLinkedList<E = any> {
20
+ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
19
21
  /**
20
22
  * The constructor initializes the linked list with an empty head, tail, and length.
21
23
  */
@@ -345,71 +347,50 @@ export declare class SinglyLinkedList<E = any> {
345
347
  */
346
348
  countOccurrences(value: E): number;
347
349
  /**
348
- * The function returns an iterator that iterates over the values of a linked list.
349
- */
350
- [Symbol.iterator](): Generator<E, void, unknown>;
351
- /**
352
- * Time Complexity: O(n), where n is the number of elements in the linked list.
353
- * Space Complexity: O(1)
354
- */
355
- /**
356
- * Time Complexity: O(n), where n is the number of elements in the linked list.
357
- * Space Complexity: O(1)
358
- *
359
- * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
360
- * @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
361
- * represents the value of the current node in the linked list, and the index argument represents the index of the
362
- * current node in the linked list.
363
- */
364
- forEach(callback: (value: E, index: number, list: SinglyLinkedList<E>) => void): void;
365
- /**
366
- * Time Complexity: O(n), where n is the number of elements in the linked list.
350
+ * Time Complexity: O(n)
367
351
  * Space Complexity: O(n)
368
352
  */
369
353
  /**
370
- * Time Complexity: O(n), where n is the number of elements in the linked list.
354
+ * Time Complexity: O(n)
371
355
  * Space Complexity: O(n)
372
356
  *
373
- * The `filter` function iterates through a SinglyLinkedList and returns a new SinglyLinkedList containing only the
374
- * elements that satisfy the given callback function.
375
- * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
376
- * It is used to determine whether a value should be included in the filtered list or not.
377
- * @returns The filtered list, which is an instance of the SinglyLinkedList class.
378
- */
379
- filter(callback: (value: E, index: number, list: SinglyLinkedList<E>) => boolean): SinglyLinkedList<E>;
357
+ * The `filter` function creates a new SinglyLinkedList by iterating over the elements of the current
358
+ * list and applying a callback function to each element to determine if it should be included in the
359
+ * filtered list.
360
+ * @param callback - The callback parameter is a function that will be called for each element in the
361
+ * list. It takes three arguments: the current element, the index of the current element, and the
362
+ * list itself. The callback function should return a boolean value indicating whether the current
363
+ * element should be included in the filtered list or not
364
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
365
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
366
+ * passed as the `this` value to the `callback` function. If `thisArg` is
367
+ * @returns The `filter` method is returning a new `SinglyLinkedList` object that contains the
368
+ * elements that pass the filter condition specified by the `callback` function.
369
+ */
370
+ filter(callback: ElementCallback<E, boolean>, thisArg?: any): SinglyLinkedList<E>;
380
371
  /**
381
372
  * Time Complexity: O(n), where n is the number of elements in the linked list.
382
373
  * Space Complexity: O(n)
383
374
  */
384
375
  /**
385
- * Time Complexity: O(n), where n is the number of elements in the linked list.
376
+ * Time Complexity: O(n)
386
377
  * Space Complexity: O(n)
387
378
  *
388
- * The `map` function takes a callback function and applies it to each element in the SinglyLinkedList, returning a new
389
- * SinglyLinkedList with the transformed values.
390
- * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
391
- * the original SinglyLinkedList) and returns a value of type T (the type of values that will be stored in the mapped
392
- * SinglyLinkedList).
393
- * @returns The `map` function is returning a new instance of `SinglyLinkedList<T>` that contains the mapped values.
394
- */
395
- map<T>(callback: (value: E, index: number, list: SinglyLinkedList<E>) => T): SinglyLinkedList<T>;
379
+ * The `map` function creates a new SinglyLinkedList by applying a callback function to each element
380
+ * of the original list.
381
+ * @param callback - The `callback` parameter is a function that will be called for each element in
382
+ * the linked list. It takes three arguments:
383
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
384
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
385
+ * passed as the `this` value to the `callback` function. If `thisArg` is
386
+ * @returns The `map` function is returning a new `SinglyLinkedList` object that contains the results
387
+ * of applying the provided `callback` function to each element in the original list.
388
+ */
389
+ map<T>(callback: ElementCallback<E, T>, thisArg?: any): SinglyLinkedList<T>;
396
390
  /**
397
391
  * Time Complexity: O(n), where n is the number of elements in the linked list.
398
392
  * Space Complexity: O(n)
399
393
  */
400
- /**
401
- * Time Complexity: O(n), where n is the number of elements in the linked list.
402
- * Space Complexity: O(n)
403
- *
404
- * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
405
- * single value.
406
- * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
407
- * used to perform a specific operation on each element of the linked list.
408
- * @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
409
- * point for the reduction operation.
410
- * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
411
- * elements in the linked list.
412
- */
413
- reduce<T>(callback: (accumulator: T, value: E, index: number, list: SinglyLinkedList<E>) => T, initialValue: T): T;
414
394
  print(): void;
395
+ protected _getIterator(): IterableIterator<E>;
415
396
  }