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,60 @@ 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 _Range {
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
+ // Determine whether a key is within the range
59
+ isInRange(key, comparator) {
60
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
61
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
62
+ return lowCheck && highCheck;
63
+ }
64
+ };
65
+ __name(_Range, "Range");
66
+ var Range = _Range;
67
+
14
68
  // src/data-structures/base/iterable-element-base.ts
15
69
  var _IterableElementBase = class _IterableElementBase {
16
70
  /**
@@ -33,7 +87,7 @@ var _IterableElementBase = class _IterableElementBase {
33
87
  if (options) {
34
88
  const { toElementFn } = options;
35
89
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
36
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
90
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
37
91
  }
38
92
  }
39
93
  /**
@@ -189,7 +243,7 @@ var _IterableElementBase = class _IterableElementBase {
189
243
  acc = initialValue;
190
244
  } else {
191
245
  const first = iter.next();
192
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
246
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
193
247
  acc = first.value;
194
248
  index = 1;
195
249
  }
@@ -575,6 +629,12 @@ var _Deque = class _Deque extends LinearBase {
575
629
 
576
630
 
577
631
 
632
+
633
+
634
+
635
+
636
+
637
+
578
638
 
579
639
 
580
640
 
@@ -595,6 +655,31 @@ var _Deque = class _Deque extends LinearBase {
595
655
  * console.log(last); // 50;
596
656
  *
597
657
  * // Length unchanged
658
+ * console.log(deque.length); // 5;
659
+ */
660
+ /**
661
+ * Peek at the front element without removing it (alias for `first`).
662
+ * @remarks Time O(1), Space O(1)
663
+ * @returns Front element or undefined.
664
+ */
665
+ peek() {
666
+ return this.first;
667
+ }
668
+ /**
669
+ * Deque peek at both ends
670
+ * @example
671
+ * // Deque peek at both ends
672
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
673
+ *
674
+ * // Get first element without removing
675
+ * const first = deque.at(0);
676
+ * console.log(first); // 10;
677
+ *
678
+ * // Get last element without removing
679
+ * const last = deque.at(deque.length - 1);
680
+ * console.log(last); // 50;
681
+ *
682
+ * // Length unchanged
598
683
  * console.log(deque.length); // 5;
599
684
  */
600
685
  get first() {
@@ -629,6 +714,13 @@ var _Deque = class _Deque extends LinearBase {
629
714
 
630
715
 
631
716
 
717
+
718
+
719
+
720
+
721
+
722
+
723
+
632
724
 
633
725
 
634
726
 
@@ -689,6 +781,13 @@ var _Deque = class _Deque extends LinearBase {
689
781
 
690
782
 
691
783
 
784
+
785
+
786
+
787
+
788
+
789
+
790
+
692
791
 
693
792
 
694
793
 
@@ -762,6 +861,13 @@ var _Deque = class _Deque extends LinearBase {
762
861
 
763
862
 
764
863
 
864
+
865
+
866
+
867
+
868
+
869
+
870
+
765
871
 
766
872
 
767
873
 
@@ -822,6 +928,13 @@ var _Deque = class _Deque extends LinearBase {
822
928
 
823
929
 
824
930
 
931
+
932
+
933
+
934
+
935
+
936
+
937
+
825
938
 
826
939
 
827
940
 
@@ -883,6 +996,13 @@ var _Deque = class _Deque extends LinearBase {
883
996
 
884
997
 
885
998
 
999
+
1000
+
1001
+
1002
+
1003
+
1004
+
1005
+
886
1006
 
887
1007
 
888
1008
 
@@ -985,6 +1105,13 @@ var _Deque = class _Deque extends LinearBase {
985
1105
 
986
1106
 
987
1107
 
1108
+
1109
+
1110
+
1111
+
1112
+
1113
+
1114
+
988
1115
 
989
1116
 
990
1117
 
@@ -1027,6 +1154,13 @@ var _Deque = class _Deque extends LinearBase {
1027
1154
 
1028
1155
 
1029
1156
 
1157
+
1158
+
1159
+
1160
+
1161
+
1162
+
1163
+
1030
1164
 
1031
1165
 
1032
1166
 
@@ -1073,6 +1207,13 @@ var _Deque = class _Deque extends LinearBase {
1073
1207
 
1074
1208
 
1075
1209
 
1210
+
1211
+
1212
+
1213
+
1214
+
1215
+
1216
+
1076
1217
 
1077
1218
 
1078
1219
 
@@ -1270,6 +1411,13 @@ var _Deque = class _Deque extends LinearBase {
1270
1411
 
1271
1412
 
1272
1413
 
1414
+
1415
+
1416
+
1417
+
1418
+
1419
+
1420
+
1273
1421
 
1274
1422
 
1275
1423
 
@@ -1354,6 +1502,13 @@ var _Deque = class _Deque extends LinearBase {
1354
1502
 
1355
1503
 
1356
1504
 
1505
+
1506
+
1507
+
1508
+
1509
+
1510
+
1511
+
1357
1512
 
1358
1513
 
1359
1514
 
@@ -1463,6 +1618,13 @@ var _Deque = class _Deque extends LinearBase {
1463
1618
 
1464
1619
 
1465
1620
 
1621
+
1622
+
1623
+
1624
+
1625
+
1626
+
1627
+
1466
1628
 
1467
1629
 
1468
1630
 
@@ -1531,6 +1693,13 @@ var _Deque = class _Deque extends LinearBase {
1531
1693
 
1532
1694
 
1533
1695
 
1696
+
1697
+
1698
+
1699
+
1700
+
1701
+
1702
+
1534
1703
 
1535
1704
 
1536
1705
 
@@ -1582,6 +1751,13 @@ var _Deque = class _Deque extends LinearBase {
1582
1751
 
1583
1752
 
1584
1753
 
1754
+
1755
+
1756
+
1757
+
1758
+
1759
+
1760
+
1585
1761
 
1586
1762
 
1587
1763
 
@@ -1653,6 +1829,13 @@ var _Deque = class _Deque extends LinearBase {
1653
1829
 
1654
1830
 
1655
1831
 
1832
+
1833
+
1834
+
1835
+
1836
+
1837
+
1838
+
1656
1839
 
1657
1840
 
1658
1841
 
@@ -1791,54 +1974,6 @@ var _Deque = class _Deque extends LinearBase {
1791
1974
  };
1792
1975
  __name(_Deque, "Deque");
1793
1976
  var Deque = _Deque;
1794
-
1795
- // src/common/error.ts
1796
- var ERR = {
1797
- // Range / index
1798
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
1799
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
1800
- // Type / argument
1801
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
1802
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
1803
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
1804
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
1805
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
1806
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
1807
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
1808
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
1809
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
1810
- // State / operation
1811
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
1812
- // Matrix
1813
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
1814
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
1815
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
1816
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
1817
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
1818
- };
1819
-
1820
- // src/common/index.ts
1821
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1822
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
1823
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1824
- return DFSOperation2;
1825
- })(DFSOperation || {});
1826
- var _Range = class _Range {
1827
- constructor(low, high, includeLow = true, includeHigh = true) {
1828
- this.low = low;
1829
- this.high = high;
1830
- this.includeLow = includeLow;
1831
- this.includeHigh = includeHigh;
1832
- }
1833
- // Determine whether a key is within the range
1834
- isInRange(key, comparator) {
1835
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
1836
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
1837
- return lowCheck && highCheck;
1838
- }
1839
- };
1840
- __name(_Range, "Range");
1841
- var Range = _Range;
1842
1977
  /**
1843
1978
  * data-structure-typed
1844
1979
  *
@@ -1847,6 +1982,6 @@ var Range = _Range;
1847
1982
  * @license MIT License
1848
1983
  */
1849
1984
 
1850
- export { DFSOperation, Deque, ERR, Range };
1985
+ export { DFSOperation, Deque, ERR, Range, raise };
1851
1986
  //# sourceMappingURL=index.mjs.map
1852
1987
  //# sourceMappingURL=index.mjs.map