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.
Files changed (73) hide show
  1. package/dist/cjs/index.cjs +118 -6
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +118 -6
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +118 -7
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +118 -7
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/common/error.d.ts +9 -0
  10. package/dist/types/common/index.d.ts +1 -1
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +77 -2
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -0
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +409 -0
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -0
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  24. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +51 -0
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +45 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  32. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  33. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  34. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  37. package/dist/umd/undirected-graph-typed.js +118 -7
  38. package/dist/umd/undirected-graph-typed.js.map +1 -1
  39. package/dist/umd/undirected-graph-typed.min.js +2 -2
  40. package/dist/umd/undirected-graph-typed.min.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/common/error.ts +19 -1
  43. package/src/common/index.ts +1 -1
  44. package/src/data-structures/base/iterable-element-base.ts +3 -2
  45. package/src/data-structures/binary-tree/avl-tree.ts +47 -0
  46. package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
  47. package/src/data-structures/binary-tree/binary-tree.ts +79 -4
  48. package/src/data-structures/binary-tree/bst.ts +441 -6
  49. package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
  50. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  51. package/src/data-structures/binary-tree/tree-map.ts +434 -9
  52. package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
  53. package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
  54. package/src/data-structures/binary-tree/tree-set.ts +410 -8
  55. package/src/data-structures/graph/abstract-graph.ts +2 -2
  56. package/src/data-structures/graph/directed-graph.ts +30 -0
  57. package/src/data-structures/graph/undirected-graph.ts +27 -0
  58. package/src/data-structures/hash/hash-map.ts +35 -4
  59. package/src/data-structures/heap/heap.ts +46 -4
  60. package/src/data-structures/heap/max-heap.ts +2 -2
  61. package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
  62. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  63. package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
  64. package/src/data-structures/matrix/matrix.ts +33 -9
  65. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  66. package/src/data-structures/queue/deque.ts +45 -0
  67. package/src/data-structures/queue/queue.ts +36 -0
  68. package/src/data-structures/stack/stack.ts +30 -0
  69. package/src/data-structures/trie/trie.ts +38 -2
  70. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  71. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  72. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  73. 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>`.
@@ -28,7 +28,8 @@ var undirectedGraphTyped = (() => {
28
28
  Range: () => Range,
29
29
  UndirectedEdge: () => UndirectedEdge,
30
30
  UndirectedGraph: () => UndirectedGraph,
31
- UndirectedVertex: () => UndirectedVertex
31
+ UndirectedVertex: () => UndirectedVertex,
32
+ raise: () => raise
32
33
  });
33
34
 
34
35
  // src/utils/utils.ts
@@ -53,6 +54,9 @@ var undirectedGraphTyped = (() => {
53
54
  };
54
55
 
55
56
  // src/common/error.ts
57
+ function raise(ErrorClass, message) {
58
+ throw new ErrorClass(message);
59
+ }
56
60
  var ERR = {
57
61
  // Range / index
58
62
  indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
@@ -74,7 +78,9 @@ var undirectedGraphTyped = (() => {
74
78
  matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
75
79
  matrixNotSquare: () => "Matrix: Must be square for inversion.",
76
80
  matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
77
- matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
81
+ matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`,
82
+ // Order statistic
83
+ orderStatisticNotEnabled: (method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`
78
84
  };
79
85
 
80
86
  // src/common/index.ts
@@ -299,7 +305,7 @@ var undirectedGraphTyped = (() => {
299
305
  if (options) {
300
306
  const { toElementFn } = options;
301
307
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
302
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
308
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
303
309
  }
304
310
  }
305
311
  /**
@@ -455,7 +461,7 @@ var undirectedGraphTyped = (() => {
455
461
  acc = initialValue;
456
462
  } else {
457
463
  const first = iter.next();
458
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
464
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
459
465
  acc = first.value;
460
466
  index = 1;
461
467
  }
@@ -702,7 +708,7 @@ var undirectedGraphTyped = (() => {
702
708
  __publicField(this, "_elements", []);
703
709
  __publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
704
710
  if (typeof a === "object" || typeof b === "object") {
705
- throw new TypeError(ERR.comparatorRequired("Heap"));
711
+ raise(TypeError, ERR.comparatorRequired("Heap"));
706
712
  }
707
713
  if (a > b) return 1;
708
714
  if (a < b) return -1;
@@ -755,6 +761,9 @@ var undirectedGraphTyped = (() => {
755
761
 
756
762
 
757
763
 
764
+
765
+
766
+
758
767
 
759
768
 
760
769
 
@@ -839,6 +848,9 @@ var undirectedGraphTyped = (() => {
839
848
 
840
849
 
841
850
 
851
+
852
+
853
+
842
854
 
843
855
 
844
856
 
@@ -893,6 +905,9 @@ var undirectedGraphTyped = (() => {
893
905
 
894
906
 
895
907
 
908
+
909
+
910
+
896
911
 
897
912
 
898
913
 
@@ -949,6 +964,9 @@ var undirectedGraphTyped = (() => {
949
964
 
950
965
 
951
966
 
967
+
968
+
969
+
952
970
 
953
971
 
954
972
 
@@ -1021,6 +1039,9 @@ var undirectedGraphTyped = (() => {
1021
1039
 
1022
1040
 
1023
1041
 
1042
+
1043
+
1044
+
1024
1045
 
1025
1046
 
1026
1047
 
@@ -1118,6 +1139,9 @@ var undirectedGraphTyped = (() => {
1118
1139
 
1119
1140
 
1120
1141
 
1142
+
1143
+
1144
+
1121
1145
 
1122
1146
 
1123
1147
 
@@ -1162,6 +1186,9 @@ var undirectedGraphTyped = (() => {
1162
1186
 
1163
1187
 
1164
1188
 
1189
+
1190
+
1191
+
1165
1192
 
1166
1193
 
1167
1194
 
@@ -1209,6 +1236,9 @@ var undirectedGraphTyped = (() => {
1209
1236
 
1210
1237
 
1211
1238
 
1239
+
1240
+
1241
+
1212
1242
 
1213
1243
 
1214
1244
 
@@ -1253,6 +1283,9 @@ var undirectedGraphTyped = (() => {
1253
1283
 
1254
1284
 
1255
1285
 
1286
+
1287
+
1288
+
1256
1289
 
1257
1290
 
1258
1291
 
@@ -1343,6 +1376,9 @@ var undirectedGraphTyped = (() => {
1343
1376
 
1344
1377
 
1345
1378
 
1379
+
1380
+
1381
+
1346
1382
 
1347
1383
 
1348
1384
 
@@ -1420,6 +1456,9 @@ var undirectedGraphTyped = (() => {
1420
1456
 
1421
1457
 
1422
1458
 
1459
+
1460
+
1461
+
1423
1462
 
1424
1463
 
1425
1464
 
@@ -1470,6 +1509,9 @@ var undirectedGraphTyped = (() => {
1470
1509
 
1471
1510
 
1472
1511
 
1512
+
1513
+
1514
+
1473
1515
 
1474
1516
 
1475
1517
 
@@ -1519,6 +1561,9 @@ var undirectedGraphTyped = (() => {
1519
1561
 
1520
1562
 
1521
1563
 
1564
+
1565
+
1566
+
1522
1567
 
1523
1568
 
1524
1569
 
@@ -1575,6 +1620,9 @@ var undirectedGraphTyped = (() => {
1575
1620
 
1576
1621
 
1577
1622
 
1623
+
1624
+
1625
+
1578
1626
 
1579
1627
 
1580
1628
 
@@ -1587,7 +1635,7 @@ var undirectedGraphTyped = (() => {
1587
1635
  */
1588
1636
  map(callback, options, thisArg) {
1589
1637
  const { comparator, toElementFn, ...rest } = options != null ? options : {};
1590
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1638
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1591
1639
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1592
1640
  let i = 0;
1593
1641
  for (const x of this) {
@@ -1773,6 +1821,9 @@ var undirectedGraphTyped = (() => {
1773
1821
 
1774
1822
 
1775
1823
 
1824
+
1825
+
1826
+
1776
1827
 
1777
1828
 
1778
1829
 
@@ -1820,6 +1871,9 @@ var undirectedGraphTyped = (() => {
1820
1871
 
1821
1872
 
1822
1873
 
1874
+
1875
+
1876
+
1823
1877
 
1824
1878
 
1825
1879
 
@@ -1883,6 +1937,9 @@ var undirectedGraphTyped = (() => {
1883
1937
 
1884
1938
 
1885
1939
 
1940
+
1941
+
1942
+
1886
1943
 
1887
1944
 
1888
1945
 
@@ -1942,6 +1999,9 @@ var undirectedGraphTyped = (() => {
1942
1999
 
1943
2000
 
1944
2001
 
2002
+
2003
+
2004
+
1945
2005
 
1946
2006
 
1947
2007
 
@@ -2008,6 +2068,9 @@ var undirectedGraphTyped = (() => {
2008
2068
 
2009
2069
 
2010
2070
 
2071
+
2072
+
2073
+
2011
2074
 
2012
2075
 
2013
2076
 
@@ -2064,6 +2127,9 @@ var undirectedGraphTyped = (() => {
2064
2127
 
2065
2128
 
2066
2129
 
2130
+
2131
+
2132
+
2067
2133
 
2068
2134
 
2069
2135
 
@@ -2113,6 +2179,9 @@ var undirectedGraphTyped = (() => {
2113
2179
 
2114
2180
 
2115
2181
 
2182
+
2183
+
2184
+
2116
2185
 
2117
2186
 
2118
2187
 
@@ -2203,6 +2272,9 @@ var undirectedGraphTyped = (() => {
2203
2272
 
2204
2273
 
2205
2274
 
2275
+
2276
+
2277
+
2206
2278
 
2207
2279
 
2208
2280
 
@@ -2246,6 +2318,9 @@ var undirectedGraphTyped = (() => {
2246
2318
 
2247
2319
 
2248
2320
 
2321
+
2322
+
2323
+
2249
2324
 
2250
2325
 
2251
2326
 
@@ -2312,6 +2387,9 @@ var undirectedGraphTyped = (() => {
2312
2387
 
2313
2388
 
2314
2389
 
2390
+
2391
+
2392
+
2315
2393
 
2316
2394
 
2317
2395
 
@@ -2362,6 +2440,9 @@ var undirectedGraphTyped = (() => {
2362
2440
 
2363
2441
 
2364
2442
 
2443
+
2444
+
2445
+
2365
2446
 
2366
2447
 
2367
2448
 
@@ -2416,6 +2497,9 @@ var undirectedGraphTyped = (() => {
2416
2497
 
2417
2498
 
2418
2499
 
2500
+
2501
+
2502
+
2419
2503
 
2420
2504
 
2421
2505
 
@@ -2648,7 +2732,7 @@ var undirectedGraphTyped = (() => {
2648
2732
  const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
2649
2733
  return this._addEdge(newEdge);
2650
2734
  } else {
2651
- throw new TypeError(ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
2735
+ raise(TypeError, ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
2652
2736
  }
2653
2737
  }
2654
2738
  }
@@ -3532,6 +3616,9 @@ var undirectedGraphTyped = (() => {
3532
3616
 
3533
3617
 
3534
3618
 
3619
+
3620
+
3621
+
3535
3622
 
3536
3623
 
3537
3624
 
@@ -3614,6 +3701,9 @@ var undirectedGraphTyped = (() => {
3614
3701
 
3615
3702
 
3616
3703
 
3704
+
3705
+
3706
+
3617
3707
 
3618
3708
 
3619
3709
 
@@ -3695,6 +3785,9 @@ var undirectedGraphTyped = (() => {
3695
3785
 
3696
3786
 
3697
3787
 
3788
+
3789
+
3790
+
3698
3791
 
3699
3792
 
3700
3793
 
@@ -3791,6 +3884,9 @@ var undirectedGraphTyped = (() => {
3791
3884
 
3792
3885
 
3793
3886
 
3887
+
3888
+
3889
+
3794
3890
 
3795
3891
 
3796
3892
 
@@ -3842,6 +3938,9 @@ var undirectedGraphTyped = (() => {
3842
3938
 
3843
3939
 
3844
3940
 
3941
+
3942
+
3943
+
3845
3944
 
3846
3945
 
3847
3946
 
@@ -3963,6 +4062,9 @@ var undirectedGraphTyped = (() => {
3963
4062
 
3964
4063
 
3965
4064
 
4065
+
4066
+
4067
+
3966
4068
 
3967
4069
 
3968
4070
 
@@ -4106,6 +4208,9 @@ var undirectedGraphTyped = (() => {
4106
4208
 
4107
4209
 
4108
4210
 
4211
+
4212
+
4213
+
4109
4214
 
4110
4215
 
4111
4216
 
@@ -4171,6 +4276,9 @@ var undirectedGraphTyped = (() => {
4171
4276
 
4172
4277
 
4173
4278
 
4279
+
4280
+
4281
+
4174
4282
 
4175
4283
 
4176
4284
 
@@ -4218,6 +4326,9 @@ var undirectedGraphTyped = (() => {
4218
4326
 
4219
4327
 
4220
4328
 
4329
+
4330
+
4331
+
4221
4332
 
4222
4333
 
4223
4334