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
@@ -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,60 @@ 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
+ * @example
587
+ * // Deque peek at both ends
588
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
589
+ *
590
+ * // Get first element without removing
591
+ * const first = deque.at(0);
592
+ * console.log(first); // 10;
593
+ *
594
+ * // Get last element without removing
595
+ * const last = deque.at(deque.length - 1);
596
+ * console.log(last); // 50;
597
+ *
598
+ * // Length unchanged
599
+ * console.log(deque.length); // 5;
600
+ */
622
601
  get first() {
623
602
  if (this._length === 0) return;
624
603
  return this._buckets[this._bucketFirst][this._firstInBucket];
625
604
  }
626
605
  /**
627
- * Get the last element without removing it.
628
- * @remarks Time O(1), Space O(1)
629
- * @returns Last element or undefined.
630
- */
606
+ * Get the last element without removing it.
607
+ * @remarks Time O(1), Space O(1)
608
+ * @returns Last element or undefined.
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+ * @example
621
+ * // Peek at the back element
622
+ * const dq = new Deque<string>(['a', 'b', 'c']);
623
+ * console.log(dq.last); // 'c';
624
+ * console.log(dq.first); // 'a';
625
+ */
631
626
  get last() {
632
627
  if (this._length === 0) return;
633
628
  return this._buckets[this._bucketLast][this._lastInBucket];
@@ -646,11 +641,40 @@ var dequeTyped = (() => {
646
641
  return new this(data, options);
647
642
  }
648
643
  /**
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
- */
644
+ * Append one element at the back.
645
+ * @remarks Time O(1) amortized, Space O(1)
646
+ * @param element - Element to append.
647
+ * @returns True when appended.
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+ * @example
660
+ * // basic Deque creation and push/pop operations
661
+ * // Create a simple Deque with initial values
662
+ * const deque = new Deque([1, 2, 3, 4, 5]);
663
+ *
664
+ * // Verify the deque maintains insertion order
665
+ * console.log([...deque]); // [1, 2, 3, 4, 5];
666
+ *
667
+ * // Check length
668
+ * console.log(deque.length); // 5;
669
+ *
670
+ * // Push to the end
671
+ * deque.push(6);
672
+ * console.log(deque.length); // 6;
673
+ *
674
+ * // Pop from the end
675
+ * const last = deque.pop();
676
+ * console.log(last); // 6;
677
+ */
654
678
  push(element) {
655
679
  if (this._length) {
656
680
  if (this._lastInBucket < this._bucketSize - 1) {
@@ -670,10 +694,26 @@ var dequeTyped = (() => {
670
694
  return true;
671
695
  }
672
696
  /**
673
- * Remove and return the last element.
674
- * @remarks Time O(1), Space O(1)
675
- * @returns Removed element or undefined.
676
- */
697
+ * Remove and return the last element.
698
+ * @remarks Time O(1), Space O(1)
699
+ * @returns Removed element or undefined.
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+ * @example
712
+ * // Remove from the back
713
+ * const dq = new Deque<number>([1, 2, 3]);
714
+ * console.log(dq.pop()); // 3;
715
+ * console.log(dq.length); // 2;
716
+ */
677
717
  pop() {
678
718
  if (this._length === 0) return;
679
719
  const element = this._buckets[this._bucketLast][this._lastInBucket];
@@ -693,10 +733,26 @@ var dequeTyped = (() => {
693
733
  return element;
694
734
  }
695
735
  /**
696
- * Remove and return the first element.
697
- * @remarks Time O(1) amortized, Space O(1)
698
- * @returns Removed element or undefined.
699
- */
736
+ * Remove and return the first element.
737
+ * @remarks Time O(1) amortized, Space O(1)
738
+ * @returns Removed element or undefined.
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+ * @example
751
+ * // Remove from the front
752
+ * const dq = new Deque<number>([1, 2, 3]);
753
+ * console.log(dq.shift()); // 1;
754
+ * console.log(dq.length); // 2;
755
+ */
700
756
  shift() {
701
757
  if (this._length === 0) return;
702
758
  const element = this._buckets[this._bucketFirst][this._firstInBucket];
@@ -716,11 +772,37 @@ var dequeTyped = (() => {
716
772
  return element;
717
773
  }
718
774
  /**
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
- */
775
+ * Prepend one element at the front.
776
+ * @remarks Time O(1) amortized, Space O(1)
777
+ * @param element - Element to prepend.
778
+ * @returns True when prepended.
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+ * @example
791
+ * // Deque shift and unshift operations
792
+ * const deque = new Deque<number>([20, 30, 40]);
793
+ *
794
+ * // Unshift adds to the front
795
+ * deque.unshift(10);
796
+ * console.log([...deque]); // [10, 20, 30, 40];
797
+ *
798
+ * // Shift removes from the front (O(1) complexity!)
799
+ * const first = deque.shift();
800
+ * console.log(first); // 10;
801
+ *
802
+ * // Verify remaining elements
803
+ * console.log([...deque]); // [20, 30, 40];
804
+ * console.log(deque.length); // 3;
805
+ */
724
806
  unshift(element) {
725
807
  if (this._length) {
726
808
  if (this._firstInBucket > 0) {
@@ -774,18 +856,45 @@ var dequeTyped = (() => {
774
856
  return ans;
775
857
  }
776
858
  /**
777
- * Check whether the deque is empty.
778
- * @remarks Time O(1), Space O(1)
779
- * @returns True if length is 0.
780
- */
859
+ * Check whether the deque is empty.
860
+ * @remarks Time O(1), Space O(1)
861
+ * @returns True if length is 0.
862
+
863
+
864
+
865
+
866
+
867
+
868
+
869
+
870
+
871
+ * @example
872
+ * // Check if empty
873
+ * const dq = new Deque();
874
+ * console.log(dq.isEmpty()); // true;
875
+ */
781
876
  isEmpty() {
782
877
  return this._length === 0;
783
878
  }
784
879
  /**
785
- * Remove all elements and reset structure.
786
- * @remarks Time O(1), Space O(1)
787
- * @returns void
788
- */
880
+ * Remove all elements and reset structure.
881
+ * @remarks Time O(1), Space O(1)
882
+ * @returns void
883
+
884
+
885
+
886
+
887
+
888
+
889
+
890
+
891
+
892
+ * @example
893
+ * // Remove all elements
894
+ * const dq = new Deque<number>([1, 2, 3]);
895
+ * dq.clear();
896
+ * console.log(dq.length); // 0;
897
+ */
789
898
  clear() {
790
899
  this._buckets = [new Array(this._bucketSize)];
791
900
  this._bucketCount = 1;
@@ -793,11 +902,24 @@ var dequeTyped = (() => {
793
902
  this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
794
903
  }
795
904
  /**
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
- */
905
+ * Get the element at a given position.
906
+ * @remarks Time O(1), Space O(1)
907
+ * @param pos - Zero-based position from the front.
908
+ * @returns Element or undefined.
909
+
910
+
911
+
912
+
913
+
914
+
915
+
916
+
917
+ * @example
918
+ * // Access by index
919
+ * const dq = new Deque<string>(['a', 'b', 'c']);
920
+ * console.log(dq.at(0)); // 'a';
921
+ * console.log(dq.at(2)); // 'c';
922
+ */
801
923
  at(pos) {
802
924
  if (pos < 0 || pos >= this._length) return void 0;
803
925
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
@@ -956,11 +1078,24 @@ var dequeTyped = (() => {
956
1078
  }
957
1079
  }
958
1080
  /**
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
- */
1081
+ * Delete the first occurrence of a value.
1082
+ * @remarks Time O(N), Space O(1)
1083
+ * @param element - Element to remove (using the configured equality).
1084
+ * @returns True if an element was removed.
1085
+
1086
+
1087
+
1088
+
1089
+
1090
+
1091
+
1092
+
1093
+ * @example
1094
+ * // Remove element
1095
+ * const dq = new Deque<number>([1, 2, 3]);
1096
+ * dq.delete(2);
1097
+ * console.log(dq.length); // 2;
1098
+ */
964
1099
  delete(element) {
965
1100
  const size = this._length;
966
1101
  if (size === 0) return false;
@@ -1004,10 +1139,39 @@ var dequeTyped = (() => {
1004
1139
  return this;
1005
1140
  }
1006
1141
  /**
1007
- * Reverse the deque by reversing buckets and pointers.
1008
- * @remarks Time O(N), Space O(N)
1009
- * @returns This deque.
1010
- */
1142
+ * Reverse the deque by reversing buckets and pointers.
1143
+ * @remarks Time O(N), Space O(N)
1144
+ * @returns This deque.
1145
+
1146
+
1147
+
1148
+
1149
+
1150
+
1151
+
1152
+
1153
+
1154
+
1155
+
1156
+ * @example
1157
+ * // Deque for...of iteration and reverse
1158
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
1159
+ *
1160
+ * // Iterate forward
1161
+ * const forward: string[] = [];
1162
+ * for (const item of deque) {
1163
+ * forward.push(item);
1164
+ * }
1165
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
1166
+ *
1167
+ * // Reverse the deque
1168
+ * deque.reverse();
1169
+ * const backward: string[] = [];
1170
+ * for (const item of deque) {
1171
+ * backward.push(item);
1172
+ * }
1173
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
1174
+ */
1011
1175
  reverse() {
1012
1176
  this._buckets.reverse().forEach(function(bucket) {
1013
1177
  bucket.reverse();
@@ -1066,10 +1230,25 @@ var dequeTyped = (() => {
1066
1230
  * @returns True if compaction was performed (bucket count reduced).
1067
1231
  */
1068
1232
  /**
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
- */
1233
+ * Compact the deque by removing unused buckets.
1234
+ * @remarks Time O(N), Space O(1)
1235
+ * @returns True if compaction was performed (bucket count reduced).
1236
+
1237
+
1238
+
1239
+
1240
+
1241
+
1242
+
1243
+
1244
+ * @example
1245
+ * // Reclaim memory
1246
+ * const dq = new Deque<number>([1, 2, 3, 4, 5]);
1247
+ * dq.shift();
1248
+ * dq.shift();
1249
+ * dq.compact();
1250
+ * console.log(dq.length); // 3;
1251
+ */
1073
1252
  compact() {
1074
1253
  const before = this._bucketCount;
1075
1254
  this.shrinkToFit();
@@ -1097,10 +1276,26 @@ var dequeTyped = (() => {
1097
1276
  this._compactCounter = 0;
1098
1277
  }
1099
1278
  /**
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
- */
1279
+ * Deep clone this deque, preserving options.
1280
+ * @remarks Time O(N), Space O(N)
1281
+ * @returns A new deque with the same content and options.
1282
+
1283
+
1284
+
1285
+
1286
+
1287
+
1288
+
1289
+
1290
+
1291
+ * @example
1292
+ * // Create independent copy
1293
+ * const dq = new Deque<number>([1, 2, 3]);
1294
+ * const copy = dq.clone();
1295
+ * copy.pop();
1296
+ * console.log(dq.length); // 3;
1297
+ * console.log(copy.length); // 2;
1298
+ */
1104
1299
  clone() {
1105
1300
  return this._createLike(this, {
1106
1301
  bucketSize: this.bucketSize,
@@ -1109,12 +1304,26 @@ var dequeTyped = (() => {
1109
1304
  });
1110
1305
  }
1111
1306
  /**
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
- */
1307
+ * Filter elements into a new deque of the same class.
1308
+ * @remarks Time O(N), Space O(N)
1309
+ * @param predicate - Predicate (value, index, deque) → boolean to keep element.
1310
+ * @param [thisArg] - Value for `this` inside the predicate.
1311
+ * @returns A new deque with kept elements.
1312
+
1313
+
1314
+
1315
+
1316
+
1317
+
1318
+
1319
+
1320
+
1321
+ * @example
1322
+ * // Filter elements
1323
+ * const dq = new Deque<number>([1, 2, 3, 4]);
1324
+ * const result = dq.filter(x => x > 2);
1325
+ * console.log(result.length); // 2;
1326
+ */
1118
1327
  filter(predicate, thisArg) {
1119
1328
  const out = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
1120
1329
  out._setBucketSize(this._bucketSize);
@@ -1143,15 +1352,28 @@ var dequeTyped = (() => {
1143
1352
  return out;
1144
1353
  }
1145
1354
  /**
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
- */
1355
+ * Map elements into a new deque (possibly different element type).
1356
+ * @remarks Time O(N), Space O(N)
1357
+ * @template EM
1358
+ * @template RM
1359
+ * @param callback - Mapping function (value, index, deque) → newElement.
1360
+ * @param [options] - Options for the output deque (e.g., bucketSize, toElementFn, maxLen).
1361
+ * @param [thisArg] - Value for `this` inside the callback.
1362
+ * @returns A new Deque with mapped elements.
1363
+
1364
+
1365
+
1366
+
1367
+
1368
+
1369
+
1370
+
1371
+ * @example
1372
+ * // Transform elements
1373
+ * const dq = new Deque<number>([1, 2, 3]);
1374
+ * const result = dq.map(x => x * 10);
1375
+ * console.log(result.toArray()); // [10, 20, 30];
1376
+ */
1155
1377
  map(callback, options, thisArg) {
1156
1378
  const out = this._createLike([], {
1157
1379
  ...options != null ? options : {},
@@ -1274,6 +1496,52 @@ var dequeTyped = (() => {
1274
1496
  }
1275
1497
  }
1276
1498
  };
1499
+
1500
+ // src/common/error.ts
1501
+ var ERR = {
1502
+ // Range / index
1503
+ indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
1504
+ invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
1505
+ // Type / argument
1506
+ invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
1507
+ comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
1508
+ invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
1509
+ notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
1510
+ invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
1511
+ invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
1512
+ invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
1513
+ reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
1514
+ callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
1515
+ // State / operation
1516
+ invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
1517
+ // Matrix
1518
+ matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
1519
+ matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
1520
+ matrixNotSquare: () => "Matrix: Must be square for inversion.",
1521
+ matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
1522
+ matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
1523
+ };
1524
+
1525
+ // src/common/index.ts
1526
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1527
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
1528
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1529
+ return DFSOperation2;
1530
+ })(DFSOperation || {});
1531
+ var Range = class {
1532
+ constructor(low, high, includeLow = true, includeHigh = true) {
1533
+ this.low = low;
1534
+ this.high = high;
1535
+ this.includeLow = includeLow;
1536
+ this.includeHigh = includeHigh;
1537
+ }
1538
+ // Determine whether a key is within the range
1539
+ isInRange(key, comparator) {
1540
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
1541
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
1542
+ return lowCheck && highCheck;
1543
+ }
1544
+ };
1277
1545
  return __toCommonJS(src_exports);
1278
1546
  })();
1279
1547
  /**