graph-typed 2.5.2 → 2.5.3

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 (59) hide show
  1. package/dist/cjs/index.cjs +248 -14
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +248 -14
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +248 -14
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +248 -14
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +50 -2
  10. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
  11. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +116 -15
  12. package/dist/types/data-structures/binary-tree/bst.d.ts +99 -3
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +79 -8
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
  15. package/dist/types/data-structures/binary-tree/tree-map.d.ts +520 -1
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +489 -1
  17. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +393 -1
  18. package/dist/types/data-structures/binary-tree/tree-set.d.ts +500 -1
  19. package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
  20. package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
  21. package/dist/types/data-structures/hash/hash-map.d.ts +51 -6
  22. package/dist/types/data-structures/heap/heap.d.ts +98 -12
  23. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -0
  24. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +61 -1
  25. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
  26. package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
  27. package/dist/types/data-structures/queue/deque.d.ts +82 -0
  28. package/dist/types/data-structures/queue/queue.d.ts +61 -0
  29. package/dist/types/data-structures/stack/stack.d.ts +42 -2
  30. package/dist/types/data-structures/trie/trie.d.ts +48 -0
  31. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  32. package/dist/umd/graph-typed.js +248 -14
  33. package/dist/umd/graph-typed.js.map +1 -1
  34. package/dist/umd/graph-typed.min.js +2 -2
  35. package/dist/umd/graph-typed.min.js.map +1 -1
  36. package/package.json +2 -2
  37. package/src/data-structures/binary-tree/avl-tree.ts +52 -5
  38. package/src/data-structures/binary-tree/binary-indexed-tree.ts +56 -0
  39. package/src/data-structures/binary-tree/binary-tree.ts +167 -81
  40. package/src/data-structures/binary-tree/bst.ts +101 -7
  41. package/src/data-structures/binary-tree/red-black-tree.ts +82 -15
  42. package/src/data-structures/binary-tree/segment-tree.ts +24 -0
  43. package/src/data-structures/binary-tree/tree-map.ts +540 -3
  44. package/src/data-structures/binary-tree/tree-multi-map.ts +490 -2
  45. package/src/data-structures/binary-tree/tree-multi-set.ts +393 -1
  46. package/src/data-structures/binary-tree/tree-set.ts +520 -3
  47. package/src/data-structures/graph/directed-graph.ts +41 -1
  48. package/src/data-structures/graph/undirected-graph.ts +37 -1
  49. package/src/data-structures/hash/hash-map.ts +67 -12
  50. package/src/data-structures/heap/heap.ts +107 -19
  51. package/src/data-structures/linked-list/doubly-linked-list.ts +88 -0
  52. package/src/data-structures/linked-list/singly-linked-list.ts +61 -1
  53. package/src/data-structures/linked-list/skip-linked-list.ts +72 -0
  54. package/src/data-structures/matrix/matrix.ts +32 -0
  55. package/src/data-structures/queue/deque.ts +85 -0
  56. package/src/data-structures/queue/queue.ts +73 -0
  57. package/src/data-structures/stack/stack.ts +45 -5
  58. package/src/data-structures/trie/trie.ts +48 -0
  59. package/src/interfaces/binary-tree.ts +1 -9
@@ -739,6 +739,10 @@ var Heap = class _Heap extends IterableElementBase {
739
739
 
740
740
 
741
741
 
742
+
743
+
744
+
745
+
742
746
 
743
747
 
744
748
 
@@ -792,7 +796,7 @@ var Heap = class _Heap extends IterableElementBase {
792
796
  }
793
797
  /**
794
798
  * Insert an element.
795
- * @remarks Time O(1) amortized, Space O(1)
799
+ * @remarks Time O(log N) amortized, Space O(1)
796
800
  * @param element - Element to insert.
797
801
  * @returns True.
798
802
 
@@ -825,6 +829,10 @@ var Heap = class _Heap extends IterableElementBase {
825
829
 
826
830
 
827
831
 
832
+
833
+
834
+
835
+
828
836
 
829
837
 
830
838
 
@@ -882,6 +890,10 @@ var Heap = class _Heap extends IterableElementBase {
882
890
 
883
891
 
884
892
 
893
+
894
+
895
+
896
+
885
897
 
886
898
 
887
899
 
@@ -942,10 +954,41 @@ var Heap = class _Heap extends IterableElementBase {
942
954
 
943
955
 
944
956
 
957
+
958
+
959
+
945
960
 
946
961
 
947
962
 
948
963
 
964
+ * @example
965
+ * // Heap with custom comparator (MaxHeap behavior)
966
+ * interface Task {
967
+ * id: number;
968
+ * priority: number;
969
+ * name: string;
970
+ * }
971
+ *
972
+ * // Custom comparator for max heap behavior (higher priority first)
973
+ * const tasks: Task[] = [
974
+ * { id: 1, priority: 5, name: 'Email' },
975
+ * { id: 2, priority: 3, name: 'Chat' },
976
+ * { id: 3, priority: 8, name: 'Alert' }
977
+ * ];
978
+ *
979
+ * const maxHeap = new Heap(tasks, {
980
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
981
+ * });
982
+ *
983
+ * console.log(maxHeap.size); // 3;
984
+ *
985
+ * // Peek returns highest priority task
986
+ * const topTask = maxHeap.peek();
987
+ * console.log(topTask?.priority); // 8;
988
+ * console.log(topTask?.name); // 'Alert';
989
+ */
990
+ /**
991
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
949
992
  * @example
950
993
  * // Heap with custom comparator (MaxHeap behavior)
951
994
  * interface Task {
@@ -973,6 +1016,14 @@ var Heap = class _Heap extends IterableElementBase {
973
1016
  * console.log(topTask?.name); // 'Alert';
974
1017
  */
975
1018
  poll() {
1019
+ return this.pop();
1020
+ }
1021
+ /**
1022
+ * Remove and return the top element (min or max depending on comparator).
1023
+ * @remarks Time O(log N) amortized, Space O(1)
1024
+ * @returns The removed top element, or undefined if empty.
1025
+ */
1026
+ pop() {
976
1027
  if (this.elements.length === 0) return;
977
1028
  const value = this.elements[0];
978
1029
  const last = this.elements.pop();
@@ -1016,6 +1067,10 @@ var Heap = class _Heap extends IterableElementBase {
1016
1067
 
1017
1068
 
1018
1069
 
1070
+
1071
+
1072
+
1073
+
1019
1074
 
1020
1075
 
1021
1076
 
@@ -1116,6 +1171,10 @@ var Heap = class _Heap extends IterableElementBase {
1116
1171
 
1117
1172
 
1118
1173
 
1174
+
1175
+
1176
+
1177
+
1119
1178
 
1120
1179
 
1121
1180
 
@@ -1163,6 +1222,10 @@ var Heap = class _Heap extends IterableElementBase {
1163
1222
 
1164
1223
 
1165
1224
 
1225
+
1226
+
1227
+
1228
+
1166
1229
 
1167
1230
 
1168
1231
 
@@ -1177,16 +1240,6 @@ var Heap = class _Heap extends IterableElementBase {
1177
1240
  clear() {
1178
1241
  this._elements = [];
1179
1242
  }
1180
- /**
1181
- * Replace the backing array and rebuild the heap.
1182
- * @remarks Time O(N), Space O(N)
1183
- * @param elements - Iterable used to refill the heap.
1184
- * @returns Array of per-node results from fixing steps.
1185
- */
1186
- refill(elements) {
1187
- this._elements = Array.from(elements);
1188
- return this.fix();
1189
- }
1190
1243
  /**
1191
1244
  * Check if an equal element exists in the heap.
1192
1245
  * @remarks Time O(N), Space O(1)
@@ -1213,6 +1266,10 @@ var Heap = class _Heap extends IterableElementBase {
1213
1266
 
1214
1267
 
1215
1268
 
1269
+
1270
+
1271
+
1272
+
1216
1273
 
1217
1274
 
1218
1275
 
@@ -1260,6 +1317,10 @@ var Heap = class _Heap extends IterableElementBase {
1260
1317
 
1261
1318
 
1262
1319
 
1320
+
1321
+
1322
+
1323
+
1263
1324
 
1264
1325
 
1265
1326
 
@@ -1281,7 +1342,7 @@ var Heap = class _Heap extends IterableElementBase {
1281
1342
  }
1282
1343
  if (index < 0) return false;
1283
1344
  if (index === 0) {
1284
- this.poll();
1345
+ this.pop();
1285
1346
  } else if (index === this.elements.length - 1) {
1286
1347
  this.elements.pop();
1287
1348
  } else {
@@ -1291,13 +1352,19 @@ var Heap = class _Heap extends IterableElementBase {
1291
1352
  }
1292
1353
  return true;
1293
1354
  }
1355
+ /**
1356
+ * @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
1357
+ */
1358
+ deleteBy(predicate) {
1359
+ return this.deleteWhere(predicate);
1360
+ }
1294
1361
  /**
1295
1362
  * Delete the first element that matches a predicate.
1296
1363
  * @remarks Time O(N), Space O(1)
1297
1364
  * @param predicate - Function (element, index, heap) → boolean.
1298
1365
  * @returns True if an element was removed.
1299
1366
  */
1300
- deleteBy(predicate) {
1367
+ deleteWhere(predicate) {
1301
1368
  let idx = -1;
1302
1369
  for (let i = 0; i < this.elements.length; i++) {
1303
1370
  if (predicate(this.elements[i], i, this)) {
@@ -1307,7 +1374,7 @@ var Heap = class _Heap extends IterableElementBase {
1307
1374
  }
1308
1375
  if (idx < 0) return false;
1309
1376
  if (idx === 0) {
1310
- this.poll();
1377
+ this.pop();
1311
1378
  } else if (idx === this.elements.length - 1) {
1312
1379
  this.elements.pop();
1313
1380
  } else {
@@ -1353,6 +1420,10 @@ var Heap = class _Heap extends IterableElementBase {
1353
1420
 
1354
1421
 
1355
1422
 
1423
+
1424
+
1425
+
1426
+
1356
1427
 
1357
1428
 
1358
1429
 
@@ -1433,6 +1504,10 @@ var Heap = class _Heap extends IterableElementBase {
1433
1504
 
1434
1505
 
1435
1506
 
1507
+
1508
+
1509
+
1510
+
1436
1511
 
1437
1512
 
1438
1513
 
@@ -1486,6 +1561,10 @@ var Heap = class _Heap extends IterableElementBase {
1486
1561
 
1487
1562
 
1488
1563
 
1564
+
1565
+
1566
+
1567
+
1489
1568
 
1490
1569
 
1491
1570
 
@@ -1538,6 +1617,10 @@ var Heap = class _Heap extends IterableElementBase {
1538
1617
 
1539
1618
 
1540
1619
 
1620
+
1621
+
1622
+
1623
+
1541
1624
 
1542
1625
 
1543
1626
 
@@ -1597,6 +1680,10 @@ var Heap = class _Heap extends IterableElementBase {
1597
1680
 
1598
1681
 
1599
1682
 
1683
+
1684
+
1685
+
1686
+
1600
1687
 
1601
1688
 
1602
1689
 
@@ -1810,6 +1897,10 @@ var Queue = class _Queue extends LinearBase {
1810
1897
 
1811
1898
 
1812
1899
 
1900
+
1901
+
1902
+
1903
+
1813
1904
 
1814
1905
 
1815
1906
 
@@ -1860,6 +1951,10 @@ var Queue = class _Queue extends LinearBase {
1860
1951
 
1861
1952
 
1862
1953
 
1954
+
1955
+
1956
+
1957
+
1863
1958
 
1864
1959
 
1865
1960
 
@@ -1874,6 +1969,14 @@ var Queue = class _Queue extends LinearBase {
1874
1969
  get first() {
1875
1970
  return this.length > 0 ? this.elements[this._offset] : void 0;
1876
1971
  }
1972
+ /**
1973
+ * Peek at the front element without removing it (alias for `first`).
1974
+ * @remarks Time O(1), Space O(1)
1975
+ * @returns Front element or undefined.
1976
+ */
1977
+ peek() {
1978
+ return this.first;
1979
+ }
1877
1980
  /**
1878
1981
  * Get the last element (back) without removing it.
1879
1982
  * @remarks Time O(1), Space O(1)
@@ -1926,6 +2029,10 @@ var Queue = class _Queue extends LinearBase {
1926
2029
 
1927
2030
 
1928
2031
 
2032
+
2033
+
2034
+
2035
+
1929
2036
 
1930
2037
 
1931
2038
 
@@ -1988,6 +2095,10 @@ var Queue = class _Queue extends LinearBase {
1988
2095
 
1989
2096
 
1990
2097
 
2098
+
2099
+
2100
+
2101
+
1991
2102
 
1992
2103
 
1993
2104
 
@@ -2057,6 +2168,10 @@ var Queue = class _Queue extends LinearBase {
2057
2168
 
2058
2169
 
2059
2170
 
2171
+
2172
+
2173
+
2174
+
2060
2175
 
2061
2176
 
2062
2177
 
@@ -2116,6 +2231,10 @@ var Queue = class _Queue extends LinearBase {
2116
2231
 
2117
2232
 
2118
2233
 
2234
+
2235
+
2236
+
2237
+
2119
2238
 
2120
2239
 
2121
2240
 
@@ -2168,6 +2287,10 @@ var Queue = class _Queue extends LinearBase {
2168
2287
 
2169
2288
 
2170
2289
 
2290
+
2291
+
2292
+
2293
+
2171
2294
 
2172
2295
 
2173
2296
 
@@ -2219,6 +2342,21 @@ var Queue = class _Queue extends LinearBase {
2219
2342
  this._elements[this._offset + index] = newElement;
2220
2343
  return true;
2221
2344
  }
2345
+ /**
2346
+ * Delete the first element that satisfies a predicate.
2347
+ * @remarks Time O(N), Space O(N)
2348
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
2349
+ * @returns True if a match was removed.
2350
+ */
2351
+ deleteWhere(predicate) {
2352
+ for (let i = 0; i < this.length; i++) {
2353
+ if (predicate(this._elements[this._offset + i], i, this)) {
2354
+ this.deleteAt(i);
2355
+ return true;
2356
+ }
2357
+ }
2358
+ return false;
2359
+ }
2222
2360
  /**
2223
2361
  * Reverse the queue in-place by compacting then reversing.
2224
2362
  * @remarks Time O(N), Space O(N)
@@ -2261,6 +2399,10 @@ var Queue = class _Queue extends LinearBase {
2261
2399
 
2262
2400
 
2263
2401
 
2402
+
2403
+
2404
+
2405
+
2264
2406
 
2265
2407
 
2266
2408
 
@@ -2307,6 +2449,10 @@ var Queue = class _Queue extends LinearBase {
2307
2449
 
2308
2450
 
2309
2451
 
2452
+
2453
+
2454
+
2455
+
2310
2456
 
2311
2457
 
2312
2458
 
@@ -2376,6 +2522,10 @@ var Queue = class _Queue extends LinearBase {
2376
2522
 
2377
2523
 
2378
2524
 
2525
+
2526
+
2527
+
2528
+
2379
2529
 
2380
2530
 
2381
2531
 
@@ -2429,6 +2579,10 @@ var Queue = class _Queue extends LinearBase {
2429
2579
 
2430
2580
 
2431
2581
 
2582
+
2583
+
2584
+
2585
+
2432
2586
 
2433
2587
 
2434
2588
 
@@ -2486,6 +2640,10 @@ var Queue = class _Queue extends LinearBase {
2486
2640
 
2487
2641
 
2488
2642
 
2643
+
2644
+
2645
+
2646
+
2489
2647
 
2490
2648
 
2491
2649
 
@@ -3625,6 +3783,10 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3625
3783
 
3626
3784
 
3627
3785
 
3786
+
3787
+
3788
+
3789
+
3628
3790
 
3629
3791
 
3630
3792
 
@@ -3713,6 +3875,10 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3713
3875
 
3714
3876
 
3715
3877
 
3878
+
3879
+
3880
+
3881
+
3716
3882
 
3717
3883
 
3718
3884
 
@@ -3799,6 +3965,10 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3799
3965
 
3800
3966
 
3801
3967
 
3968
+
3969
+
3970
+
3971
+
3802
3972
 
3803
3973
 
3804
3974
 
@@ -3876,6 +4046,10 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3876
4046
 
3877
4047
 
3878
4048
 
4049
+
4050
+
4051
+
4052
+
3879
4053
 
3880
4054
 
3881
4055
 
@@ -3930,6 +4104,10 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
3930
4104
 
3931
4105
 
3932
4106
 
4107
+
4108
+
4109
+
4110
+
3933
4111
 
3934
4112
 
3935
4113
 
@@ -4037,6 +4215,10 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
4037
4215
 
4038
4216
 
4039
4217
 
4218
+
4219
+
4220
+
4221
+
4040
4222
 
4041
4223
 
4042
4224
 
@@ -4125,6 +4307,10 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
4125
4307
 
4126
4308
 
4127
4309
 
4310
+
4311
+
4312
+
4313
+
4128
4314
 
4129
4315
 
4130
4316
 
@@ -4175,6 +4361,10 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
4175
4361
 
4176
4362
 
4177
4363
 
4364
+
4365
+
4366
+
4367
+
4178
4368
 
4179
4369
 
4180
4370
 
@@ -4278,6 +4468,10 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
4278
4468
 
4279
4469
 
4280
4470
 
4471
+
4472
+
4473
+
4474
+
4281
4475
 
4282
4476
 
4283
4477
 
@@ -4384,6 +4578,10 @@ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
4384
4578
 
4385
4579
 
4386
4580
 
4581
+
4582
+
4583
+
4584
+
4387
4585
 
4388
4586
 
4389
4587
 
@@ -4556,6 +4754,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4556
4754
 
4557
4755
 
4558
4756
 
4757
+
4758
+
4759
+
4760
+
4559
4761
 
4560
4762
 
4561
4763
 
@@ -4640,6 +4842,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4640
4842
 
4641
4843
 
4642
4844
 
4845
+
4846
+
4847
+
4848
+
4643
4849
 
4644
4850
 
4645
4851
 
@@ -4724,6 +4930,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4724
4930
 
4725
4931
 
4726
4932
 
4933
+
4934
+
4935
+
4936
+
4727
4937
 
4728
4938
 
4729
4939
 
@@ -4822,6 +5032,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4822
5032
 
4823
5033
 
4824
5034
 
5035
+
5036
+
5037
+
5038
+
4825
5039
 
4826
5040
 
4827
5041
 
@@ -4876,6 +5090,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4876
5090
 
4877
5091
 
4878
5092
 
5093
+
5094
+
5095
+
5096
+
4879
5097
 
4880
5098
 
4881
5099
 
@@ -5000,6 +5218,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
5000
5218
 
5001
5219
 
5002
5220
 
5221
+
5222
+
5223
+
5224
+
5003
5225
 
5004
5226
 
5005
5227
 
@@ -5146,6 +5368,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
5146
5368
 
5147
5369
 
5148
5370
 
5371
+
5372
+
5373
+
5374
+
5149
5375
 
5150
5376
 
5151
5377
 
@@ -5214,6 +5440,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
5214
5440
 
5215
5441
 
5216
5442
 
5443
+
5444
+
5445
+
5446
+
5217
5447
 
5218
5448
 
5219
5449
 
@@ -5264,6 +5494,10 @@ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
5264
5494
 
5265
5495
 
5266
5496
 
5497
+
5498
+
5499
+
5500
+
5267
5501
 
5268
5502
 
5269
5503