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
|
@@ -8,6 +8,11 @@ export interface TreeMapOptions<K, V, R = [K, V]> {
|
|
|
8
8
|
* - `false`: store values on tree nodes (Node Mode).
|
|
9
9
|
*/
|
|
10
10
|
isMapMode?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Enable order-statistic operations (select, rank, rangeByRank).
|
|
13
|
+
* When true, subtree counts are maintained on every node.
|
|
14
|
+
*/
|
|
15
|
+
enableOrderStatistic?: boolean;
|
|
11
16
|
/**
|
|
12
17
|
* Transform raw elements into `[key, value]` entries.
|
|
13
18
|
* When provided, the constructor accepts `Iterable<R>` instead of `Iterable<[K, V]>`.
|
|
@@ -8,6 +8,10 @@ export interface TreeMultiSetOptions<K, R = K> {
|
|
|
8
8
|
* - `false`: Node Mode.
|
|
9
9
|
*/
|
|
10
10
|
isMapMode?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Enable order-statistic operations (select, rank, rangeByRank).
|
|
13
|
+
*/
|
|
14
|
+
enableOrderStatistic?: boolean;
|
|
11
15
|
/**
|
|
12
16
|
* Transform raw elements into keys.
|
|
13
17
|
* When provided, the constructor accepts `Iterable<R>` instead of `Iterable<K>`.
|
|
@@ -8,6 +8,10 @@ export interface TreeSetOptions<K, R = K> {
|
|
|
8
8
|
* - `false`: store values on tree nodes (Node Mode).
|
|
9
9
|
*/
|
|
10
10
|
isMapMode?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Enable order-statistic operations (select, rank, rangeByRank).
|
|
13
|
+
*/
|
|
14
|
+
enableOrderStatistic?: boolean;
|
|
11
15
|
/**
|
|
12
16
|
* Transform raw elements into keys.
|
|
13
17
|
* When provided, the constructor accepts `Iterable<R>` instead of `Iterable<K>`.
|
package/dist/umd/deque-typed.js
CHANGED
|
@@ -26,7 +26,8 @@ var dequeTyped = (() => {
|
|
|
26
26
|
DFSOperation: () => DFSOperation,
|
|
27
27
|
Deque: () => Deque,
|
|
28
28
|
ERR: () => ERR,
|
|
29
|
-
Range: () => Range
|
|
29
|
+
Range: () => Range,
|
|
30
|
+
raise: () => raise
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
// src/utils/utils.ts
|
|
@@ -37,6 +38,57 @@ var dequeTyped = (() => {
|
|
|
37
38
|
};
|
|
38
39
|
var calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
|
|
39
40
|
|
|
41
|
+
// src/common/error.ts
|
|
42
|
+
function raise(ErrorClass, message) {
|
|
43
|
+
throw new ErrorClass(message);
|
|
44
|
+
}
|
|
45
|
+
var ERR = {
|
|
46
|
+
// Range / index
|
|
47
|
+
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
48
|
+
invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
|
|
49
|
+
// Type / argument
|
|
50
|
+
invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
51
|
+
comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
|
|
52
|
+
invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
53
|
+
notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
|
|
54
|
+
invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
|
|
55
|
+
invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
|
|
56
|
+
invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
|
|
57
|
+
reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
|
|
58
|
+
callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
|
|
59
|
+
// State / operation
|
|
60
|
+
invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
61
|
+
// Matrix
|
|
62
|
+
matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
|
|
63
|
+
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
64
|
+
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
65
|
+
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
66
|
+
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`,
|
|
67
|
+
// Order statistic
|
|
68
|
+
orderStatisticNotEnabled: (method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/common/index.ts
|
|
72
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
73
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
74
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
75
|
+
return DFSOperation2;
|
|
76
|
+
})(DFSOperation || {});
|
|
77
|
+
var Range = class {
|
|
78
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
79
|
+
this.low = low;
|
|
80
|
+
this.high = high;
|
|
81
|
+
this.includeLow = includeLow;
|
|
82
|
+
this.includeHigh = includeHigh;
|
|
83
|
+
}
|
|
84
|
+
// Determine whether a key is within the range
|
|
85
|
+
isInRange(key, comparator) {
|
|
86
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
87
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
88
|
+
return lowCheck && highCheck;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
40
92
|
// src/data-structures/base/iterable-element-base.ts
|
|
41
93
|
var IterableElementBase = class {
|
|
42
94
|
/**
|
|
@@ -59,7 +111,7 @@ var dequeTyped = (() => {
|
|
|
59
111
|
if (options) {
|
|
60
112
|
const { toElementFn } = options;
|
|
61
113
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
62
|
-
else if (toElementFn)
|
|
114
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
63
115
|
}
|
|
64
116
|
}
|
|
65
117
|
/**
|
|
@@ -215,7 +267,7 @@ var dequeTyped = (() => {
|
|
|
215
267
|
acc = initialValue;
|
|
216
268
|
} else {
|
|
217
269
|
const first = iter.next();
|
|
218
|
-
if (first.done)
|
|
270
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
219
271
|
acc = first.value;
|
|
220
272
|
index = 1;
|
|
221
273
|
}
|
|
@@ -600,6 +652,9 @@ var dequeTyped = (() => {
|
|
|
600
652
|
|
|
601
653
|
|
|
602
654
|
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
603
658
|
|
|
604
659
|
|
|
605
660
|
|
|
@@ -655,6 +710,9 @@ var dequeTyped = (() => {
|
|
|
655
710
|
|
|
656
711
|
|
|
657
712
|
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
658
716
|
|
|
659
717
|
|
|
660
718
|
|
|
@@ -715,6 +773,9 @@ var dequeTyped = (() => {
|
|
|
715
773
|
|
|
716
774
|
|
|
717
775
|
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
718
779
|
|
|
719
780
|
|
|
720
781
|
|
|
@@ -788,6 +849,9 @@ var dequeTyped = (() => {
|
|
|
788
849
|
|
|
789
850
|
|
|
790
851
|
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
791
855
|
|
|
792
856
|
|
|
793
857
|
|
|
@@ -848,6 +912,9 @@ var dequeTyped = (() => {
|
|
|
848
912
|
|
|
849
913
|
|
|
850
914
|
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
851
918
|
|
|
852
919
|
|
|
853
920
|
|
|
@@ -909,6 +976,9 @@ var dequeTyped = (() => {
|
|
|
909
976
|
|
|
910
977
|
|
|
911
978
|
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
912
982
|
|
|
913
983
|
|
|
914
984
|
|
|
@@ -1011,6 +1081,9 @@ var dequeTyped = (() => {
|
|
|
1011
1081
|
|
|
1012
1082
|
|
|
1013
1083
|
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1014
1087
|
|
|
1015
1088
|
|
|
1016
1089
|
|
|
@@ -1053,6 +1126,9 @@ var dequeTyped = (() => {
|
|
|
1053
1126
|
|
|
1054
1127
|
|
|
1055
1128
|
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1056
1132
|
|
|
1057
1133
|
|
|
1058
1134
|
|
|
@@ -1099,6 +1175,9 @@ var dequeTyped = (() => {
|
|
|
1099
1175
|
|
|
1100
1176
|
|
|
1101
1177
|
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1102
1181
|
|
|
1103
1182
|
|
|
1104
1183
|
|
|
@@ -1296,6 +1375,9 @@ var dequeTyped = (() => {
|
|
|
1296
1375
|
|
|
1297
1376
|
|
|
1298
1377
|
|
|
1378
|
+
|
|
1379
|
+
|
|
1380
|
+
|
|
1299
1381
|
|
|
1300
1382
|
|
|
1301
1383
|
|
|
@@ -1380,6 +1462,9 @@ var dequeTyped = (() => {
|
|
|
1380
1462
|
|
|
1381
1463
|
|
|
1382
1464
|
|
|
1465
|
+
|
|
1466
|
+
|
|
1467
|
+
|
|
1383
1468
|
|
|
1384
1469
|
|
|
1385
1470
|
|
|
@@ -1489,6 +1574,9 @@ var dequeTyped = (() => {
|
|
|
1489
1574
|
|
|
1490
1575
|
|
|
1491
1576
|
|
|
1577
|
+
|
|
1578
|
+
|
|
1579
|
+
|
|
1492
1580
|
|
|
1493
1581
|
|
|
1494
1582
|
|
|
@@ -1557,6 +1645,9 @@ var dequeTyped = (() => {
|
|
|
1557
1645
|
|
|
1558
1646
|
|
|
1559
1647
|
|
|
1648
|
+
|
|
1649
|
+
|
|
1650
|
+
|
|
1560
1651
|
|
|
1561
1652
|
|
|
1562
1653
|
|
|
@@ -1608,6 +1699,9 @@ var dequeTyped = (() => {
|
|
|
1608
1699
|
|
|
1609
1700
|
|
|
1610
1701
|
|
|
1702
|
+
|
|
1703
|
+
|
|
1704
|
+
|
|
1611
1705
|
|
|
1612
1706
|
|
|
1613
1707
|
|
|
@@ -1679,6 +1773,9 @@ var dequeTyped = (() => {
|
|
|
1679
1773
|
|
|
1680
1774
|
|
|
1681
1775
|
|
|
1776
|
+
|
|
1777
|
+
|
|
1778
|
+
|
|
1682
1779
|
|
|
1683
1780
|
|
|
1684
1781
|
|
|
@@ -1811,52 +1908,6 @@ var dequeTyped = (() => {
|
|
|
1811
1908
|
}
|
|
1812
1909
|
}
|
|
1813
1910
|
};
|
|
1814
|
-
|
|
1815
|
-
// src/common/error.ts
|
|
1816
|
-
var ERR = {
|
|
1817
|
-
// Range / index
|
|
1818
|
-
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
1819
|
-
invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
|
|
1820
|
-
// Type / argument
|
|
1821
|
-
invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
1822
|
-
comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
|
|
1823
|
-
invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
1824
|
-
notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
|
|
1825
|
-
invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
|
|
1826
|
-
invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
|
|
1827
|
-
invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
|
|
1828
|
-
reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
|
|
1829
|
-
callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
|
|
1830
|
-
// State / operation
|
|
1831
|
-
invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
1832
|
-
// Matrix
|
|
1833
|
-
matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
|
|
1834
|
-
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
1835
|
-
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
1836
|
-
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
1837
|
-
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
|
|
1838
|
-
};
|
|
1839
|
-
|
|
1840
|
-
// src/common/index.ts
|
|
1841
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
1842
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
1843
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
1844
|
-
return DFSOperation2;
|
|
1845
|
-
})(DFSOperation || {});
|
|
1846
|
-
var Range = class {
|
|
1847
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
1848
|
-
this.low = low;
|
|
1849
|
-
this.high = high;
|
|
1850
|
-
this.includeLow = includeLow;
|
|
1851
|
-
this.includeHigh = includeHigh;
|
|
1852
|
-
}
|
|
1853
|
-
// Determine whether a key is within the range
|
|
1854
|
-
isInRange(key, comparator) {
|
|
1855
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
1856
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
1857
|
-
return lowCheck && highCheck;
|
|
1858
|
-
}
|
|
1859
|
-
};
|
|
1860
1911
|
return __toCommonJS(src_exports);
|
|
1861
1912
|
})();
|
|
1862
1913
|
/**
|