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
|
@@ -13,6 +13,60 @@ var rangeCheck = /* @__PURE__ */ __name((index, min, max, message) => {
|
|
|
13
13
|
}, "rangeCheck");
|
|
14
14
|
var calcMinUnitsRequired = /* @__PURE__ */ __name((totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize), "calcMinUnitsRequired");
|
|
15
15
|
|
|
16
|
+
// src/common/error.ts
|
|
17
|
+
function raise(ErrorClass, message) {
|
|
18
|
+
throw new ErrorClass(message);
|
|
19
|
+
}
|
|
20
|
+
__name(raise, "raise");
|
|
21
|
+
var ERR = {
|
|
22
|
+
// Range / index
|
|
23
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
24
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
25
|
+
// Type / argument
|
|
26
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
27
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
28
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
29
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
30
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
31
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
32
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
33
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
34
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
35
|
+
// State / operation
|
|
36
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
37
|
+
// Matrix
|
|
38
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
39
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
40
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
41
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
42
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
43
|
+
// Order statistic
|
|
44
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/common/index.ts
|
|
48
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
49
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
50
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
51
|
+
return DFSOperation2;
|
|
52
|
+
})(DFSOperation || {});
|
|
53
|
+
var _Range = class _Range {
|
|
54
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
55
|
+
this.low = low;
|
|
56
|
+
this.high = high;
|
|
57
|
+
this.includeLow = includeLow;
|
|
58
|
+
this.includeHigh = includeHigh;
|
|
59
|
+
}
|
|
60
|
+
// Determine whether a key is within the range
|
|
61
|
+
isInRange(key, comparator) {
|
|
62
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
63
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
64
|
+
return lowCheck && highCheck;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
__name(_Range, "Range");
|
|
68
|
+
var Range = _Range;
|
|
69
|
+
|
|
16
70
|
// src/data-structures/base/iterable-element-base.ts
|
|
17
71
|
var _IterableElementBase = class _IterableElementBase {
|
|
18
72
|
/**
|
|
@@ -35,7 +89,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
35
89
|
if (options) {
|
|
36
90
|
const { toElementFn } = options;
|
|
37
91
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
38
|
-
else if (toElementFn)
|
|
92
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
39
93
|
}
|
|
40
94
|
}
|
|
41
95
|
/**
|
|
@@ -191,7 +245,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
191
245
|
acc = initialValue;
|
|
192
246
|
} else {
|
|
193
247
|
const first = iter.next();
|
|
194
|
-
if (first.done)
|
|
248
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
195
249
|
acc = first.value;
|
|
196
250
|
index = 1;
|
|
197
251
|
}
|
|
@@ -580,6 +634,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
580
634
|
|
|
581
635
|
|
|
582
636
|
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
583
640
|
|
|
584
641
|
|
|
585
642
|
|
|
@@ -635,6 +692,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
635
692
|
|
|
636
693
|
|
|
637
694
|
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
638
698
|
|
|
639
699
|
|
|
640
700
|
|
|
@@ -695,6 +755,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
695
755
|
|
|
696
756
|
|
|
697
757
|
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
698
761
|
|
|
699
762
|
|
|
700
763
|
|
|
@@ -768,6 +831,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
768
831
|
|
|
769
832
|
|
|
770
833
|
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
771
837
|
|
|
772
838
|
|
|
773
839
|
|
|
@@ -828,6 +894,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
828
894
|
|
|
829
895
|
|
|
830
896
|
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
831
900
|
|
|
832
901
|
|
|
833
902
|
|
|
@@ -889,6 +958,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
889
958
|
|
|
890
959
|
|
|
891
960
|
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
|
|
892
964
|
|
|
893
965
|
|
|
894
966
|
|
|
@@ -991,6 +1063,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
991
1063
|
|
|
992
1064
|
|
|
993
1065
|
|
|
1066
|
+
|
|
1067
|
+
|
|
1068
|
+
|
|
994
1069
|
|
|
995
1070
|
|
|
996
1071
|
|
|
@@ -1033,6 +1108,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1033
1108
|
|
|
1034
1109
|
|
|
1035
1110
|
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1036
1114
|
|
|
1037
1115
|
|
|
1038
1116
|
|
|
@@ -1079,6 +1157,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1079
1157
|
|
|
1080
1158
|
|
|
1081
1159
|
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
|
|
1082
1163
|
|
|
1083
1164
|
|
|
1084
1165
|
|
|
@@ -1276,6 +1357,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1276
1357
|
|
|
1277
1358
|
|
|
1278
1359
|
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1279
1363
|
|
|
1280
1364
|
|
|
1281
1365
|
|
|
@@ -1360,6 +1444,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1360
1444
|
|
|
1361
1445
|
|
|
1362
1446
|
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
|
|
1363
1450
|
|
|
1364
1451
|
|
|
1365
1452
|
|
|
@@ -1469,6 +1556,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1469
1556
|
|
|
1470
1557
|
|
|
1471
1558
|
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
|
|
1472
1562
|
|
|
1473
1563
|
|
|
1474
1564
|
|
|
@@ -1537,6 +1627,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1537
1627
|
|
|
1538
1628
|
|
|
1539
1629
|
|
|
1630
|
+
|
|
1631
|
+
|
|
1632
|
+
|
|
1540
1633
|
|
|
1541
1634
|
|
|
1542
1635
|
|
|
@@ -1588,6 +1681,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1588
1681
|
|
|
1589
1682
|
|
|
1590
1683
|
|
|
1684
|
+
|
|
1685
|
+
|
|
1686
|
+
|
|
1591
1687
|
|
|
1592
1688
|
|
|
1593
1689
|
|
|
@@ -1659,6 +1755,9 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1659
1755
|
|
|
1660
1756
|
|
|
1661
1757
|
|
|
1758
|
+
|
|
1759
|
+
|
|
1760
|
+
|
|
1662
1761
|
|
|
1663
1762
|
|
|
1664
1763
|
|
|
@@ -1793,54 +1892,6 @@ var _Deque = class _Deque extends LinearBase {
|
|
|
1793
1892
|
};
|
|
1794
1893
|
__name(_Deque, "Deque");
|
|
1795
1894
|
var Deque = _Deque;
|
|
1796
|
-
|
|
1797
|
-
// src/common/error.ts
|
|
1798
|
-
var ERR = {
|
|
1799
|
-
// Range / index
|
|
1800
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
1801
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
1802
|
-
// Type / argument
|
|
1803
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
1804
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
1805
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
1806
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
1807
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
1808
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
1809
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
1810
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
1811
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
1812
|
-
// State / operation
|
|
1813
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
1814
|
-
// Matrix
|
|
1815
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
1816
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
1817
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
1818
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
1819
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
1820
|
-
};
|
|
1821
|
-
|
|
1822
|
-
// src/common/index.ts
|
|
1823
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
1824
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
1825
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
1826
|
-
return DFSOperation2;
|
|
1827
|
-
})(DFSOperation || {});
|
|
1828
|
-
var _Range = class _Range {
|
|
1829
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
1830
|
-
this.low = low;
|
|
1831
|
-
this.high = high;
|
|
1832
|
-
this.includeLow = includeLow;
|
|
1833
|
-
this.includeHigh = includeHigh;
|
|
1834
|
-
}
|
|
1835
|
-
// Determine whether a key is within the range
|
|
1836
|
-
isInRange(key, comparator) {
|
|
1837
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
1838
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
1839
|
-
return lowCheck && highCheck;
|
|
1840
|
-
}
|
|
1841
|
-
};
|
|
1842
|
-
__name(_Range, "Range");
|
|
1843
|
-
var Range = _Range;
|
|
1844
1895
|
/**
|
|
1845
1896
|
* data-structure-typed
|
|
1846
1897
|
*
|
|
@@ -1853,5 +1904,6 @@ exports.DFSOperation = DFSOperation;
|
|
|
1853
1904
|
exports.Deque = Deque;
|
|
1854
1905
|
exports.ERR = ERR;
|
|
1855
1906
|
exports.Range = Range;
|
|
1907
|
+
exports.raise = raise;
|
|
1856
1908
|
//# sourceMappingURL=index.cjs.map
|
|
1857
1909
|
//# sourceMappingURL=index.cjs.map
|