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
@@ -743,6 +743,10 @@ var _Heap = class _Heap extends IterableElementBase {
743
743
 
744
744
 
745
745
 
746
+
747
+
748
+
749
+
746
750
 
747
751
 
748
752
 
@@ -797,7 +801,7 @@ var _Heap = class _Heap extends IterableElementBase {
797
801
  }
798
802
  /**
799
803
  * Insert an element.
800
- * @remarks Time O(1) amortized, Space O(1)
804
+ * @remarks Time O(log N) amortized, Space O(1)
801
805
  * @param element - Element to insert.
802
806
  * @returns True.
803
807
 
@@ -830,6 +834,10 @@ var _Heap = class _Heap extends IterableElementBase {
830
834
 
831
835
 
832
836
 
837
+
838
+
839
+
840
+
833
841
 
834
842
 
835
843
 
@@ -887,6 +895,10 @@ var _Heap = class _Heap extends IterableElementBase {
887
895
 
888
896
 
889
897
 
898
+
899
+
900
+
901
+
890
902
 
891
903
 
892
904
 
@@ -947,10 +959,41 @@ var _Heap = class _Heap extends IterableElementBase {
947
959
 
948
960
 
949
961
 
962
+
963
+
964
+
950
965
 
951
966
 
952
967
 
953
968
 
969
+ * @example
970
+ * // Heap with custom comparator (MaxHeap behavior)
971
+ * interface Task {
972
+ * id: number;
973
+ * priority: number;
974
+ * name: string;
975
+ * }
976
+ *
977
+ * // Custom comparator for max heap behavior (higher priority first)
978
+ * const tasks: Task[] = [
979
+ * { id: 1, priority: 5, name: 'Email' },
980
+ * { id: 2, priority: 3, name: 'Chat' },
981
+ * { id: 3, priority: 8, name: 'Alert' }
982
+ * ];
983
+ *
984
+ * const maxHeap = new Heap(tasks, {
985
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
986
+ * });
987
+ *
988
+ * console.log(maxHeap.size); // 3;
989
+ *
990
+ * // Peek returns highest priority task
991
+ * const topTask = maxHeap.peek();
992
+ * console.log(topTask?.priority); // 8;
993
+ * console.log(topTask?.name); // 'Alert';
994
+ */
995
+ /**
996
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
954
997
  * @example
955
998
  * // Heap with custom comparator (MaxHeap behavior)
956
999
  * interface Task {
@@ -978,6 +1021,14 @@ var _Heap = class _Heap extends IterableElementBase {
978
1021
  * console.log(topTask?.name); // 'Alert';
979
1022
  */
980
1023
  poll() {
1024
+ return this.pop();
1025
+ }
1026
+ /**
1027
+ * Remove and return the top element (min or max depending on comparator).
1028
+ * @remarks Time O(log N) amortized, Space O(1)
1029
+ * @returns The removed top element, or undefined if empty.
1030
+ */
1031
+ pop() {
981
1032
  if (this.elements.length === 0) return;
982
1033
  const value = this.elements[0];
983
1034
  const last = this.elements.pop();
@@ -1021,6 +1072,10 @@ var _Heap = class _Heap extends IterableElementBase {
1021
1072
 
1022
1073
 
1023
1074
 
1075
+
1076
+
1077
+
1078
+
1024
1079
 
1025
1080
 
1026
1081
 
@@ -1121,6 +1176,10 @@ var _Heap = class _Heap extends IterableElementBase {
1121
1176
 
1122
1177
 
1123
1178
 
1179
+
1180
+
1181
+
1182
+
1124
1183
 
1125
1184
 
1126
1185
 
@@ -1168,6 +1227,10 @@ var _Heap = class _Heap extends IterableElementBase {
1168
1227
 
1169
1228
 
1170
1229
 
1230
+
1231
+
1232
+
1233
+
1171
1234
 
1172
1235
 
1173
1236
 
@@ -1182,16 +1245,6 @@ var _Heap = class _Heap extends IterableElementBase {
1182
1245
  clear() {
1183
1246
  this._elements = [];
1184
1247
  }
1185
- /**
1186
- * Replace the backing array and rebuild the heap.
1187
- * @remarks Time O(N), Space O(N)
1188
- * @param elements - Iterable used to refill the heap.
1189
- * @returns Array of per-node results from fixing steps.
1190
- */
1191
- refill(elements) {
1192
- this._elements = Array.from(elements);
1193
- return this.fix();
1194
- }
1195
1248
  /**
1196
1249
  * Check if an equal element exists in the heap.
1197
1250
  * @remarks Time O(N), Space O(1)
@@ -1218,6 +1271,10 @@ var _Heap = class _Heap extends IterableElementBase {
1218
1271
 
1219
1272
 
1220
1273
 
1274
+
1275
+
1276
+
1277
+
1221
1278
 
1222
1279
 
1223
1280
 
@@ -1265,6 +1322,10 @@ var _Heap = class _Heap extends IterableElementBase {
1265
1322
 
1266
1323
 
1267
1324
 
1325
+
1326
+
1327
+
1328
+
1268
1329
 
1269
1330
 
1270
1331
 
@@ -1286,7 +1347,7 @@ var _Heap = class _Heap extends IterableElementBase {
1286
1347
  }
1287
1348
  if (index < 0) return false;
1288
1349
  if (index === 0) {
1289
- this.poll();
1350
+ this.pop();
1290
1351
  } else if (index === this.elements.length - 1) {
1291
1352
  this.elements.pop();
1292
1353
  } else {
@@ -1296,13 +1357,19 @@ var _Heap = class _Heap extends IterableElementBase {
1296
1357
  }
1297
1358
  return true;
1298
1359
  }
1360
+ /**
1361
+ * @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
1362
+ */
1363
+ deleteBy(predicate) {
1364
+ return this.deleteWhere(predicate);
1365
+ }
1299
1366
  /**
1300
1367
  * Delete the first element that matches a predicate.
1301
1368
  * @remarks Time O(N), Space O(1)
1302
1369
  * @param predicate - Function (element, index, heap) → boolean.
1303
1370
  * @returns True if an element was removed.
1304
1371
  */
1305
- deleteBy(predicate) {
1372
+ deleteWhere(predicate) {
1306
1373
  let idx = -1;
1307
1374
  for (let i = 0; i < this.elements.length; i++) {
1308
1375
  if (predicate(this.elements[i], i, this)) {
@@ -1312,7 +1379,7 @@ var _Heap = class _Heap extends IterableElementBase {
1312
1379
  }
1313
1380
  if (idx < 0) return false;
1314
1381
  if (idx === 0) {
1315
- this.poll();
1382
+ this.pop();
1316
1383
  } else if (idx === this.elements.length - 1) {
1317
1384
  this.elements.pop();
1318
1385
  } else {
@@ -1358,6 +1425,10 @@ var _Heap = class _Heap extends IterableElementBase {
1358
1425
 
1359
1426
 
1360
1427
 
1428
+
1429
+
1430
+
1431
+
1361
1432
 
1362
1433
 
1363
1434
 
@@ -1438,6 +1509,10 @@ var _Heap = class _Heap extends IterableElementBase {
1438
1509
 
1439
1510
 
1440
1511
 
1512
+
1513
+
1514
+
1515
+
1441
1516
 
1442
1517
 
1443
1518
 
@@ -1491,6 +1566,10 @@ var _Heap = class _Heap extends IterableElementBase {
1491
1566
 
1492
1567
 
1493
1568
 
1569
+
1570
+
1571
+
1572
+
1494
1573
 
1495
1574
 
1496
1575
 
@@ -1543,6 +1622,10 @@ var _Heap = class _Heap extends IterableElementBase {
1543
1622
 
1544
1623
 
1545
1624
 
1625
+
1626
+
1627
+
1628
+
1546
1629
 
1547
1630
 
1548
1631
 
@@ -1602,6 +1685,10 @@ var _Heap = class _Heap extends IterableElementBase {
1602
1685
 
1603
1686
 
1604
1687
 
1688
+
1689
+
1690
+
1691
+
1605
1692
 
1606
1693
 
1607
1694
 
@@ -1805,6 +1892,10 @@ var _Queue = class _Queue extends LinearBase {
1805
1892
 
1806
1893
 
1807
1894
 
1895
+
1896
+
1897
+
1898
+
1808
1899
 
1809
1900
 
1810
1901
 
@@ -1855,6 +1946,10 @@ var _Queue = class _Queue extends LinearBase {
1855
1946
 
1856
1947
 
1857
1948
 
1949
+
1950
+
1951
+
1952
+
1858
1953
 
1859
1954
 
1860
1955
 
@@ -1869,6 +1964,14 @@ var _Queue = class _Queue extends LinearBase {
1869
1964
  get first() {
1870
1965
  return this.length > 0 ? this.elements[this._offset] : void 0;
1871
1966
  }
1967
+ /**
1968
+ * Peek at the front element without removing it (alias for `first`).
1969
+ * @remarks Time O(1), Space O(1)
1970
+ * @returns Front element or undefined.
1971
+ */
1972
+ peek() {
1973
+ return this.first;
1974
+ }
1872
1975
  /**
1873
1976
  * Get the last element (back) without removing it.
1874
1977
  * @remarks Time O(1), Space O(1)
@@ -1921,6 +2024,10 @@ var _Queue = class _Queue extends LinearBase {
1921
2024
 
1922
2025
 
1923
2026
 
2027
+
2028
+
2029
+
2030
+
1924
2031
 
1925
2032
 
1926
2033
 
@@ -1983,6 +2090,10 @@ var _Queue = class _Queue extends LinearBase {
1983
2090
 
1984
2091
 
1985
2092
 
2093
+
2094
+
2095
+
2096
+
1986
2097
 
1987
2098
 
1988
2099
 
@@ -2052,6 +2163,10 @@ var _Queue = class _Queue extends LinearBase {
2052
2163
 
2053
2164
 
2054
2165
 
2166
+
2167
+
2168
+
2169
+
2055
2170
 
2056
2171
 
2057
2172
 
@@ -2111,6 +2226,10 @@ var _Queue = class _Queue extends LinearBase {
2111
2226
 
2112
2227
 
2113
2228
 
2229
+
2230
+
2231
+
2232
+
2114
2233
 
2115
2234
 
2116
2235
 
@@ -2163,6 +2282,10 @@ var _Queue = class _Queue extends LinearBase {
2163
2282
 
2164
2283
 
2165
2284
 
2285
+
2286
+
2287
+
2288
+
2166
2289
 
2167
2290
 
2168
2291
 
@@ -2214,6 +2337,21 @@ var _Queue = class _Queue extends LinearBase {
2214
2337
  this._elements[this._offset + index] = newElement;
2215
2338
  return true;
2216
2339
  }
2340
+ /**
2341
+ * Delete the first element that satisfies a predicate.
2342
+ * @remarks Time O(N), Space O(N)
2343
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
2344
+ * @returns True if a match was removed.
2345
+ */
2346
+ deleteWhere(predicate) {
2347
+ for (let i = 0; i < this.length; i++) {
2348
+ if (predicate(this._elements[this._offset + i], i, this)) {
2349
+ this.deleteAt(i);
2350
+ return true;
2351
+ }
2352
+ }
2353
+ return false;
2354
+ }
2217
2355
  /**
2218
2356
  * Reverse the queue in-place by compacting then reversing.
2219
2357
  * @remarks Time O(N), Space O(N)
@@ -2256,6 +2394,10 @@ var _Queue = class _Queue extends LinearBase {
2256
2394
 
2257
2395
 
2258
2396
 
2397
+
2398
+
2399
+
2400
+
2259
2401
 
2260
2402
 
2261
2403
 
@@ -2302,6 +2444,10 @@ var _Queue = class _Queue extends LinearBase {
2302
2444
 
2303
2445
 
2304
2446
 
2447
+
2448
+
2449
+
2450
+
2305
2451
 
2306
2452
 
2307
2453
 
@@ -2371,6 +2517,10 @@ var _Queue = class _Queue extends LinearBase {
2371
2517
 
2372
2518
 
2373
2519
 
2520
+
2521
+
2522
+
2523
+
2374
2524
 
2375
2525
 
2376
2526
 
@@ -2424,6 +2574,10 @@ var _Queue = class _Queue extends LinearBase {
2424
2574
 
2425
2575
 
2426
2576
 
2577
+
2578
+
2579
+
2580
+
2427
2581
 
2428
2582
 
2429
2583
 
@@ -2481,6 +2635,10 @@ var _Queue = class _Queue extends LinearBase {
2481
2635
 
2482
2636
 
2483
2637
 
2638
+
2639
+
2640
+
2641
+
2484
2642
 
2485
2643
 
2486
2644
 
@@ -3623,6 +3781,10 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
3623
3781
 
3624
3782
 
3625
3783
 
3784
+
3785
+
3786
+
3787
+
3626
3788
 
3627
3789
 
3628
3790
 
@@ -3711,6 +3873,10 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
3711
3873
 
3712
3874
 
3713
3875
 
3876
+
3877
+
3878
+
3879
+
3714
3880
 
3715
3881
 
3716
3882
 
@@ -3797,6 +3963,10 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
3797
3963
 
3798
3964
 
3799
3965
 
3966
+
3967
+
3968
+
3969
+
3800
3970
 
3801
3971
 
3802
3972
 
@@ -3874,6 +4044,10 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
3874
4044
 
3875
4045
 
3876
4046
 
4047
+
4048
+
4049
+
4050
+
3877
4051
 
3878
4052
 
3879
4053
 
@@ -3928,6 +4102,10 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
3928
4102
 
3929
4103
 
3930
4104
 
4105
+
4106
+
4107
+
4108
+
3931
4109
 
3932
4110
 
3933
4111
 
@@ -4035,6 +4213,10 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
4035
4213
 
4036
4214
 
4037
4215
 
4216
+
4217
+
4218
+
4219
+
4038
4220
 
4039
4221
 
4040
4222
 
@@ -4123,6 +4305,10 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
4123
4305
 
4124
4306
 
4125
4307
 
4308
+
4309
+
4310
+
4311
+
4126
4312
 
4127
4313
 
4128
4314
 
@@ -4173,6 +4359,10 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
4173
4359
 
4174
4360
 
4175
4361
 
4362
+
4363
+
4364
+
4365
+
4176
4366
 
4177
4367
 
4178
4368
 
@@ -4276,6 +4466,10 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
4276
4466
 
4277
4467
 
4278
4468
 
4469
+
4470
+
4471
+
4472
+
4279
4473
 
4280
4474
 
4281
4475
 
@@ -4382,6 +4576,10 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
4382
4576
 
4383
4577
 
4384
4578
 
4579
+
4580
+
4581
+
4582
+
4385
4583
 
4386
4584
 
4387
4585
 
@@ -4552,6 +4750,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4552
4750
 
4553
4751
 
4554
4752
 
4753
+
4754
+
4755
+
4756
+
4555
4757
 
4556
4758
 
4557
4759
 
@@ -4637,6 +4839,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4637
4839
 
4638
4840
 
4639
4841
 
4842
+
4843
+
4844
+
4845
+
4640
4846
 
4641
4847
 
4642
4848
 
@@ -4721,6 +4927,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4721
4927
 
4722
4928
 
4723
4929
 
4930
+
4931
+
4932
+
4933
+
4724
4934
 
4725
4935
 
4726
4936
 
@@ -4820,6 +5030,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4820
5030
 
4821
5031
 
4822
5032
 
5033
+
5034
+
5035
+
5036
+
4823
5037
 
4824
5038
 
4825
5039
 
@@ -4874,6 +5088,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4874
5088
 
4875
5089
 
4876
5090
 
5091
+
5092
+
5093
+
5094
+
4877
5095
 
4878
5096
 
4879
5097
 
@@ -4998,6 +5216,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4998
5216
 
4999
5217
 
5000
5218
 
5219
+
5220
+
5221
+
5222
+
5001
5223
 
5002
5224
 
5003
5225
 
@@ -5144,6 +5366,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
5144
5366
 
5145
5367
 
5146
5368
 
5369
+
5370
+
5371
+
5372
+
5147
5373
 
5148
5374
 
5149
5375
 
@@ -5212,6 +5438,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
5212
5438
 
5213
5439
 
5214
5440
 
5441
+
5442
+
5443
+
5444
+
5215
5445
 
5216
5446
 
5217
5447
 
@@ -5262,6 +5492,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
5262
5492
 
5263
5493
 
5264
5494
 
5495
+
5496
+
5497
+
5498
+
5265
5499
 
5266
5500
 
5267
5501