deque-typed 2.4.5 → 2.5.1

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 (94) hide show
  1. package/README.md +6 -73
  2. package/dist/cjs/index.cjs +705 -122
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +704 -121
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +705 -122
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +704 -121
  9. package/dist/esm-legacy/index.mjs.map +1 -1
  10. package/dist/types/data-structures/base/index.d.ts +1 -0
  11. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  12. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  13. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  14. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +380 -51
  15. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +487 -147
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +956 -80
  17. package/dist/types/data-structures/binary-tree/bst.d.ts +816 -29
  18. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +610 -31
  19. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +326 -135
  20. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3781 -6
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3607 -201
  22. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2874 -65
  23. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3528 -6
  24. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  25. package/dist/types/data-structures/graph/directed-graph.d.ts +429 -47
  26. package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
  27. package/dist/types/data-structures/graph/undirected-graph.d.ts +393 -59
  28. package/dist/types/data-structures/hash/hash-map.d.ts +473 -89
  29. package/dist/types/data-structures/heap/heap.d.ts +581 -99
  30. package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
  31. package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
  32. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +646 -47
  33. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +596 -68
  34. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +793 -12
  35. package/dist/types/data-structures/matrix/matrix.d.ts +499 -0
  36. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
  37. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
  38. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
  39. package/dist/types/data-structures/queue/deque.d.ts +593 -71
  40. package/dist/types/data-structures/queue/queue.d.ts +463 -42
  41. package/dist/types/data-structures/stack/stack.d.ts +384 -32
  42. package/dist/types/data-structures/trie/trie.d.ts +470 -48
  43. package/dist/types/interfaces/graph.d.ts +1 -1
  44. package/dist/types/types/common.d.ts +2 -2
  45. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
  46. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  47. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
  48. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  49. package/dist/types/types/utils/validate-type.d.ts +4 -4
  50. package/dist/umd/deque-typed.js +702 -119
  51. package/dist/umd/deque-typed.js.map +1 -1
  52. package/dist/umd/deque-typed.min.js +1 -1
  53. package/dist/umd/deque-typed.min.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/data-structures/base/index.ts +1 -0
  56. package/src/data-structures/base/iterable-element-base.ts +4 -5
  57. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  58. package/src/data-structures/base/linear-base.ts +3 -3
  59. package/src/data-structures/binary-tree/avl-tree.ts +386 -51
  60. package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
  61. package/src/data-structures/binary-tree/binary-tree.ts +956 -81
  62. package/src/data-structures/binary-tree/bst.ts +840 -35
  63. package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
  64. package/src/data-structures/binary-tree/segment-tree.ts +498 -249
  65. package/src/data-structures/binary-tree/tree-map.ts +3784 -7
  66. package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
  67. package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
  68. package/src/data-structures/binary-tree/tree-set.ts +3531 -10
  69. package/src/data-structures/graph/abstract-graph.ts +4 -4
  70. package/src/data-structures/graph/directed-graph.ts +429 -47
  71. package/src/data-structures/graph/map-graph.ts +59 -1
  72. package/src/data-structures/graph/undirected-graph.ts +393 -59
  73. package/src/data-structures/hash/hash-map.ts +476 -92
  74. package/src/data-structures/heap/heap.ts +581 -99
  75. package/src/data-structures/heap/max-heap.ts +46 -0
  76. package/src/data-structures/heap/min-heap.ts +59 -0
  77. package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
  78. package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
  79. package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
  80. package/src/data-structures/matrix/matrix.ts +584 -12
  81. package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
  82. package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
  83. package/src/data-structures/priority-queue/priority-queue.ts +60 -0
  84. package/src/data-structures/queue/deque.ts +592 -70
  85. package/src/data-structures/queue/queue.ts +463 -42
  86. package/src/data-structures/stack/stack.ts +384 -32
  87. package/src/data-structures/trie/trie.ts +470 -48
  88. package/src/interfaces/graph.ts +1 -1
  89. package/src/types/common.ts +2 -2
  90. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
  91. package/src/types/data-structures/heap/heap.ts +1 -0
  92. package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
  93. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  94. package/src/types/utils/validate-type.ts +4 -4
@@ -37,52 +37,6 @@ var dequeTyped = (() => {
37
37
  };
38
38
  var calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
39
39
 
40
- // src/common/error.ts
41
- var ERR = {
42
- // Range / index
43
- indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
44
- invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
45
- // Type / argument
46
- invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
47
- comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
48
- invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
49
- notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
50
- invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
51
- invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
52
- invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
53
- reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
54
- callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
55
- // State / operation
56
- invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
57
- // Matrix
58
- matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
59
- matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
60
- matrixNotSquare: () => "Matrix: Must be square for inversion.",
61
- matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
62
- matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
63
- };
64
-
65
- // src/common/index.ts
66
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
67
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
68
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
69
- return DFSOperation2;
70
- })(DFSOperation || {});
71
- var Range = class {
72
- constructor(low, high, includeLow = true, includeHigh = true) {
73
- this.low = low;
74
- this.high = high;
75
- this.includeLow = includeLow;
76
- this.includeHigh = includeHigh;
77
- }
78
- // Determine whether a key is within the range
79
- isInRange(key, comparator) {
80
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
81
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
82
- return lowCheck && highCheck;
83
- }
84
- };
85
-
86
40
  // src/data-structures/base/iterable-element-base.ts
87
41
  var IterableElementBase = class {
88
42
  /**
@@ -105,7 +59,7 @@ var dequeTyped = (() => {
105
59
  if (options) {
106
60
  const { toElementFn } = options;
107
61
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
108
- else if (toElementFn) throw new TypeError(ERR.notAFunction("toElementFn"));
62
+ else if (toElementFn) throw new TypeError("toElementFn must be a function type");
109
63
  }
110
64
  }
111
65
  /**
@@ -261,7 +215,7 @@ var dequeTyped = (() => {
261
215
  acc = initialValue;
262
216
  } else {
263
217
  const first = iter.next();
264
- if (first.done) throw new TypeError(ERR.reduceEmpty());
218
+ if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
265
219
  acc = first.value;
266
220
  index = 1;
267
221
  }
@@ -615,19 +569,102 @@ var dequeTyped = (() => {
615
569
  return this._length;
616
570
  }
617
571
  /**
618
- * Get the first element without removing it.
619
- * @remarks Time O(1), Space O(1)
620
- * @returns First element or undefined.
621
- */
572
+ * Get the first element without removing it.
573
+ * @remarks Time O(1), Space O(1)
574
+ * @returns First element or undefined.
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
584
+
585
+
586
+
587
+
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+
602
+
603
+
604
+
605
+
606
+
607
+ * @example
608
+ * // Deque peek at both ends
609
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
610
+ *
611
+ * // Get first element without removing
612
+ * const first = deque.at(0);
613
+ * console.log(first); // 10;
614
+ *
615
+ * // Get last element without removing
616
+ * const last = deque.at(deque.length - 1);
617
+ * console.log(last); // 50;
618
+ *
619
+ * // Length unchanged
620
+ * console.log(deque.length); // 5;
621
+ */
622
622
  get first() {
623
623
  if (this._length === 0) return;
624
624
  return this._buckets[this._bucketFirst][this._firstInBucket];
625
625
  }
626
626
  /**
627
- * Get the last element without removing it.
628
- * @remarks Time O(1), Space O(1)
629
- * @returns Last element or undefined.
630
- */
627
+ * Get the last element without removing it.
628
+ * @remarks Time O(1), Space O(1)
629
+ * @returns Last element or undefined.
630
+
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+ * @example
663
+ * // Peek at the back element
664
+ * const dq = new Deque<string>(['a', 'b', 'c']);
665
+ * console.log(dq.last); // 'c';
666
+ * console.log(dq.first); // 'a';
667
+ */
631
668
  get last() {
632
669
  if (this._length === 0) return;
633
670
  return this._buckets[this._bucketLast][this._lastInBucket];
@@ -646,11 +683,61 @@ var dequeTyped = (() => {
646
683
  return new this(data, options);
647
684
  }
648
685
  /**
649
- * Append one element at the back.
650
- * @remarks Time O(1) amortized, Space O(1)
651
- * @param element - Element to append.
652
- * @returns True when appended.
653
- */
686
+ * Append one element at the back.
687
+ * @remarks Time O(1) amortized, Space O(1)
688
+ * @param element - Element to append.
689
+ * @returns True when appended.
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+ * @example
723
+ * // basic Deque creation and push/pop operations
724
+ * // Create a simple Deque with initial values
725
+ * const deque = new Deque([1, 2, 3, 4, 5]);
726
+ *
727
+ * // Verify the deque maintains insertion order
728
+ * console.log([...deque]); // [1, 2, 3, 4, 5];
729
+ *
730
+ * // Check length
731
+ * console.log(deque.length); // 5;
732
+ *
733
+ * // Push to the end
734
+ * deque.push(6);
735
+ * console.log(deque.length); // 6;
736
+ *
737
+ * // Pop from the end
738
+ * const last = deque.pop();
739
+ * console.log(last); // 6;
740
+ */
654
741
  push(element) {
655
742
  if (this._length) {
656
743
  if (this._lastInBucket < this._bucketSize - 1) {
@@ -670,10 +757,47 @@ var dequeTyped = (() => {
670
757
  return true;
671
758
  }
672
759
  /**
673
- * Remove and return the last element.
674
- * @remarks Time O(1), Space O(1)
675
- * @returns Removed element or undefined.
676
- */
760
+ * Remove and return the last element.
761
+ * @remarks Time O(1), Space O(1)
762
+ * @returns Removed element or undefined.
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+ * @example
796
+ * // Remove from the back
797
+ * const dq = new Deque<number>([1, 2, 3]);
798
+ * console.log(dq.pop()); // 3;
799
+ * console.log(dq.length); // 2;
800
+ */
677
801
  pop() {
678
802
  if (this._length === 0) return;
679
803
  const element = this._buckets[this._bucketLast][this._lastInBucket];
@@ -693,10 +817,47 @@ var dequeTyped = (() => {
693
817
  return element;
694
818
  }
695
819
  /**
696
- * Remove and return the first element.
697
- * @remarks Time O(1) amortized, Space O(1)
698
- * @returns Removed element or undefined.
699
- */
820
+ * Remove and return the first element.
821
+ * @remarks Time O(1) amortized, Space O(1)
822
+ * @returns Removed element or undefined.
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+
834
+
835
+
836
+
837
+
838
+
839
+
840
+
841
+
842
+
843
+
844
+
845
+
846
+
847
+
848
+
849
+
850
+
851
+
852
+
853
+
854
+
855
+ * @example
856
+ * // Remove from the front
857
+ * const dq = new Deque<number>([1, 2, 3]);
858
+ * console.log(dq.shift()); // 1;
859
+ * console.log(dq.length); // 2;
860
+ */
700
861
  shift() {
701
862
  if (this._length === 0) return;
702
863
  const element = this._buckets[this._bucketFirst][this._firstInBucket];
@@ -716,11 +877,58 @@ var dequeTyped = (() => {
716
877
  return element;
717
878
  }
718
879
  /**
719
- * Prepend one element at the front.
720
- * @remarks Time O(1) amortized, Space O(1)
721
- * @param element - Element to prepend.
722
- * @returns True when prepended.
723
- */
880
+ * Prepend one element at the front.
881
+ * @remarks Time O(1) amortized, Space O(1)
882
+ * @param element - Element to prepend.
883
+ * @returns True when prepended.
884
+
885
+
886
+
887
+
888
+
889
+
890
+
891
+
892
+
893
+
894
+
895
+
896
+
897
+
898
+
899
+
900
+
901
+
902
+
903
+
904
+
905
+
906
+
907
+
908
+
909
+
910
+
911
+
912
+
913
+
914
+
915
+
916
+ * @example
917
+ * // Deque shift and unshift operations
918
+ * const deque = new Deque<number>([20, 30, 40]);
919
+ *
920
+ * // Unshift adds to the front
921
+ * deque.unshift(10);
922
+ * console.log([...deque]); // [10, 20, 30, 40];
923
+ *
924
+ * // Shift removes from the front (O(1) complexity!)
925
+ * const first = deque.shift();
926
+ * console.log(first); // 10;
927
+ *
928
+ * // Verify remaining elements
929
+ * console.log([...deque]); // [20, 30, 40];
930
+ * console.log(deque.length); // 3;
931
+ */
724
932
  unshift(element) {
725
933
  if (this._length) {
726
934
  if (this._firstInBucket > 0) {
@@ -774,18 +982,87 @@ var dequeTyped = (() => {
774
982
  return ans;
775
983
  }
776
984
  /**
777
- * Check whether the deque is empty.
778
- * @remarks Time O(1), Space O(1)
779
- * @returns True if length is 0.
780
- */
985
+ * Check whether the deque is empty.
986
+ * @remarks Time O(1), Space O(1)
987
+ * @returns True if length is 0.
988
+
989
+
990
+
991
+
992
+
993
+
994
+
995
+
996
+
997
+
998
+
999
+
1000
+
1001
+
1002
+
1003
+
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+ * @example
1019
+ * // Check if empty
1020
+ * const dq = new Deque();
1021
+ * console.log(dq.isEmpty()); // true;
1022
+ */
781
1023
  isEmpty() {
782
1024
  return this._length === 0;
783
1025
  }
784
1026
  /**
785
- * Remove all elements and reset structure.
786
- * @remarks Time O(1), Space O(1)
787
- * @returns void
788
- */
1027
+ * Remove all elements and reset structure.
1028
+ * @remarks Time O(1), Space O(1)
1029
+ * @returns void
1030
+
1031
+
1032
+
1033
+
1034
+
1035
+
1036
+
1037
+
1038
+
1039
+
1040
+
1041
+
1042
+
1043
+
1044
+
1045
+
1046
+
1047
+
1048
+
1049
+
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
1060
+ * @example
1061
+ * // Remove all elements
1062
+ * const dq = new Deque<number>([1, 2, 3]);
1063
+ * dq.clear();
1064
+ * console.log(dq.length); // 0;
1065
+ */
789
1066
  clear() {
790
1067
  this._buckets = [new Array(this._bucketSize)];
791
1068
  this._bucketCount = 1;
@@ -793,11 +1070,45 @@ var dequeTyped = (() => {
793
1070
  this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
794
1071
  }
795
1072
  /**
796
- * Get the element at a given position.
797
- * @remarks Time O(1), Space O(1)
798
- * @param pos - Zero-based position from the front.
799
- * @returns Element or undefined.
800
- */
1073
+ * Get the element at a given position.
1074
+ * @remarks Time O(1), Space O(1)
1075
+ * @param pos - Zero-based position from the front.
1076
+ * @returns Element or undefined.
1077
+
1078
+
1079
+
1080
+
1081
+
1082
+
1083
+
1084
+
1085
+
1086
+
1087
+
1088
+
1089
+
1090
+
1091
+
1092
+
1093
+
1094
+
1095
+
1096
+
1097
+
1098
+
1099
+
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+
1106
+ * @example
1107
+ * // Access by index
1108
+ * const dq = new Deque<string>(['a', 'b', 'c']);
1109
+ * console.log(dq.at(0)); // 'a';
1110
+ * console.log(dq.at(2)); // 'c';
1111
+ */
801
1112
  at(pos) {
802
1113
  if (pos < 0 || pos >= this._length) return void 0;
803
1114
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
@@ -956,11 +1267,45 @@ var dequeTyped = (() => {
956
1267
  }
957
1268
  }
958
1269
  /**
959
- * Delete the first occurrence of a value.
960
- * @remarks Time O(N), Space O(1)
961
- * @param element - Element to remove (using the configured equality).
962
- * @returns True if an element was removed.
963
- */
1270
+ * Delete the first occurrence of a value.
1271
+ * @remarks Time O(N), Space O(1)
1272
+ * @param element - Element to remove (using the configured equality).
1273
+ * @returns True if an element was removed.
1274
+
1275
+
1276
+
1277
+
1278
+
1279
+
1280
+
1281
+
1282
+
1283
+
1284
+
1285
+
1286
+
1287
+
1288
+
1289
+
1290
+
1291
+
1292
+
1293
+
1294
+
1295
+
1296
+
1297
+
1298
+
1299
+
1300
+
1301
+
1302
+
1303
+ * @example
1304
+ * // Remove element
1305
+ * const dq = new Deque<number>([1, 2, 3]);
1306
+ * dq.delete(2);
1307
+ * console.log(dq.length); // 2;
1308
+ */
964
1309
  delete(element) {
965
1310
  const size = this._length;
966
1311
  if (size === 0) return false;
@@ -1004,10 +1349,60 @@ var dequeTyped = (() => {
1004
1349
  return this;
1005
1350
  }
1006
1351
  /**
1007
- * Reverse the deque by reversing buckets and pointers.
1008
- * @remarks Time O(N), Space O(N)
1009
- * @returns This deque.
1010
- */
1352
+ * Reverse the deque by reversing buckets and pointers.
1353
+ * @remarks Time O(N), Space O(N)
1354
+ * @returns This deque.
1355
+
1356
+
1357
+
1358
+
1359
+
1360
+
1361
+
1362
+
1363
+
1364
+
1365
+
1366
+
1367
+
1368
+
1369
+
1370
+
1371
+
1372
+
1373
+
1374
+
1375
+
1376
+
1377
+
1378
+
1379
+
1380
+
1381
+
1382
+
1383
+
1384
+
1385
+
1386
+
1387
+ * @example
1388
+ * // Deque for...of iteration and reverse
1389
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
1390
+ *
1391
+ * // Iterate forward
1392
+ * const forward: string[] = [];
1393
+ * for (const item of deque) {
1394
+ * forward.push(item);
1395
+ * }
1396
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
1397
+ *
1398
+ * // Reverse the deque
1399
+ * deque.reverse();
1400
+ * const backward: string[] = [];
1401
+ * for (const item of deque) {
1402
+ * backward.push(item);
1403
+ * }
1404
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
1405
+ */
1011
1406
  reverse() {
1012
1407
  this._buckets.reverse().forEach(function(bucket) {
1013
1408
  bucket.reverse();
@@ -1066,10 +1461,46 @@ var dequeTyped = (() => {
1066
1461
  * @returns True if compaction was performed (bucket count reduced).
1067
1462
  */
1068
1463
  /**
1069
- * Compact the deque by removing unused buckets.
1070
- * @remarks Time O(N), Space O(1)
1071
- * @returns True if compaction was performed (bucket count reduced).
1072
- */
1464
+ * Compact the deque by removing unused buckets.
1465
+ * @remarks Time O(N), Space O(1)
1466
+ * @returns True if compaction was performed (bucket count reduced).
1467
+
1468
+
1469
+
1470
+
1471
+
1472
+
1473
+
1474
+
1475
+
1476
+
1477
+
1478
+
1479
+
1480
+
1481
+
1482
+
1483
+
1484
+
1485
+
1486
+
1487
+
1488
+
1489
+
1490
+
1491
+
1492
+
1493
+
1494
+
1495
+
1496
+ * @example
1497
+ * // Reclaim memory
1498
+ * const dq = new Deque<number>([1, 2, 3, 4, 5]);
1499
+ * dq.shift();
1500
+ * dq.shift();
1501
+ * dq.compact();
1502
+ * console.log(dq.length); // 3;
1503
+ */
1073
1504
  compact() {
1074
1505
  const before = this._bucketCount;
1075
1506
  this.shrinkToFit();
@@ -1097,10 +1528,47 @@ var dequeTyped = (() => {
1097
1528
  this._compactCounter = 0;
1098
1529
  }
1099
1530
  /**
1100
- * Deep clone this deque, preserving options.
1101
- * @remarks Time O(N), Space O(N)
1102
- * @returns A new deque with the same content and options.
1103
- */
1531
+ * Deep clone this deque, preserving options.
1532
+ * @remarks Time O(N), Space O(N)
1533
+ * @returns A new deque with the same content and options.
1534
+
1535
+
1536
+
1537
+
1538
+
1539
+
1540
+
1541
+
1542
+
1543
+
1544
+
1545
+
1546
+
1547
+
1548
+
1549
+
1550
+
1551
+
1552
+
1553
+
1554
+
1555
+
1556
+
1557
+
1558
+
1559
+
1560
+
1561
+
1562
+
1563
+
1564
+ * @example
1565
+ * // Create independent copy
1566
+ * const dq = new Deque<number>([1, 2, 3]);
1567
+ * const copy = dq.clone();
1568
+ * copy.pop();
1569
+ * console.log(dq.length); // 3;
1570
+ * console.log(copy.length); // 2;
1571
+ */
1104
1572
  clone() {
1105
1573
  return this._createLike(this, {
1106
1574
  bucketSize: this.bucketSize,
@@ -1109,12 +1577,47 @@ var dequeTyped = (() => {
1109
1577
  });
1110
1578
  }
1111
1579
  /**
1112
- * Filter elements into a new deque of the same class.
1113
- * @remarks Time O(N), Space O(N)
1114
- * @param predicate - Predicate (value, index, deque) → boolean to keep element.
1115
- * @param [thisArg] - Value for `this` inside the predicate.
1116
- * @returns A new deque with kept elements.
1117
- */
1580
+ * Filter elements into a new deque of the same class.
1581
+ * @remarks Time O(N), Space O(N)
1582
+ * @param predicate - Predicate (value, index, deque) → boolean to keep element.
1583
+ * @param [thisArg] - Value for `this` inside the predicate.
1584
+ * @returns A new deque with kept elements.
1585
+
1586
+
1587
+
1588
+
1589
+
1590
+
1591
+
1592
+
1593
+
1594
+
1595
+
1596
+
1597
+
1598
+
1599
+
1600
+
1601
+
1602
+
1603
+
1604
+
1605
+
1606
+
1607
+
1608
+
1609
+
1610
+
1611
+
1612
+
1613
+
1614
+
1615
+ * @example
1616
+ * // Filter elements
1617
+ * const dq = new Deque<number>([1, 2, 3, 4]);
1618
+ * const result = dq.filter(x => x > 2);
1619
+ * console.log(result.length); // 2;
1620
+ */
1118
1621
  filter(predicate, thisArg) {
1119
1622
  const out = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
1120
1623
  out._setBucketSize(this._bucketSize);
@@ -1143,15 +1646,49 @@ var dequeTyped = (() => {
1143
1646
  return out;
1144
1647
  }
1145
1648
  /**
1146
- * Map elements into a new deque (possibly different element type).
1147
- * @remarks Time O(N), Space O(N)
1148
- * @template EM
1149
- * @template RM
1150
- * @param callback - Mapping function (value, index, deque) → newElement.
1151
- * @param [options] - Options for the output deque (e.g., bucketSize, toElementFn, maxLen).
1152
- * @param [thisArg] - Value for `this` inside the callback.
1153
- * @returns A new Deque with mapped elements.
1154
- */
1649
+ * Map elements into a new deque (possibly different element type).
1650
+ * @remarks Time O(N), Space O(N)
1651
+ * @template EM
1652
+ * @template RM
1653
+ * @param callback - Mapping function (value, index, deque) → newElement.
1654
+ * @param [options] - Options for the output deque (e.g., bucketSize, toElementFn, maxLen).
1655
+ * @param [thisArg] - Value for `this` inside the callback.
1656
+ * @returns A new Deque with mapped elements.
1657
+
1658
+
1659
+
1660
+
1661
+
1662
+
1663
+
1664
+
1665
+
1666
+
1667
+
1668
+
1669
+
1670
+
1671
+
1672
+
1673
+
1674
+
1675
+
1676
+
1677
+
1678
+
1679
+
1680
+
1681
+
1682
+
1683
+
1684
+
1685
+
1686
+ * @example
1687
+ * // Transform elements
1688
+ * const dq = new Deque<number>([1, 2, 3]);
1689
+ * const result = dq.map(x => x * 10);
1690
+ * console.log(result.toArray()); // [10, 20, 30];
1691
+ */
1155
1692
  map(callback, options, thisArg) {
1156
1693
  const out = this._createLike([], {
1157
1694
  ...options != null ? options : {},
@@ -1274,6 +1811,52 @@ var dequeTyped = (() => {
1274
1811
  }
1275
1812
  }
1276
1813
  };
1814
+
1815
+ // src/common/error.ts
1816
+ var ERR = {
1817
+ // Range / index
1818
+ indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
1819
+ invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
1820
+ // Type / argument
1821
+ invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
1822
+ comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
1823
+ invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
1824
+ notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
1825
+ invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
1826
+ invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
1827
+ invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
1828
+ reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
1829
+ callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
1830
+ // State / operation
1831
+ invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
1832
+ // Matrix
1833
+ matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
1834
+ matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
1835
+ matrixNotSquare: () => "Matrix: Must be square for inversion.",
1836
+ matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
1837
+ matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
1838
+ };
1839
+
1840
+ // src/common/index.ts
1841
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1842
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
1843
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1844
+ return DFSOperation2;
1845
+ })(DFSOperation || {});
1846
+ var Range = class {
1847
+ constructor(low, high, includeLow = true, includeHigh = true) {
1848
+ this.low = low;
1849
+ this.high = high;
1850
+ this.includeLow = includeLow;
1851
+ this.includeHigh = includeHigh;
1852
+ }
1853
+ // Determine whether a key is within the range
1854
+ isInRange(key, comparator) {
1855
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
1856
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
1857
+ return lowCheck && highCheck;
1858
+ }
1859
+ };
1277
1860
  return __toCommonJS(src_exports);
1278
1861
  })();
1279
1862
  /**