undirected-graph-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 +118 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +118 -6
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +118 -7
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +118 -7
- 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/undirected-graph-typed.js +118 -7
- package/dist/umd/undirected-graph-typed.js.map +1 -1
- package/dist/umd/undirected-graph-typed.min.js +2 -2
- package/dist/umd/undirected-graph-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
|
@@ -23,6 +23,10 @@ var arrayRemove = /* @__PURE__ */ __name(function(array, predicate) {
|
|
|
23
23
|
}, "arrayRemove");
|
|
24
24
|
|
|
25
25
|
// src/common/error.ts
|
|
26
|
+
function raise(ErrorClass, message) {
|
|
27
|
+
throw new ErrorClass(message);
|
|
28
|
+
}
|
|
29
|
+
__name(raise, "raise");
|
|
26
30
|
var ERR = {
|
|
27
31
|
// Range / index
|
|
28
32
|
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
@@ -44,7 +48,9 @@ var ERR = {
|
|
|
44
48
|
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
45
49
|
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
46
50
|
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
47
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
51
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
52
|
+
// Order statistic
|
|
53
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
// src/common/index.ts
|
|
@@ -271,7 +277,7 @@ var IterableElementBase = class {
|
|
|
271
277
|
if (options) {
|
|
272
278
|
const { toElementFn } = options;
|
|
273
279
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
274
|
-
else if (toElementFn)
|
|
280
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
275
281
|
}
|
|
276
282
|
}
|
|
277
283
|
/**
|
|
@@ -434,7 +440,7 @@ var IterableElementBase = class {
|
|
|
434
440
|
acc = initialValue;
|
|
435
441
|
} else {
|
|
436
442
|
const first = iter.next();
|
|
437
|
-
if (first.done)
|
|
443
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
438
444
|
acc = first.value;
|
|
439
445
|
index = 1;
|
|
440
446
|
}
|
|
@@ -731,6 +737,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
731
737
|
|
|
732
738
|
|
|
733
739
|
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
734
743
|
|
|
735
744
|
|
|
736
745
|
|
|
@@ -814,6 +823,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
814
823
|
|
|
815
824
|
|
|
816
825
|
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
817
829
|
|
|
818
830
|
|
|
819
831
|
|
|
@@ -868,6 +880,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
868
880
|
|
|
869
881
|
|
|
870
882
|
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
|
|
871
886
|
|
|
872
887
|
|
|
873
888
|
|
|
@@ -924,6 +939,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
924
939
|
|
|
925
940
|
|
|
926
941
|
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
927
945
|
|
|
928
946
|
|
|
929
947
|
|
|
@@ -996,6 +1014,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
996
1014
|
|
|
997
1015
|
|
|
998
1016
|
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
999
1020
|
|
|
1000
1021
|
|
|
1001
1022
|
|
|
@@ -1093,6 +1114,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1093
1114
|
|
|
1094
1115
|
|
|
1095
1116
|
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1096
1120
|
|
|
1097
1121
|
|
|
1098
1122
|
|
|
@@ -1137,6 +1161,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1137
1161
|
|
|
1138
1162
|
|
|
1139
1163
|
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
|
|
1140
1167
|
|
|
1141
1168
|
|
|
1142
1169
|
|
|
@@ -1184,6 +1211,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1184
1211
|
|
|
1185
1212
|
|
|
1186
1213
|
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1187
1217
|
|
|
1188
1218
|
|
|
1189
1219
|
|
|
@@ -1228,6 +1258,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1228
1258
|
|
|
1229
1259
|
|
|
1230
1260
|
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1231
1264
|
|
|
1232
1265
|
|
|
1233
1266
|
|
|
@@ -1318,6 +1351,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1318
1351
|
|
|
1319
1352
|
|
|
1320
1353
|
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
|
|
1321
1357
|
|
|
1322
1358
|
|
|
1323
1359
|
|
|
@@ -1395,6 +1431,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1395
1431
|
|
|
1396
1432
|
|
|
1397
1433
|
|
|
1434
|
+
|
|
1435
|
+
|
|
1436
|
+
|
|
1398
1437
|
|
|
1399
1438
|
|
|
1400
1439
|
|
|
@@ -1445,6 +1484,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1445
1484
|
|
|
1446
1485
|
|
|
1447
1486
|
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1448
1490
|
|
|
1449
1491
|
|
|
1450
1492
|
|
|
@@ -1494,6 +1536,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1494
1536
|
|
|
1495
1537
|
|
|
1496
1538
|
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
|
|
1497
1542
|
|
|
1498
1543
|
|
|
1499
1544
|
|
|
@@ -1550,6 +1595,9 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1550
1595
|
|
|
1551
1596
|
|
|
1552
1597
|
|
|
1598
|
+
|
|
1599
|
+
|
|
1600
|
+
|
|
1553
1601
|
|
|
1554
1602
|
|
|
1555
1603
|
|
|
@@ -1562,7 +1610,7 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1562
1610
|
*/
|
|
1563
1611
|
map(callback, options, thisArg) {
|
|
1564
1612
|
const { comparator, toElementFn, ...rest } = options ?? {};
|
|
1565
|
-
if (!comparator)
|
|
1613
|
+
if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
|
|
1566
1614
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
1567
1615
|
let i = 0;
|
|
1568
1616
|
for (const x of this) {
|
|
@@ -1589,7 +1637,7 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1589
1637
|
}
|
|
1590
1638
|
_DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
|
|
1591
1639
|
if (typeof a === "object" || typeof b === "object") {
|
|
1592
|
-
|
|
1640
|
+
raise(TypeError, ERR.comparatorRequired("Heap"));
|
|
1593
1641
|
}
|
|
1594
1642
|
if (a > b) return 1;
|
|
1595
1643
|
if (a < b) return -1;
|
|
@@ -1760,6 +1808,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1760
1808
|
|
|
1761
1809
|
|
|
1762
1810
|
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
|
|
1763
1814
|
|
|
1764
1815
|
|
|
1765
1816
|
|
|
@@ -1807,6 +1858,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1807
1858
|
|
|
1808
1859
|
|
|
1809
1860
|
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
|
|
1810
1864
|
|
|
1811
1865
|
|
|
1812
1866
|
|
|
@@ -1870,6 +1924,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1870
1924
|
|
|
1871
1925
|
|
|
1872
1926
|
|
|
1927
|
+
|
|
1928
|
+
|
|
1929
|
+
|
|
1873
1930
|
|
|
1874
1931
|
|
|
1875
1932
|
|
|
@@ -1929,6 +1986,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1929
1986
|
|
|
1930
1987
|
|
|
1931
1988
|
|
|
1989
|
+
|
|
1990
|
+
|
|
1991
|
+
|
|
1932
1992
|
|
|
1933
1993
|
|
|
1934
1994
|
|
|
@@ -1995,6 +2055,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
1995
2055
|
|
|
1996
2056
|
|
|
1997
2057
|
|
|
2058
|
+
|
|
2059
|
+
|
|
2060
|
+
|
|
1998
2061
|
|
|
1999
2062
|
|
|
2000
2063
|
|
|
@@ -2051,6 +2114,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
2051
2114
|
|
|
2052
2115
|
|
|
2053
2116
|
|
|
2117
|
+
|
|
2118
|
+
|
|
2119
|
+
|
|
2054
2120
|
|
|
2055
2121
|
|
|
2056
2122
|
|
|
@@ -2100,6 +2166,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
2100
2166
|
|
|
2101
2167
|
|
|
2102
2168
|
|
|
2169
|
+
|
|
2170
|
+
|
|
2171
|
+
|
|
2103
2172
|
|
|
2104
2173
|
|
|
2105
2174
|
|
|
@@ -2190,6 +2259,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
2190
2259
|
|
|
2191
2260
|
|
|
2192
2261
|
|
|
2262
|
+
|
|
2263
|
+
|
|
2264
|
+
|
|
2193
2265
|
|
|
2194
2266
|
|
|
2195
2267
|
|
|
@@ -2233,6 +2305,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
2233
2305
|
|
|
2234
2306
|
|
|
2235
2307
|
|
|
2308
|
+
|
|
2309
|
+
|
|
2310
|
+
|
|
2236
2311
|
|
|
2237
2312
|
|
|
2238
2313
|
|
|
@@ -2299,6 +2374,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
2299
2374
|
|
|
2300
2375
|
|
|
2301
2376
|
|
|
2377
|
+
|
|
2378
|
+
|
|
2379
|
+
|
|
2302
2380
|
|
|
2303
2381
|
|
|
2304
2382
|
|
|
@@ -2349,6 +2427,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
2349
2427
|
|
|
2350
2428
|
|
|
2351
2429
|
|
|
2430
|
+
|
|
2431
|
+
|
|
2432
|
+
|
|
2352
2433
|
|
|
2353
2434
|
|
|
2354
2435
|
|
|
@@ -2403,6 +2484,9 @@ var Queue = class _Queue extends LinearBase {
|
|
|
2403
2484
|
|
|
2404
2485
|
|
|
2405
2486
|
|
|
2487
|
+
|
|
2488
|
+
|
|
2489
|
+
|
|
2406
2490
|
|
|
2407
2491
|
|
|
2408
2492
|
|
|
@@ -2642,7 +2726,7 @@ var AbstractGraph = class extends IterableEntryBase {
|
|
|
2642
2726
|
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
2643
2727
|
return this._addEdge(newEdge);
|
|
2644
2728
|
} else {
|
|
2645
|
-
|
|
2729
|
+
raise(TypeError, ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
|
|
2646
2730
|
}
|
|
2647
2731
|
}
|
|
2648
2732
|
}
|
|
@@ -3528,6 +3612,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3528
3612
|
|
|
3529
3613
|
|
|
3530
3614
|
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
|
|
3531
3618
|
|
|
3532
3619
|
|
|
3533
3620
|
|
|
@@ -3609,6 +3696,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3609
3696
|
|
|
3610
3697
|
|
|
3611
3698
|
|
|
3699
|
+
|
|
3700
|
+
|
|
3701
|
+
|
|
3612
3702
|
|
|
3613
3703
|
|
|
3614
3704
|
|
|
@@ -3690,6 +3780,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3690
3780
|
|
|
3691
3781
|
|
|
3692
3782
|
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
|
|
3693
3786
|
|
|
3694
3787
|
|
|
3695
3788
|
|
|
@@ -3785,6 +3878,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3785
3878
|
|
|
3786
3879
|
|
|
3787
3880
|
|
|
3881
|
+
|
|
3882
|
+
|
|
3883
|
+
|
|
3788
3884
|
|
|
3789
3885
|
|
|
3790
3886
|
|
|
@@ -3836,6 +3932,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3836
3932
|
|
|
3837
3933
|
|
|
3838
3934
|
|
|
3935
|
+
|
|
3936
|
+
|
|
3937
|
+
|
|
3839
3938
|
|
|
3840
3939
|
|
|
3841
3940
|
|
|
@@ -3957,6 +4056,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
3957
4056
|
|
|
3958
4057
|
|
|
3959
4058
|
|
|
4059
|
+
|
|
4060
|
+
|
|
4061
|
+
|
|
3960
4062
|
|
|
3961
4063
|
|
|
3962
4064
|
|
|
@@ -4100,6 +4202,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
4100
4202
|
|
|
4101
4203
|
|
|
4102
4204
|
|
|
4205
|
+
|
|
4206
|
+
|
|
4207
|
+
|
|
4103
4208
|
|
|
4104
4209
|
|
|
4105
4210
|
|
|
@@ -4165,6 +4270,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
4165
4270
|
|
|
4166
4271
|
|
|
4167
4272
|
|
|
4273
|
+
|
|
4274
|
+
|
|
4275
|
+
|
|
4168
4276
|
|
|
4169
4277
|
|
|
4170
4278
|
|
|
@@ -4212,6 +4320,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
4212
4320
|
|
|
4213
4321
|
|
|
4214
4322
|
|
|
4323
|
+
|
|
4324
|
+
|
|
4325
|
+
|
|
4215
4326
|
|
|
4216
4327
|
|
|
4217
4328
|
|
|
@@ -4277,6 +4388,6 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
|
|
|
4277
4388
|
* @license MIT License
|
|
4278
4389
|
*/
|
|
4279
4390
|
|
|
4280
|
-
export { DFSOperation, ERR, Range, UndirectedEdge, UndirectedGraph, UndirectedVertex };
|
|
4391
|
+
export { DFSOperation, ERR, Range, UndirectedEdge, UndirectedGraph, UndirectedVertex, raise };
|
|
4281
4392
|
//# sourceMappingURL=index.mjs.map
|
|
4282
4393
|
//# sourceMappingURL=index.mjs.map
|