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
@@ -745,6 +745,10 @@ var _Heap = class _Heap extends IterableElementBase {
745
745
 
746
746
 
747
747
 
748
+
749
+
750
+
751
+
748
752
 
749
753
 
750
754
 
@@ -799,7 +803,7 @@ var _Heap = class _Heap extends IterableElementBase {
799
803
  }
800
804
  /**
801
805
  * Insert an element.
802
- * @remarks Time O(1) amortized, Space O(1)
806
+ * @remarks Time O(log N) amortized, Space O(1)
803
807
  * @param element - Element to insert.
804
808
  * @returns True.
805
809
 
@@ -832,6 +836,10 @@ var _Heap = class _Heap extends IterableElementBase {
832
836
 
833
837
 
834
838
 
839
+
840
+
841
+
842
+
835
843
 
836
844
 
837
845
 
@@ -889,6 +897,10 @@ var _Heap = class _Heap extends IterableElementBase {
889
897
 
890
898
 
891
899
 
900
+
901
+
902
+
903
+
892
904
 
893
905
 
894
906
 
@@ -949,10 +961,41 @@ var _Heap = class _Heap extends IterableElementBase {
949
961
 
950
962
 
951
963
 
964
+
965
+
966
+
952
967
 
953
968
 
954
969
 
955
970
 
971
+ * @example
972
+ * // Heap with custom comparator (MaxHeap behavior)
973
+ * interface Task {
974
+ * id: number;
975
+ * priority: number;
976
+ * name: string;
977
+ * }
978
+ *
979
+ * // Custom comparator for max heap behavior (higher priority first)
980
+ * const tasks: Task[] = [
981
+ * { id: 1, priority: 5, name: 'Email' },
982
+ * { id: 2, priority: 3, name: 'Chat' },
983
+ * { id: 3, priority: 8, name: 'Alert' }
984
+ * ];
985
+ *
986
+ * const maxHeap = new Heap(tasks, {
987
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
988
+ * });
989
+ *
990
+ * console.log(maxHeap.size); // 3;
991
+ *
992
+ * // Peek returns highest priority task
993
+ * const topTask = maxHeap.peek();
994
+ * console.log(topTask?.priority); // 8;
995
+ * console.log(topTask?.name); // 'Alert';
996
+ */
997
+ /**
998
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
956
999
  * @example
957
1000
  * // Heap with custom comparator (MaxHeap behavior)
958
1001
  * interface Task {
@@ -980,6 +1023,14 @@ var _Heap = class _Heap extends IterableElementBase {
980
1023
  * console.log(topTask?.name); // 'Alert';
981
1024
  */
982
1025
  poll() {
1026
+ return this.pop();
1027
+ }
1028
+ /**
1029
+ * Remove and return the top element (min or max depending on comparator).
1030
+ * @remarks Time O(log N) amortized, Space O(1)
1031
+ * @returns The removed top element, or undefined if empty.
1032
+ */
1033
+ pop() {
983
1034
  if (this.elements.length === 0) return;
984
1035
  const value = this.elements[0];
985
1036
  const last = this.elements.pop();
@@ -1023,6 +1074,10 @@ var _Heap = class _Heap extends IterableElementBase {
1023
1074
 
1024
1075
 
1025
1076
 
1077
+
1078
+
1079
+
1080
+
1026
1081
 
1027
1082
 
1028
1083
 
@@ -1123,6 +1178,10 @@ var _Heap = class _Heap extends IterableElementBase {
1123
1178
 
1124
1179
 
1125
1180
 
1181
+
1182
+
1183
+
1184
+
1126
1185
 
1127
1186
 
1128
1187
 
@@ -1170,6 +1229,10 @@ var _Heap = class _Heap extends IterableElementBase {
1170
1229
 
1171
1230
 
1172
1231
 
1232
+
1233
+
1234
+
1235
+
1173
1236
 
1174
1237
 
1175
1238
 
@@ -1184,16 +1247,6 @@ var _Heap = class _Heap extends IterableElementBase {
1184
1247
  clear() {
1185
1248
  this._elements = [];
1186
1249
  }
1187
- /**
1188
- * Replace the backing array and rebuild the heap.
1189
- * @remarks Time O(N), Space O(N)
1190
- * @param elements - Iterable used to refill the heap.
1191
- * @returns Array of per-node results from fixing steps.
1192
- */
1193
- refill(elements) {
1194
- this._elements = Array.from(elements);
1195
- return this.fix();
1196
- }
1197
1250
  /**
1198
1251
  * Check if an equal element exists in the heap.
1199
1252
  * @remarks Time O(N), Space O(1)
@@ -1220,6 +1273,10 @@ var _Heap = class _Heap extends IterableElementBase {
1220
1273
 
1221
1274
 
1222
1275
 
1276
+
1277
+
1278
+
1279
+
1223
1280
 
1224
1281
 
1225
1282
 
@@ -1267,6 +1324,10 @@ var _Heap = class _Heap extends IterableElementBase {
1267
1324
 
1268
1325
 
1269
1326
 
1327
+
1328
+
1329
+
1330
+
1270
1331
 
1271
1332
 
1272
1333
 
@@ -1288,7 +1349,7 @@ var _Heap = class _Heap extends IterableElementBase {
1288
1349
  }
1289
1350
  if (index < 0) return false;
1290
1351
  if (index === 0) {
1291
- this.poll();
1352
+ this.pop();
1292
1353
  } else if (index === this.elements.length - 1) {
1293
1354
  this.elements.pop();
1294
1355
  } else {
@@ -1298,13 +1359,19 @@ var _Heap = class _Heap extends IterableElementBase {
1298
1359
  }
1299
1360
  return true;
1300
1361
  }
1362
+ /**
1363
+ * @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
1364
+ */
1365
+ deleteBy(predicate) {
1366
+ return this.deleteWhere(predicate);
1367
+ }
1301
1368
  /**
1302
1369
  * Delete the first element that matches a predicate.
1303
1370
  * @remarks Time O(N), Space O(1)
1304
1371
  * @param predicate - Function (element, index, heap) → boolean.
1305
1372
  * @returns True if an element was removed.
1306
1373
  */
1307
- deleteBy(predicate) {
1374
+ deleteWhere(predicate) {
1308
1375
  let idx = -1;
1309
1376
  for (let i = 0; i < this.elements.length; i++) {
1310
1377
  if (predicate(this.elements[i], i, this)) {
@@ -1314,7 +1381,7 @@ var _Heap = class _Heap extends IterableElementBase {
1314
1381
  }
1315
1382
  if (idx < 0) return false;
1316
1383
  if (idx === 0) {
1317
- this.poll();
1384
+ this.pop();
1318
1385
  } else if (idx === this.elements.length - 1) {
1319
1386
  this.elements.pop();
1320
1387
  } else {
@@ -1360,6 +1427,10 @@ var _Heap = class _Heap extends IterableElementBase {
1360
1427
 
1361
1428
 
1362
1429
 
1430
+
1431
+
1432
+
1433
+
1363
1434
 
1364
1435
 
1365
1436
 
@@ -1440,6 +1511,10 @@ var _Heap = class _Heap extends IterableElementBase {
1440
1511
 
1441
1512
 
1442
1513
 
1514
+
1515
+
1516
+
1517
+
1443
1518
 
1444
1519
 
1445
1520
 
@@ -1493,6 +1568,10 @@ var _Heap = class _Heap extends IterableElementBase {
1493
1568
 
1494
1569
 
1495
1570
 
1571
+
1572
+
1573
+
1574
+
1496
1575
 
1497
1576
 
1498
1577
 
@@ -1545,6 +1624,10 @@ var _Heap = class _Heap extends IterableElementBase {
1545
1624
 
1546
1625
 
1547
1626
 
1627
+
1628
+
1629
+
1630
+
1548
1631
 
1549
1632
 
1550
1633
 
@@ -1604,6 +1687,10 @@ var _Heap = class _Heap extends IterableElementBase {
1604
1687
 
1605
1688
 
1606
1689
 
1690
+
1691
+
1692
+
1693
+
1607
1694
 
1608
1695
 
1609
1696
 
@@ -1807,6 +1894,10 @@ var _Queue = class _Queue extends LinearBase {
1807
1894
 
1808
1895
 
1809
1896
 
1897
+
1898
+
1899
+
1900
+
1810
1901
 
1811
1902
 
1812
1903
 
@@ -1857,6 +1948,10 @@ var _Queue = class _Queue extends LinearBase {
1857
1948
 
1858
1949
 
1859
1950
 
1951
+
1952
+
1953
+
1954
+
1860
1955
 
1861
1956
 
1862
1957
 
@@ -1871,6 +1966,14 @@ var _Queue = class _Queue extends LinearBase {
1871
1966
  get first() {
1872
1967
  return this.length > 0 ? this.elements[this._offset] : void 0;
1873
1968
  }
1969
+ /**
1970
+ * Peek at the front element without removing it (alias for `first`).
1971
+ * @remarks Time O(1), Space O(1)
1972
+ * @returns Front element or undefined.
1973
+ */
1974
+ peek() {
1975
+ return this.first;
1976
+ }
1874
1977
  /**
1875
1978
  * Get the last element (back) without removing it.
1876
1979
  * @remarks Time O(1), Space O(1)
@@ -1923,6 +2026,10 @@ var _Queue = class _Queue extends LinearBase {
1923
2026
 
1924
2027
 
1925
2028
 
2029
+
2030
+
2031
+
2032
+
1926
2033
 
1927
2034
 
1928
2035
 
@@ -1985,6 +2092,10 @@ var _Queue = class _Queue extends LinearBase {
1985
2092
 
1986
2093
 
1987
2094
 
2095
+
2096
+
2097
+
2098
+
1988
2099
 
1989
2100
 
1990
2101
 
@@ -2054,6 +2165,10 @@ var _Queue = class _Queue extends LinearBase {
2054
2165
 
2055
2166
 
2056
2167
 
2168
+
2169
+
2170
+
2171
+
2057
2172
 
2058
2173
 
2059
2174
 
@@ -2113,6 +2228,10 @@ var _Queue = class _Queue extends LinearBase {
2113
2228
 
2114
2229
 
2115
2230
 
2231
+
2232
+
2233
+
2234
+
2116
2235
 
2117
2236
 
2118
2237
 
@@ -2165,6 +2284,10 @@ var _Queue = class _Queue extends LinearBase {
2165
2284
 
2166
2285
 
2167
2286
 
2287
+
2288
+
2289
+
2290
+
2168
2291
 
2169
2292
 
2170
2293
 
@@ -2216,6 +2339,21 @@ var _Queue = class _Queue extends LinearBase {
2216
2339
  this._elements[this._offset + index] = newElement;
2217
2340
  return true;
2218
2341
  }
2342
+ /**
2343
+ * Delete the first element that satisfies a predicate.
2344
+ * @remarks Time O(N), Space O(N)
2345
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
2346
+ * @returns True if a match was removed.
2347
+ */
2348
+ deleteWhere(predicate) {
2349
+ for (let i = 0; i < this.length; i++) {
2350
+ if (predicate(this._elements[this._offset + i], i, this)) {
2351
+ this.deleteAt(i);
2352
+ return true;
2353
+ }
2354
+ }
2355
+ return false;
2356
+ }
2219
2357
  /**
2220
2358
  * Reverse the queue in-place by compacting then reversing.
2221
2359
  * @remarks Time O(N), Space O(N)
@@ -2258,6 +2396,10 @@ var _Queue = class _Queue extends LinearBase {
2258
2396
 
2259
2397
 
2260
2398
 
2399
+
2400
+
2401
+
2402
+
2261
2403
 
2262
2404
 
2263
2405
 
@@ -2304,6 +2446,10 @@ var _Queue = class _Queue extends LinearBase {
2304
2446
 
2305
2447
 
2306
2448
 
2449
+
2450
+
2451
+
2452
+
2307
2453
 
2308
2454
 
2309
2455
 
@@ -2373,6 +2519,10 @@ var _Queue = class _Queue extends LinearBase {
2373
2519
 
2374
2520
 
2375
2521
 
2522
+
2523
+
2524
+
2525
+
2376
2526
 
2377
2527
 
2378
2528
 
@@ -2426,6 +2576,10 @@ var _Queue = class _Queue extends LinearBase {
2426
2576
 
2427
2577
 
2428
2578
 
2579
+
2580
+
2581
+
2582
+
2429
2583
 
2430
2584
 
2431
2585
 
@@ -2483,6 +2637,10 @@ var _Queue = class _Queue extends LinearBase {
2483
2637
 
2484
2638
 
2485
2639
 
2640
+
2641
+
2642
+
2643
+
2486
2644
 
2487
2645
 
2488
2646
 
@@ -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
 
@@ -4554,6 +4752,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4554
4752
 
4555
4753
 
4556
4754
 
4755
+
4756
+
4757
+
4758
+
4557
4759
 
4558
4760
 
4559
4761
 
@@ -4639,6 +4841,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4639
4841
 
4640
4842
 
4641
4843
 
4844
+
4845
+
4846
+
4847
+
4642
4848
 
4643
4849
 
4644
4850
 
@@ -4723,6 +4929,10 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
4723
4929
 
4724
4930
 
4725
4931
 
4932
+
4933
+
4934
+
4935
+
4726
4936
 
4727
4937
 
4728
4938
 
@@ -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