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