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/cjs/index.cjs
CHANGED
|
@@ -3,6 +3,61 @@
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
5
|
|
|
6
|
+
// src/common/error.ts
|
|
7
|
+
function raise(ErrorClass, message) {
|
|
8
|
+
throw new ErrorClass(message);
|
|
9
|
+
}
|
|
10
|
+
__name(raise, "raise");
|
|
11
|
+
var ERR = {
|
|
12
|
+
// Range / index
|
|
13
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
14
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
15
|
+
// Type / argument
|
|
16
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
17
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
18
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
19
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
20
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
21
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
22
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
23
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
24
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
25
|
+
// State / operation
|
|
26
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
27
|
+
// Matrix
|
|
28
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
29
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
30
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
31
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
32
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
33
|
+
// Order statistic
|
|
34
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/common/index.ts
|
|
38
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
39
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
40
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
41
|
+
return DFSOperation2;
|
|
42
|
+
})(DFSOperation || {});
|
|
43
|
+
var Range = class {
|
|
44
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
45
|
+
this.low = low;
|
|
46
|
+
this.high = high;
|
|
47
|
+
this.includeLow = includeLow;
|
|
48
|
+
this.includeHigh = includeHigh;
|
|
49
|
+
}
|
|
50
|
+
static {
|
|
51
|
+
__name(this, "Range");
|
|
52
|
+
}
|
|
53
|
+
// Determine whether a key is within the range
|
|
54
|
+
isInRange(key, comparator) {
|
|
55
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
56
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
57
|
+
return lowCheck && highCheck;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
6
61
|
// src/data-structures/base/iterable-element-base.ts
|
|
7
62
|
var IterableElementBase = class {
|
|
8
63
|
static {
|
|
@@ -21,7 +76,7 @@ var IterableElementBase = class {
|
|
|
21
76
|
if (options) {
|
|
22
77
|
const { toElementFn } = options;
|
|
23
78
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
24
|
-
else if (toElementFn)
|
|
79
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
25
80
|
}
|
|
26
81
|
}
|
|
27
82
|
/**
|
|
@@ -184,7 +239,7 @@ var IterableElementBase = class {
|
|
|
184
239
|
acc = initialValue;
|
|
185
240
|
} else {
|
|
186
241
|
const first = iter.next();
|
|
187
|
-
if (first.done)
|
|
242
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
188
243
|
acc = first.value;
|
|
189
244
|
index = 1;
|
|
190
245
|
}
|
|
@@ -757,6 +812,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
757
812
|
|
|
758
813
|
|
|
759
814
|
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
760
818
|
|
|
761
819
|
|
|
762
820
|
|
|
@@ -821,6 +879,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
821
879
|
|
|
822
880
|
|
|
823
881
|
|
|
882
|
+
|
|
883
|
+
|
|
884
|
+
|
|
824
885
|
|
|
825
886
|
|
|
826
887
|
|
|
@@ -890,6 +951,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
890
951
|
|
|
891
952
|
|
|
892
953
|
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
|
|
893
957
|
|
|
894
958
|
|
|
895
959
|
|
|
@@ -941,6 +1005,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
941
1005
|
|
|
942
1006
|
|
|
943
1007
|
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
944
1011
|
|
|
945
1012
|
|
|
946
1013
|
|
|
@@ -1053,6 +1120,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1053
1120
|
|
|
1054
1121
|
|
|
1055
1122
|
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
|
|
1056
1126
|
|
|
1057
1127
|
|
|
1058
1128
|
|
|
@@ -1109,6 +1179,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1109
1179
|
|
|
1110
1180
|
|
|
1111
1181
|
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
|
|
1112
1185
|
|
|
1113
1186
|
|
|
1114
1187
|
|
|
@@ -1154,6 +1227,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1154
1227
|
|
|
1155
1228
|
|
|
1156
1229
|
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1157
1233
|
|
|
1158
1234
|
|
|
1159
1235
|
|
|
@@ -1205,6 +1281,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1205
1281
|
|
|
1206
1282
|
|
|
1207
1283
|
|
|
1284
|
+
|
|
1285
|
+
|
|
1286
|
+
|
|
1208
1287
|
|
|
1209
1288
|
|
|
1210
1289
|
|
|
@@ -1261,6 +1340,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1261
1340
|
|
|
1262
1341
|
|
|
1263
1342
|
|
|
1343
|
+
|
|
1344
|
+
|
|
1345
|
+
|
|
1264
1346
|
|
|
1265
1347
|
|
|
1266
1348
|
|
|
@@ -1325,6 +1407,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1325
1407
|
|
|
1326
1408
|
|
|
1327
1409
|
|
|
1410
|
+
|
|
1411
|
+
|
|
1412
|
+
|
|
1328
1413
|
|
|
1329
1414
|
|
|
1330
1415
|
|
|
@@ -1366,6 +1451,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1366
1451
|
|
|
1367
1452
|
|
|
1368
1453
|
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1369
1457
|
|
|
1370
1458
|
|
|
1371
1459
|
|
|
@@ -1413,6 +1501,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1413
1501
|
|
|
1414
1502
|
|
|
1415
1503
|
|
|
1504
|
+
|
|
1505
|
+
|
|
1506
|
+
|
|
1416
1507
|
|
|
1417
1508
|
|
|
1418
1509
|
|
|
@@ -1626,6 +1717,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1626
1717
|
|
|
1627
1718
|
|
|
1628
1719
|
|
|
1720
|
+
|
|
1721
|
+
|
|
1722
|
+
|
|
1629
1723
|
|
|
1630
1724
|
|
|
1631
1725
|
|
|
@@ -1677,6 +1771,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1677
1771
|
|
|
1678
1772
|
|
|
1679
1773
|
|
|
1774
|
+
|
|
1775
|
+
|
|
1776
|
+
|
|
1680
1777
|
|
|
1681
1778
|
|
|
1682
1779
|
|
|
@@ -1756,6 +1853,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
|
|
|
1756
1853
|
|
|
1757
1854
|
|
|
1758
1855
|
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
|
|
1759
1859
|
|
|
1760
1860
|
|
|
1761
1861
|
|
|
@@ -1899,55 +1999,6 @@ function elementOrPredicate(input, equals) {
|
|
|
1899
1999
|
return (node) => equals(node.value, value);
|
|
1900
2000
|
}
|
|
1901
2001
|
__name(elementOrPredicate, "elementOrPredicate");
|
|
1902
|
-
|
|
1903
|
-
// src/common/error.ts
|
|
1904
|
-
var ERR = {
|
|
1905
|
-
// Range / index
|
|
1906
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
1907
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
1908
|
-
// Type / argument
|
|
1909
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
1910
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
1911
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
1912
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
1913
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
1914
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
1915
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
1916
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
1917
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
1918
|
-
// State / operation
|
|
1919
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
1920
|
-
// Matrix
|
|
1921
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
1922
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
1923
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
1924
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
1925
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
1926
|
-
};
|
|
1927
|
-
|
|
1928
|
-
// src/common/index.ts
|
|
1929
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
1930
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
1931
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
1932
|
-
return DFSOperation2;
|
|
1933
|
-
})(DFSOperation || {});
|
|
1934
|
-
var Range = class {
|
|
1935
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
1936
|
-
this.low = low;
|
|
1937
|
-
this.high = high;
|
|
1938
|
-
this.includeLow = includeLow;
|
|
1939
|
-
this.includeHigh = includeHigh;
|
|
1940
|
-
}
|
|
1941
|
-
static {
|
|
1942
|
-
__name(this, "Range");
|
|
1943
|
-
}
|
|
1944
|
-
// Determine whether a key is within the range
|
|
1945
|
-
isInRange(key, comparator) {
|
|
1946
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
1947
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
1948
|
-
return lowCheck && highCheck;
|
|
1949
|
-
}
|
|
1950
|
-
};
|
|
1951
2002
|
/**
|
|
1952
2003
|
* data-structure-typed
|
|
1953
2004
|
*
|
|
@@ -1961,5 +2012,6 @@ exports.ERR = ERR;
|
|
|
1961
2012
|
exports.Range = Range;
|
|
1962
2013
|
exports.SinglyLinkedList = SinglyLinkedList;
|
|
1963
2014
|
exports.SinglyLinkedListNode = SinglyLinkedListNode;
|
|
2015
|
+
exports.raise = raise;
|
|
1964
2016
|
//# sourceMappingURL=index.cjs.map
|
|
1965
2017
|
//# sourceMappingURL=index.cjs.map
|