deque-typed 2.5.1 → 2.5.3

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 (75) hide show
  1. package/dist/cjs/index.cjs +187 -51
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +186 -50
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +187 -52
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +186 -51
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/common/error.d.ts +9 -0
  10. package/dist/types/common/index.d.ts +1 -1
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +189 -13
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +270 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1089 -161
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1243 -350
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +980 -255
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1174 -284
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +126 -0
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +127 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  37. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  38. package/dist/umd/deque-typed.js +184 -49
  39. package/dist/umd/deque-typed.js.map +1 -1
  40. package/dist/umd/deque-typed.min.js +1 -1
  41. package/dist/umd/deque-typed.min.js.map +1 -1
  42. package/package.json +2 -2
  43. package/src/common/error.ts +19 -1
  44. package/src/common/index.ts +1 -1
  45. package/src/data-structures/base/iterable-element-base.ts +3 -2
  46. package/src/data-structures/binary-tree/avl-tree.ts +99 -5
  47. package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
  48. package/src/data-structures/binary-tree/binary-tree.ts +239 -78
  49. package/src/data-structures/binary-tree/bst.ts +542 -13
  50. package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
  51. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  52. package/src/data-structures/binary-tree/tree-map.ts +1223 -261
  53. package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
  54. package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
  55. package/src/data-structures/binary-tree/tree-set.ts +1018 -99
  56. package/src/data-structures/graph/abstract-graph.ts +2 -2
  57. package/src/data-structures/graph/directed-graph.ts +71 -1
  58. package/src/data-structures/graph/undirected-graph.ts +64 -1
  59. package/src/data-structures/hash/hash-map.ts +102 -16
  60. package/src/data-structures/heap/heap.ts +153 -23
  61. package/src/data-structures/heap/max-heap.ts +2 -2
  62. package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
  63. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  64. package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
  65. package/src/data-structures/matrix/matrix.ts +65 -9
  66. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  67. package/src/data-structures/queue/deque.ts +130 -0
  68. package/src/data-structures/queue/queue.ts +109 -0
  69. package/src/data-structures/stack/stack.ts +75 -5
  70. package/src/data-structures/trie/trie.ts +86 -2
  71. package/src/interfaces/binary-tree.ts +1 -9
  72. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  73. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  74. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  75. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
@@ -11,6 +11,61 @@ 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
+ function raise(ErrorClass, message) {
16
+ throw new ErrorClass(message);
17
+ }
18
+ __name(raise, "raise");
19
+ var ERR = {
20
+ // Range / index
21
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
22
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
23
+ // Type / argument
24
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
25
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
26
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
27
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
28
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
29
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
30
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
31
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
32
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
33
+ // State / operation
34
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
35
+ // Matrix
36
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
37
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
38
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
39
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
40
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
41
+ // Order statistic
42
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
43
+ };
44
+
45
+ // src/common/index.ts
46
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
47
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
48
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
49
+ return DFSOperation2;
50
+ })(DFSOperation || {});
51
+ var Range = class {
52
+ constructor(low, high, includeLow = true, includeHigh = true) {
53
+ this.low = low;
54
+ this.high = high;
55
+ this.includeLow = includeLow;
56
+ this.includeHigh = includeHigh;
57
+ }
58
+ static {
59
+ __name(this, "Range");
60
+ }
61
+ // Determine whether a key is within the range
62
+ isInRange(key, comparator) {
63
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
64
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
65
+ return lowCheck && highCheck;
66
+ }
67
+ };
68
+
14
69
  // src/data-structures/base/iterable-element-base.ts
15
70
  var IterableElementBase = class {
16
71
  static {
@@ -29,7 +84,7 @@ var IterableElementBase = class {
29
84
  if (options) {
30
85
  const { toElementFn } = options;
31
86
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
32
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
87
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
33
88
  }
34
89
  }
35
90
  /**
@@ -192,7 +247,7 @@ var IterableElementBase = class {
192
247
  acc = initialValue;
193
248
  } else {
194
249
  const first = iter.next();
195
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
250
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
196
251
  acc = first.value;
197
252
  index = 1;
198
253
  }
@@ -580,6 +635,12 @@ var Deque = class extends LinearBase {
580
635
 
581
636
 
582
637
 
638
+
639
+
640
+
641
+
642
+
643
+
583
644
 
584
645
 
585
646
 
@@ -600,6 +661,31 @@ var Deque = class extends LinearBase {
600
661
  * console.log(last); // 50;
601
662
  *
602
663
  * // Length unchanged
664
+ * console.log(deque.length); // 5;
665
+ */
666
+ /**
667
+ * Peek at the front element without removing it (alias for `first`).
668
+ * @remarks Time O(1), Space O(1)
669
+ * @returns Front element or undefined.
670
+ */
671
+ peek() {
672
+ return this.first;
673
+ }
674
+ /**
675
+ * Deque peek at both ends
676
+ * @example
677
+ * // Deque peek at both ends
678
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
679
+ *
680
+ * // Get first element without removing
681
+ * const first = deque.at(0);
682
+ * console.log(first); // 10;
683
+ *
684
+ * // Get last element without removing
685
+ * const last = deque.at(deque.length - 1);
686
+ * console.log(last); // 50;
687
+ *
688
+ * // Length unchanged
603
689
  * console.log(deque.length); // 5;
604
690
  */
605
691
  get first() {
@@ -634,6 +720,13 @@ var Deque = class extends LinearBase {
634
720
 
635
721
 
636
722
 
723
+
724
+
725
+
726
+
727
+
728
+
729
+
637
730
 
638
731
 
639
732
 
@@ -694,6 +787,13 @@ var Deque = class extends LinearBase {
694
787
 
695
788
 
696
789
 
790
+
791
+
792
+
793
+
794
+
795
+
796
+
697
797
 
698
798
 
699
799
 
@@ -767,6 +867,13 @@ var Deque = class extends LinearBase {
767
867
 
768
868
 
769
869
 
870
+
871
+
872
+
873
+
874
+
875
+
876
+
770
877
 
771
878
 
772
879
 
@@ -827,6 +934,13 @@ var Deque = class extends LinearBase {
827
934
 
828
935
 
829
936
 
937
+
938
+
939
+
940
+
941
+
942
+
943
+
830
944
 
831
945
 
832
946
 
@@ -888,6 +1002,13 @@ var Deque = class extends LinearBase {
888
1002
 
889
1003
 
890
1004
 
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
891
1012
 
892
1013
 
893
1014
 
@@ -990,6 +1111,13 @@ var Deque = class extends LinearBase {
990
1111
 
991
1112
 
992
1113
 
1114
+
1115
+
1116
+
1117
+
1118
+
1119
+
1120
+
993
1121
 
994
1122
 
995
1123
 
@@ -1032,6 +1160,13 @@ var Deque = class extends LinearBase {
1032
1160
 
1033
1161
 
1034
1162
 
1163
+
1164
+
1165
+
1166
+
1167
+
1168
+
1169
+
1035
1170
 
1036
1171
 
1037
1172
 
@@ -1078,6 +1213,13 @@ var Deque = class extends LinearBase {
1078
1213
 
1079
1214
 
1080
1215
 
1216
+
1217
+
1218
+
1219
+
1220
+
1221
+
1222
+
1081
1223
 
1082
1224
 
1083
1225
 
@@ -1275,6 +1417,13 @@ var Deque = class extends LinearBase {
1275
1417
 
1276
1418
 
1277
1419
 
1420
+
1421
+
1422
+
1423
+
1424
+
1425
+
1426
+
1278
1427
 
1279
1428
 
1280
1429
 
@@ -1359,6 +1508,13 @@ var Deque = class extends LinearBase {
1359
1508
 
1360
1509
 
1361
1510
 
1511
+
1512
+
1513
+
1514
+
1515
+
1516
+
1517
+
1362
1518
 
1363
1519
 
1364
1520
 
@@ -1468,6 +1624,13 @@ var Deque = class extends LinearBase {
1468
1624
 
1469
1625
 
1470
1626
 
1627
+
1628
+
1629
+
1630
+
1631
+
1632
+
1633
+
1471
1634
 
1472
1635
 
1473
1636
 
@@ -1536,6 +1699,13 @@ var Deque = class extends LinearBase {
1536
1699
 
1537
1700
 
1538
1701
 
1702
+
1703
+
1704
+
1705
+
1706
+
1707
+
1708
+
1539
1709
 
1540
1710
 
1541
1711
 
@@ -1587,6 +1757,13 @@ var Deque = class extends LinearBase {
1587
1757
 
1588
1758
 
1589
1759
 
1760
+
1761
+
1762
+
1763
+
1764
+
1765
+
1766
+
1590
1767
 
1591
1768
 
1592
1769
 
@@ -1658,6 +1835,13 @@ var Deque = class extends LinearBase {
1658
1835
 
1659
1836
 
1660
1837
 
1838
+
1839
+
1840
+
1841
+
1842
+
1843
+
1844
+
1661
1845
 
1662
1846
 
1663
1847
 
@@ -1794,55 +1978,6 @@ var Deque = class extends LinearBase {
1794
1978
  }
1795
1979
  }
1796
1980
  };
1797
-
1798
- // src/common/error.ts
1799
- var ERR = {
1800
- // Range / index
1801
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
1802
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
1803
- // Type / argument
1804
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
1805
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
1806
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
1807
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
1808
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
1809
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
1810
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
1811
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
1812
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
1813
- // State / operation
1814
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
1815
- // Matrix
1816
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
1817
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
1818
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
1819
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
1820
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
1821
- };
1822
-
1823
- // src/common/index.ts
1824
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1825
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
1826
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1827
- return DFSOperation2;
1828
- })(DFSOperation || {});
1829
- var Range = class {
1830
- constructor(low, high, includeLow = true, includeHigh = true) {
1831
- this.low = low;
1832
- this.high = high;
1833
- this.includeLow = includeLow;
1834
- this.includeHigh = includeHigh;
1835
- }
1836
- static {
1837
- __name(this, "Range");
1838
- }
1839
- // Determine whether a key is within the range
1840
- isInRange(key, comparator) {
1841
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
1842
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
1843
- return lowCheck && highCheck;
1844
- }
1845
- };
1846
1981
  /**
1847
1982
  * data-structure-typed
1848
1983
  *
@@ -1855,5 +1990,6 @@ exports.DFSOperation = DFSOperation;
1855
1990
  exports.Deque = Deque;
1856
1991
  exports.ERR = ERR;
1857
1992
  exports.Range = Range;
1993
+ exports.raise = raise;
1858
1994
  //# sourceMappingURL=index.cjs.map
1859
1995
  //# sourceMappingURL=index.cjs.map