singly-linked-list-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/singly-linked-list-typed.js +100 -49
- package/dist/umd/singly-linked-list-typed.js.map +1 -1
- package/dist/umd/singly-linked-list-typed.min.js +1 -1
- package/dist/umd/singly-linked-list-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
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
+
// src/common/error.ts
|
|
5
|
+
function raise(ErrorClass, message) {
|
|
6
|
+
throw new ErrorClass(message);
|
|
7
|
+
}
|
|
8
|
+
__name(raise, "raise");
|
|
9
|
+
var ERR = {
|
|
10
|
+
// Range / index
|
|
11
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
12
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
13
|
+
// Type / argument
|
|
14
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
15
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
16
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
17
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
18
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
19
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
20
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
21
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
22
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
23
|
+
// State / operation
|
|
24
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
25
|
+
// Matrix
|
|
26
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
27
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
28
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
29
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
30
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
31
|
+
// Order statistic
|
|
32
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/common/index.ts
|
|
36
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
37
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
38
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
39
|
+
return DFSOperation2;
|
|
40
|
+
})(DFSOperation || {});
|
|
41
|
+
var Range = class {
|
|
42
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
43
|
+
this.low = low;
|
|
44
|
+
this.high = high;
|
|
45
|
+
this.includeLow = includeLow;
|
|
46
|
+
this.includeHigh = includeHigh;
|
|
47
|
+
}
|
|
48
|
+
static {
|
|
49
|
+
__name(this, "Range");
|
|
50
|
+
}
|
|
51
|
+
// Determine whether a key is within the range
|
|
52
|
+
isInRange(key, comparator) {
|
|
53
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
54
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
55
|
+
return lowCheck && highCheck;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
4
59
|
// src/data-structures/base/iterable-element-base.ts
|
|
5
60
|
var IterableElementBase = class {
|
|
6
61
|
static {
|
|
@@ -19,7 +74,7 @@ var IterableElementBase = class {
|
|
|
19
74
|
if (options) {
|
|
20
75
|
const { toElementFn } = options;
|
|
21
76
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
22
|
-
else if (toElementFn)
|
|
77
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
23
78
|
}
|
|
24
79
|
}
|
|
25
80
|
/**
|
|
@@ -182,7 +237,7 @@ var IterableElementBase = class {
|
|
|
182
237
|
acc = initialValue;
|
|
183
238
|
} else {
|
|
184
239
|
const first = iter.next();
|
|
185
|
-
if (first.done)
|
|
240
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
186
241
|
acc = first.value;
|
|
187
242
|
index = 1;
|
|
188
243
|
}
|
|
@@ -755,6 +810,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
755
810
|
|
|
756
811
|
|
|
757
812
|
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
758
816
|
|
|
759
817
|
|
|
760
818
|
|
|
@@ -819,6 +877,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
819
877
|
|
|
820
878
|
|
|
821
879
|
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
|
|
822
883
|
|
|
823
884
|
|
|
824
885
|
|
|
@@ -888,6 +949,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
888
949
|
|
|
889
950
|
|
|
890
951
|
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
|
|
891
955
|
|
|
892
956
|
|
|
893
957
|
|
|
@@ -939,6 +1003,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
939
1003
|
|
|
940
1004
|
|
|
941
1005
|
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
|
|
942
1009
|
|
|
943
1010
|
|
|
944
1011
|
|
|
@@ -1051,6 +1118,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1051
1118
|
|
|
1052
1119
|
|
|
1053
1120
|
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
|
|
1054
1124
|
|
|
1055
1125
|
|
|
1056
1126
|
|
|
@@ -1107,6 +1177,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1107
1177
|
|
|
1108
1178
|
|
|
1109
1179
|
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1110
1183
|
|
|
1111
1184
|
|
|
1112
1185
|
|
|
@@ -1152,6 +1225,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1152
1225
|
|
|
1153
1226
|
|
|
1154
1227
|
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
|
|
1155
1231
|
|
|
1156
1232
|
|
|
1157
1233
|
|
|
@@ -1203,6 +1279,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1203
1279
|
|
|
1204
1280
|
|
|
1205
1281
|
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
|
|
1206
1285
|
|
|
1207
1286
|
|
|
1208
1287
|
|
|
@@ -1259,6 +1338,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1259
1338
|
|
|
1260
1339
|
|
|
1261
1340
|
|
|
1341
|
+
|
|
1342
|
+
|
|
1343
|
+
|
|
1262
1344
|
|
|
1263
1345
|
|
|
1264
1346
|
|
|
@@ -1323,6 +1405,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1323
1405
|
|
|
1324
1406
|
|
|
1325
1407
|
|
|
1408
|
+
|
|
1409
|
+
|
|
1410
|
+
|
|
1326
1411
|
|
|
1327
1412
|
|
|
1328
1413
|
|
|
@@ -1364,6 +1449,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1364
1449
|
|
|
1365
1450
|
|
|
1366
1451
|
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1367
1455
|
|
|
1368
1456
|
|
|
1369
1457
|
|
|
@@ -1411,6 +1499,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1411
1499
|
|
|
1412
1500
|
|
|
1413
1501
|
|
|
1502
|
+
|
|
1503
|
+
|
|
1504
|
+
|
|
1414
1505
|
|
|
1415
1506
|
|
|
1416
1507
|
|
|
@@ -1624,6 +1715,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1624
1715
|
|
|
1625
1716
|
|
|
1626
1717
|
|
|
1718
|
+
|
|
1719
|
+
|
|
1720
|
+
|
|
1627
1721
|
|
|
1628
1722
|
|
|
1629
1723
|
|
|
@@ -1675,6 +1769,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1675
1769
|
|
|
1676
1770
|
|
|
1677
1771
|
|
|
1772
|
+
|
|
1773
|
+
|
|
1774
|
+
|
|
1678
1775
|
|
|
1679
1776
|
|
|
1680
1777
|
|
|
@@ -1754,6 +1851,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1754
1851
|
|
|
1755
1852
|
|
|
1756
1853
|
|
|
1854
|
+
|
|
1855
|
+
|
|
1856
|
+
|
|
1757
1857
|
|
|
1758
1858
|
|
|
1759
1859
|
|
|
@@ -1897,55 +1997,6 @@ function elementOrPredicate(input, equals) {
|
|
|
1897
1997
|
return (node) => equals(node.value, value);
|
|
1898
1998
|
}
|
|
1899
1999
|
__name(elementOrPredicate, "elementOrPredicate");
|
|
1900
|
-
|
|
1901
|
-
// src/common/error.ts
|
|
1902
|
-
var ERR = {
|
|
1903
|
-
// Range / index
|
|
1904
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
1905
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
1906
|
-
// Type / argument
|
|
1907
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
1908
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
1909
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
1910
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
1911
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
1912
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
1913
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
1914
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
1915
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
1916
|
-
// State / operation
|
|
1917
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
1918
|
-
// Matrix
|
|
1919
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
1920
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
1921
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
1922
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
1923
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
1924
|
-
};
|
|
1925
|
-
|
|
1926
|
-
// src/common/index.ts
|
|
1927
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
1928
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
1929
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
1930
|
-
return DFSOperation2;
|
|
1931
|
-
})(DFSOperation || {});
|
|
1932
|
-
var Range = class {
|
|
1933
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
1934
|
-
this.low = low;
|
|
1935
|
-
this.high = high;
|
|
1936
|
-
this.includeLow = includeLow;
|
|
1937
|
-
this.includeHigh = includeHigh;
|
|
1938
|
-
}
|
|
1939
|
-
static {
|
|
1940
|
-
__name(this, "Range");
|
|
1941
|
-
}
|
|
1942
|
-
// Determine whether a key is within the range
|
|
1943
|
-
isInRange(key, comparator) {
|
|
1944
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
1945
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
1946
|
-
return lowCheck && highCheck;
|
|
1947
|
-
}
|
|
1948
|
-
};
|
|
1949
2000
|
/**
|
|
1950
2001
|
* data-structure-typed
|
|
1951
2002
|
*
|
|
@@ -1954,6 +2005,6 @@ var Range = class {
|
|
|
1954
2005
|
* @license MIT License
|
|
1955
2006
|
*/
|
|
1956
2007
|
|
|
1957
|
-
export { DFSOperation, ERR, Range, SinglyLinkedList, SinglyLinkedListNode };
|
|
2008
|
+
export { DFSOperation, ERR, Range, SinglyLinkedList, SinglyLinkedListNode, raise };
|
|
1958
2009
|
//# sourceMappingURL=index.mjs.map
|
|
1959
2010
|
//# sourceMappingURL=index.mjs.map
|