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
|
@@ -5,6 +5,60 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
5
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
6
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
7
|
|
|
8
|
+
// src/common/error.ts
|
|
9
|
+
function raise(ErrorClass, message) {
|
|
10
|
+
throw new ErrorClass(message);
|
|
11
|
+
}
|
|
12
|
+
__name(raise, "raise");
|
|
13
|
+
var ERR = {
|
|
14
|
+
// Range / index
|
|
15
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
16
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
17
|
+
// Type / argument
|
|
18
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
19
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
20
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
21
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
22
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
23
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
24
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
25
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
26
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
27
|
+
// State / operation
|
|
28
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
29
|
+
// Matrix
|
|
30
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
31
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
32
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
33
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
34
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
35
|
+
// Order statistic
|
|
36
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/common/index.ts
|
|
40
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
41
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
42
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
43
|
+
return DFSOperation2;
|
|
44
|
+
})(DFSOperation || {});
|
|
45
|
+
var _Range = class _Range {
|
|
46
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
47
|
+
this.low = low;
|
|
48
|
+
this.high = high;
|
|
49
|
+
this.includeLow = includeLow;
|
|
50
|
+
this.includeHigh = includeHigh;
|
|
51
|
+
}
|
|
52
|
+
// Determine whether a key is within the range
|
|
53
|
+
isInRange(key, comparator) {
|
|
54
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
55
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
56
|
+
return lowCheck && highCheck;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
__name(_Range, "Range");
|
|
60
|
+
var Range = _Range;
|
|
61
|
+
|
|
8
62
|
// src/data-structures/base/iterable-element-base.ts
|
|
9
63
|
var _IterableElementBase = class _IterableElementBase {
|
|
10
64
|
/**
|
|
@@ -27,7 +81,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
27
81
|
if (options) {
|
|
28
82
|
const { toElementFn } = options;
|
|
29
83
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
30
|
-
else if (toElementFn)
|
|
84
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
31
85
|
}
|
|
32
86
|
}
|
|
33
87
|
/**
|
|
@@ -183,7 +237,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
183
237
|
acc = initialValue;
|
|
184
238
|
} else {
|
|
185
239
|
const first = iter.next();
|
|
186
|
-
if (first.done)
|
|
240
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
187
241
|
acc = first.value;
|
|
188
242
|
index = 1;
|
|
189
243
|
}
|
|
@@ -753,6 +807,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
753
807
|
|
|
754
808
|
|
|
755
809
|
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
756
813
|
|
|
757
814
|
|
|
758
815
|
|
|
@@ -817,6 +874,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
817
874
|
|
|
818
875
|
|
|
819
876
|
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
820
880
|
|
|
821
881
|
|
|
822
882
|
|
|
@@ -887,6 +947,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
887
947
|
|
|
888
948
|
|
|
889
949
|
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
890
953
|
|
|
891
954
|
|
|
892
955
|
|
|
@@ -938,6 +1001,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
938
1001
|
|
|
939
1002
|
|
|
940
1003
|
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
|
|
941
1007
|
|
|
942
1008
|
|
|
943
1009
|
|
|
@@ -1050,6 +1116,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1050
1116
|
|
|
1051
1117
|
|
|
1052
1118
|
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1053
1122
|
|
|
1054
1123
|
|
|
1055
1124
|
|
|
@@ -1106,6 +1175,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1106
1175
|
|
|
1107
1176
|
|
|
1108
1177
|
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1109
1181
|
|
|
1110
1182
|
|
|
1111
1183
|
|
|
@@ -1151,6 +1223,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1151
1223
|
|
|
1152
1224
|
|
|
1153
1225
|
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
|
|
1154
1229
|
|
|
1155
1230
|
|
|
1156
1231
|
|
|
@@ -1202,6 +1277,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1202
1277
|
|
|
1203
1278
|
|
|
1204
1279
|
|
|
1280
|
+
|
|
1281
|
+
|
|
1282
|
+
|
|
1205
1283
|
|
|
1206
1284
|
|
|
1207
1285
|
|
|
@@ -1258,6 +1336,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1258
1336
|
|
|
1259
1337
|
|
|
1260
1338
|
|
|
1339
|
+
|
|
1340
|
+
|
|
1341
|
+
|
|
1261
1342
|
|
|
1262
1343
|
|
|
1263
1344
|
|
|
@@ -1322,6 +1403,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1322
1403
|
|
|
1323
1404
|
|
|
1324
1405
|
|
|
1406
|
+
|
|
1407
|
+
|
|
1408
|
+
|
|
1325
1409
|
|
|
1326
1410
|
|
|
1327
1411
|
|
|
@@ -1363,6 +1447,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1363
1447
|
|
|
1364
1448
|
|
|
1365
1449
|
|
|
1450
|
+
|
|
1451
|
+
|
|
1452
|
+
|
|
1366
1453
|
|
|
1367
1454
|
|
|
1368
1455
|
|
|
@@ -1410,6 +1497,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1410
1497
|
|
|
1411
1498
|
|
|
1412
1499
|
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
|
|
1413
1503
|
|
|
1414
1504
|
|
|
1415
1505
|
|
|
@@ -1623,6 +1713,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1623
1713
|
|
|
1624
1714
|
|
|
1625
1715
|
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
|
|
1626
1719
|
|
|
1627
1720
|
|
|
1628
1721
|
|
|
@@ -1674,6 +1767,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1674
1767
|
|
|
1675
1768
|
|
|
1676
1769
|
|
|
1770
|
+
|
|
1771
|
+
|
|
1772
|
+
|
|
1677
1773
|
|
|
1678
1774
|
|
|
1679
1775
|
|
|
@@ -1753,6 +1849,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
|
|
|
1753
1849
|
|
|
1754
1850
|
|
|
1755
1851
|
|
|
1852
|
+
|
|
1853
|
+
|
|
1854
|
+
|
|
1756
1855
|
|
|
1757
1856
|
|
|
1758
1857
|
|
|
@@ -1898,54 +1997,6 @@ function elementOrPredicate(input, equals) {
|
|
|
1898
1997
|
return (node) => equals(node.value, value);
|
|
1899
1998
|
}
|
|
1900
1999
|
__name(elementOrPredicate, "elementOrPredicate");
|
|
1901
|
-
|
|
1902
|
-
// src/common/error.ts
|
|
1903
|
-
var ERR = {
|
|
1904
|
-
// Range / index
|
|
1905
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
1906
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
1907
|
-
// Type / argument
|
|
1908
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
1909
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
1910
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
1911
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
1912
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
1913
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
1914
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
1915
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
1916
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
1917
|
-
// State / operation
|
|
1918
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
1919
|
-
// Matrix
|
|
1920
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
1921
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
1922
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
1923
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
1924
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
1925
|
-
};
|
|
1926
|
-
|
|
1927
|
-
// src/common/index.ts
|
|
1928
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
1929
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
1930
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
1931
|
-
return DFSOperation2;
|
|
1932
|
-
})(DFSOperation || {});
|
|
1933
|
-
var _Range = class _Range {
|
|
1934
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
1935
|
-
this.low = low;
|
|
1936
|
-
this.high = high;
|
|
1937
|
-
this.includeLow = includeLow;
|
|
1938
|
-
this.includeHigh = includeHigh;
|
|
1939
|
-
}
|
|
1940
|
-
// Determine whether a key is within the range
|
|
1941
|
-
isInRange(key, comparator) {
|
|
1942
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
1943
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
1944
|
-
return lowCheck && highCheck;
|
|
1945
|
-
}
|
|
1946
|
-
};
|
|
1947
|
-
__name(_Range, "Range");
|
|
1948
|
-
var Range = _Range;
|
|
1949
2000
|
/**
|
|
1950
2001
|
* data-structure-typed
|
|
1951
2002
|
*
|
|
@@ -1959,5 +2010,6 @@ exports.ERR = ERR;
|
|
|
1959
2010
|
exports.Range = Range;
|
|
1960
2011
|
exports.SinglyLinkedList = SinglyLinkedList;
|
|
1961
2012
|
exports.SinglyLinkedListNode = SinglyLinkedListNode;
|
|
2013
|
+
exports.raise = raise;
|
|
1962
2014
|
//# sourceMappingURL=index.cjs.map
|
|
1963
2015
|
//# sourceMappingURL=index.cjs.map
|