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
@@ -25,6 +25,10 @@ var arrayRemove = /* @__PURE__ */ __name(function(array, predicate) {
25
25
  }, "arrayRemove");
26
26
 
27
27
  // src/common/error.ts
28
+ function raise(ErrorClass, message) {
29
+ throw new ErrorClass(message);
30
+ }
31
+ __name(raise, "raise");
28
32
  var ERR = {
29
33
  // Range / index
30
34
  indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
@@ -46,7 +50,9 @@ var ERR = {
46
50
  matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
47
51
  matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
48
52
  matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
49
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
53
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
54
+ // Order statistic
55
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
50
56
  };
51
57
 
52
58
  // src/common/index.ts
@@ -273,7 +279,7 @@ var IterableElementBase = class {
273
279
  if (options) {
274
280
  const { toElementFn } = options;
275
281
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
276
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
282
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
277
283
  }
278
284
  }
279
285
  /**
@@ -436,7 +442,7 @@ var IterableElementBase = class {
436
442
  acc = initialValue;
437
443
  } else {
438
444
  const first = iter.next();
439
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
445
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
440
446
  acc = first.value;
441
447
  index = 1;
442
448
  }
@@ -733,6 +739,9 @@ var Heap = class _Heap extends IterableElementBase {
733
739
 
734
740
 
735
741
 
742
+
743
+
744
+
736
745
 
737
746
 
738
747
 
@@ -816,6 +825,9 @@ var Heap = class _Heap extends IterableElementBase {
816
825
 
817
826
 
818
827
 
828
+
829
+
830
+
819
831
 
820
832
 
821
833
 
@@ -870,6 +882,9 @@ var Heap = class _Heap extends IterableElementBase {
870
882
 
871
883
 
872
884
 
885
+
886
+
887
+
873
888
 
874
889
 
875
890
 
@@ -926,6 +941,9 @@ var Heap = class _Heap extends IterableElementBase {
926
941
 
927
942
 
928
943
 
944
+
945
+
946
+
929
947
 
930
948
 
931
949
 
@@ -998,6 +1016,9 @@ var Heap = class _Heap extends IterableElementBase {
998
1016
 
999
1017
 
1000
1018
 
1019
+
1020
+
1021
+
1001
1022
 
1002
1023
 
1003
1024
 
@@ -1095,6 +1116,9 @@ var Heap = class _Heap extends IterableElementBase {
1095
1116
 
1096
1117
 
1097
1118
 
1119
+
1120
+
1121
+
1098
1122
 
1099
1123
 
1100
1124
 
@@ -1139,6 +1163,9 @@ var Heap = class _Heap extends IterableElementBase {
1139
1163
 
1140
1164
 
1141
1165
 
1166
+
1167
+
1168
+
1142
1169
 
1143
1170
 
1144
1171
 
@@ -1186,6 +1213,9 @@ var Heap = class _Heap extends IterableElementBase {
1186
1213
 
1187
1214
 
1188
1215
 
1216
+
1217
+
1218
+
1189
1219
 
1190
1220
 
1191
1221
 
@@ -1230,6 +1260,9 @@ var Heap = class _Heap extends IterableElementBase {
1230
1260
 
1231
1261
 
1232
1262
 
1263
+
1264
+
1265
+
1233
1266
 
1234
1267
 
1235
1268
 
@@ -1320,6 +1353,9 @@ var Heap = class _Heap extends IterableElementBase {
1320
1353
 
1321
1354
 
1322
1355
 
1356
+
1357
+
1358
+
1323
1359
 
1324
1360
 
1325
1361
 
@@ -1397,6 +1433,9 @@ var Heap = class _Heap extends IterableElementBase {
1397
1433
 
1398
1434
 
1399
1435
 
1436
+
1437
+
1438
+
1400
1439
 
1401
1440
 
1402
1441
 
@@ -1447,6 +1486,9 @@ var Heap = class _Heap extends IterableElementBase {
1447
1486
 
1448
1487
 
1449
1488
 
1489
+
1490
+
1491
+
1450
1492
 
1451
1493
 
1452
1494
 
@@ -1496,6 +1538,9 @@ var Heap = class _Heap extends IterableElementBase {
1496
1538
 
1497
1539
 
1498
1540
 
1541
+
1542
+
1543
+
1499
1544
 
1500
1545
 
1501
1546
 
@@ -1552,6 +1597,9 @@ var Heap = class _Heap extends IterableElementBase {
1552
1597
 
1553
1598
 
1554
1599
 
1600
+
1601
+
1602
+
1555
1603
 
1556
1604
 
1557
1605
 
@@ -1564,7 +1612,7 @@ var Heap = class _Heap extends IterableElementBase {
1564
1612
  */
1565
1613
  map(callback, options, thisArg) {
1566
1614
  const { comparator, toElementFn, ...rest } = options ?? {};
1567
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1615
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1568
1616
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1569
1617
  let i = 0;
1570
1618
  for (const x of this) {
@@ -1591,7 +1639,7 @@ var Heap = class _Heap extends IterableElementBase {
1591
1639
  }
1592
1640
  _DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
1593
1641
  if (typeof a === "object" || typeof b === "object") {
1594
- throw new TypeError(ERR.comparatorRequired("Heap"));
1642
+ raise(TypeError, ERR.comparatorRequired("Heap"));
1595
1643
  }
1596
1644
  if (a > b) return 1;
1597
1645
  if (a < b) return -1;
@@ -1762,6 +1810,9 @@ var Queue = class _Queue extends LinearBase {
1762
1810
 
1763
1811
 
1764
1812
 
1813
+
1814
+
1815
+
1765
1816
 
1766
1817
 
1767
1818
 
@@ -1809,6 +1860,9 @@ var Queue = class _Queue extends LinearBase {
1809
1860
 
1810
1861
 
1811
1862
 
1863
+
1864
+
1865
+
1812
1866
 
1813
1867
 
1814
1868
 
@@ -1872,6 +1926,9 @@ var Queue = class _Queue extends LinearBase {
1872
1926
 
1873
1927
 
1874
1928
 
1929
+
1930
+
1931
+
1875
1932
 
1876
1933
 
1877
1934
 
@@ -1931,6 +1988,9 @@ var Queue = class _Queue extends LinearBase {
1931
1988
 
1932
1989
 
1933
1990
 
1991
+
1992
+
1993
+
1934
1994
 
1935
1995
 
1936
1996
 
@@ -1997,6 +2057,9 @@ var Queue = class _Queue extends LinearBase {
1997
2057
 
1998
2058
 
1999
2059
 
2060
+
2061
+
2062
+
2000
2063
 
2001
2064
 
2002
2065
 
@@ -2053,6 +2116,9 @@ var Queue = class _Queue extends LinearBase {
2053
2116
 
2054
2117
 
2055
2118
 
2119
+
2120
+
2121
+
2056
2122
 
2057
2123
 
2058
2124
 
@@ -2102,6 +2168,9 @@ var Queue = class _Queue extends LinearBase {
2102
2168
 
2103
2169
 
2104
2170
 
2171
+
2172
+
2173
+
2105
2174
 
2106
2175
 
2107
2176
 
@@ -2192,6 +2261,9 @@ var Queue = class _Queue extends LinearBase {
2192
2261
 
2193
2262
 
2194
2263
 
2264
+
2265
+
2266
+
2195
2267
 
2196
2268
 
2197
2269
 
@@ -2235,6 +2307,9 @@ var Queue = class _Queue extends LinearBase {
2235
2307
 
2236
2308
 
2237
2309
 
2310
+
2311
+
2312
+
2238
2313
 
2239
2314
 
2240
2315
 
@@ -2301,6 +2376,9 @@ var Queue = class _Queue extends LinearBase {
2301
2376
 
2302
2377
 
2303
2378
 
2379
+
2380
+
2381
+
2304
2382
 
2305
2383
 
2306
2384
 
@@ -2351,6 +2429,9 @@ var Queue = class _Queue extends LinearBase {
2351
2429
 
2352
2430
 
2353
2431
 
2432
+
2433
+
2434
+
2354
2435
 
2355
2436
 
2356
2437
 
@@ -2405,6 +2486,9 @@ var Queue = class _Queue extends LinearBase {
2405
2486
 
2406
2487
 
2407
2488
 
2489
+
2490
+
2491
+
2408
2492
 
2409
2493
 
2410
2494
 
@@ -2644,7 +2728,7 @@ var AbstractGraph = class extends IterableEntryBase {
2644
2728
  const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
2645
2729
  return this._addEdge(newEdge);
2646
2730
  } else {
2647
- throw new TypeError(ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
2731
+ raise(TypeError, ERR.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.", "Graph"));
2648
2732
  }
2649
2733
  }
2650
2734
  }
@@ -3530,6 +3614,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3530
3614
 
3531
3615
 
3532
3616
 
3617
+
3618
+
3619
+
3533
3620
 
3534
3621
 
3535
3622
 
@@ -3611,6 +3698,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3611
3698
 
3612
3699
 
3613
3700
 
3701
+
3702
+
3703
+
3614
3704
 
3615
3705
 
3616
3706
 
@@ -3692,6 +3782,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3692
3782
 
3693
3783
 
3694
3784
 
3785
+
3786
+
3787
+
3695
3788
 
3696
3789
 
3697
3790
 
@@ -3787,6 +3880,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3787
3880
 
3788
3881
 
3789
3882
 
3883
+
3884
+
3885
+
3790
3886
 
3791
3887
 
3792
3888
 
@@ -3838,6 +3934,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3838
3934
 
3839
3935
 
3840
3936
 
3937
+
3938
+
3939
+
3841
3940
 
3842
3941
 
3843
3942
 
@@ -3959,6 +4058,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3959
4058
 
3960
4059
 
3961
4060
 
4061
+
4062
+
4063
+
3962
4064
 
3963
4065
 
3964
4066
 
@@ -4102,6 +4204,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4102
4204
 
4103
4205
 
4104
4206
 
4207
+
4208
+
4209
+
4105
4210
 
4106
4211
 
4107
4212
 
@@ -4167,6 +4272,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4167
4272
 
4168
4273
 
4169
4274
 
4275
+
4276
+
4277
+
4170
4278
 
4171
4279
 
4172
4280
 
@@ -4214,6 +4322,9 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4214
4322
 
4215
4323
 
4216
4324
 
4325
+
4326
+
4327
+
4217
4328
 
4218
4329
 
4219
4330
 
@@ -4285,5 +4396,6 @@ exports.Range = Range;
4285
4396
  exports.UndirectedEdge = UndirectedEdge;
4286
4397
  exports.UndirectedGraph = UndirectedGraph;
4287
4398
  exports.UndirectedVertex = UndirectedVertex;
4399
+ exports.raise = raise;
4288
4400
  //# sourceMappingURL=index.cjs.map
4289
4401
  //# sourceMappingURL=index.cjs.map