undirected-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 +208 -14
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +208 -14
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +208 -14
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +208 -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/undirected-graph-typed.js +208 -14
  33. package/dist/umd/undirected-graph-typed.js.map +1 -1
  34. package/dist/umd/undirected-graph-typed.min.js +1 -1
  35. package/dist/umd/undirected-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
@@ -763,6 +763,10 @@ var undirectedGraphTyped = (() => {
763
763
 
764
764
 
765
765
 
766
+
767
+
768
+
769
+
766
770
 
767
771
 
768
772
 
@@ -817,7 +821,7 @@ var undirectedGraphTyped = (() => {
817
821
  }
818
822
  /**
819
823
  * Insert an element.
820
- * @remarks Time O(1) amortized, Space O(1)
824
+ * @remarks Time O(log N) amortized, Space O(1)
821
825
  * @param element - Element to insert.
822
826
  * @returns True.
823
827
 
@@ -850,6 +854,10 @@ var undirectedGraphTyped = (() => {
850
854
 
851
855
 
852
856
 
857
+
858
+
859
+
860
+
853
861
 
854
862
 
855
863
 
@@ -907,6 +915,10 @@ var undirectedGraphTyped = (() => {
907
915
 
908
916
 
909
917
 
918
+
919
+
920
+
921
+
910
922
 
911
923
 
912
924
 
@@ -967,10 +979,41 @@ var undirectedGraphTyped = (() => {
967
979
 
968
980
 
969
981
 
982
+
983
+
984
+
970
985
 
971
986
 
972
987
 
973
988
 
989
+ * @example
990
+ * // Heap with custom comparator (MaxHeap behavior)
991
+ * interface Task {
992
+ * id: number;
993
+ * priority: number;
994
+ * name: string;
995
+ * }
996
+ *
997
+ * // Custom comparator for max heap behavior (higher priority first)
998
+ * const tasks: Task[] = [
999
+ * { id: 1, priority: 5, name: 'Email' },
1000
+ * { id: 2, priority: 3, name: 'Chat' },
1001
+ * { id: 3, priority: 8, name: 'Alert' }
1002
+ * ];
1003
+ *
1004
+ * const maxHeap = new Heap(tasks, {
1005
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
1006
+ * });
1007
+ *
1008
+ * console.log(maxHeap.size); // 3;
1009
+ *
1010
+ * // Peek returns highest priority task
1011
+ * const topTask = maxHeap.peek();
1012
+ * console.log(topTask?.priority); // 8;
1013
+ * console.log(topTask?.name); // 'Alert';
1014
+ */
1015
+ /**
1016
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
974
1017
  * @example
975
1018
  * // Heap with custom comparator (MaxHeap behavior)
976
1019
  * interface Task {
@@ -998,6 +1041,14 @@ var undirectedGraphTyped = (() => {
998
1041
  * console.log(topTask?.name); // 'Alert';
999
1042
  */
1000
1043
  poll() {
1044
+ return this.pop();
1045
+ }
1046
+ /**
1047
+ * Remove and return the top element (min or max depending on comparator).
1048
+ * @remarks Time O(log N) amortized, Space O(1)
1049
+ * @returns The removed top element, or undefined if empty.
1050
+ */
1051
+ pop() {
1001
1052
  if (this.elements.length === 0) return;
1002
1053
  const value = this.elements[0];
1003
1054
  const last = this.elements.pop();
@@ -1041,6 +1092,10 @@ var undirectedGraphTyped = (() => {
1041
1092
 
1042
1093
 
1043
1094
 
1095
+
1096
+
1097
+
1098
+
1044
1099
 
1045
1100
 
1046
1101
 
@@ -1141,6 +1196,10 @@ var undirectedGraphTyped = (() => {
1141
1196
 
1142
1197
 
1143
1198
 
1199
+
1200
+
1201
+
1202
+
1144
1203
 
1145
1204
 
1146
1205
 
@@ -1188,6 +1247,10 @@ var undirectedGraphTyped = (() => {
1188
1247
 
1189
1248
 
1190
1249
 
1250
+
1251
+
1252
+
1253
+
1191
1254
 
1192
1255
 
1193
1256
 
@@ -1202,16 +1265,6 @@ var undirectedGraphTyped = (() => {
1202
1265
  clear() {
1203
1266
  this._elements = [];
1204
1267
  }
1205
- /**
1206
- * Replace the backing array and rebuild the heap.
1207
- * @remarks Time O(N), Space O(N)
1208
- * @param elements - Iterable used to refill the heap.
1209
- * @returns Array of per-node results from fixing steps.
1210
- */
1211
- refill(elements) {
1212
- this._elements = Array.from(elements);
1213
- return this.fix();
1214
- }
1215
1268
  /**
1216
1269
  * Check if an equal element exists in the heap.
1217
1270
  * @remarks Time O(N), Space O(1)
@@ -1238,6 +1291,10 @@ var undirectedGraphTyped = (() => {
1238
1291
 
1239
1292
 
1240
1293
 
1294
+
1295
+
1296
+
1297
+
1241
1298
 
1242
1299
 
1243
1300
 
@@ -1285,6 +1342,10 @@ var undirectedGraphTyped = (() => {
1285
1342
 
1286
1343
 
1287
1344
 
1345
+
1346
+
1347
+
1348
+
1288
1349
 
1289
1350
 
1290
1351
 
@@ -1306,7 +1367,7 @@ var undirectedGraphTyped = (() => {
1306
1367
  }
1307
1368
  if (index < 0) return false;
1308
1369
  if (index === 0) {
1309
- this.poll();
1370
+ this.pop();
1310
1371
  } else if (index === this.elements.length - 1) {
1311
1372
  this.elements.pop();
1312
1373
  } else {
@@ -1316,13 +1377,19 @@ var undirectedGraphTyped = (() => {
1316
1377
  }
1317
1378
  return true;
1318
1379
  }
1380
+ /**
1381
+ * @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
1382
+ */
1383
+ deleteBy(predicate) {
1384
+ return this.deleteWhere(predicate);
1385
+ }
1319
1386
  /**
1320
1387
  * Delete the first element that matches a predicate.
1321
1388
  * @remarks Time O(N), Space O(1)
1322
1389
  * @param predicate - Function (element, index, heap) → boolean.
1323
1390
  * @returns True if an element was removed.
1324
1391
  */
1325
- deleteBy(predicate) {
1392
+ deleteWhere(predicate) {
1326
1393
  let idx = -1;
1327
1394
  for (let i = 0; i < this.elements.length; i++) {
1328
1395
  if (predicate(this.elements[i], i, this)) {
@@ -1332,7 +1399,7 @@ var undirectedGraphTyped = (() => {
1332
1399
  }
1333
1400
  if (idx < 0) return false;
1334
1401
  if (idx === 0) {
1335
- this.poll();
1402
+ this.pop();
1336
1403
  } else if (idx === this.elements.length - 1) {
1337
1404
  this.elements.pop();
1338
1405
  } else {
@@ -1378,6 +1445,10 @@ var undirectedGraphTyped = (() => {
1378
1445
 
1379
1446
 
1380
1447
 
1448
+
1449
+
1450
+
1451
+
1381
1452
 
1382
1453
 
1383
1454
 
@@ -1458,6 +1529,10 @@ var undirectedGraphTyped = (() => {
1458
1529
 
1459
1530
 
1460
1531
 
1532
+
1533
+
1534
+
1535
+
1461
1536
 
1462
1537
 
1463
1538
 
@@ -1511,6 +1586,10 @@ var undirectedGraphTyped = (() => {
1511
1586
 
1512
1587
 
1513
1588
 
1589
+
1590
+
1591
+
1592
+
1514
1593
 
1515
1594
 
1516
1595
 
@@ -1563,6 +1642,10 @@ var undirectedGraphTyped = (() => {
1563
1642
 
1564
1643
 
1565
1644
 
1645
+
1646
+
1647
+
1648
+
1566
1649
 
1567
1650
 
1568
1651
 
@@ -1622,6 +1705,10 @@ var undirectedGraphTyped = (() => {
1622
1705
 
1623
1706
 
1624
1707
 
1708
+
1709
+
1710
+
1711
+
1625
1712
 
1626
1713
 
1627
1714
 
@@ -1823,6 +1910,10 @@ var undirectedGraphTyped = (() => {
1823
1910
 
1824
1911
 
1825
1912
 
1913
+
1914
+
1915
+
1916
+
1826
1917
 
1827
1918
 
1828
1919
 
@@ -1873,6 +1964,10 @@ var undirectedGraphTyped = (() => {
1873
1964
 
1874
1965
 
1875
1966
 
1967
+
1968
+
1969
+
1970
+
1876
1971
 
1877
1972
 
1878
1973
 
@@ -1887,6 +1982,14 @@ var undirectedGraphTyped = (() => {
1887
1982
  get first() {
1888
1983
  return this.length > 0 ? this.elements[this._offset] : void 0;
1889
1984
  }
1985
+ /**
1986
+ * Peek at the front element without removing it (alias for `first`).
1987
+ * @remarks Time O(1), Space O(1)
1988
+ * @returns Front element or undefined.
1989
+ */
1990
+ peek() {
1991
+ return this.first;
1992
+ }
1890
1993
  /**
1891
1994
  * Get the last element (back) without removing it.
1892
1995
  * @remarks Time O(1), Space O(1)
@@ -1939,6 +2042,10 @@ var undirectedGraphTyped = (() => {
1939
2042
 
1940
2043
 
1941
2044
 
2045
+
2046
+
2047
+
2048
+
1942
2049
 
1943
2050
 
1944
2051
 
@@ -2001,6 +2108,10 @@ var undirectedGraphTyped = (() => {
2001
2108
 
2002
2109
 
2003
2110
 
2111
+
2112
+
2113
+
2114
+
2004
2115
 
2005
2116
 
2006
2117
 
@@ -2070,6 +2181,10 @@ var undirectedGraphTyped = (() => {
2070
2181
 
2071
2182
 
2072
2183
 
2184
+
2185
+
2186
+
2187
+
2073
2188
 
2074
2189
 
2075
2190
 
@@ -2129,6 +2244,10 @@ var undirectedGraphTyped = (() => {
2129
2244
 
2130
2245
 
2131
2246
 
2247
+
2248
+
2249
+
2250
+
2132
2251
 
2133
2252
 
2134
2253
 
@@ -2181,6 +2300,10 @@ var undirectedGraphTyped = (() => {
2181
2300
 
2182
2301
 
2183
2302
 
2303
+
2304
+
2305
+
2306
+
2184
2307
 
2185
2308
 
2186
2309
 
@@ -2232,6 +2355,21 @@ var undirectedGraphTyped = (() => {
2232
2355
  this._elements[this._offset + index] = newElement;
2233
2356
  return true;
2234
2357
  }
2358
+ /**
2359
+ * Delete the first element that satisfies a predicate.
2360
+ * @remarks Time O(N), Space O(N)
2361
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
2362
+ * @returns True if a match was removed.
2363
+ */
2364
+ deleteWhere(predicate) {
2365
+ for (let i = 0; i < this.length; i++) {
2366
+ if (predicate(this._elements[this._offset + i], i, this)) {
2367
+ this.deleteAt(i);
2368
+ return true;
2369
+ }
2370
+ }
2371
+ return false;
2372
+ }
2235
2373
  /**
2236
2374
  * Reverse the queue in-place by compacting then reversing.
2237
2375
  * @remarks Time O(N), Space O(N)
@@ -2274,6 +2412,10 @@ var undirectedGraphTyped = (() => {
2274
2412
 
2275
2413
 
2276
2414
 
2415
+
2416
+
2417
+
2418
+
2277
2419
 
2278
2420
 
2279
2421
 
@@ -2320,6 +2462,10 @@ var undirectedGraphTyped = (() => {
2320
2462
 
2321
2463
 
2322
2464
 
2465
+
2466
+
2467
+
2468
+
2323
2469
 
2324
2470
 
2325
2471
 
@@ -2389,6 +2535,10 @@ var undirectedGraphTyped = (() => {
2389
2535
 
2390
2536
 
2391
2537
 
2538
+
2539
+
2540
+
2541
+
2392
2542
 
2393
2543
 
2394
2544
 
@@ -2442,6 +2592,10 @@ var undirectedGraphTyped = (() => {
2442
2592
 
2443
2593
 
2444
2594
 
2595
+
2596
+
2597
+
2598
+
2445
2599
 
2446
2600
 
2447
2601
 
@@ -2499,6 +2653,10 @@ var undirectedGraphTyped = (() => {
2499
2653
 
2500
2654
 
2501
2655
 
2656
+
2657
+
2658
+
2659
+
2502
2660
 
2503
2661
 
2504
2662
 
@@ -3618,6 +3776,10 @@ var undirectedGraphTyped = (() => {
3618
3776
 
3619
3777
 
3620
3778
 
3779
+
3780
+
3781
+
3782
+
3621
3783
 
3622
3784
 
3623
3785
 
@@ -3703,6 +3865,10 @@ var undirectedGraphTyped = (() => {
3703
3865
 
3704
3866
 
3705
3867
 
3868
+
3869
+
3870
+
3871
+
3706
3872
 
3707
3873
 
3708
3874
 
@@ -3787,6 +3953,10 @@ var undirectedGraphTyped = (() => {
3787
3953
 
3788
3954
 
3789
3955
 
3956
+
3957
+
3958
+
3959
+
3790
3960
 
3791
3961
 
3792
3962
 
@@ -3886,6 +4056,10 @@ var undirectedGraphTyped = (() => {
3886
4056
 
3887
4057
 
3888
4058
 
4059
+
4060
+
4061
+
4062
+
3889
4063
 
3890
4064
 
3891
4065
 
@@ -3940,6 +4114,10 @@ var undirectedGraphTyped = (() => {
3940
4114
 
3941
4115
 
3942
4116
 
4117
+
4118
+
4119
+
4120
+
3943
4121
 
3944
4122
 
3945
4123
 
@@ -4064,6 +4242,10 @@ var undirectedGraphTyped = (() => {
4064
4242
 
4065
4243
 
4066
4244
 
4245
+
4246
+
4247
+
4248
+
4067
4249
 
4068
4250
 
4069
4251
 
@@ -4210,6 +4392,10 @@ var undirectedGraphTyped = (() => {
4210
4392
 
4211
4393
 
4212
4394
 
4395
+
4396
+
4397
+
4398
+
4213
4399
 
4214
4400
 
4215
4401
 
@@ -4278,6 +4464,10 @@ var undirectedGraphTyped = (() => {
4278
4464
 
4279
4465
 
4280
4466
 
4467
+
4468
+
4469
+
4470
+
4281
4471
 
4282
4472
 
4283
4473
 
@@ -4328,6 +4518,10 @@ var undirectedGraphTyped = (() => {
4328
4518
 
4329
4519
 
4330
4520
 
4521
+
4522
+
4523
+
4524
+
4331
4525
 
4332
4526
 
4333
4527