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/esm/index.mjs
CHANGED
|
@@ -9,6 +9,61 @@ var rangeCheck = /* @__PURE__ */ __name((index, min, max, message) => {
|
|
|
9
9
|
}, "rangeCheck");
|
|
10
10
|
var calcMinUnitsRequired = /* @__PURE__ */ __name((totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize), "calcMinUnitsRequired");
|
|
11
11
|
|
|
12
|
+
// src/common/error.ts
|
|
13
|
+
function raise(ErrorClass, message) {
|
|
14
|
+
throw new ErrorClass(message);
|
|
15
|
+
}
|
|
16
|
+
__name(raise, "raise");
|
|
17
|
+
var ERR = {
|
|
18
|
+
// Range / index
|
|
19
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
20
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
21
|
+
// Type / argument
|
|
22
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
23
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
24
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
25
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
26
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
27
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
28
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
29
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
30
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
31
|
+
// State / operation
|
|
32
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
33
|
+
// Matrix
|
|
34
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
35
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
36
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
37
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
38
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
39
|
+
// Order statistic
|
|
40
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/common/index.ts
|
|
44
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
45
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
46
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
47
|
+
return DFSOperation2;
|
|
48
|
+
})(DFSOperation || {});
|
|
49
|
+
var Range = class {
|
|
50
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
51
|
+
this.low = low;
|
|
52
|
+
this.high = high;
|
|
53
|
+
this.includeLow = includeLow;
|
|
54
|
+
this.includeHigh = includeHigh;
|
|
55
|
+
}
|
|
56
|
+
static {
|
|
57
|
+
__name(this, "Range");
|
|
58
|
+
}
|
|
59
|
+
// Determine whether a key is within the range
|
|
60
|
+
isInRange(key, comparator) {
|
|
61
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
62
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
63
|
+
return lowCheck && highCheck;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
12
67
|
// src/data-structures/base/iterable-element-base.ts
|
|
13
68
|
var IterableElementBase = class {
|
|
14
69
|
static {
|
|
@@ -27,7 +82,7 @@ var IterableElementBase = class {
|
|
|
27
82
|
if (options) {
|
|
28
83
|
const { toElementFn } = options;
|
|
29
84
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
30
|
-
else if (toElementFn)
|
|
85
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
31
86
|
}
|
|
32
87
|
}
|
|
33
88
|
/**
|
|
@@ -190,7 +245,7 @@ var IterableElementBase = class {
|
|
|
190
245
|
acc = initialValue;
|
|
191
246
|
} else {
|
|
192
247
|
const first = iter.next();
|
|
193
|
-
if (first.done)
|
|
248
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
194
249
|
acc = first.value;
|
|
195
250
|
index = 1;
|
|
196
251
|
}
|
|
@@ -581,6 +636,9 @@ var Deque = class extends LinearBase {
|
|
|
581
636
|
|
|
582
637
|
|
|
583
638
|
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
584
642
|
|
|
585
643
|
|
|
586
644
|
|
|
@@ -636,6 +694,9 @@ var Deque = class extends LinearBase {
|
|
|
636
694
|
|
|
637
695
|
|
|
638
696
|
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
|
|
639
700
|
|
|
640
701
|
|
|
641
702
|
|
|
@@ -696,6 +757,9 @@ var Deque = class extends LinearBase {
|
|
|
696
757
|
|
|
697
758
|
|
|
698
759
|
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
699
763
|
|
|
700
764
|
|
|
701
765
|
|
|
@@ -769,6 +833,9 @@ var Deque = class extends LinearBase {
|
|
|
769
833
|
|
|
770
834
|
|
|
771
835
|
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
772
839
|
|
|
773
840
|
|
|
774
841
|
|
|
@@ -829,6 +896,9 @@ var Deque = class extends LinearBase {
|
|
|
829
896
|
|
|
830
897
|
|
|
831
898
|
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
832
902
|
|
|
833
903
|
|
|
834
904
|
|
|
@@ -890,6 +960,9 @@ var Deque = class extends LinearBase {
|
|
|
890
960
|
|
|
891
961
|
|
|
892
962
|
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
|
|
893
966
|
|
|
894
967
|
|
|
895
968
|
|
|
@@ -992,6 +1065,9 @@ var Deque = class extends LinearBase {
|
|
|
992
1065
|
|
|
993
1066
|
|
|
994
1067
|
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
|
|
995
1071
|
|
|
996
1072
|
|
|
997
1073
|
|
|
@@ -1034,6 +1110,9 @@ var Deque = class extends LinearBase {
|
|
|
1034
1110
|
|
|
1035
1111
|
|
|
1036
1112
|
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
|
|
1037
1116
|
|
|
1038
1117
|
|
|
1039
1118
|
|
|
@@ -1080,6 +1159,9 @@ var Deque = class extends LinearBase {
|
|
|
1080
1159
|
|
|
1081
1160
|
|
|
1082
1161
|
|
|
1162
|
+
|
|
1163
|
+
|
|
1164
|
+
|
|
1083
1165
|
|
|
1084
1166
|
|
|
1085
1167
|
|
|
@@ -1277,6 +1359,9 @@ var Deque = class extends LinearBase {
|
|
|
1277
1359
|
|
|
1278
1360
|
|
|
1279
1361
|
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1280
1365
|
|
|
1281
1366
|
|
|
1282
1367
|
|
|
@@ -1361,6 +1446,9 @@ var Deque = class extends LinearBase {
|
|
|
1361
1446
|
|
|
1362
1447
|
|
|
1363
1448
|
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1364
1452
|
|
|
1365
1453
|
|
|
1366
1454
|
|
|
@@ -1470,6 +1558,9 @@ var Deque = class extends LinearBase {
|
|
|
1470
1558
|
|
|
1471
1559
|
|
|
1472
1560
|
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
|
|
1473
1564
|
|
|
1474
1565
|
|
|
1475
1566
|
|
|
@@ -1538,6 +1629,9 @@ var Deque = class extends LinearBase {
|
|
|
1538
1629
|
|
|
1539
1630
|
|
|
1540
1631
|
|
|
1632
|
+
|
|
1633
|
+
|
|
1634
|
+
|
|
1541
1635
|
|
|
1542
1636
|
|
|
1543
1637
|
|
|
@@ -1589,6 +1683,9 @@ var Deque = class extends LinearBase {
|
|
|
1589
1683
|
|
|
1590
1684
|
|
|
1591
1685
|
|
|
1686
|
+
|
|
1687
|
+
|
|
1688
|
+
|
|
1592
1689
|
|
|
1593
1690
|
|
|
1594
1691
|
|
|
@@ -1660,6 +1757,9 @@ var Deque = class extends LinearBase {
|
|
|
1660
1757
|
|
|
1661
1758
|
|
|
1662
1759
|
|
|
1760
|
+
|
|
1761
|
+
|
|
1762
|
+
|
|
1663
1763
|
|
|
1664
1764
|
|
|
1665
1765
|
|
|
@@ -1792,55 +1892,6 @@ var Deque = class extends LinearBase {
|
|
|
1792
1892
|
}
|
|
1793
1893
|
}
|
|
1794
1894
|
};
|
|
1795
|
-
|
|
1796
|
-
// src/common/error.ts
|
|
1797
|
-
var ERR = {
|
|
1798
|
-
// Range / index
|
|
1799
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
1800
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
1801
|
-
// Type / argument
|
|
1802
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
1803
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
1804
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
1805
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
1806
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
1807
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
1808
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
1809
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
1810
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
1811
|
-
// State / operation
|
|
1812
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
1813
|
-
// Matrix
|
|
1814
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
1815
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
1816
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
1817
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
1818
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
1819
|
-
};
|
|
1820
|
-
|
|
1821
|
-
// src/common/index.ts
|
|
1822
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
1823
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
1824
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
1825
|
-
return DFSOperation2;
|
|
1826
|
-
})(DFSOperation || {});
|
|
1827
|
-
var Range = class {
|
|
1828
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
1829
|
-
this.low = low;
|
|
1830
|
-
this.high = high;
|
|
1831
|
-
this.includeLow = includeLow;
|
|
1832
|
-
this.includeHigh = includeHigh;
|
|
1833
|
-
}
|
|
1834
|
-
static {
|
|
1835
|
-
__name(this, "Range");
|
|
1836
|
-
}
|
|
1837
|
-
// Determine whether a key is within the range
|
|
1838
|
-
isInRange(key, comparator) {
|
|
1839
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
1840
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
1841
|
-
return lowCheck && highCheck;
|
|
1842
|
-
}
|
|
1843
|
-
};
|
|
1844
1895
|
/**
|
|
1845
1896
|
* data-structure-typed
|
|
1846
1897
|
*
|
|
@@ -1849,6 +1900,6 @@ var Range = class {
|
|
|
1849
1900
|
* @license MIT License
|
|
1850
1901
|
*/
|
|
1851
1902
|
|
|
1852
|
-
export { DFSOperation, Deque, ERR, Range };
|
|
1903
|
+
export { DFSOperation, Deque, ERR, Range, raise };
|
|
1853
1904
|
//# sourceMappingURL=index.mjs.map
|
|
1854
1905
|
//# sourceMappingURL=index.mjs.map
|