directed-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 +121 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +121 -6
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +121 -7
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +121 -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/directed-graph-typed.js +121 -7
- package/dist/umd/directed-graph-typed.js.map +1 -1
- package/dist/umd/directed-graph-typed.min.js +2 -2
- package/dist/umd/directed-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
|
@@ -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>`.
|
|
@@ -31,7 +31,8 @@ var directedGraphTyped = (() => {
|
|
|
31
31
|
DirectedGraph: () => DirectedGraph,
|
|
32
32
|
DirectedVertex: () => DirectedVertex,
|
|
33
33
|
ERR: () => ERR,
|
|
34
|
-
Range: () => Range
|
|
34
|
+
Range: () => Range,
|
|
35
|
+
raise: () => raise
|
|
35
36
|
});
|
|
36
37
|
|
|
37
38
|
// src/utils/utils.ts
|
|
@@ -56,6 +57,9 @@ var directedGraphTyped = (() => {
|
|
|
56
57
|
};
|
|
57
58
|
|
|
58
59
|
// src/common/error.ts
|
|
60
|
+
function raise(ErrorClass, message) {
|
|
61
|
+
throw new ErrorClass(message);
|
|
62
|
+
}
|
|
59
63
|
var ERR = {
|
|
60
64
|
// Range / index
|
|
61
65
|
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
@@ -77,7 +81,9 @@ var directedGraphTyped = (() => {
|
|
|
77
81
|
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
78
82
|
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
79
83
|
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
80
|
-
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}
|
|
84
|
+
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`,
|
|
85
|
+
// Order statistic
|
|
86
|
+
orderStatisticNotEnabled: (method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`
|
|
81
87
|
};
|
|
82
88
|
|
|
83
89
|
// src/common/index.ts
|
|
@@ -302,7 +308,7 @@ var directedGraphTyped = (() => {
|
|
|
302
308
|
if (options) {
|
|
303
309
|
const { toElementFn } = options;
|
|
304
310
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
305
|
-
else if (toElementFn)
|
|
311
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
306
312
|
}
|
|
307
313
|
}
|
|
308
314
|
/**
|
|
@@ -458,7 +464,7 @@ var directedGraphTyped = (() => {
|
|
|
458
464
|
acc = initialValue;
|
|
459
465
|
} else {
|
|
460
466
|
const first = iter.next();
|
|
461
|
-
if (first.done)
|
|
467
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
462
468
|
acc = first.value;
|
|
463
469
|
index = 1;
|
|
464
470
|
}
|
|
@@ -705,7 +711,7 @@ var directedGraphTyped = (() => {
|
|
|
705
711
|
__publicField(this, "_elements", []);
|
|
706
712
|
__publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
|
|
707
713
|
if (typeof a === "object" || typeof b === "object") {
|
|
708
|
-
|
|
714
|
+
raise(TypeError, ERR.comparatorRequired("Heap"));
|
|
709
715
|
}
|
|
710
716
|
if (a > b) return 1;
|
|
711
717
|
if (a < b) return -1;
|
|
@@ -758,6 +764,9 @@ var directedGraphTyped = (() => {
|
|
|
758
764
|
|
|
759
765
|
|
|
760
766
|
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
761
770
|
|
|
762
771
|
|
|
763
772
|
|
|
@@ -842,6 +851,9 @@ var directedGraphTyped = (() => {
|
|
|
842
851
|
|
|
843
852
|
|
|
844
853
|
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
845
857
|
|
|
846
858
|
|
|
847
859
|
|
|
@@ -896,6 +908,9 @@ var directedGraphTyped = (() => {
|
|
|
896
908
|
|
|
897
909
|
|
|
898
910
|
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
899
914
|
|
|
900
915
|
|
|
901
916
|
|
|
@@ -952,6 +967,9 @@ var directedGraphTyped = (() => {
|
|
|
952
967
|
|
|
953
968
|
|
|
954
969
|
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
955
973
|
|
|
956
974
|
|
|
957
975
|
|
|
@@ -1024,6 +1042,9 @@ var directedGraphTyped = (() => {
|
|
|
1024
1042
|
|
|
1025
1043
|
|
|
1026
1044
|
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1027
1048
|
|
|
1028
1049
|
|
|
1029
1050
|
|
|
@@ -1121,6 +1142,9 @@ var directedGraphTyped = (() => {
|
|
|
1121
1142
|
|
|
1122
1143
|
|
|
1123
1144
|
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1124
1148
|
|
|
1125
1149
|
|
|
1126
1150
|
|
|
@@ -1165,6 +1189,9 @@ var directedGraphTyped = (() => {
|
|
|
1165
1189
|
|
|
1166
1190
|
|
|
1167
1191
|
|
|
1192
|
+
|
|
1193
|
+
|
|
1194
|
+
|
|
1168
1195
|
|
|
1169
1196
|
|
|
1170
1197
|
|
|
@@ -1212,6 +1239,9 @@ var directedGraphTyped = (() => {
|
|
|
1212
1239
|
|
|
1213
1240
|
|
|
1214
1241
|
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1215
1245
|
|
|
1216
1246
|
|
|
1217
1247
|
|
|
@@ -1256,6 +1286,9 @@ var directedGraphTyped = (() => {
|
|
|
1256
1286
|
|
|
1257
1287
|
|
|
1258
1288
|
|
|
1289
|
+
|
|
1290
|
+
|
|
1291
|
+
|
|
1259
1292
|
|
|
1260
1293
|
|
|
1261
1294
|
|
|
@@ -1346,6 +1379,9 @@ var directedGraphTyped = (() => {
|
|
|
1346
1379
|
|
|
1347
1380
|
|
|
1348
1381
|
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
|
|
1349
1385
|
|
|
1350
1386
|
|
|
1351
1387
|
|
|
@@ -1423,6 +1459,9 @@ var directedGraphTyped = (() => {
|
|
|
1423
1459
|
|
|
1424
1460
|
|
|
1425
1461
|
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
|
|
1426
1465
|
|
|
1427
1466
|
|
|
1428
1467
|
|
|
@@ -1473,6 +1512,9 @@ var directedGraphTyped = (() => {
|
|
|
1473
1512
|
|
|
1474
1513
|
|
|
1475
1514
|
|
|
1515
|
+
|
|
1516
|
+
|
|
1517
|
+
|
|
1476
1518
|
|
|
1477
1519
|
|
|
1478
1520
|
|
|
@@ -1522,6 +1564,9 @@ var directedGraphTyped = (() => {
|
|
|
1522
1564
|
|
|
1523
1565
|
|
|
1524
1566
|
|
|
1567
|
+
|
|
1568
|
+
|
|
1569
|
+
|
|
1525
1570
|
|
|
1526
1571
|
|
|
1527
1572
|
|
|
@@ -1578,6 +1623,9 @@ var directedGraphTyped = (() => {
|
|
|
1578
1623
|
|
|
1579
1624
|
|
|
1580
1625
|
|
|
1626
|
+
|
|
1627
|
+
|
|
1628
|
+
|
|
1581
1629
|
|
|
1582
1630
|
|
|
1583
1631
|
|
|
@@ -1590,7 +1638,7 @@ var directedGraphTyped = (() => {
|
|
|
1590
1638
|
*/
|
|
1591
1639
|
map(callback, options, thisArg) {
|
|
1592
1640
|
const { comparator, toElementFn, ...rest } = options != null ? options : {};
|
|
1593
|
-
if (!comparator)
|
|
1641
|
+
if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
|
|
1594
1642
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
1595
1643
|
let i = 0;
|
|
1596
1644
|
for (const x of this) {
|
|
@@ -1776,6 +1824,9 @@ var directedGraphTyped = (() => {
|
|
|
1776
1824
|
|
|
1777
1825
|
|
|
1778
1826
|
|
|
1827
|
+
|
|
1828
|
+
|
|
1829
|
+
|
|
1779
1830
|
|
|
1780
1831
|
|
|
1781
1832
|
|
|
@@ -1823,6 +1874,9 @@ var directedGraphTyped = (() => {
|
|
|
1823
1874
|
|
|
1824
1875
|
|
|
1825
1876
|
|
|
1877
|
+
|
|
1878
|
+
|
|
1879
|
+
|
|
1826
1880
|
|
|
1827
1881
|
|
|
1828
1882
|
|
|
@@ -1886,6 +1940,9 @@ var directedGraphTyped = (() => {
|
|
|
1886
1940
|
|
|
1887
1941
|
|
|
1888
1942
|
|
|
1943
|
+
|
|
1944
|
+
|
|
1945
|
+
|
|
1889
1946
|
|
|
1890
1947
|
|
|
1891
1948
|
|
|
@@ -1945,6 +2002,9 @@ var directedGraphTyped = (() => {
|
|
|
1945
2002
|
|
|
1946
2003
|
|
|
1947
2004
|
|
|
2005
|
+
|
|
2006
|
+
|
|
2007
|
+
|
|
1948
2008
|
|
|
1949
2009
|
|
|
1950
2010
|
|
|
@@ -2011,6 +2071,9 @@ var directedGraphTyped = (() => {
|
|
|
2011
2071
|
|
|
2012
2072
|
|
|
2013
2073
|
|
|
2074
|
+
|
|
2075
|
+
|
|
2076
|
+
|
|
2014
2077
|
|
|
2015
2078
|
|
|
2016
2079
|
|
|
@@ -2067,6 +2130,9 @@ var directedGraphTyped = (() => {
|
|
|
2067
2130
|
|
|
2068
2131
|
|
|
2069
2132
|
|
|
2133
|
+
|
|
2134
|
+
|
|
2135
|
+
|
|
2070
2136
|
|
|
2071
2137
|
|
|
2072
2138
|
|
|
@@ -2116,6 +2182,9 @@ var directedGraphTyped = (() => {
|
|
|
2116
2182
|
|
|
2117
2183
|
|
|
2118
2184
|
|
|
2185
|
+
|
|
2186
|
+
|
|
2187
|
+
|
|
2119
2188
|
|
|
2120
2189
|
|
|
2121
2190
|
|
|
@@ -2206,6 +2275,9 @@ var directedGraphTyped = (() => {
|
|
|
2206
2275
|
|
|
2207
2276
|
|
|
2208
2277
|
|
|
2278
|
+
|
|
2279
|
+
|
|
2280
|
+
|
|
2209
2281
|
|
|
2210
2282
|
|
|
2211
2283
|
|
|
@@ -2249,6 +2321,9 @@ var directedGraphTyped = (() => {
|
|
|
2249
2321
|
|
|
2250
2322
|
|
|
2251
2323
|
|
|
2324
|
+
|
|
2325
|
+
|
|
2326
|
+
|
|
2252
2327
|
|
|
2253
2328
|
|
|
2254
2329
|
|
|
@@ -2315,6 +2390,9 @@ var directedGraphTyped = (() => {
|
|
|
2315
2390
|
|
|
2316
2391
|
|
|
2317
2392
|
|
|
2393
|
+
|
|
2394
|
+
|
|
2395
|
+
|
|
2318
2396
|
|
|
2319
2397
|
|
|
2320
2398
|
|
|
@@ -2365,6 +2443,9 @@ var directedGraphTyped = (() => {
|
|
|
2365
2443
|
|
|
2366
2444
|
|
|
2367
2445
|
|
|
2446
|
+
|
|
2447
|
+
|
|
2448
|
+
|
|
2368
2449
|
|
|
2369
2450
|
|
|
2370
2451
|
|
|
@@ -2419,6 +2500,9 @@ var directedGraphTyped = (() => {
|
|
|
2419
2500
|
|
|
2420
2501
|
|
|
2421
2502
|
|
|
2503
|
+
|
|
2504
|
+
|
|
2505
|
+
|
|
2422
2506
|
|
|
2423
2507
|
|
|
2424
2508
|
|
|
@@ -2651,7 +2735,7 @@ var directedGraphTyped = (() => {
|
|
|
2651
2735
|
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
2652
2736
|
return this._addEdge(newEdge);
|
|
2653
2737
|
} else {
|
|
2654
|
-
|
|
2738
|
+
raise(TypeError, ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
|
|
2655
2739
|
}
|
|
2656
2740
|
}
|
|
2657
2741
|
}
|
|
@@ -3546,6 +3630,9 @@ var directedGraphTyped = (() => {
|
|
|
3546
3630
|
|
|
3547
3631
|
|
|
3548
3632
|
|
|
3633
|
+
|
|
3634
|
+
|
|
3635
|
+
|
|
3549
3636
|
|
|
3550
3637
|
|
|
3551
3638
|
|
|
@@ -3631,6 +3718,9 @@ var directedGraphTyped = (() => {
|
|
|
3631
3718
|
|
|
3632
3719
|
|
|
3633
3720
|
|
|
3721
|
+
|
|
3722
|
+
|
|
3723
|
+
|
|
3634
3724
|
|
|
3635
3725
|
|
|
3636
3726
|
|
|
@@ -3714,6 +3804,9 @@ var directedGraphTyped = (() => {
|
|
|
3714
3804
|
|
|
3715
3805
|
|
|
3716
3806
|
|
|
3807
|
+
|
|
3808
|
+
|
|
3809
|
+
|
|
3717
3810
|
|
|
3718
3811
|
|
|
3719
3812
|
|
|
@@ -3788,6 +3881,9 @@ var directedGraphTyped = (() => {
|
|
|
3788
3881
|
|
|
3789
3882
|
|
|
3790
3883
|
|
|
3884
|
+
|
|
3885
|
+
|
|
3886
|
+
|
|
3791
3887
|
|
|
3792
3888
|
|
|
3793
3889
|
|
|
@@ -3839,6 +3935,9 @@ var directedGraphTyped = (() => {
|
|
|
3839
3935
|
|
|
3840
3936
|
|
|
3841
3937
|
|
|
3938
|
+
|
|
3939
|
+
|
|
3940
|
+
|
|
3842
3941
|
|
|
3843
3942
|
|
|
3844
3943
|
|
|
@@ -3943,6 +4042,9 @@ var directedGraphTyped = (() => {
|
|
|
3943
4042
|
|
|
3944
4043
|
|
|
3945
4044
|
|
|
4045
|
+
|
|
4046
|
+
|
|
4047
|
+
|
|
3946
4048
|
|
|
3947
4049
|
|
|
3948
4050
|
|
|
@@ -4028,6 +4130,9 @@ var directedGraphTyped = (() => {
|
|
|
4028
4130
|
|
|
4029
4131
|
|
|
4030
4132
|
|
|
4133
|
+
|
|
4134
|
+
|
|
4135
|
+
|
|
4031
4136
|
|
|
4032
4137
|
|
|
4033
4138
|
|
|
@@ -4075,6 +4180,9 @@ var directedGraphTyped = (() => {
|
|
|
4075
4180
|
|
|
4076
4181
|
|
|
4077
4182
|
|
|
4183
|
+
|
|
4184
|
+
|
|
4185
|
+
|
|
4078
4186
|
|
|
4079
4187
|
|
|
4080
4188
|
|
|
@@ -4175,6 +4283,9 @@ var directedGraphTyped = (() => {
|
|
|
4175
4283
|
|
|
4176
4284
|
|
|
4177
4285
|
|
|
4286
|
+
|
|
4287
|
+
|
|
4288
|
+
|
|
4178
4289
|
|
|
4179
4290
|
|
|
4180
4291
|
|
|
@@ -4278,6 +4389,9 @@ var directedGraphTyped = (() => {
|
|
|
4278
4389
|
|
|
4279
4390
|
|
|
4280
4391
|
|
|
4392
|
+
|
|
4393
|
+
|
|
4394
|
+
|
|
4281
4395
|
|
|
4282
4396
|
|
|
4283
4397
|
|