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
package/dist/cjs/index.cjs
CHANGED
|
@@ -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)
|
|
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)
|
|
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
|
}
|
|
@@ -583,6 +638,9 @@ var Deque = class extends LinearBase {
|
|
|
583
638
|
|
|
584
639
|
|
|
585
640
|
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
586
644
|
|
|
587
645
|
|
|
588
646
|
|
|
@@ -638,6 +696,9 @@ var Deque = class extends LinearBase {
|
|
|
638
696
|
|
|
639
697
|
|
|
640
698
|
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
|
|
641
702
|
|
|
642
703
|
|
|
643
704
|
|
|
@@ -698,6 +759,9 @@ var Deque = class extends LinearBase {
|
|
|
698
759
|
|
|
699
760
|
|
|
700
761
|
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
701
765
|
|
|
702
766
|
|
|
703
767
|
|
|
@@ -771,6 +835,9 @@ var Deque = class extends LinearBase {
|
|
|
771
835
|
|
|
772
836
|
|
|
773
837
|
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
774
841
|
|
|
775
842
|
|
|
776
843
|
|
|
@@ -831,6 +898,9 @@ var Deque = class extends LinearBase {
|
|
|
831
898
|
|
|
832
899
|
|
|
833
900
|
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
834
904
|
|
|
835
905
|
|
|
836
906
|
|
|
@@ -892,6 +962,9 @@ var Deque = class extends LinearBase {
|
|
|
892
962
|
|
|
893
963
|
|
|
894
964
|
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
|
|
895
968
|
|
|
896
969
|
|
|
897
970
|
|
|
@@ -994,6 +1067,9 @@ var Deque = class extends LinearBase {
|
|
|
994
1067
|
|
|
995
1068
|
|
|
996
1069
|
|
|
1070
|
+
|
|
1071
|
+
|
|
1072
|
+
|
|
997
1073
|
|
|
998
1074
|
|
|
999
1075
|
|
|
@@ -1036,6 +1112,9 @@ var Deque = class extends LinearBase {
|
|
|
1036
1112
|
|
|
1037
1113
|
|
|
1038
1114
|
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
|
|
1039
1118
|
|
|
1040
1119
|
|
|
1041
1120
|
|
|
@@ -1082,6 +1161,9 @@ var Deque = class extends LinearBase {
|
|
|
1082
1161
|
|
|
1083
1162
|
|
|
1084
1163
|
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
|
|
1085
1167
|
|
|
1086
1168
|
|
|
1087
1169
|
|
|
@@ -1279,6 +1361,9 @@ var Deque = class extends LinearBase {
|
|
|
1279
1361
|
|
|
1280
1362
|
|
|
1281
1363
|
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
|
|
1282
1367
|
|
|
1283
1368
|
|
|
1284
1369
|
|
|
@@ -1363,6 +1448,9 @@ var Deque = class extends LinearBase {
|
|
|
1363
1448
|
|
|
1364
1449
|
|
|
1365
1450
|
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
|
|
1366
1454
|
|
|
1367
1455
|
|
|
1368
1456
|
|
|
@@ -1472,6 +1560,9 @@ var Deque = class extends LinearBase {
|
|
|
1472
1560
|
|
|
1473
1561
|
|
|
1474
1562
|
|
|
1563
|
+
|
|
1564
|
+
|
|
1565
|
+
|
|
1475
1566
|
|
|
1476
1567
|
|
|
1477
1568
|
|
|
@@ -1540,6 +1631,9 @@ var Deque = class extends LinearBase {
|
|
|
1540
1631
|
|
|
1541
1632
|
|
|
1542
1633
|
|
|
1634
|
+
|
|
1635
|
+
|
|
1636
|
+
|
|
1543
1637
|
|
|
1544
1638
|
|
|
1545
1639
|
|
|
@@ -1591,6 +1685,9 @@ var Deque = class extends LinearBase {
|
|
|
1591
1685
|
|
|
1592
1686
|
|
|
1593
1687
|
|
|
1688
|
+
|
|
1689
|
+
|
|
1690
|
+
|
|
1594
1691
|
|
|
1595
1692
|
|
|
1596
1693
|
|
|
@@ -1662,6 +1759,9 @@ var Deque = class extends LinearBase {
|
|
|
1662
1759
|
|
|
1663
1760
|
|
|
1664
1761
|
|
|
1762
|
+
|
|
1763
|
+
|
|
1764
|
+
|
|
1665
1765
|
|
|
1666
1766
|
|
|
1667
1767
|
|
|
@@ -1794,55 +1894,6 @@ var Deque = class extends LinearBase {
|
|
|
1794
1894
|
}
|
|
1795
1895
|
}
|
|
1796
1896
|
};
|
|
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
1897
|
/**
|
|
1847
1898
|
* data-structure-typed
|
|
1848
1899
|
*
|
|
@@ -1855,5 +1906,6 @@ exports.DFSOperation = DFSOperation;
|
|
|
1855
1906
|
exports.Deque = Deque;
|
|
1856
1907
|
exports.ERR = ERR;
|
|
1857
1908
|
exports.Range = Range;
|
|
1909
|
+
exports.raise = raise;
|
|
1858
1910
|
//# sourceMappingURL=index.cjs.map
|
|
1859
1911
|
//# sourceMappingURL=index.cjs.map
|