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
|
@@ -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>`.
|
|
@@ -27,9 +27,61 @@ var singlyLinkedListTyped = (() => {
|
|
|
27
27
|
ERR: () => ERR,
|
|
28
28
|
Range: () => Range,
|
|
29
29
|
SinglyLinkedList: () => SinglyLinkedList,
|
|
30
|
-
SinglyLinkedListNode: () => SinglyLinkedListNode
|
|
30
|
+
SinglyLinkedListNode: () => SinglyLinkedListNode,
|
|
31
|
+
raise: () => raise
|
|
31
32
|
});
|
|
32
33
|
|
|
34
|
+
// src/common/error.ts
|
|
35
|
+
function raise(ErrorClass, message) {
|
|
36
|
+
throw new ErrorClass(message);
|
|
37
|
+
}
|
|
38
|
+
var ERR = {
|
|
39
|
+
// Range / index
|
|
40
|
+
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
41
|
+
invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
|
|
42
|
+
// Type / argument
|
|
43
|
+
invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
44
|
+
comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
|
|
45
|
+
invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
46
|
+
notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
|
|
47
|
+
invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
|
|
48
|
+
invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
|
|
49
|
+
invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
|
|
50
|
+
reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
|
|
51
|
+
callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
|
|
52
|
+
// State / operation
|
|
53
|
+
invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
54
|
+
// Matrix
|
|
55
|
+
matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
|
|
56
|
+
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
57
|
+
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
58
|
+
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
59
|
+
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`,
|
|
60
|
+
// Order statistic
|
|
61
|
+
orderStatisticNotEnabled: (method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/common/index.ts
|
|
65
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
66
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
67
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
68
|
+
return DFSOperation2;
|
|
69
|
+
})(DFSOperation || {});
|
|
70
|
+
var Range = class {
|
|
71
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
72
|
+
this.low = low;
|
|
73
|
+
this.high = high;
|
|
74
|
+
this.includeLow = includeLow;
|
|
75
|
+
this.includeHigh = includeHigh;
|
|
76
|
+
}
|
|
77
|
+
// Determine whether a key is within the range
|
|
78
|
+
isInRange(key, comparator) {
|
|
79
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
80
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
81
|
+
return lowCheck && highCheck;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
33
85
|
// src/data-structures/base/iterable-element-base.ts
|
|
34
86
|
var IterableElementBase = class {
|
|
35
87
|
/**
|
|
@@ -52,7 +104,7 @@ var singlyLinkedListTyped = (() => {
|
|
|
52
104
|
if (options) {
|
|
53
105
|
const { toElementFn } = options;
|
|
54
106
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
55
|
-
else if (toElementFn)
|
|
107
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
56
108
|
}
|
|
57
109
|
}
|
|
58
110
|
/**
|
|
@@ -208,7 +260,7 @@ var singlyLinkedListTyped = (() => {
|
|
|
208
260
|
acc = initialValue;
|
|
209
261
|
} else {
|
|
210
262
|
const first = iter.next();
|
|
211
|
-
if (first.done)
|
|
263
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
212
264
|
acc = first.value;
|
|
213
265
|
index = 1;
|
|
214
266
|
}
|
|
@@ -768,6 +820,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
768
820
|
|
|
769
821
|
|
|
770
822
|
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
771
826
|
|
|
772
827
|
|
|
773
828
|
|
|
@@ -832,6 +887,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
832
887
|
|
|
833
888
|
|
|
834
889
|
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
835
893
|
|
|
836
894
|
|
|
837
895
|
|
|
@@ -902,6 +960,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
902
960
|
|
|
903
961
|
|
|
904
962
|
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
|
|
905
966
|
|
|
906
967
|
|
|
907
968
|
|
|
@@ -953,6 +1014,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
953
1014
|
|
|
954
1015
|
|
|
955
1016
|
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
956
1020
|
|
|
957
1021
|
|
|
958
1022
|
|
|
@@ -1065,6 +1129,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1065
1129
|
|
|
1066
1130
|
|
|
1067
1131
|
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1068
1135
|
|
|
1069
1136
|
|
|
1070
1137
|
|
|
@@ -1121,6 +1188,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1121
1188
|
|
|
1122
1189
|
|
|
1123
1190
|
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
|
|
1124
1194
|
|
|
1125
1195
|
|
|
1126
1196
|
|
|
@@ -1166,6 +1236,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1166
1236
|
|
|
1167
1237
|
|
|
1168
1238
|
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1169
1242
|
|
|
1170
1243
|
|
|
1171
1244
|
|
|
@@ -1217,6 +1290,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1217
1290
|
|
|
1218
1291
|
|
|
1219
1292
|
|
|
1293
|
+
|
|
1294
|
+
|
|
1295
|
+
|
|
1220
1296
|
|
|
1221
1297
|
|
|
1222
1298
|
|
|
@@ -1273,6 +1349,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1273
1349
|
|
|
1274
1350
|
|
|
1275
1351
|
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
|
|
1276
1355
|
|
|
1277
1356
|
|
|
1278
1357
|
|
|
@@ -1337,6 +1416,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1337
1416
|
|
|
1338
1417
|
|
|
1339
1418
|
|
|
1419
|
+
|
|
1420
|
+
|
|
1421
|
+
|
|
1340
1422
|
|
|
1341
1423
|
|
|
1342
1424
|
|
|
@@ -1378,6 +1460,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1378
1460
|
|
|
1379
1461
|
|
|
1380
1462
|
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
|
|
1381
1466
|
|
|
1382
1467
|
|
|
1383
1468
|
|
|
@@ -1425,6 +1510,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1425
1510
|
|
|
1426
1511
|
|
|
1427
1512
|
|
|
1513
|
+
|
|
1514
|
+
|
|
1515
|
+
|
|
1428
1516
|
|
|
1429
1517
|
|
|
1430
1518
|
|
|
@@ -1638,6 +1726,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1638
1726
|
|
|
1639
1727
|
|
|
1640
1728
|
|
|
1729
|
+
|
|
1730
|
+
|
|
1731
|
+
|
|
1641
1732
|
|
|
1642
1733
|
|
|
1643
1734
|
|
|
@@ -1689,6 +1780,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1689
1780
|
|
|
1690
1781
|
|
|
1691
1782
|
|
|
1783
|
+
|
|
1784
|
+
|
|
1785
|
+
|
|
1692
1786
|
|
|
1693
1787
|
|
|
1694
1788
|
|
|
@@ -1768,6 +1862,9 @@ var singlyLinkedListTyped = (() => {
|
|
|
1768
1862
|
|
|
1769
1863
|
|
|
1770
1864
|
|
|
1865
|
+
|
|
1866
|
+
|
|
1867
|
+
|
|
1771
1868
|
|
|
1772
1869
|
|
|
1773
1870
|
|
|
@@ -1910,52 +2007,6 @@ var singlyLinkedListTyped = (() => {
|
|
|
1910
2007
|
const value = input;
|
|
1911
2008
|
return (node) => equals(node.value, value);
|
|
1912
2009
|
}
|
|
1913
|
-
|
|
1914
|
-
// src/common/error.ts
|
|
1915
|
-
var ERR = {
|
|
1916
|
-
// Range / index
|
|
1917
|
-
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
1918
|
-
invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
|
|
1919
|
-
// Type / argument
|
|
1920
|
-
invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
1921
|
-
comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
|
|
1922
|
-
invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
1923
|
-
notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
|
|
1924
|
-
invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
|
|
1925
|
-
invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
|
|
1926
|
-
invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
|
|
1927
|
-
reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
|
|
1928
|
-
callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
|
|
1929
|
-
// State / operation
|
|
1930
|
-
invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
1931
|
-
// Matrix
|
|
1932
|
-
matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
|
|
1933
|
-
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
1934
|
-
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
1935
|
-
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
1936
|
-
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
|
|
1937
|
-
};
|
|
1938
|
-
|
|
1939
|
-
// src/common/index.ts
|
|
1940
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
1941
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
1942
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
1943
|
-
return DFSOperation2;
|
|
1944
|
-
})(DFSOperation || {});
|
|
1945
|
-
var Range = class {
|
|
1946
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
1947
|
-
this.low = low;
|
|
1948
|
-
this.high = high;
|
|
1949
|
-
this.includeLow = includeLow;
|
|
1950
|
-
this.includeHigh = includeHigh;
|
|
1951
|
-
}
|
|
1952
|
-
// Determine whether a key is within the range
|
|
1953
|
-
isInRange(key, comparator) {
|
|
1954
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
1955
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
1956
|
-
return lowCheck && highCheck;
|
|
1957
|
-
}
|
|
1958
|
-
};
|
|
1959
2010
|
return __toCommonJS(src_exports);
|
|
1960
2011
|
})();
|
|
1961
2012
|
/**
|