data-structure-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 (114) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +24 -18
  3. package/benchmark/report.html +16 -16
  4. package/benchmark/report.json +182 -182
  5. package/dist/cjs/data-structures/base/index.d.ts +1 -0
  6. package/dist/cjs/data-structures/base/index.js +18 -0
  7. package/dist/cjs/data-structures/base/index.js.map +1 -0
  8. package/dist/cjs/data-structures/base/iterable-base.d.ts +232 -0
  9. package/dist/cjs/data-structures/base/iterable-base.js +313 -0
  10. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -0
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +36 -69
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +78 -129
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +44 -6
  15. package/dist/cjs/data-structures/graph/abstract-graph.js +50 -27
  16. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  17. package/dist/cjs/data-structures/hash/hash-map.d.ts +59 -100
  18. package/dist/cjs/data-structures/hash/hash-map.js +69 -173
  19. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  20. package/dist/cjs/data-structures/heap/heap.d.ts +50 -7
  21. package/dist/cjs/data-structures/heap/heap.js +60 -30
  22. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  23. package/dist/cjs/data-structures/index.d.ts +1 -0
  24. package/dist/cjs/data-structures/index.js +1 -0
  25. package/dist/cjs/data-structures/index.js.map +1 -1
  26. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
  27. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +46 -73
  28. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  29. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +32 -51
  30. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +40 -73
  31. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  32. package/dist/cjs/data-structures/queue/deque.d.ts +29 -51
  33. package/dist/cjs/data-structures/queue/deque.js +36 -71
  34. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  35. package/dist/cjs/data-structures/queue/queue.d.ts +49 -48
  36. package/dist/cjs/data-structures/queue/queue.js +69 -82
  37. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  38. package/dist/cjs/data-structures/stack/stack.d.ts +43 -10
  39. package/dist/cjs/data-structures/stack/stack.js +50 -31
  40. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  41. package/dist/cjs/data-structures/trie/trie.d.ts +41 -6
  42. package/dist/cjs/data-structures/trie/trie.js +53 -32
  43. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  44. package/dist/cjs/types/data-structures/base/base.d.ts +5 -0
  45. package/dist/cjs/types/data-structures/base/base.js +3 -0
  46. package/dist/cjs/types/data-structures/base/base.js.map +1 -0
  47. package/dist/cjs/types/data-structures/base/index.d.ts +1 -0
  48. package/dist/cjs/types/data-structures/base/index.js +18 -0
  49. package/dist/cjs/types/data-structures/base/index.js.map +1 -0
  50. package/dist/cjs/types/data-structures/index.d.ts +1 -0
  51. package/dist/cjs/types/data-structures/index.js +1 -0
  52. package/dist/cjs/types/data-structures/index.js.map +1 -1
  53. package/dist/mjs/data-structures/base/index.d.ts +1 -0
  54. package/dist/mjs/data-structures/base/index.js +1 -0
  55. package/dist/mjs/data-structures/base/iterable-base.d.ts +232 -0
  56. package/dist/mjs/data-structures/base/iterable-base.js +307 -0
  57. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +36 -69
  58. package/dist/mjs/data-structures/binary-tree/binary-tree.js +78 -129
  59. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +44 -6
  60. package/dist/mjs/data-structures/graph/abstract-graph.js +52 -27
  61. package/dist/mjs/data-structures/hash/hash-map.d.ts +59 -100
  62. package/dist/mjs/data-structures/hash/hash-map.js +69 -173
  63. package/dist/mjs/data-structures/heap/heap.d.ts +50 -7
  64. package/dist/mjs/data-structures/heap/heap.js +60 -30
  65. package/dist/mjs/data-structures/index.d.ts +1 -0
  66. package/dist/mjs/data-structures/index.js +1 -0
  67. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
  68. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +46 -73
  69. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +32 -51
  70. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +40 -73
  71. package/dist/mjs/data-structures/queue/deque.d.ts +29 -51
  72. package/dist/mjs/data-structures/queue/deque.js +36 -71
  73. package/dist/mjs/data-structures/queue/queue.d.ts +49 -48
  74. package/dist/mjs/data-structures/queue/queue.js +66 -79
  75. package/dist/mjs/data-structures/stack/stack.d.ts +43 -10
  76. package/dist/mjs/data-structures/stack/stack.js +50 -31
  77. package/dist/mjs/data-structures/trie/trie.d.ts +41 -6
  78. package/dist/mjs/data-structures/trie/trie.js +53 -32
  79. package/dist/mjs/types/data-structures/base/base.d.ts +5 -0
  80. package/dist/mjs/types/data-structures/base/base.js +1 -0
  81. package/dist/mjs/types/data-structures/base/index.d.ts +1 -0
  82. package/dist/mjs/types/data-structures/base/index.js +1 -0
  83. package/dist/mjs/types/data-structures/index.d.ts +1 -0
  84. package/dist/mjs/types/data-structures/index.js +1 -0
  85. package/dist/umd/data-structure-typed.js +846 -715
  86. package/dist/umd/data-structure-typed.min.js +2 -2
  87. package/dist/umd/data-structure-typed.min.js.map +1 -1
  88. package/package.json +1 -1
  89. package/src/data-structures/base/index.ts +1 -0
  90. package/src/data-structures/base/iterable-base.ts +329 -0
  91. package/src/data-structures/binary-tree/binary-tree.ts +82 -138
  92. package/src/data-structures/graph/abstract-graph.ts +55 -28
  93. package/src/data-structures/hash/hash-map.ts +76 -185
  94. package/src/data-structures/heap/heap.ts +63 -36
  95. package/src/data-structures/index.ts +1 -0
  96. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -79
  97. package/src/data-structures/linked-list/singly-linked-list.ts +45 -80
  98. package/src/data-structures/queue/deque.ts +40 -82
  99. package/src/data-structures/queue/queue.ts +72 -87
  100. package/src/data-structures/stack/stack.ts +53 -34
  101. package/src/data-structures/trie/trie.ts +58 -35
  102. package/src/types/data-structures/base/base.ts +6 -0
  103. package/src/types/data-structures/base/index.ts +1 -0
  104. package/src/types/data-structures/index.ts +1 -0
  105. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +10 -10
  106. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +10 -10
  107. package/test/unit/data-structures/binary-tree/bst.test.ts +10 -10
  108. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +8 -8
  109. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +10 -10
  110. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
  111. package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
  112. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +28 -0
  113. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +25 -0
  114. package/test/unit/data-structures/queue/deque.test.ts +25 -0
@@ -126,6 +126,8 @@ var dataStructureTyped = (() => {
126
126
  HashTable: () => HashTable,
127
127
  HashTableNode: () => HashTableNode,
128
128
  Heap: () => Heap,
129
+ IterableElementBase: () => IterableElementBase,
130
+ IterablePairBase: () => IterablePairBase,
129
131
  IterationType: () => IterationType,
130
132
  LinkedHashMap: () => LinkedHashMap,
131
133
  LinkedListQueue: () => LinkedListQueue,
@@ -516,8 +518,317 @@ var dataStructureTyped = (() => {
516
518
  };
517
519
  var calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
518
520
 
521
+ // src/data-structures/base/iterable-base.ts
522
+ var IterablePairBase = class {
523
+ /**
524
+ * Time Complexity: O(n)
525
+ * Space Complexity: O(1)
526
+ */
527
+ /**
528
+ * Time Complexity: O(n)
529
+ * Space Complexity: O(1)
530
+ *
531
+ * The function is an implementation of the Symbol.iterator method that returns an iterable iterator.
532
+ * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
533
+ * allows the function to accept any number of arguments as an array. In this case, the `args`
534
+ * parameter is used to pass any additional arguments to the `_getIterator` method.
535
+ */
536
+ *[Symbol.iterator](...args) {
537
+ yield* __yieldStar(this._getIterator(...args));
538
+ }
539
+ /**
540
+ * Time Complexity: O(n)
541
+ * Space Complexity: O(n)
542
+ */
543
+ /**
544
+ * Time Complexity: O(n)
545
+ * Space Complexity: O(n)
546
+ *
547
+ * The function returns an iterator that yields key-value pairs from the object, where the value can
548
+ * be undefined.
549
+ */
550
+ *entries() {
551
+ for (const item of this) {
552
+ yield item;
553
+ }
554
+ }
555
+ /**
556
+ * Time Complexity: O(n)
557
+ * Space Complexity: O(n)
558
+ */
559
+ /**
560
+ * Time Complexity: O(n)
561
+ * Space Complexity: O(n)
562
+ *
563
+ * The function returns an iterator that yields the keys of a data structure.
564
+ */
565
+ *keys() {
566
+ for (const item of this) {
567
+ yield item[0];
568
+ }
569
+ }
570
+ /**
571
+ * Time Complexity: O(n)
572
+ * Space Complexity: O(n)
573
+ */
574
+ /**
575
+ * Time Complexity: O(n)
576
+ * Space Complexity: O(n)
577
+ *
578
+ * The function returns an iterator that yields the values of a collection.
579
+ */
580
+ *values() {
581
+ for (const item of this) {
582
+ yield item[1];
583
+ }
584
+ }
585
+ /**
586
+ * Time Complexity: O(n)
587
+ * Space Complexity: O(1)
588
+ */
589
+ /**
590
+ * Time Complexity: O(n)
591
+ * Space Complexity: O(1)
592
+ *
593
+ * The `every` function checks if every element in a collection satisfies a given condition.
594
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
595
+ * `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
596
+ * met for the current element in the iteration.
597
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
598
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
599
+ * passed as the first argument to the `predicate` function. If `thisArg` is not provided
600
+ * @returns The `every` method is returning a boolean value. It returns `true` if every element in
601
+ * the collection satisfies the provided predicate function, and `false` otherwise.
602
+ */
603
+ every(predicate, thisArg) {
604
+ let index = 0;
605
+ for (const item of this) {
606
+ if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
607
+ return false;
608
+ }
609
+ }
610
+ return true;
611
+ }
612
+ /**
613
+ * Time Complexity: O(n)
614
+ * Space Complexity: O(1)
615
+ */
616
+ /**
617
+ * Time Complexity: O(n)
618
+ * Space Complexity: O(1)
619
+ *
620
+ * The "some" function iterates over a collection and returns true if at least one element satisfies
621
+ * a given predicate.
622
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
623
+ * `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
624
+ * met for the current element in the iteration.
625
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
626
+ * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
627
+ * it will be passed as the first argument to the `predicate` function. If `thisArg` is
628
+ * @returns a boolean value. It returns true if the predicate function returns true for any pair in
629
+ * the collection, and false otherwise.
630
+ */
631
+ some(predicate, thisArg) {
632
+ let index = 0;
633
+ for (const item of this) {
634
+ if (predicate.call(thisArg, item[1], item[0], index++, this)) {
635
+ return true;
636
+ }
637
+ }
638
+ return false;
639
+ }
640
+ /**
641
+ * Time Complexity: O(n)
642
+ * Space Complexity: O(1)
643
+ */
644
+ /**
645
+ * Time Complexity: O(n)
646
+ * Space Complexity: O(1)
647
+ *
648
+ * The `forEach` function iterates over each key-value pair in a collection and executes a callback
649
+ * function for each pair.
650
+ * @param callbackfn - The callback function that will be called for each element in the collection.
651
+ * It takes four parameters: the value of the current element, the key of the current element, the
652
+ * index of the current element, and the collection itself.
653
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
654
+ * specify the value of `this` within the callback function. If `thisArg` is provided, it will be
655
+ * used as the `this` value when calling the callback function. If `thisArg` is not provided, `
656
+ */
657
+ forEach(callbackfn, thisArg) {
658
+ let index = 0;
659
+ for (const item of this) {
660
+ const [key, value] = item;
661
+ callbackfn.call(thisArg, value, key, index++, this);
662
+ }
663
+ }
664
+ /**
665
+ * Time Complexity: O(n)
666
+ * Space Complexity: O(1)
667
+ */
668
+ /**
669
+ * Time Complexity: O(n)
670
+ * Space Complexity: O(1)
671
+ *
672
+ * The `reduce` function iterates over key-value pairs and applies a callback function to each pair,
673
+ * accumulating a single value.
674
+ * @param callbackfn - The callback function that will be called for each element in the collection.
675
+ * It takes four arguments: the current accumulator value, the current value of the element, the key
676
+ * of the element, and the index of the element in the collection. It should return the updated
677
+ * accumulator value.
678
+ * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
679
+ * is the value that will be used as the first argument to the `callbackfn` function when reducing
680
+ * the elements of the collection.
681
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating over
682
+ * all the elements in the collection.
683
+ */
684
+ reduce(callbackfn, initialValue) {
685
+ let accumulator = initialValue;
686
+ let index = 0;
687
+ for (const item of this) {
688
+ const [key, value] = item;
689
+ accumulator = callbackfn(accumulator, value, key, index++, this);
690
+ }
691
+ return accumulator;
692
+ }
693
+ };
694
+ var IterableElementBase = class {
695
+ /**
696
+ * Time Complexity: O(n)
697
+ * Space Complexity: O(1)
698
+ */
699
+ /**
700
+ * Time Complexity: O(n)
701
+ * Space Complexity: O(1)
702
+ *
703
+ * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
704
+ * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
705
+ * allows the function to accept any number of arguments as an array. In this case, the `args`
706
+ * parameter is used to pass any number of arguments to the `_getIterator` method.
707
+ */
708
+ *[Symbol.iterator](...args) {
709
+ yield* __yieldStar(this._getIterator(...args));
710
+ }
711
+ /**
712
+ * Time Complexity: O(n)
713
+ * Space Complexity: O(n)
714
+ */
715
+ /**
716
+ * Time Complexity: O(n)
717
+ * Space Complexity: O(n)
718
+ *
719
+ * The function returns an iterator that yields all the values in the object.
720
+ */
721
+ *values() {
722
+ for (const item of this) {
723
+ yield item;
724
+ }
725
+ }
726
+ /**
727
+ * Time Complexity: O(n)
728
+ * Space Complexity: O(1)
729
+ */
730
+ /**
731
+ * Time Complexity: O(n)
732
+ * Space Complexity: O(1)
733
+ *
734
+ * The `every` function checks if every element in the array satisfies a given predicate.
735
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
736
+ * the current element being processed, its index, and the array it belongs to. It should return a
737
+ * boolean value indicating whether the element satisfies a certain condition or not.
738
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
739
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
740
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
741
+ * @returns The `every` method is returning a boolean value. It returns `true` if every element in
742
+ * the array satisfies the provided predicate function, and `false` otherwise.
743
+ */
744
+ every(predicate, thisArg) {
745
+ let index = 0;
746
+ for (const item of this) {
747
+ if (!predicate.call(thisArg, item, index++, this)) {
748
+ return false;
749
+ }
750
+ }
751
+ return true;
752
+ }
753
+ /**
754
+ * Time Complexity: O(n)
755
+ * Space Complexity: O(1)
756
+ */
757
+ /**
758
+ * Time Complexity: O(n)
759
+ * Space Complexity: O(1)
760
+ *
761
+ * The "some" function checks if at least one element in a collection satisfies a given predicate.
762
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
763
+ * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
764
+ * element satisfies the condition.
765
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
766
+ * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
767
+ * it will be passed as the `this` value to the `predicate` function. If `thisArg
768
+ * @returns a boolean value. It returns true if the predicate function returns true for any element
769
+ * in the collection, and false otherwise.
770
+ */
771
+ some(predicate, thisArg) {
772
+ let index = 0;
773
+ for (const item of this) {
774
+ if (predicate.call(thisArg, item, index++, this)) {
775
+ return true;
776
+ }
777
+ }
778
+ return false;
779
+ }
780
+ /**
781
+ * Time Complexity: O(n)
782
+ * Space Complexity: O(1)
783
+ */
784
+ /**
785
+ * Time Complexity: O(n)
786
+ * Space Complexity: O(1)
787
+ *
788
+ * The `forEach` function iterates over each element in an array-like object and calls a callback
789
+ * function for each element.
790
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
791
+ * the array. It takes three arguments: the current element being processed, the index of the current
792
+ * element, and the array that forEach was called upon.
793
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
794
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
795
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
796
+ */
797
+ forEach(callbackfn, thisArg) {
798
+ let index = 0;
799
+ for (const item of this) {
800
+ callbackfn.call(thisArg, item, index++, this);
801
+ }
802
+ }
803
+ /**
804
+ * Time Complexity: O(n)
805
+ * Space Complexity: O(1)
806
+ */
807
+ /**
808
+ * Time Complexity: O(n)
809
+ * Space Complexity: O(1)
810
+ *
811
+ * The `reduce` function iterates over the elements of an array-like object and applies a callback
812
+ * function to reduce them into a single value.
813
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
814
+ * the array. It takes four arguments:
815
+ * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
816
+ * is the value that the accumulator starts with before the reduction operation begins.
817
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating over
818
+ * all the elements in the array and applying the callback function to each element.
819
+ */
820
+ reduce(callbackfn, initialValue) {
821
+ let accumulator = initialValue;
822
+ let index = 0;
823
+ for (const item of this) {
824
+ accumulator = callbackfn(accumulator, item, index++, this);
825
+ }
826
+ return accumulator;
827
+ }
828
+ };
829
+
519
830
  // src/data-structures/hash/hash-map.ts
520
- var HashMap = class _HashMap {
831
+ var HashMap = class _HashMap extends IterablePairBase {
521
832
  /**
522
833
  * The constructor function initializes a new instance of a class with optional elements and options.
523
834
  * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
@@ -527,6 +838,7 @@ var dataStructureTyped = (() => {
527
838
  * configuration options for the constructor. In this case, it has one property:
528
839
  */
529
840
  constructor(elements = [], options) {
841
+ super();
530
842
  __publicField(this, "_store", {});
531
843
  __publicField(this, "_objMap", /* @__PURE__ */ new Map());
532
844
  __publicField(this, "_size", 0);
@@ -639,95 +951,13 @@ var dataStructureTyped = (() => {
639
951
  }
640
952
  }
641
953
  /**
642
- * The function returns an iterator that yields key-value pairs from both an object store and an
643
- * object map.
644
- */
645
- *[Symbol.iterator]() {
646
- for (const node of Object.values(this._store)) {
647
- yield [node.key, node.value];
648
- }
649
- for (const node of this._objMap) {
650
- yield node;
651
- }
652
- }
653
- /**
654
- * The function returns an iterator that yields key-value pairs from the object.
655
- */
656
- *entries() {
657
- for (const item of this) {
658
- yield item;
659
- }
660
- }
661
- /**
662
- * The function `keys()` returns an iterator that yields all the keys of the object.
663
- */
664
- *keys() {
665
- for (const [key] of this) {
666
- yield key;
667
- }
668
- }
669
- *values() {
670
- for (const [, value] of this) {
671
- yield value;
672
- }
673
- }
674
- /**
675
- * The `every` function checks if every element in a HashMap satisfies a given predicate function.
676
- * @param predicate - The predicate parameter is a function that takes four arguments: value, key,
677
- * index, and map. It is used to test each element in the map against a condition. If the predicate
678
- * function returns false for any element, the every() method will return false. If the predicate
679
- * function returns true for all
680
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
681
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
682
- * passed as the `this` value to the `predicate` function. If `thisArg` is
683
- * @returns The method is returning a boolean value. It returns true if the predicate function
684
- * returns true for every element in the map, and false otherwise.
685
- */
686
- every(predicate, thisArg) {
687
- let index = 0;
688
- for (const [key, value] of this) {
689
- if (!predicate.call(thisArg, value, key, index++, this)) {
690
- return false;
691
- }
692
- }
693
- return true;
694
- }
695
- /**
696
- * The "some" function checks if at least one element in a HashMap satisfies a given predicate.
697
- * @param predicate - The `predicate` parameter is a function that takes four arguments: `value`,
698
- * `key`, `index`, and `map`. It is used to determine whether a specific condition is met for a given
699
- * key-value pair in the `HashMap`.
700
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
701
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
702
- * passed as the `this` value to the `predicate` function. If `thisArg` is
703
- * @returns a boolean value. It returns true if the predicate function returns true for any element
704
- * in the map, and false otherwise.
705
- */
706
- some(predicate, thisArg) {
707
- let index = 0;
708
- for (const [key, value] of this) {
709
- if (predicate.call(thisArg, value, key, index++, this)) {
710
- return true;
711
- }
712
- }
713
- return false;
714
- }
715
- /**
716
- * The `forEach` function iterates over the elements of a HashMap and applies a callback function to
717
- * each element.
718
- * @param callbackfn - A function that will be called for each key-value pair in the HashMap. It
719
- * takes four parameters:
720
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
721
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
722
- * be passed as the `this` value inside the `callbackfn` function. If `thisArg
954
+ * Time Complexity: O(n)
955
+ * Space Complexity: O(n)
723
956
  */
724
- forEach(callbackfn, thisArg) {
725
- let index = 0;
726
- for (const [key, value] of this) {
727
- callbackfn.call(thisArg, value, key, index++, this);
728
- }
729
- }
730
957
  /**
958
+ * Time Complexity: O(n)
959
+ * Space Complexity: O(n)
960
+ *
731
961
  * The `map` function in TypeScript creates a new HashMap by applying a callback function to each
732
962
  * key-value pair in the original HashMap.
733
963
  * @param callbackfn - The callback function that will be called for each key-value pair in the
@@ -747,6 +977,13 @@ var dataStructureTyped = (() => {
747
977
  return resultMap;
748
978
  }
749
979
  /**
980
+ * Time Complexity: O(n)
981
+ * Space Complexity: O(n)
982
+ */
983
+ /**
984
+ * Time Complexity: O(n)
985
+ * Space Complexity: O(n)
986
+ *
750
987
  * The `filter` function creates a new HashMap containing key-value pairs from the original HashMap
751
988
  * that satisfy a given predicate function.
752
989
  * @param predicate - The predicate parameter is a function that takes four arguments: value, key,
@@ -769,27 +1006,20 @@ var dataStructureTyped = (() => {
769
1006
  }
770
1007
  return filteredMap;
771
1008
  }
1009
+ print() {
1010
+ console.log([...this.entries()]);
1011
+ }
772
1012
  /**
773
- * The `reduce` function iterates over the elements of a HashMap and applies a callback function to
774
- * each element, accumulating a single value.
775
- * @param callbackfn - The callback function that will be called for each element in the HashMap. It
776
- * takes five parameters:
777
- * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
778
- * is the value that will be used as the first argument of the callback function when reducing the
779
- * elements of the map.
780
- * @returns The `reduce` method is returning the final value of the accumulator after iterating over
781
- * all the elements in the `HashMap`.
1013
+ * The function returns an iterator that yields key-value pairs from both an object store and an
1014
+ * object map.
782
1015
  */
783
- reduce(callbackfn, initialValue) {
784
- let accumulator = initialValue;
785
- let index = 0;
786
- for (const [key, value] of this) {
787
- accumulator = callbackfn(accumulator, value, key, index++, this);
1016
+ *_getIterator() {
1017
+ for (const node of Object.values(this._store)) {
1018
+ yield [node.key, node.value];
1019
+ }
1020
+ for (const node of this._objMap) {
1021
+ yield node;
788
1022
  }
789
- return accumulator;
790
- }
791
- print() {
792
- console.log([...this.entries()]);
793
1023
  }
794
1024
  _isObjKey(key) {
795
1025
  const keyType = typeof key;
@@ -810,11 +1040,12 @@ var dataStructureTyped = (() => {
810
1040
  return strKey;
811
1041
  }
812
1042
  };
813
- var LinkedHashMap = class _LinkedHashMap {
1043
+ var LinkedHashMap = class _LinkedHashMap extends IterablePairBase {
814
1044
  constructor(elements, options = {
815
1045
  hashFn: (key) => String(key),
816
1046
  objHashFn: (key) => key
817
1047
  }) {
1048
+ super();
818
1049
  __publicField(this, "_noObjMap", {});
819
1050
  __publicField(this, "_objMap", /* @__PURE__ */ new WeakMap());
820
1051
  __publicField(this, "_head");
@@ -946,18 +1177,6 @@ var dataStructureTyped = (() => {
946
1177
  this.set(key, value);
947
1178
  }
948
1179
  }
949
- keys() {
950
- const keys = [];
951
- for (const [key] of this)
952
- keys.push(key);
953
- return keys;
954
- }
955
- values() {
956
- const values = [];
957
- for (const [, value] of this)
958
- values.push(value);
959
- return values;
960
- }
961
1180
  /**
962
1181
  * Time Complexity: O(1)
963
1182
  * Space Complexity: O(1)
@@ -1080,35 +1299,29 @@ var dataStructureTyped = (() => {
1080
1299
  return cloned;
1081
1300
  }
1082
1301
  /**
1083
- * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
1084
- * Space Complexity: O(1)
1085
- *
1086
- * The `forEach` function iterates over each element in a LinkedHashMap and executes a callback function on
1087
- * each element.
1088
- * @param callback - The callback parameter is a function that will be called for each element in the
1089
- * LinkedHashMap. It takes three arguments:
1302
+ * Time Complexity: O(n)
1303
+ * Space Complexity: O(n)
1090
1304
  */
1091
- forEach(callback) {
1092
- let index = 0;
1093
- let node = this._head;
1094
- while (node !== this._sentinel) {
1095
- callback([node.key, node.value], index++, this);
1096
- node = node.next;
1097
- }
1098
- }
1099
1305
  /**
1100
- * The `filter` function takes a predicate function and returns a new LinkedHashMap containing only the
1101
- * key-value pairs that satisfy the predicate.
1102
- * @param predicate - The `predicate` parameter is a function that takes two arguments: `element` and
1103
- * `map`.
1104
- * @returns a new LinkedHashMap object that contains the key-value pairs from the original LinkedHashMap that
1105
- * satisfy the given predicate function.
1306
+ * Time Complexity: O(n)
1307
+ * Space Complexity: O(n)
1308
+ *
1309
+ * The `filter` function creates a new `LinkedHashMap` containing key-value pairs from the original
1310
+ * map that satisfy a given predicate function.
1311
+ * @param predicate - The `predicate` parameter is a callback function that takes four arguments:
1312
+ * `value`, `key`, `index`, and `this`. It should return a boolean value indicating whether the
1313
+ * current element should be included in the filtered map or not.
1314
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
1315
+ * specify the value of `this` within the `predicate` function. It is used when you want to bind a
1316
+ * specific object as the context for the `predicate` function. If `thisArg` is not provided, `this
1317
+ * @returns a new `LinkedHashMap` object that contains the key-value pairs from the original
1318
+ * `LinkedHashMap` object that satisfy the given predicate function.
1106
1319
  */
1107
- filter(predicate) {
1320
+ filter(predicate, thisArg) {
1108
1321
  const filteredMap = new _LinkedHashMap();
1109
1322
  let index = 0;
1110
1323
  for (const [key, value] of this) {
1111
- if (predicate([key, value], index, this)) {
1324
+ if (predicate.call(thisArg, value, key, index, this)) {
1112
1325
  filteredMap.set(key, value);
1113
1326
  }
1114
1327
  index++;
@@ -1116,42 +1329,38 @@ var dataStructureTyped = (() => {
1116
1329
  return filteredMap;
1117
1330
  }
1118
1331
  /**
1119
- * The `map` function takes a callback function and returns a new LinkedHashMap with the values transformed
1120
- * by the callback.
1121
- * @param callback - The `callback` parameter is a function that takes two arguments: `element` and
1122
- * `map`.
1123
- * @returns a new LinkedHashMap object with the values mapped according to the provided callback function.
1332
+ * Time Complexity: O(n)
1333
+ * Space Complexity: O(n)
1124
1334
  */
1125
- map(callback) {
1335
+ /**
1336
+ * Time Complexity: O(n)
1337
+ * Space Complexity: O(n)
1338
+ *
1339
+ * The `map` function in TypeScript creates a new `LinkedHashMap` by applying a callback function to
1340
+ * each key-value pair in the original map.
1341
+ * @param callback - The callback parameter is a function that will be called for each key-value pair
1342
+ * in the map. It takes four arguments: the value of the current key-value pair, the key of the
1343
+ * current key-value pair, the index of the current key-value pair, and the map itself. The callback
1344
+ * function should
1345
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
1346
+ * specify the value of `this` within the callback function. If provided, the callback function will
1347
+ * be called with `thisArg` as its `this` value. If not provided, `this` will refer to the current
1348
+ * map
1349
+ * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
1350
+ * function.
1351
+ */
1352
+ map(callback, thisArg) {
1126
1353
  const mappedMap = new _LinkedHashMap();
1127
1354
  let index = 0;
1128
1355
  for (const [key, value] of this) {
1129
- const newValue = callback([key, value], index, this);
1356
+ const newValue = callback.call(thisArg, value, key, index, this);
1130
1357
  mappedMap.set(key, newValue);
1131
1358
  index++;
1132
1359
  }
1133
1360
  return mappedMap;
1134
1361
  }
1135
- /**
1136
- * The `reduce` function iterates over the elements of a LinkedHashMap and applies a callback function to
1137
- * each element, accumulating a single value.
1138
- * @param callback - The callback parameter is a function that takes three arguments: accumulator,
1139
- * element, and map. It is called for each element in the LinkedHashMap and is used to accumulate a single
1140
- * result.
1141
- * @param {A} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
1142
- * is the value that will be passed as the first argument to the `callback` function when reducing
1143
- * the elements of the map.
1144
- * @returns The `reduce` function is returning the final value of the accumulator after iterating
1145
- * over all the elements in the LinkedHashMap and applying the callback function to each element.
1146
- */
1147
- reduce(callback, initialValue) {
1148
- let accumulator = initialValue;
1149
- let index = 0;
1150
- for (const entry of this) {
1151
- accumulator = callback(accumulator, entry, index, this);
1152
- index++;
1153
- }
1154
- return accumulator;
1362
+ print() {
1363
+ console.log([...this]);
1155
1364
  }
1156
1365
  /**
1157
1366
  * Time Complexity: O(n), where n is the number of elements in the LinkedHashMap.
@@ -1159,16 +1368,13 @@ var dataStructureTyped = (() => {
1159
1368
  *
1160
1369
  * The above function is an iterator that yields key-value pairs from a linked list.
1161
1370
  */
1162
- *[Symbol.iterator]() {
1371
+ *_getIterator() {
1163
1372
  let node = this._head;
1164
1373
  while (node !== this._sentinel) {
1165
1374
  yield [node.key, node.value];
1166
1375
  node = node.next;
1167
1376
  }
1168
1377
  }
1169
- print() {
1170
- console.log([...this]);
1171
- }
1172
1378
  /**
1173
1379
  * Time Complexity: O(1)
1174
1380
  * Space Complexity: O(1)
@@ -1207,11 +1413,12 @@ var dataStructureTyped = (() => {
1207
1413
  this.next = void 0;
1208
1414
  }
1209
1415
  };
1210
- var SinglyLinkedList = class _SinglyLinkedList {
1416
+ var SinglyLinkedList = class _SinglyLinkedList extends IterableElementBase {
1211
1417
  /**
1212
1418
  * The constructor initializes the linked list with an empty head, tail, and length.
1213
1419
  */
1214
1420
  constructor(elements) {
1421
+ super();
1215
1422
  __publicField(this, "_head");
1216
1423
  __publicField(this, "_tail");
1217
1424
  __publicField(this, "_length");
@@ -1793,54 +2000,31 @@ var dataStructureTyped = (() => {
1793
2000
  return count;
1794
2001
  }
1795
2002
  /**
1796
- * The function returns an iterator that iterates over the values of a linked list.
1797
- */
1798
- *[Symbol.iterator]() {
1799
- let current = this.head;
1800
- while (current) {
1801
- yield current.value;
1802
- current = current.next;
1803
- }
1804
- }
1805
- /**
1806
- * Time Complexity: O(n), where n is the number of elements in the linked list.
1807
- * Space Complexity: O(1)
1808
- */
1809
- /**
1810
- * Time Complexity: O(n), where n is the number of elements in the linked list.
1811
- * Space Complexity: O(1)
1812
- *
1813
- * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
1814
- * @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
1815
- * represents the value of the current node in the linked list, and the index argument represents the index of the
1816
- * current node in the linked list.
1817
- */
1818
- forEach(callback) {
1819
- let index = 0;
1820
- for (const el of this) {
1821
- callback(el, index, this);
1822
- index++;
1823
- }
1824
- }
1825
- /**
1826
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2003
+ * Time Complexity: O(n)
1827
2004
  * Space Complexity: O(n)
1828
2005
  */
1829
2006
  /**
1830
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2007
+ * Time Complexity: O(n)
1831
2008
  * Space Complexity: O(n)
1832
2009
  *
1833
- * The `filter` function iterates through a SinglyLinkedList and returns a new SinglyLinkedList containing only the
1834
- * elements that satisfy the given callback function.
1835
- * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
1836
- * It is used to determine whether a value should be included in the filtered list or not.
1837
- * @returns The filtered list, which is an instance of the SinglyLinkedList class.
2010
+ * The `filter` function creates a new SinglyLinkedList by iterating over the elements of the current
2011
+ * list and applying a callback function to each element to determine if it should be included in the
2012
+ * filtered list.
2013
+ * @param callback - The callback parameter is a function that will be called for each element in the
2014
+ * list. It takes three arguments: the current element, the index of the current element, and the
2015
+ * list itself. The callback function should return a boolean value indicating whether the current
2016
+ * element should be included in the filtered list or not
2017
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
2018
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
2019
+ * passed as the `this` value to the `callback` function. If `thisArg` is
2020
+ * @returns The `filter` method is returning a new `SinglyLinkedList` object that contains the
2021
+ * elements that pass the filter condition specified by the `callback` function.
1838
2022
  */
1839
- filter(callback) {
2023
+ filter(callback, thisArg) {
1840
2024
  const filteredList = new _SinglyLinkedList();
1841
2025
  let index = 0;
1842
2026
  for (const current of this) {
1843
- if (callback(current, index, this)) {
2027
+ if (callback.call(thisArg, current, index, this)) {
1844
2028
  filteredList.push(current);
1845
2029
  }
1846
2030
  index++;
@@ -1852,21 +2036,24 @@ var dataStructureTyped = (() => {
1852
2036
  * Space Complexity: O(n)
1853
2037
  */
1854
2038
  /**
1855
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2039
+ * Time Complexity: O(n)
1856
2040
  * Space Complexity: O(n)
1857
2041
  *
1858
- * The `map` function takes a callback function and applies it to each element in the SinglyLinkedList, returning a new
1859
- * SinglyLinkedList with the transformed values.
1860
- * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
1861
- * the original SinglyLinkedList) and returns a value of type T (the type of values that will be stored in the mapped
1862
- * SinglyLinkedList).
1863
- * @returns The `map` function is returning a new instance of `SinglyLinkedList<T>` that contains the mapped values.
2042
+ * The `map` function creates a new SinglyLinkedList by applying a callback function to each element
2043
+ * of the original list.
2044
+ * @param callback - The `callback` parameter is a function that will be called for each element in
2045
+ * the linked list. It takes three arguments:
2046
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
2047
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
2048
+ * passed as the `this` value to the `callback` function. If `thisArg` is
2049
+ * @returns The `map` function is returning a new `SinglyLinkedList` object that contains the results
2050
+ * of applying the provided `callback` function to each element in the original list.
1864
2051
  */
1865
- map(callback) {
2052
+ map(callback, thisArg) {
1866
2053
  const mappedList = new _SinglyLinkedList();
1867
2054
  let index = 0;
1868
2055
  for (const current of this) {
1869
- mappedList.push(callback(current, index, this));
2056
+ mappedList.push(callback.call(thisArg, current, index, this));
1870
2057
  index++;
1871
2058
  }
1872
2059
  return mappedList;
@@ -1875,31 +2062,16 @@ var dataStructureTyped = (() => {
1875
2062
  * Time Complexity: O(n), where n is the number of elements in the linked list.
1876
2063
  * Space Complexity: O(n)
1877
2064
  */
1878
- /**
1879
- * Time Complexity: O(n), where n is the number of elements in the linked list.
1880
- * Space Complexity: O(n)
1881
- *
1882
- * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
1883
- * single value.
1884
- * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
1885
- * used to perform a specific operation on each element of the linked list.
1886
- * @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
1887
- * point for the reduction operation.
1888
- * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
1889
- * elements in the linked list.
1890
- */
1891
- reduce(callback, initialValue) {
1892
- let accumulator = initialValue;
1893
- let index = 0;
1894
- for (const current of this) {
1895
- accumulator = callback(accumulator, current, index, this);
1896
- index++;
1897
- }
1898
- return accumulator;
1899
- }
1900
2065
  print() {
1901
2066
  console.log([...this]);
1902
2067
  }
2068
+ *_getIterator() {
2069
+ let current = this.head;
2070
+ while (current) {
2071
+ yield current.value;
2072
+ current = current.next;
2073
+ }
2074
+ }
1903
2075
  };
1904
2076
 
1905
2077
  // src/data-structures/linked-list/doubly-linked-list.ts
@@ -1918,11 +2090,12 @@ var dataStructureTyped = (() => {
1918
2090
  this.prev = void 0;
1919
2091
  }
1920
2092
  };
1921
- var DoublyLinkedList = class _DoublyLinkedList {
2093
+ var DoublyLinkedList = class _DoublyLinkedList extends IterableElementBase {
1922
2094
  /**
1923
2095
  * The constructor initializes the linked list with an empty head, tail, and length.
1924
2096
  */
1925
2097
  constructor(elements) {
2098
+ super();
1926
2099
  __publicField(this, "_head");
1927
2100
  __publicField(this, "_tail");
1928
2101
  __publicField(this, "_length");
@@ -2558,113 +2731,84 @@ var dataStructureTyped = (() => {
2558
2731
  return array;
2559
2732
  }
2560
2733
  /**
2561
- * The function returns an iterator that iterates over the values of a linked list.
2562
- */
2563
- *[Symbol.iterator]() {
2564
- let current = this.head;
2565
- while (current) {
2566
- yield current.value;
2567
- current = current.next;
2568
- }
2569
- }
2570
- /**
2571
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2572
- * Space Complexity: O(1)
2573
- */
2574
- /**
2575
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2576
- * Space Complexity: O(1)
2577
- *
2578
- * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
2579
- * @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
2580
- * represents the value of the current node in the linked list, and the index argument represents the index of the
2581
- * current node in the linked list.
2582
- */
2583
- forEach(callback) {
2584
- let index = 0;
2585
- for (const el of this) {
2586
- callback(el, index, this);
2587
- index++;
2588
- }
2589
- }
2590
- /**
2591
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2734
+ * Time Complexity: O(n)
2592
2735
  * Space Complexity: O(n)
2593
2736
  */
2594
2737
  /**
2595
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2738
+ * Time Complexity: O(n)
2596
2739
  * Space Complexity: O(n)
2597
2740
  *
2598
- * The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
2599
- * elements that satisfy the given callback function.
2600
- * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
2601
- * It is used to determine whether a value should be included in the filtered list or not.
2602
- * @returns The filtered list, which is an instance of the DoublyLinkedList class.
2741
+ * The `filter` function creates a new DoublyLinkedList by iterating over the elements of the current
2742
+ * list and applying a callback function to each element, returning only the elements for which the
2743
+ * callback function returns true.
2744
+ * @param callback - The `callback` parameter is a function that will be called for each element in
2745
+ * the DoublyLinkedList. It takes three arguments: the current element, the index of the current
2746
+ * element, and the DoublyLinkedList itself. The callback function should return a boolean value
2747
+ * indicating whether the current element should be included
2748
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
2749
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
2750
+ * passed as the `this` value to the `callback` function. If `thisArg` is
2751
+ * @returns The `filter` method is returning a new `DoublyLinkedList` object that contains the
2752
+ * elements that pass the filter condition specified by the `callback` function.
2603
2753
  */
2604
- filter(callback) {
2754
+ filter(callback, thisArg) {
2605
2755
  const filteredList = new _DoublyLinkedList();
2606
2756
  let index = 0;
2607
2757
  for (const current of this) {
2608
- if (callback(current, index, this)) {
2758
+ if (callback.call(thisArg, current, index, this)) {
2609
2759
  filteredList.push(current);
2610
2760
  }
2611
2761
  index++;
2612
2762
  }
2613
- return filteredList;
2614
- }
2615
- /**
2616
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2617
- * Space Complexity: O(n)
2618
- */
2619
- /**
2620
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2621
- * Space Complexity: O(n)
2622
- *
2623
- * The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
2624
- * DoublyLinkedList with the transformed values.
2625
- * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
2626
- * the original DoublyLinkedList) and returns a value of type T (the type of values that will be stored in the mapped
2627
- * DoublyLinkedList).
2628
- * @returns The `map` function is returning a new instance of `DoublyLinkedList<T>` that contains the mapped values.
2629
- */
2630
- map(callback) {
2631
- const mappedList = new _DoublyLinkedList();
2632
- let index = 0;
2633
- for (const current of this) {
2634
- mappedList.push(callback(current, index, this));
2635
- index++;
2636
- }
2637
- return mappedList;
2763
+ return filteredList;
2638
2764
  }
2639
2765
  /**
2640
2766
  * Time Complexity: O(n), where n is the number of elements in the linked list.
2641
2767
  * Space Complexity: O(n)
2642
2768
  */
2643
2769
  /**
2644
- * Time Complexity: O(n), where n is the number of elements in the linked list.
2770
+ * Time Complexity: O(n)
2645
2771
  * Space Complexity: O(n)
2646
2772
  *
2647
- * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
2648
- * single value.
2649
- * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
2650
- * used to perform a specific operation on each element of the linked list.
2651
- * @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
2652
- * point for the reduction operation.
2653
- * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
2654
- * elements in the linked list.
2773
+ * The `map` function creates a new DoublyLinkedList by applying a callback function to each element
2774
+ * in the original list.
2775
+ * @param callback - The callback parameter is a function that will be called for each element in the
2776
+ * DoublyLinkedList. It takes three arguments: the current element, the index of the current element,
2777
+ * and the DoublyLinkedList itself. The callback function should return a value that will be added to
2778
+ * the new DoublyLinkedList that
2779
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
2780
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
2781
+ * passed as the `this` value to the `callback` function. If `thisArg` is
2782
+ * @returns The `map` function is returning a new `DoublyLinkedList` object that contains the results
2783
+ * of applying the provided `callback` function to each element in the original `DoublyLinkedList`
2784
+ * object.
2655
2785
  */
2656
- reduce(callback, initialValue) {
2657
- let accumulator = initialValue;
2786
+ map(callback, thisArg) {
2787
+ const mappedList = new _DoublyLinkedList();
2658
2788
  let index = 0;
2659
2789
  for (const current of this) {
2660
- accumulator = callback(accumulator, current, index, this);
2790
+ mappedList.push(callback.call(thisArg, current, index, this));
2661
2791
  index++;
2662
2792
  }
2663
- return accumulator;
2793
+ return mappedList;
2664
2794
  }
2795
+ /**
2796
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
2797
+ * Space Complexity: O(n)
2798
+ */
2665
2799
  print() {
2666
2800
  console.log([...this]);
2667
2801
  }
2802
+ /**
2803
+ * The function returns an iterator that iterates over the values of a linked list.
2804
+ */
2805
+ *_getIterator() {
2806
+ let current = this.head;
2807
+ while (current) {
2808
+ yield current.value;
2809
+ current = current.next;
2810
+ }
2811
+ }
2668
2812
  };
2669
2813
 
2670
2814
  // src/data-structures/linked-list/skip-linked-list.ts
@@ -2916,7 +3060,7 @@ var dataStructureTyped = (() => {
2916
3060
  };
2917
3061
 
2918
3062
  // src/data-structures/stack/stack.ts
2919
- var Stack = class _Stack {
3063
+ var Stack = class _Stack extends IterableElementBase {
2920
3064
  /**
2921
3065
  * The constructor initializes an array of elements, which can be provided as an optional parameter.
2922
3066
  * @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
@@ -2924,6 +3068,7 @@ var dataStructureTyped = (() => {
2924
3068
  * is provided and is an array, it is assigned to the `_elements
2925
3069
  */
2926
3070
  constructor(elements) {
3071
+ super();
2927
3072
  __publicField(this, "_elements");
2928
3073
  this._elements = [];
2929
3074
  if (elements) {
@@ -3049,92 +3194,78 @@ var dataStructureTyped = (() => {
3049
3194
  return new _Stack(this.elements.slice());
3050
3195
  }
3051
3196
  /**
3052
- * Custom iterator for the Stack class.
3053
- * @returns An iterator object.
3197
+ * Time Complexity: O(n)
3198
+ * Space Complexity: O(n)
3054
3199
  */
3055
- *[Symbol.iterator]() {
3056
- for (let i = 0; i < this.elements.length; i++) {
3057
- yield this.elements[i];
3058
- }
3059
- }
3060
3200
  /**
3061
- * Applies a function to each element of the stack.
3062
- * @param {function(E): void} callback - A function to apply to each element.
3201
+ * Time Complexity: O(n)
3202
+ * Space Complexity: O(n)
3203
+ *
3204
+ * The `filter` function creates a new stack containing elements from the original stack that satisfy
3205
+ * a given predicate function.
3206
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
3207
+ * the current element being iterated over, the index of the current element, and the stack itself.
3208
+ * It should return a boolean value indicating whether the element should be included in the filtered
3209
+ * stack or not.
3210
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
3211
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
3212
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
3213
+ * @returns The `filter` method is returning a new `Stack` object that contains the elements that
3214
+ * satisfy the given predicate function.
3063
3215
  */
3064
- forEach(callback) {
3065
- let index = 0;
3066
- for (const el of this) {
3067
- callback(el, index, this);
3068
- index++;
3069
- }
3070
- }
3071
- filter(predicate) {
3216
+ filter(predicate, thisArg) {
3072
3217
  const newStack = new _Stack();
3073
3218
  let index = 0;
3074
3219
  for (const el of this) {
3075
- if (predicate(el, index, this)) {
3220
+ if (predicate.call(thisArg, el, index, this)) {
3076
3221
  newStack.push(el);
3077
3222
  }
3078
3223
  index++;
3079
3224
  }
3080
3225
  return newStack;
3081
3226
  }
3082
- map(callback) {
3227
+ /**
3228
+ * Time Complexity: O(n)
3229
+ * Space Complexity: O(n)
3230
+ */
3231
+ /**
3232
+ * Time Complexity: O(n)
3233
+ * Space Complexity: O(n)
3234
+ *
3235
+ * The `map` function takes a callback function and applies it to each element in the stack,
3236
+ * returning a new stack with the results.
3237
+ * @param callback - The `callback` parameter is a function that will be called for each element in
3238
+ * the stack. It takes three arguments:
3239
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
3240
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
3241
+ * passed as the `this` value to the `callback` function. If `thisArg` is
3242
+ * @returns The `map` method is returning a new `Stack` object.
3243
+ */
3244
+ map(callback, thisArg) {
3083
3245
  const newStack = new _Stack();
3084
3246
  let index = 0;
3085
3247
  for (const el of this) {
3086
- newStack.push(callback(el, index, this));
3248
+ newStack.push(callback.call(thisArg, el, index, this));
3087
3249
  index++;
3088
3250
  }
3089
3251
  return newStack;
3090
3252
  }
3091
- reduce(callback, initialValue) {
3092
- let accumulator = initialValue;
3093
- let index = 0;
3094
- for (const el of this) {
3095
- accumulator = callback(accumulator, el, index, this);
3096
- index++;
3097
- }
3098
- return accumulator;
3099
- }
3100
3253
  print() {
3101
3254
  console.log([...this]);
3102
3255
  }
3103
- };
3104
-
3105
- // src/data-structures/queue/queue.ts
3106
- var LinkedListQueue = class extends SinglyLinkedList {
3107
- /**
3108
- * The enqueue function adds a value to the end of an array.
3109
- * @param {E} value - The value parameter represents the value that you want to add to the queue.
3110
- */
3111
- enqueue(value) {
3112
- this.push(value);
3113
- }
3114
3256
  /**
3115
- * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
3116
- * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
3117
- */
3118
- dequeue() {
3119
- return this.shift();
3120
- }
3121
- /**
3122
- * The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
3123
- * @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
3124
- */
3125
- getFirst() {
3126
- var _a;
3127
- return (_a = this.head) == null ? void 0 : _a.value;
3128
- }
3129
- /**
3130
- * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
3131
- * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
3257
+ * Custom iterator for the Stack class.
3258
+ * @returns An iterator object.
3132
3259
  */
3133
- peek() {
3134
- return this.getFirst();
3260
+ *_getIterator() {
3261
+ for (let i = 0; i < this.elements.length; i++) {
3262
+ yield this.elements[i];
3263
+ }
3135
3264
  }
3136
3265
  };
3137
- var Queue = class _Queue {
3266
+
3267
+ // src/data-structures/queue/queue.ts
3268
+ var Queue = class _Queue extends IterableElementBase {
3138
3269
  /**
3139
3270
  * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
3140
3271
  * @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
@@ -3142,6 +3273,7 @@ var dataStructureTyped = (() => {
3142
3273
  * initialized as an empty array.
3143
3274
  */
3144
3275
  constructor(elements) {
3276
+ super();
3145
3277
  __publicField(this, "_nodes");
3146
3278
  __publicField(this, "_offset");
3147
3279
  this._nodes = elements || [];
@@ -3363,31 +3495,6 @@ var dataStructureTyped = (() => {
3363
3495
  print() {
3364
3496
  console.log([...this]);
3365
3497
  }
3366
- *[Symbol.iterator]() {
3367
- for (const item of this.nodes) {
3368
- yield item;
3369
- }
3370
- }
3371
- /**
3372
- * Time Complexity: O(n)
3373
- * Space Complexity: O(1)
3374
- */
3375
- /**
3376
- * Time Complexity: O(n)
3377
- * Space Complexity: O(1)
3378
- *
3379
- * The `forEach` function iterates over each element in a deque and applies a callback function to
3380
- * each element.
3381
- * @param callback - The callback parameter is a function that will be called for each element in the
3382
- * deque. It takes three parameters:
3383
- */
3384
- forEach(callback) {
3385
- let index = 0;
3386
- for (const el of this) {
3387
- callback(el, index, this);
3388
- index++;
3389
- }
3390
- }
3391
3498
  /**
3392
3499
  * Time Complexity: O(n)
3393
3500
  * Space Complexity: O(n)
@@ -3396,18 +3503,23 @@ var dataStructureTyped = (() => {
3396
3503
  * Time Complexity: O(n)
3397
3504
  * Space Complexity: O(n)
3398
3505
  *
3399
- * The `filter` function creates a new deque containing only the elements that satisfy the given
3400
- * predicate function.
3401
- * @param predicate - The `predicate` parameter is a function that takes three arguments: `element`,
3402
- * `index`, and `deque`.
3403
- * @returns The `filter` method is returning a new `Queue` object that contains only the elements
3404
- * that satisfy the given `predicate` function.
3506
+ * The `filter` function creates a new `Queue` object containing elements from the original `Queue`
3507
+ * that satisfy a given predicate function.
3508
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
3509
+ * the current element being iterated over, the index of the current element, and the queue itself.
3510
+ * It should return a boolean value indicating whether the element should be included in the filtered
3511
+ * queue or not.
3512
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
3513
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
3514
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
3515
+ * @returns The `filter` method is returning a new `Queue` object that contains the elements that
3516
+ * satisfy the given predicate function.
3405
3517
  */
3406
- filter(predicate) {
3518
+ filter(predicate, thisArg) {
3407
3519
  const newDeque = new _Queue([]);
3408
3520
  let index = 0;
3409
3521
  for (const el of this) {
3410
- if (predicate(el, index, this)) {
3522
+ if (predicate.call(thisArg, el, index, this)) {
3411
3523
  newDeque.push(el);
3412
3524
  }
3413
3525
  index++;
@@ -3422,33 +3534,69 @@ var dataStructureTyped = (() => {
3422
3534
  * Time Complexity: O(n)
3423
3535
  * Space Complexity: O(n)
3424
3536
  *
3425
- * The `map` function takes a callback function and applies it to each element in the deque,
3426
- * returning a new deque with the results.
3427
- * @param callback - The `callback` parameter is a function that takes three arguments:
3428
- * @returns The `map` method is returning a new `Queue` object with the transformed elements.
3537
+ * The `map` function takes a callback function and applies it to each element in the queue,
3538
+ * returning a new queue with the results.
3539
+ * @param callback - The callback parameter is a function that will be called for each element in the
3540
+ * queue. It takes three arguments: the current element, the index of the current element, and the
3541
+ * queue itself. The callback function should return a new value that will be added to the new queue.
3542
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
3543
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
3544
+ * passed as the `this` value to the `callback` function. If `thisArg` is
3545
+ * @returns The `map` function is returning a new `Queue` object with the transformed elements.
3429
3546
  */
3430
- map(callback) {
3547
+ map(callback, thisArg) {
3431
3548
  const newDeque = new _Queue([]);
3432
3549
  let index = 0;
3433
3550
  for (const el of this) {
3434
- newDeque.push(callback(el, index, this));
3551
+ newDeque.push(callback.call(thisArg, el, index, this));
3435
3552
  index++;
3436
3553
  }
3437
3554
  return newDeque;
3438
3555
  }
3439
- reduce(callback, initialValue) {
3440
- let accumulator = initialValue;
3441
- let index = 0;
3442
- for (const el of this) {
3443
- accumulator = callback(accumulator, el, index, this);
3444
- index++;
3556
+ /**
3557
+ * Time Complexity: O(n)
3558
+ * Space Complexity: O(n)
3559
+ */
3560
+ *_getIterator() {
3561
+ for (const item of this.nodes) {
3562
+ yield item;
3445
3563
  }
3446
- return accumulator;
3564
+ }
3565
+ };
3566
+ var LinkedListQueue = class extends SinglyLinkedList {
3567
+ /**
3568
+ * The enqueue function adds a value to the end of an array.
3569
+ * @param {E} value - The value parameter represents the value that you want to add to the queue.
3570
+ */
3571
+ enqueue(value) {
3572
+ this.push(value);
3573
+ }
3574
+ /**
3575
+ * The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
3576
+ * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
3577
+ */
3578
+ dequeue() {
3579
+ return this.shift();
3580
+ }
3581
+ /**
3582
+ * The `getFirst` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
3583
+ * @returns The `getFirst()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
3584
+ */
3585
+ getFirst() {
3586
+ var _a;
3587
+ return (_a = this.head) == null ? void 0 : _a.value;
3588
+ }
3589
+ /**
3590
+ * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
3591
+ * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
3592
+ */
3593
+ peek() {
3594
+ return this.getFirst();
3447
3595
  }
3448
3596
  };
3449
3597
 
3450
3598
  // src/data-structures/queue/deque.ts
3451
- var Deque = class _Deque {
3599
+ var Deque = class _Deque extends IterableElementBase {
3452
3600
  /**
3453
3601
  * The constructor initializes a data structure with a specified bucket size and populates it with
3454
3602
  * elements from an iterable.
@@ -3459,6 +3607,7 @@ var dataStructureTyped = (() => {
3459
3607
  * stored in each bucket. It determines the size of each bucket in the data structure.
3460
3608
  */
3461
3609
  constructor(elements = [], bucketSize = 1 << 12) {
3610
+ super();
3462
3611
  __publicField(this, "_bucketFirst", 0);
3463
3612
  __publicField(this, "_firstInBucket", 0);
3464
3613
  __publicField(this, "_bucketLast", 0);
@@ -4086,42 +4235,6 @@ var dataStructureTyped = (() => {
4086
4235
  }
4087
4236
  return arr;
4088
4237
  }
4089
- /**
4090
- * Time Complexity: O(n)
4091
- * Space Complexity: O(1)
4092
- */
4093
- /**
4094
- * Time Complexity: O(n)
4095
- * Space Complexity: O(1)
4096
- *
4097
- * The above function is an implementation of the iterator protocol in TypeScript, allowing the
4098
- * object to be iterated over using a for...of loop.
4099
- */
4100
- *[Symbol.iterator]() {
4101
- for (let i = 0; i < this.size; ++i) {
4102
- yield this.getAt(i);
4103
- }
4104
- }
4105
- /**
4106
- * Time Complexity: O(n)
4107
- * Space Complexity: O(1)
4108
- */
4109
- /**
4110
- * Time Complexity: O(n)
4111
- * Space Complexity: O(1)
4112
- *
4113
- * The `forEach` function iterates over each element in a deque and applies a callback function to
4114
- * each element.
4115
- * @param callback - The callback parameter is a function that will be called for each element in the
4116
- * deque. It takes three parameters:
4117
- */
4118
- forEach(callback) {
4119
- let index = 0;
4120
- for (const el of this) {
4121
- callback(el, index, this);
4122
- index++;
4123
- }
4124
- }
4125
4238
  /**
4126
4239
  * Time Complexity: O(n)
4127
4240
  * Space Complexity: O(n)
@@ -4130,18 +4243,23 @@ var dataStructureTyped = (() => {
4130
4243
  * Time Complexity: O(n)
4131
4244
  * Space Complexity: O(n)
4132
4245
  *
4133
- * The `filter` function creates a new deque containing only the elements that satisfy the given
4134
- * predicate function.
4135
- * @param predicate - The `predicate` parameter is a function that takes three arguments: `element`,
4136
- * `index`, and `deque`.
4137
- * @returns The `filter` method is returning a new `Deque` object that contains only the elements
4138
- * that satisfy the given `predicate` function.
4246
+ * The `filter` function creates a new deque containing elements from the original deque that satisfy
4247
+ * a given predicate function.
4248
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
4249
+ * the current element being iterated over, the index of the current element, and the deque itself.
4250
+ * It should return a boolean value indicating whether the element should be included in the filtered
4251
+ * deque or not.
4252
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
4253
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
4254
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
4255
+ * @returns The `filter` method is returning a new `Deque` object that contains the elements that
4256
+ * satisfy the given predicate function.
4139
4257
  */
4140
- filter(predicate) {
4258
+ filter(predicate, thisArg) {
4141
4259
  const newDeque = new _Deque([], this._bucketSize);
4142
4260
  let index = 0;
4143
4261
  for (const el of this) {
4144
- if (predicate(el, index, this)) {
4262
+ if (predicate.call(thisArg, el, index, this)) {
4145
4263
  newDeque.push(el);
4146
4264
  }
4147
4265
  index++;
@@ -4156,48 +4274,42 @@ var dataStructureTyped = (() => {
4156
4274
  * Time Complexity: O(n)
4157
4275
  * Space Complexity: O(n)
4158
4276
  *
4159
- * The `map` function takes a callback function and applies it to each element in the deque,
4160
- * returning a new deque with the results.
4161
- * @param callback - The `callback` parameter is a function that takes three arguments:
4162
- * @returns The `map` method is returning a new `Deque` object with the transformed elements.
4277
+ * The `map` function creates a new Deque by applying a callback function to each element of the
4278
+ * original Deque.
4279
+ * @param callback - The `callback` parameter is a function that will be called for each element in
4280
+ * the deque. It takes three arguments:
4281
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
4282
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
4283
+ * passed as the `this` value to the `callback` function. If `thisArg` is
4284
+ * @returns a new Deque object with the mapped values.
4163
4285
  */
4164
- map(callback) {
4286
+ map(callback, thisArg) {
4165
4287
  const newDeque = new _Deque([], this._bucketSize);
4166
4288
  let index = 0;
4167
4289
  for (const el of this) {
4168
- newDeque.push(callback(el, index, this));
4290
+ newDeque.push(callback.call(thisArg, el, index, this));
4169
4291
  index++;
4170
4292
  }
4171
4293
  return newDeque;
4172
4294
  }
4173
4295
  /**
4174
4296
  * Time Complexity: O(n)
4175
- * Space Complexity: O(1)
4297
+ * Space Complexity: O(n)
4176
4298
  */
4299
+ print() {
4300
+ console.log([...this]);
4301
+ }
4177
4302
  /**
4178
4303
  * Time Complexity: O(n)
4179
4304
  * Space Complexity: O(1)
4180
4305
  *
4181
- * The `reduce` function iterates over the elements of a deque and applies a callback function to
4182
- * each element, accumulating a single value.
4183
- * @param callback - The `callback` parameter is a function that takes four arguments:
4184
- * @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
4185
- * is the value that will be passed as the first argument to the `callback` function when reducing
4186
- * the elements of the deque.
4187
- * @returns the final value of the accumulator after iterating over all elements in the deque and
4188
- * applying the callback function to each element.
4306
+ * The above function is an implementation of the iterator protocol in TypeScript, allowing the
4307
+ * object to be iterated over using a for...of loop.
4189
4308
  */
4190
- reduce(callback, initialValue) {
4191
- let accumulator = initialValue;
4192
- let index = 0;
4193
- for (const el of this) {
4194
- accumulator = callback(accumulator, el, index, this);
4195
- index++;
4309
+ *_getIterator() {
4310
+ for (let i = 0; i < this.size; ++i) {
4311
+ yield this.getAt(i);
4196
4312
  }
4197
- return accumulator;
4198
- }
4199
- print() {
4200
- console.log([...this]);
4201
4313
  }
4202
4314
  /**
4203
4315
  * Time Complexity: O(n)
@@ -4428,8 +4540,9 @@ var dataStructureTyped = (() => {
4428
4540
  };
4429
4541
 
4430
4542
  // src/data-structures/heap/heap.ts
4431
- var Heap = class _Heap {
4543
+ var Heap = class _Heap extends IterableElementBase {
4432
4544
  constructor(elements, options) {
4545
+ super();
4433
4546
  __publicField(this, "options");
4434
4547
  __publicField(this, "_elements", []);
4435
4548
  const defaultComparator = (a, b) => {
@@ -4724,47 +4837,70 @@ var dataStructureTyped = (() => {
4724
4837
  for (let i = Math.floor(this.size / 2); i >= 0; i--)
4725
4838
  this._sinkDown(i, this.elements.length >> 1);
4726
4839
  }
4727
- *[Symbol.iterator]() {
4728
- for (const element of this.elements) {
4729
- yield element;
4730
- }
4731
- }
4732
- forEach(callback) {
4733
- let index = 0;
4734
- for (const el of this) {
4735
- callback(el, index, this);
4736
- index++;
4737
- }
4738
- }
4739
- filter(predicate) {
4740
- const filteredHeap = new _Heap([], this.options);
4840
+ /**
4841
+ * Time Complexity: O(n)
4842
+ * Space Complexity: O(n)
4843
+ */
4844
+ /**
4845
+ * Time Complexity: O(n)
4846
+ * Space Complexity: O(n)
4847
+ *
4848
+ * The `filter` function creates a new Heap object containing elements that pass a given callback
4849
+ * function.
4850
+ * @param callback - The `callback` parameter is a function that will be called for each element in
4851
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
4852
+ * heap itself. The callback function should return a boolean value indicating whether the current
4853
+ * element should be included in the filtered list
4854
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
4855
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
4856
+ * passed as the `this` value to the `callback` function. If `thisArg` is
4857
+ * @returns The `filter` method is returning a new `Heap` object that contains the elements that pass
4858
+ * the filter condition specified by the `callback` function.
4859
+ */
4860
+ filter(callback, thisArg) {
4861
+ const filteredList = new _Heap();
4741
4862
  let index = 0;
4742
- for (const el of this) {
4743
- if (predicate(el, index, this)) {
4744
- filteredHeap.push(el);
4863
+ for (const current of this) {
4864
+ if (callback.call(thisArg, current, index, this)) {
4865
+ filteredList.push(current);
4745
4866
  }
4746
4867
  index++;
4747
4868
  }
4748
- return filteredHeap;
4869
+ return filteredList;
4749
4870
  }
4750
- map(callback, comparator) {
4871
+ /**
4872
+ * Time Complexity: O(n)
4873
+ * Space Complexity: O(n)
4874
+ */
4875
+ /**
4876
+ * Time Complexity: O(n)
4877
+ * Space Complexity: O(n)
4878
+ *
4879
+ * The `map` function creates a new heap by applying a callback function to each element of the
4880
+ * original heap.
4881
+ * @param callback - The callback parameter is a function that will be called for each element in the
4882
+ * original heap. It takes three arguments: the current element, the index of the current element,
4883
+ * and the original heap itself. The callback function should return a value of type T, which will be
4884
+ * added to the mapped heap.
4885
+ * @param comparator - The `comparator` parameter is a function that is used to compare elements in
4886
+ * the heap. It takes two arguments, `a` and `b`, and returns a negative number if `a` is less than
4887
+ * `b`, a positive number if `a` is greater than `b`, or
4888
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
4889
+ * specify the value of `this` within the callback function. It is used when you want to bind a
4890
+ * specific object as the context for the callback function. If `thisArg` is not provided,
4891
+ * `undefined` is used as
4892
+ * @returns a new instance of the Heap class, which is created using the mapped elements from the
4893
+ * original Heap.
4894
+ */
4895
+ map(callback, comparator, thisArg) {
4751
4896
  const mappedHeap = new _Heap([], { comparator });
4752
4897
  let index = 0;
4753
4898
  for (const el of this) {
4754
- mappedHeap.add(callback(el, index, this));
4899
+ mappedHeap.add(callback.call(thisArg, el, index, this));
4755
4900
  index++;
4756
4901
  }
4757
4902
  return mappedHeap;
4758
4903
  }
4759
- reduce(callback, initialValue) {
4760
- let accumulator = initialValue;
4761
- let index = 0;
4762
- for (const el of this) {
4763
- accumulator = callback(accumulator, el, index, this);
4764
- index++;
4765
- }
4766
- return accumulator;
4767
- }
4768
4904
  /**
4769
4905
  * Time Complexity: O(log n)
4770
4906
  * Space Complexity: O(1)
@@ -4772,6 +4908,11 @@ var dataStructureTyped = (() => {
4772
4908
  print() {
4773
4909
  console.log([...this]);
4774
4910
  }
4911
+ *_getIterator() {
4912
+ for (const element of this.elements) {
4913
+ yield element;
4914
+ }
4915
+ }
4775
4916
  /**
4776
4917
  * Time Complexity: O(n)
4777
4918
  * Space Complexity: O(1)
@@ -5278,8 +5419,9 @@ var dataStructureTyped = (() => {
5278
5419
  * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
5279
5420
  */
5280
5421
  };
5281
- var AbstractGraph = class {
5422
+ var AbstractGraph = class extends IterablePairBase {
5282
5423
  constructor() {
5424
+ super();
5283
5425
  __publicField(this, "_vertices", /* @__PURE__ */ new Map());
5284
5426
  }
5285
5427
  get vertices() {
@@ -6236,46 +6378,67 @@ var dataStructureTyped = (() => {
6236
6378
  getBridges() {
6237
6379
  return this.tarjan(false, true, false, false).bridges;
6238
6380
  }
6239
- *[Symbol.iterator]() {
6240
- for (const vertex of this._vertices.values()) {
6241
- yield [vertex.key, vertex.value];
6242
- }
6243
- }
6244
- forEach(callback) {
6245
- let index = 0;
6246
- for (const vertex of this) {
6247
- callback(vertex, index, this._vertices);
6248
- index++;
6249
- }
6250
- }
6251
- filter(predicate) {
6381
+ /**
6382
+ * Time Complexity: O(n)
6383
+ * Space Complexity: O(n)
6384
+ */
6385
+ /**
6386
+ * Time Complexity: O(n)
6387
+ * Space Complexity: O(n)
6388
+ *
6389
+ * The `filter` function iterates over key-value pairs in a data structure and returns an array of
6390
+ * pairs that satisfy a given predicate.
6391
+ * @param predicate - The `predicate` parameter is a callback function that takes four arguments:
6392
+ * `value`, `key`, `index`, and `this`. It is used to determine whether an element should be included
6393
+ * in the filtered array. The callback function should return `true` if the element should be
6394
+ * included, and `
6395
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
6396
+ * specify the value of `this` within the `predicate` function. It is used when you want to bind a
6397
+ * specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
6398
+ * @returns The `filter` method returns an array of key-value pairs `[VertexKey, V | undefined][]`
6399
+ * that satisfy the given predicate function.
6400
+ */
6401
+ filter(predicate, thisArg) {
6252
6402
  const filtered = [];
6253
6403
  let index = 0;
6254
- for (const entry of this) {
6255
- if (predicate(entry, index, this._vertices)) {
6256
- filtered.push(entry);
6404
+ for (const [key, value] of this) {
6405
+ if (predicate.call(thisArg, value, key, index, this)) {
6406
+ filtered.push([key, value]);
6257
6407
  }
6258
6408
  index++;
6259
6409
  }
6260
6410
  return filtered;
6261
6411
  }
6262
- map(callback) {
6412
+ /**
6413
+ * Time Complexity: O(n)
6414
+ * Space Complexity: O(n)
6415
+ */
6416
+ /**
6417
+ * Time Complexity: O(n)
6418
+ * Space Complexity: O(n)
6419
+ *
6420
+ * The `map` function iterates over the elements of a collection and applies a callback function to
6421
+ * each element, returning an array of the results.
6422
+ * @param callback - The callback parameter is a function that will be called for each element in the
6423
+ * map. It takes four arguments:
6424
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
6425
+ * specify the value of `this` within the callback function. If `thisArg` is provided, it will be
6426
+ * used as the `this` value when calling the callback function. If `thisArg` is not provided, `
6427
+ * @returns The `map` function is returning an array of type `T[]`.
6428
+ */
6429
+ map(callback, thisArg) {
6263
6430
  const mapped = [];
6264
6431
  let index = 0;
6265
- for (const entry of this) {
6266
- mapped.push(callback(entry, index, this._vertices));
6432
+ for (const [key, value] of this) {
6433
+ mapped.push(callback.call(thisArg, value, key, index, this));
6267
6434
  index++;
6268
6435
  }
6269
6436
  return mapped;
6270
6437
  }
6271
- reduce(callback, initialValue) {
6272
- let accumulator = initialValue;
6273
- let index = 0;
6274
- for (const entry of this) {
6275
- accumulator = callback(accumulator, entry, index, this._vertices);
6276
- index++;
6438
+ *_getIterator() {
6439
+ for (const vertex of this._vertices.values()) {
6440
+ yield [vertex.key, vertex.value];
6277
6441
  }
6278
- return accumulator;
6279
6442
  }
6280
6443
  _addVertexOnly(newVertex) {
6281
6444
  if (this.hasVertex(newVertex)) {
@@ -7259,7 +7422,7 @@ var dataStructureTyped = (() => {
7259
7422
  return "MAL_NODE" /* MAL_NODE */;
7260
7423
  }
7261
7424
  };
7262
- var BinaryTree = class _BinaryTree {
7425
+ var BinaryTree = class _BinaryTree extends IterablePairBase {
7263
7426
  /**
7264
7427
  * The constructor function initializes a binary tree object with optional elements and options.
7265
7428
  * @param [elements] - An optional iterable of BTNodeExemplar objects. These objects represent the
@@ -7270,6 +7433,7 @@ var dataStructureTyped = (() => {
7270
7433
  * required.
7271
7434
  */
7272
7435
  constructor(elements, options) {
7436
+ super();
7273
7437
  __publicField(this, "iterationType", "ITERATIVE" /* ITERATIVE */);
7274
7438
  __publicField(this, "_root");
7275
7439
  __publicField(this, "_size");
@@ -8546,43 +8710,6 @@ var dataStructureTyped = (() => {
8546
8710
  }
8547
8711
  return ans;
8548
8712
  }
8549
- /**
8550
- * Time complexity: O(n)
8551
- * Space complexity: O(n)
8552
- */
8553
- /**
8554
- * Time complexity: O(n)
8555
- * Space complexity: O(n)
8556
- *
8557
- * The function "keys" returns an array of keys from a given object.
8558
- * @returns an array of BTNKey objects.
8559
- */
8560
- keys() {
8561
- const keys = [];
8562
- for (const entry of this) {
8563
- keys.push(entry[0]);
8564
- }
8565
- return keys;
8566
- }
8567
- /**
8568
- * Time complexity: O(n)
8569
- * Space complexity: O(n)
8570
- */
8571
- /**
8572
- * Time complexity: O(n)
8573
- * Space complexity: O(n)
8574
- *
8575
- * The function "values" returns an array of values from a map-like object.
8576
- * @returns The `values()` method is returning an array of values (`V`) from the entries in the
8577
- * object.
8578
- */
8579
- values() {
8580
- const values = [];
8581
- for (const entry of this) {
8582
- values.push(entry[1]);
8583
- }
8584
- return values;
8585
- }
8586
8713
  /**
8587
8714
  * Time complexity: O(n)
8588
8715
  * Space complexity: O(n)
@@ -8601,113 +8728,70 @@ var dataStructureTyped = (() => {
8601
8728
  return cloned;
8602
8729
  }
8603
8730
  /**
8604
- * Time complexity: O(n)
8605
- * Space complexity: O(1)
8606
- */
8607
- /**
8608
- * The `forEach` function iterates over each entry in a tree and calls a callback function with the
8609
- * entry and the tree as arguments.
8610
- * @param callback - The callback parameter is a function that will be called for each entry in the
8611
- * tree. It takes two parameters: entry and tree.
8731
+ * Time Complexity: O(n)
8732
+ * Space Complexity: O(n)
8612
8733
  */
8613
- forEach(callback) {
8614
- for (const entry of this) {
8615
- callback(entry, this);
8616
- }
8617
- }
8618
8734
  /**
8619
- * The `filter` function creates a new tree by iterating over the entries of the current tree and
8620
- * adding the entries that satisfy the given predicate.
8621
- * @param predicate - The `predicate` parameter is a function that takes two arguments: `entry` and
8622
- * `tree`.
8623
- * @returns The `filter` method is returning a new tree object that contains only the entries that
8624
- * satisfy the given predicate function.
8735
+ * Time Complexity: O(n)
8736
+ * Space Complexity: O(n)
8737
+ *
8738
+ * The `filter` function creates a new tree by iterating over the elements of the current tree and
8739
+ * adding only the elements that satisfy the given predicate function.
8740
+ * @param predicate - The `predicate` parameter is a function that takes three arguments: `value`,
8741
+ * `key`, and `index`. It should return a boolean value indicating whether the pair should be
8742
+ * included in the filtered tree or not.
8743
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
8744
+ * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
8745
+ * it will be passed as the first argument to the `predicate` function. If `thisArg` is
8746
+ * @returns The `filter` method is returning a new tree object that contains the key-value pairs that
8747
+ * pass the given predicate function.
8625
8748
  */
8626
- filter(predicate) {
8749
+ filter(predicate, thisArg) {
8627
8750
  const newTree = this.createTree();
8751
+ let index = 0;
8628
8752
  for (const [key, value] of this) {
8629
- if (predicate([key, value], this)) {
8753
+ if (predicate.call(thisArg, value, key, index++, this)) {
8630
8754
  newTree.add([key, value]);
8631
8755
  }
8632
8756
  }
8633
8757
  return newTree;
8634
8758
  }
8635
8759
  /**
8636
- * The `map` function creates a new tree by applying a callback function to each entry in the current
8637
- * tree.
8638
- * @param callback - The callback parameter is a function that takes two arguments: entry and tree.
8760
+ * Time Complexity: O(n)
8761
+ * Space Complexity: O(n)
8762
+ */
8763
+ /**
8764
+ * Time Complexity: O(n)
8765
+ * Space Complexity: O(n)
8766
+ *
8767
+ * The `map` function creates a new tree by applying a callback function to each key-value pair in
8768
+ * the original tree.
8769
+ * @param callback - The callback parameter is a function that will be called for each key-value pair
8770
+ * in the tree. It takes four arguments: the value of the current pair, the key of the current pair,
8771
+ * the index of the current pair, and a reference to the tree itself. The callback function should
8772
+ * return a new
8773
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
8774
+ * specify the value of `this` within the callback function. If you pass a value for `thisArg`, it
8775
+ * will be used as the `this` value when the callback function is called. If you don't pass a value
8639
8776
  * @returns The `map` method is returning a new tree object.
8640
8777
  */
8641
- map(callback) {
8778
+ map(callback, thisArg) {
8642
8779
  const newTree = this.createTree();
8780
+ let index = 0;
8643
8781
  for (const [key, value] of this) {
8644
- newTree.add([key, callback([key, value], this)]);
8782
+ newTree.add([key, callback.call(thisArg, value, key, index++, this)]);
8645
8783
  }
8646
8784
  return newTree;
8647
8785
  }
8648
- // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
8649
- // map<NV>(callback: (entry: [BTNKey, V | undefined], tree: this) => NV) {
8650
- // const newTree = this.createTree();
8651
- // for (const [key, value] of this) {
8652
- // newTree.add(key, callback([key, value], this));
8653
- // }
8654
- // return newTree;
8655
- // }
8656
- /**
8657
- * The `reduce` function iterates over the entries of a tree and applies a callback function to each
8658
- * entry, accumulating a single value.
8659
- * @param callback - The callback parameter is a function that takes three arguments: accumulator,
8660
- * entry, and tree. It is called for each entry in the tree and is used to accumulate a single value
8661
- * based on the logic defined in the callback function.
8662
- * @param {T} initialValue - The initialValue parameter is the initial value of the accumulator. It
8663
- * is the value that will be passed as the first argument to the callback function when reducing the
8664
- * elements of the tree.
8665
- * @returns The `reduce` method is returning the final value of the accumulator after iterating over
8666
- * all the entries in the tree and applying the callback function to each entry.
8667
- */
8668
- reduce(callback, initialValue) {
8669
- let accumulator = initialValue;
8670
- for (const [key, value] of this) {
8671
- accumulator = callback(accumulator, [key, value], this);
8672
- }
8673
- return accumulator;
8674
- }
8675
- /**
8676
- * The above function is an iterator for a binary tree that can be used to traverse the tree in
8677
- * either an iterative or recursive manner.
8678
- * @param node - The `node` parameter represents the current node in the binary tree from which the
8679
- * iteration starts. It is an optional parameter with a default value of `this.root`, which means
8680
- * that if no node is provided, the iteration will start from the root of the binary tree.
8681
- * @returns The `*[Symbol.iterator]` method returns a generator object that yields the keys of the
8682
- * binary tree nodes in a specific order.
8683
- */
8684
- *[Symbol.iterator](node = this.root) {
8685
- if (!node)
8686
- return;
8687
- if (this.iterationType === "ITERATIVE" /* ITERATIVE */) {
8688
- const stack = [];
8689
- let current = node;
8690
- while (current || stack.length > 0) {
8691
- while (current && !isNaN(current.key)) {
8692
- stack.push(current);
8693
- current = current.left;
8694
- }
8695
- current = stack.pop();
8696
- if (current && !isNaN(current.key)) {
8697
- yield [current.key, current.value];
8698
- current = current.right;
8699
- }
8700
- }
8701
- } else {
8702
- if (node.left && !isNaN(node.key)) {
8703
- yield* __yieldStar(this[Symbol.iterator](node.left));
8704
- }
8705
- yield [node.key, node.value];
8706
- if (node.right && !isNaN(node.key)) {
8707
- yield* __yieldStar(this[Symbol.iterator](node.right));
8708
- }
8709
- }
8710
- }
8786
+ // // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
8787
+ // // map<NV>(callback: (entry: [BTNKey, V | undefined], tree: this) => NV) {
8788
+ // // const newTree = this.createTree();
8789
+ // // for (const [key, value] of this) {
8790
+ // // newTree.add(key, callback([key, value], this));
8791
+ // // }
8792
+ // // return newTree;
8793
+ // // }
8794
+ //
8711
8795
  /**
8712
8796
  * The `print` function is used to display a binary tree structure in a visually appealing way.
8713
8797
  * @param {BTNKey | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `BTNKey | N | null |
@@ -8737,6 +8821,33 @@ var dataStructureTyped = (() => {
8737
8821
  };
8738
8822
  display(beginRoot);
8739
8823
  }
8824
+ *_getIterator(node = this.root) {
8825
+ if (!node)
8826
+ return;
8827
+ if (this.iterationType === "ITERATIVE" /* ITERATIVE */) {
8828
+ const stack = [];
8829
+ let current = node;
8830
+ while (current || stack.length > 0) {
8831
+ while (current && !isNaN(current.key)) {
8832
+ stack.push(current);
8833
+ current = current.left;
8834
+ }
8835
+ current = stack.pop();
8836
+ if (current && !isNaN(current.key)) {
8837
+ yield [current.key, current.value];
8838
+ current = current.right;
8839
+ }
8840
+ }
8841
+ } else {
8842
+ if (node.left && !isNaN(node.key)) {
8843
+ yield* __yieldStar(this[Symbol.iterator](node.left));
8844
+ }
8845
+ yield [node.key, node.value];
8846
+ if (node.right && !isNaN(node.key)) {
8847
+ yield* __yieldStar(this[Symbol.iterator](node.right));
8848
+ }
8849
+ }
8850
+ }
8740
8851
  _displayAux(node, options) {
8741
8852
  const { isShowNull, isShowUndefined, isShowRedBlackNIL } = options;
8742
8853
  const emptyDisplayLayout = [["\u2500"], 1, 0, 0];
@@ -11890,8 +12001,9 @@ var dataStructureTyped = (() => {
11890
12001
  this.children = /* @__PURE__ */ new Map();
11891
12002
  }
11892
12003
  };
11893
- var Trie = class _Trie {
12004
+ var Trie = class _Trie extends IterableElementBase {
11894
12005
  constructor(words, caseSensitive = true) {
12006
+ super();
11895
12007
  __publicField(this, "_size");
11896
12008
  __publicField(this, "_caseSensitive");
11897
12009
  __publicField(this, "_root");
@@ -12186,56 +12298,75 @@ var dataStructureTyped = (() => {
12186
12298
  dfs(startNode, prefix);
12187
12299
  return words;
12188
12300
  }
12189
- *[Symbol.iterator]() {
12190
- function* _dfs(node, path) {
12191
- if (node.isEnd) {
12192
- yield path;
12193
- }
12194
- for (const [char, childNode] of node.children) {
12195
- yield* __yieldStar(_dfs(childNode, path + char));
12196
- }
12197
- }
12198
- yield* __yieldStar(_dfs(this.root, ""));
12199
- }
12200
- forEach(callback) {
12201
- let index = 0;
12202
- for (const word of this) {
12203
- callback(word, index, this);
12204
- index++;
12205
- }
12206
- }
12207
- filter(predicate) {
12301
+ /**
12302
+ * Time Complexity: O(n)
12303
+ * Space Complexity: O(n)
12304
+ */
12305
+ /**
12306
+ * Time Complexity: O(n)
12307
+ * Space Complexity: O(n)
12308
+ *
12309
+ * The `filter` function takes a predicate function and returns a new array containing all the
12310
+ * elements for which the predicate function returns true.
12311
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
12312
+ * `word`, `index`, and `this`. It should return a boolean value indicating whether the current
12313
+ * element should be included in the filtered results or not.
12314
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
12315
+ * specify the value of `this` within the `predicate` function. It is used when you want to bind a
12316
+ * specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
12317
+ * @returns The `filter` method is returning an array of strings (`string[]`).
12318
+ */
12319
+ filter(predicate, thisArg) {
12208
12320
  const results = [];
12209
12321
  let index = 0;
12210
12322
  for (const word of this) {
12211
- if (predicate(word, index, this)) {
12323
+ if (predicate.call(thisArg, word, index, this)) {
12212
12324
  results.push(word);
12213
12325
  }
12214
12326
  index++;
12215
12327
  }
12216
12328
  return results;
12217
12329
  }
12218
- map(callback) {
12330
+ /**
12331
+ * Time Complexity: O(n)
12332
+ * Space Complexity: O(n)
12333
+ */
12334
+ /**
12335
+ * Time Complexity: O(n)
12336
+ * Space Complexity: O(n)
12337
+ *
12338
+ * The `map` function creates a new Trie by applying a callback function to each element in the Trie.
12339
+ * @param callback - The callback parameter is a function that will be called for each element in the
12340
+ * Trie. It takes three arguments: the current element in the Trie, the index of the current element,
12341
+ * and the Trie itself. The callback function should return a new value for the element.
12342
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
12343
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
12344
+ * passed as the `this` value to the `callback` function. If `thisArg` is
12345
+ * @returns The `map` function is returning a new Trie object.
12346
+ */
12347
+ map(callback, thisArg) {
12219
12348
  const newTrie = new _Trie();
12220
12349
  let index = 0;
12221
12350
  for (const word of this) {
12222
- newTrie.add(callback(word, index, this));
12351
+ newTrie.add(callback.call(thisArg, word, index, this));
12223
12352
  index++;
12224
12353
  }
12225
12354
  return newTrie;
12226
12355
  }
12227
- reduce(callback, initialValue) {
12228
- let accumulator = initialValue;
12229
- let index = 0;
12230
- for (const word of this) {
12231
- accumulator = callback(accumulator, word, index, this);
12232
- index++;
12233
- }
12234
- return accumulator;
12235
- }
12236
12356
  print() {
12237
12357
  console.log([...this]);
12238
12358
  }
12359
+ *_getIterator() {
12360
+ function* _dfs(node, path) {
12361
+ if (node.isEnd) {
12362
+ yield path;
12363
+ }
12364
+ for (const [char, childNode] of node.children) {
12365
+ yield* __yieldStar(_dfs(childNode, path + char));
12366
+ }
12367
+ }
12368
+ yield* __yieldStar(_dfs(this.root, ""));
12369
+ }
12239
12370
  /**
12240
12371
  * Time Complexity: O(M), where M is the length of the input string.
12241
12372
  * Space Complexity: O(1) - Constant space.