deque-typed 2.5.1 → 2.5.2
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.
- package/dist/cjs/index.cjs +103 -51
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +102 -50
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +103 -52
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +102 -51
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +77 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +409 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
- package/dist/types/data-structures/heap/heap.d.ts +42 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +51 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
- package/dist/types/data-structures/queue/deque.d.ts +45 -0
- package/dist/types/data-structures/queue/queue.d.ts +36 -0
- package/dist/types/data-structures/stack/stack.d.ts +30 -0
- package/dist/types/data-structures/trie/trie.d.ts +36 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/umd/deque-typed.js +100 -49
- package/dist/umd/deque-typed.js.map +1 -1
- package/dist/umd/deque-typed.min.js +1 -1
- package/dist/umd/deque-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/binary-tree/avl-tree.ts +47 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
- package/src/data-structures/binary-tree/binary-tree.ts +79 -4
- package/src/data-structures/binary-tree/bst.ts +441 -6
- package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
- package/src/data-structures/binary-tree/segment-tree.ts +18 -0
- package/src/data-structures/binary-tree/tree-map.ts +434 -9
- package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
- package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
- package/src/data-structures/binary-tree/tree-set.ts +410 -8
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/undirected-graph.ts +27 -0
- package/src/data-structures/hash/hash-map.ts +35 -4
- package/src/data-structures/heap/heap.ts +46 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
- package/src/data-structures/matrix/matrix.ts +33 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +45 -0
- package/src/data-structures/queue/queue.ts +36 -0
- package/src/data-structures/stack/stack.ts +30 -0
- package/src/data-structures/trie/trie.ts +38 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- 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)
|
|
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)
|
|
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
|
}
|
|
@@ -578,6 +632,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
578
632
|
|
|
579
633
|
|
|
580
634
|
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
581
638
|
|
|
582
639
|
|
|
583
640
|
|
|
@@ -633,6 +690,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
633
690
|
|
|
634
691
|
|
|
635
692
|
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
636
696
|
|
|
637
697
|
|
|
638
698
|
|
|
@@ -693,6 +753,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
693
753
|
|
|
694
754
|
|
|
695
755
|
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
696
759
|
|
|
697
760
|
|
|
698
761
|
|
|
@@ -766,6 +829,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
766
829
|
|
|
767
830
|
|
|
768
831
|
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
769
835
|
|
|
770
836
|
|
|
771
837
|
|
|
@@ -826,6 +892,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
826
892
|
|
|
827
893
|
|
|
828
894
|
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
829
898
|
|
|
830
899
|
|
|
831
900
|
|
|
@@ -887,6 +956,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
887
956
|
|
|
888
957
|
|
|
889
958
|
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
|
|
890
962
|
|
|
891
963
|
|
|
892
964
|
|
|
@@ -989,6 +1061,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
989
1061
|
|
|
990
1062
|
|
|
991
1063
|
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
|
|
992
1067
|
|
|
993
1068
|
|
|
994
1069
|
|
|
@@ -1031,6 +1106,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1031
1106
|
|
|
1032
1107
|
|
|
1033
1108
|
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1034
1112
|
|
|
1035
1113
|
|
|
1036
1114
|
|
|
@@ -1077,6 +1155,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1077
1155
|
|
|
1078
1156
|
|
|
1079
1157
|
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
|
|
1080
1161
|
|
|
1081
1162
|
|
|
1082
1163
|
|
|
@@ -1274,6 +1355,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1274
1355
|
|
|
1275
1356
|
|
|
1276
1357
|
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1277
1361
|
|
|
1278
1362
|
|
|
1279
1363
|
|
|
@@ -1358,6 +1442,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1358
1442
|
|
|
1359
1443
|
|
|
1360
1444
|
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
1361
1448
|
|
|
1362
1449
|
|
|
1363
1450
|
|
|
@@ -1467,6 +1554,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1467
1554
|
|
|
1468
1555
|
|
|
1469
1556
|
|
|
1557
|
+
|
|
1558
|
+
|
|
1559
|
+
|
|
1470
1560
|
|
|
1471
1561
|
|
|
1472
1562
|
|
|
@@ -1535,6 +1625,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1535
1625
|
|
|
1536
1626
|
|
|
1537
1627
|
|
|
1628
|
+
|
|
1629
|
+
|
|
1630
|
+
|
|
1538
1631
|
|
|
1539
1632
|
|
|
1540
1633
|
|
|
@@ -1586,6 +1679,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1586
1679
|
|
|
1587
1680
|
|
|
1588
1681
|
|
|
1682
|
+
|
|
1683
|
+
|
|
1684
|
+
|
|
1589
1685
|
|
|
1590
1686
|
|
|
1591
1687
|
|
|
@@ -1657,6 +1753,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1657
1753
|
|
|
1658
1754
|
|
|
1659
1755
|
|
|
1756
|
+
|
|
1757
|
+
|
|
1758
|
+
|
|
1660
1759
|
|
|
1661
1760
|
|
|
1662
1761
|
|
|
@@ -1791,54 +1890,6 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1791
1890
|
};
|
|
1792
1891
|
__name(_Deque, "Deque");
|
|
1793
1892
|
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
1893
|
/**
|
|
1843
1894
|
* data-structure-typed
|
|
1844
1895
|
*
|
|
@@ -1847,6 +1898,6 @@ var Range = _Range;
|
|
|
1847
1898
|
* @license MIT License
|
|
1848
1899
|
*/
|
|
1849
1900
|
|
|
1850
|
-
export { DFSOperation, Deque, ERR, Range };
|
|
1901
|
+
export { DFSOperation, Deque, ERR, Range, raise };
|
|
1851
1902
|
//# sourceMappingURL=index.mjs.map
|
|
1852
1903
|
//# sourceMappingURL=index.mjs.map
|