deque-typed 2.4.5 → 2.5.0

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 (76) hide show
  1. package/README.md +6 -73
  2. package/dist/cjs/index.cjs +390 -122
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +389 -121
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +390 -122
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +389 -121
  9. package/dist/esm-legacy/index.mjs.map +1 -1
  10. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +128 -51
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +210 -164
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +429 -78
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +311 -28
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +212 -32
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +218 -152
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1281 -5
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1087 -201
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +858 -65
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1133 -5
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +219 -47
  22. package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
  23. package/dist/types/data-structures/graph/undirected-graph.d.ts +204 -59
  24. package/dist/types/data-structures/hash/hash-map.d.ts +230 -77
  25. package/dist/types/data-structures/heap/heap.d.ts +287 -99
  26. package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
  27. package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
  28. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +286 -44
  29. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +278 -65
  30. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +415 -12
  31. package/dist/types/data-structures/matrix/matrix.d.ts +331 -0
  32. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
  33. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
  34. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
  35. package/dist/types/data-structures/queue/deque.d.ts +272 -65
  36. package/dist/types/data-structures/queue/queue.d.ts +211 -42
  37. package/dist/types/data-structures/stack/stack.d.ts +174 -32
  38. package/dist/types/data-structures/trie/trie.d.ts +213 -43
  39. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
  40. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
  41. package/dist/umd/deque-typed.js +387 -119
  42. package/dist/umd/deque-typed.js.map +1 -1
  43. package/dist/umd/deque-typed.min.js +1 -1
  44. package/dist/umd/deque-typed.min.js.map +1 -1
  45. package/package.json +2 -2
  46. package/src/data-structures/base/iterable-element-base.ts +4 -5
  47. package/src/data-structures/binary-tree/avl-tree.ts +134 -51
  48. package/src/data-structures/binary-tree/binary-indexed-tree.ts +302 -247
  49. package/src/data-structures/binary-tree/binary-tree.ts +429 -79
  50. package/src/data-structures/binary-tree/bst.ts +335 -34
  51. package/src/data-structures/binary-tree/red-black-tree.ts +290 -97
  52. package/src/data-structures/binary-tree/segment-tree.ts +372 -248
  53. package/src/data-structures/binary-tree/tree-map.ts +1284 -6
  54. package/src/data-structures/binary-tree/tree-multi-map.ts +1094 -211
  55. package/src/data-structures/binary-tree/tree-multi-set.ts +858 -65
  56. package/src/data-structures/binary-tree/tree-set.ts +1136 -9
  57. package/src/data-structures/graph/directed-graph.ts +219 -47
  58. package/src/data-structures/graph/map-graph.ts +59 -1
  59. package/src/data-structures/graph/undirected-graph.ts +204 -59
  60. package/src/data-structures/hash/hash-map.ts +230 -77
  61. package/src/data-structures/heap/heap.ts +287 -99
  62. package/src/data-structures/heap/max-heap.ts +46 -0
  63. package/src/data-structures/heap/min-heap.ts +59 -0
  64. package/src/data-structures/linked-list/doubly-linked-list.ts +286 -44
  65. package/src/data-structures/linked-list/singly-linked-list.ts +278 -65
  66. package/src/data-structures/linked-list/skip-linked-list.ts +689 -90
  67. package/src/data-structures/matrix/matrix.ts +416 -12
  68. package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
  69. package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
  70. package/src/data-structures/priority-queue/priority-queue.ts +60 -0
  71. package/src/data-structures/queue/deque.ts +272 -65
  72. package/src/data-structures/queue/queue.ts +211 -42
  73. package/src/data-structures/stack/stack.ts +174 -32
  74. package/src/data-structures/trie/trie.ts +213 -43
  75. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
  76. package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
@@ -13,54 +13,6 @@ var rangeCheck = /* @__PURE__ */ __name((index, min, max, message) => {
13
13
  }, "rangeCheck");
14
14
  var calcMinUnitsRequired = /* @__PURE__ */ __name((totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize), "calcMinUnitsRequired");
15
15
 
16
- // src/common/error.ts
17
- var ERR = {
18
- // Range / index
19
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
20
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
21
- // Type / argument
22
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
23
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
24
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
25
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
26
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
27
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
28
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
29
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
30
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
31
- // State / operation
32
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
33
- // Matrix
34
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
35
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
36
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
37
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
38
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
39
- };
40
-
41
- // src/common/index.ts
42
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
43
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
44
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
45
- return DFSOperation2;
46
- })(DFSOperation || {});
47
- var _Range = class _Range {
48
- constructor(low, high, includeLow = true, includeHigh = true) {
49
- this.low = low;
50
- this.high = high;
51
- this.includeLow = includeLow;
52
- this.includeHigh = includeHigh;
53
- }
54
- // Determine whether a key is within the range
55
- isInRange(key, comparator) {
56
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
57
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
58
- return lowCheck && highCheck;
59
- }
60
- };
61
- __name(_Range, "Range");
62
- var Range = _Range;
63
-
64
16
  // src/data-structures/base/iterable-element-base.ts
65
17
  var _IterableElementBase = class _IterableElementBase {
66
18
  /**
@@ -83,7 +35,7 @@ var _IterableElementBase = class _IterableElementBase {
83
35
  if (options) {
84
36
  const { toElementFn } = options;
85
37
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
86
- else if (toElementFn) throw new TypeError(ERR.notAFunction("toElementFn"));
38
+ else if (toElementFn) throw new TypeError("toElementFn must be a function type");
87
39
  }
88
40
  }
89
41
  /**
@@ -239,7 +191,7 @@ var _IterableElementBase = class _IterableElementBase {
239
191
  acc = initialValue;
240
192
  } else {
241
193
  const first = iter.next();
242
- if (first.done) throw new TypeError(ERR.reduceEmpty());
194
+ if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
243
195
  acc = first.value;
244
196
  index = 1;
245
197
  }
@@ -597,19 +549,60 @@ var _Deque = class _Deque extends LinearBase {
597
549
  return this._length;
598
550
  }
599
551
  /**
600
- * Get the first element without removing it.
601
- * @remarks Time O(1), Space O(1)
602
- * @returns First element or undefined.
603
- */
552
+ * Get the first element without removing it.
553
+ * @remarks Time O(1), Space O(1)
554
+ * @returns First element or undefined.
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+ * @example
567
+ * // Deque peek at both ends
568
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
569
+ *
570
+ * // Get first element without removing
571
+ * const first = deque.at(0);
572
+ * console.log(first); // 10;
573
+ *
574
+ * // Get last element without removing
575
+ * const last = deque.at(deque.length - 1);
576
+ * console.log(last); // 50;
577
+ *
578
+ * // Length unchanged
579
+ * console.log(deque.length); // 5;
580
+ */
604
581
  get first() {
605
582
  if (this._length === 0) return;
606
583
  return this._buckets[this._bucketFirst][this._firstInBucket];
607
584
  }
608
585
  /**
609
- * Get the last element without removing it.
610
- * @remarks Time O(1), Space O(1)
611
- * @returns Last element or undefined.
612
- */
586
+ * Get the last element without removing it.
587
+ * @remarks Time O(1), Space O(1)
588
+ * @returns Last element or undefined.
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+ * @example
601
+ * // Peek at the back element
602
+ * const dq = new Deque<string>(['a', 'b', 'c']);
603
+ * console.log(dq.last); // 'c';
604
+ * console.log(dq.first); // 'a';
605
+ */
613
606
  get last() {
614
607
  if (this._length === 0) return;
615
608
  return this._buckets[this._bucketLast][this._lastInBucket];
@@ -628,11 +621,40 @@ var _Deque = class _Deque extends LinearBase {
628
621
  return new this(data, options);
629
622
  }
630
623
  /**
631
- * Append one element at the back.
632
- * @remarks Time O(1) amortized, Space O(1)
633
- * @param element - Element to append.
634
- * @returns True when appended.
635
- */
624
+ * Append one element at the back.
625
+ * @remarks Time O(1) amortized, Space O(1)
626
+ * @param element - Element to append.
627
+ * @returns True when appended.
628
+
629
+
630
+
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+ * @example
640
+ * // basic Deque creation and push/pop operations
641
+ * // Create a simple Deque with initial values
642
+ * const deque = new Deque([1, 2, 3, 4, 5]);
643
+ *
644
+ * // Verify the deque maintains insertion order
645
+ * console.log([...deque]); // [1, 2, 3, 4, 5];
646
+ *
647
+ * // Check length
648
+ * console.log(deque.length); // 5;
649
+ *
650
+ * // Push to the end
651
+ * deque.push(6);
652
+ * console.log(deque.length); // 6;
653
+ *
654
+ * // Pop from the end
655
+ * const last = deque.pop();
656
+ * console.log(last); // 6;
657
+ */
636
658
  push(element) {
637
659
  if (this._length) {
638
660
  if (this._lastInBucket < this._bucketSize - 1) {
@@ -652,10 +674,26 @@ var _Deque = class _Deque extends LinearBase {
652
674
  return true;
653
675
  }
654
676
  /**
655
- * Remove and return the last element.
656
- * @remarks Time O(1), Space O(1)
657
- * @returns Removed element or undefined.
658
- */
677
+ * Remove and return the last element.
678
+ * @remarks Time O(1), Space O(1)
679
+ * @returns Removed element or undefined.
680
+
681
+
682
+
683
+
684
+
685
+
686
+
687
+
688
+
689
+
690
+
691
+ * @example
692
+ * // Remove from the back
693
+ * const dq = new Deque<number>([1, 2, 3]);
694
+ * console.log(dq.pop()); // 3;
695
+ * console.log(dq.length); // 2;
696
+ */
659
697
  pop() {
660
698
  if (this._length === 0) return;
661
699
  const element = this._buckets[this._bucketLast][this._lastInBucket];
@@ -675,10 +713,26 @@ var _Deque = class _Deque extends LinearBase {
675
713
  return element;
676
714
  }
677
715
  /**
678
- * Remove and return the first element.
679
- * @remarks Time O(1) amortized, Space O(1)
680
- * @returns Removed element or undefined.
681
- */
716
+ * Remove and return the first element.
717
+ * @remarks Time O(1) amortized, Space O(1)
718
+ * @returns Removed element or undefined.
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
729
+
730
+ * @example
731
+ * // Remove from the front
732
+ * const dq = new Deque<number>([1, 2, 3]);
733
+ * console.log(dq.shift()); // 1;
734
+ * console.log(dq.length); // 2;
735
+ */
682
736
  shift() {
683
737
  if (this._length === 0) return;
684
738
  const element = this._buckets[this._bucketFirst][this._firstInBucket];
@@ -698,11 +752,37 @@ var _Deque = class _Deque extends LinearBase {
698
752
  return element;
699
753
  }
700
754
  /**
701
- * Prepend one element at the front.
702
- * @remarks Time O(1) amortized, Space O(1)
703
- * @param element - Element to prepend.
704
- * @returns True when prepended.
705
- */
755
+ * Prepend one element at the front.
756
+ * @remarks Time O(1) amortized, Space O(1)
757
+ * @param element - Element to prepend.
758
+ * @returns True when prepended.
759
+
760
+
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+ * @example
771
+ * // Deque shift and unshift operations
772
+ * const deque = new Deque<number>([20, 30, 40]);
773
+ *
774
+ * // Unshift adds to the front
775
+ * deque.unshift(10);
776
+ * console.log([...deque]); // [10, 20, 30, 40];
777
+ *
778
+ * // Shift removes from the front (O(1) complexity!)
779
+ * const first = deque.shift();
780
+ * console.log(first); // 10;
781
+ *
782
+ * // Verify remaining elements
783
+ * console.log([...deque]); // [20, 30, 40];
784
+ * console.log(deque.length); // 3;
785
+ */
706
786
  unshift(element) {
707
787
  if (this._length) {
708
788
  if (this._firstInBucket > 0) {
@@ -756,18 +836,45 @@ var _Deque = class _Deque extends LinearBase {
756
836
  return ans;
757
837
  }
758
838
  /**
759
- * Check whether the deque is empty.
760
- * @remarks Time O(1), Space O(1)
761
- * @returns True if length is 0.
762
- */
839
+ * Check whether the deque is empty.
840
+ * @remarks Time O(1), Space O(1)
841
+ * @returns True if length is 0.
842
+
843
+
844
+
845
+
846
+
847
+
848
+
849
+
850
+
851
+ * @example
852
+ * // Check if empty
853
+ * const dq = new Deque();
854
+ * console.log(dq.isEmpty()); // true;
855
+ */
763
856
  isEmpty() {
764
857
  return this._length === 0;
765
858
  }
766
859
  /**
767
- * Remove all elements and reset structure.
768
- * @remarks Time O(1), Space O(1)
769
- * @returns void
770
- */
860
+ * Remove all elements and reset structure.
861
+ * @remarks Time O(1), Space O(1)
862
+ * @returns void
863
+
864
+
865
+
866
+
867
+
868
+
869
+
870
+
871
+
872
+ * @example
873
+ * // Remove all elements
874
+ * const dq = new Deque<number>([1, 2, 3]);
875
+ * dq.clear();
876
+ * console.log(dq.length); // 0;
877
+ */
771
878
  clear() {
772
879
  this._buckets = [new Array(this._bucketSize)];
773
880
  this._bucketCount = 1;
@@ -775,11 +882,24 @@ var _Deque = class _Deque extends LinearBase {
775
882
  this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
776
883
  }
777
884
  /**
778
- * Get the element at a given position.
779
- * @remarks Time O(1), Space O(1)
780
- * @param pos - Zero-based position from the front.
781
- * @returns Element or undefined.
782
- */
885
+ * Get the element at a given position.
886
+ * @remarks Time O(1), Space O(1)
887
+ * @param pos - Zero-based position from the front.
888
+ * @returns Element or undefined.
889
+
890
+
891
+
892
+
893
+
894
+
895
+
896
+
897
+ * @example
898
+ * // Access by index
899
+ * const dq = new Deque<string>(['a', 'b', 'c']);
900
+ * console.log(dq.at(0)); // 'a';
901
+ * console.log(dq.at(2)); // 'c';
902
+ */
783
903
  at(pos) {
784
904
  if (pos < 0 || pos >= this._length) return void 0;
785
905
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
@@ -938,11 +1058,24 @@ var _Deque = class _Deque extends LinearBase {
938
1058
  }
939
1059
  }
940
1060
  /**
941
- * Delete the first occurrence of a value.
942
- * @remarks Time O(N), Space O(1)
943
- * @param element - Element to remove (using the configured equality).
944
- * @returns True if an element was removed.
945
- */
1061
+ * Delete the first occurrence of a value.
1062
+ * @remarks Time O(N), Space O(1)
1063
+ * @param element - Element to remove (using the configured equality).
1064
+ * @returns True if an element was removed.
1065
+
1066
+
1067
+
1068
+
1069
+
1070
+
1071
+
1072
+
1073
+ * @example
1074
+ * // Remove element
1075
+ * const dq = new Deque<number>([1, 2, 3]);
1076
+ * dq.delete(2);
1077
+ * console.log(dq.length); // 2;
1078
+ */
946
1079
  delete(element) {
947
1080
  const size = this._length;
948
1081
  if (size === 0) return false;
@@ -986,10 +1119,39 @@ var _Deque = class _Deque extends LinearBase {
986
1119
  return this;
987
1120
  }
988
1121
  /**
989
- * Reverse the deque by reversing buckets and pointers.
990
- * @remarks Time O(N), Space O(N)
991
- * @returns This deque.
992
- */
1122
+ * Reverse the deque by reversing buckets and pointers.
1123
+ * @remarks Time O(N), Space O(N)
1124
+ * @returns This deque.
1125
+
1126
+
1127
+
1128
+
1129
+
1130
+
1131
+
1132
+
1133
+
1134
+
1135
+
1136
+ * @example
1137
+ * // Deque for...of iteration and reverse
1138
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
1139
+ *
1140
+ * // Iterate forward
1141
+ * const forward: string[] = [];
1142
+ * for (const item of deque) {
1143
+ * forward.push(item);
1144
+ * }
1145
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
1146
+ *
1147
+ * // Reverse the deque
1148
+ * deque.reverse();
1149
+ * const backward: string[] = [];
1150
+ * for (const item of deque) {
1151
+ * backward.push(item);
1152
+ * }
1153
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
1154
+ */
993
1155
  reverse() {
994
1156
  this._buckets.reverse().forEach(function(bucket) {
995
1157
  bucket.reverse();
@@ -1048,10 +1210,25 @@ var _Deque = class _Deque extends LinearBase {
1048
1210
  * @returns True if compaction was performed (bucket count reduced).
1049
1211
  */
1050
1212
  /**
1051
- * Compact the deque by removing unused buckets.
1052
- * @remarks Time O(N), Space O(1)
1053
- * @returns True if compaction was performed (bucket count reduced).
1054
- */
1213
+ * Compact the deque by removing unused buckets.
1214
+ * @remarks Time O(N), Space O(1)
1215
+ * @returns True if compaction was performed (bucket count reduced).
1216
+
1217
+
1218
+
1219
+
1220
+
1221
+
1222
+
1223
+
1224
+ * @example
1225
+ * // Reclaim memory
1226
+ * const dq = new Deque<number>([1, 2, 3, 4, 5]);
1227
+ * dq.shift();
1228
+ * dq.shift();
1229
+ * dq.compact();
1230
+ * console.log(dq.length); // 3;
1231
+ */
1055
1232
  compact() {
1056
1233
  const before = this._bucketCount;
1057
1234
  this.shrinkToFit();
@@ -1079,10 +1256,26 @@ var _Deque = class _Deque extends LinearBase {
1079
1256
  this._compactCounter = 0;
1080
1257
  }
1081
1258
  /**
1082
- * Deep clone this deque, preserving options.
1083
- * @remarks Time O(N), Space O(N)
1084
- * @returns A new deque with the same content and options.
1085
- */
1259
+ * Deep clone this deque, preserving options.
1260
+ * @remarks Time O(N), Space O(N)
1261
+ * @returns A new deque with the same content and options.
1262
+
1263
+
1264
+
1265
+
1266
+
1267
+
1268
+
1269
+
1270
+
1271
+ * @example
1272
+ * // Create independent copy
1273
+ * const dq = new Deque<number>([1, 2, 3]);
1274
+ * const copy = dq.clone();
1275
+ * copy.pop();
1276
+ * console.log(dq.length); // 3;
1277
+ * console.log(copy.length); // 2;
1278
+ */
1086
1279
  clone() {
1087
1280
  return this._createLike(this, {
1088
1281
  bucketSize: this.bucketSize,
@@ -1091,12 +1284,26 @@ var _Deque = class _Deque extends LinearBase {
1091
1284
  });
1092
1285
  }
1093
1286
  /**
1094
- * Filter elements into a new deque of the same class.
1095
- * @remarks Time O(N), Space O(N)
1096
- * @param predicate - Predicate (value, index, deque) → boolean to keep element.
1097
- * @param [thisArg] - Value for `this` inside the predicate.
1098
- * @returns A new deque with kept elements.
1099
- */
1287
+ * Filter elements into a new deque of the same class.
1288
+ * @remarks Time O(N), Space O(N)
1289
+ * @param predicate - Predicate (value, index, deque) → boolean to keep element.
1290
+ * @param [thisArg] - Value for `this` inside the predicate.
1291
+ * @returns A new deque with kept elements.
1292
+
1293
+
1294
+
1295
+
1296
+
1297
+
1298
+
1299
+
1300
+
1301
+ * @example
1302
+ * // Filter elements
1303
+ * const dq = new Deque<number>([1, 2, 3, 4]);
1304
+ * const result = dq.filter(x => x > 2);
1305
+ * console.log(result.length); // 2;
1306
+ */
1100
1307
  filter(predicate, thisArg) {
1101
1308
  const out = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
1102
1309
  out._setBucketSize(this._bucketSize);
@@ -1125,15 +1332,28 @@ var _Deque = class _Deque extends LinearBase {
1125
1332
  return out;
1126
1333
  }
1127
1334
  /**
1128
- * Map elements into a new deque (possibly different element type).
1129
- * @remarks Time O(N), Space O(N)
1130
- * @template EM
1131
- * @template RM
1132
- * @param callback - Mapping function (value, index, deque) → newElement.
1133
- * @param [options] - Options for the output deque (e.g., bucketSize, toElementFn, maxLen).
1134
- * @param [thisArg] - Value for `this` inside the callback.
1135
- * @returns A new Deque with mapped elements.
1136
- */
1335
+ * Map elements into a new deque (possibly different element type).
1336
+ * @remarks Time O(N), Space O(N)
1337
+ * @template EM
1338
+ * @template RM
1339
+ * @param callback - Mapping function (value, index, deque) → newElement.
1340
+ * @param [options] - Options for the output deque (e.g., bucketSize, toElementFn, maxLen).
1341
+ * @param [thisArg] - Value for `this` inside the callback.
1342
+ * @returns A new Deque with mapped elements.
1343
+
1344
+
1345
+
1346
+
1347
+
1348
+
1349
+
1350
+
1351
+ * @example
1352
+ * // Transform elements
1353
+ * const dq = new Deque<number>([1, 2, 3]);
1354
+ * const result = dq.map(x => x * 10);
1355
+ * console.log(result.toArray()); // [10, 20, 30];
1356
+ */
1137
1357
  map(callback, options, thisArg) {
1138
1358
  const out = this._createLike([], {
1139
1359
  ...options != null ? options : {},
@@ -1258,6 +1478,54 @@ var _Deque = class _Deque extends LinearBase {
1258
1478
  };
1259
1479
  __name(_Deque, "Deque");
1260
1480
  var Deque = _Deque;
1481
+
1482
+ // src/common/error.ts
1483
+ var ERR = {
1484
+ // Range / index
1485
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
1486
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
1487
+ // Type / argument
1488
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
1489
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
1490
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
1491
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
1492
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
1493
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
1494
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
1495
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
1496
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
1497
+ // State / operation
1498
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
1499
+ // Matrix
1500
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
1501
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
1502
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
1503
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
1504
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
1505
+ };
1506
+
1507
+ // src/common/index.ts
1508
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1509
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
1510
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1511
+ return DFSOperation2;
1512
+ })(DFSOperation || {});
1513
+ var _Range = class _Range {
1514
+ constructor(low, high, includeLow = true, includeHigh = true) {
1515
+ this.low = low;
1516
+ this.high = high;
1517
+ this.includeLow = includeLow;
1518
+ this.includeHigh = includeHigh;
1519
+ }
1520
+ // Determine whether a key is within the range
1521
+ isInRange(key, comparator) {
1522
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
1523
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
1524
+ return lowCheck && highCheck;
1525
+ }
1526
+ };
1527
+ __name(_Range, "Range");
1528
+ var Range = _Range;
1261
1529
  /**
1262
1530
  * data-structure-typed
1263
1531
  *