undirected-graph-typed 2.5.2 → 2.6.0

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 (63) hide show
  1. package/dist/cjs/index.cjs +352 -14
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +352 -14
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +352 -14
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +352 -14
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  10. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +171 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/umd/undirected-graph-typed.js +352 -14
  35. package/dist/umd/undirected-graph-typed.js.map +1 -1
  36. package/dist/umd/undirected-graph-typed.min.js +1 -1
  37. package/dist/umd/undirected-graph-typed.min.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/data-structures/base/iterable-element-base.ts +32 -0
  40. package/src/data-structures/base/linear-base.ts +11 -0
  41. package/src/data-structures/binary-tree/avl-tree.ts +88 -5
  42. package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
  43. package/src/data-structures/binary-tree/binary-tree.ts +242 -81
  44. package/src/data-structures/binary-tree/bst.ts +173 -7
  45. package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
  46. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  47. package/src/data-structures/binary-tree/tree-map.ts +948 -36
  48. package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
  49. package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
  50. package/src/data-structures/binary-tree/tree-set.ts +1260 -251
  51. package/src/data-structures/graph/directed-graph.ts +71 -1
  52. package/src/data-structures/graph/undirected-graph.ts +64 -1
  53. package/src/data-structures/hash/hash-map.ts +100 -12
  54. package/src/data-structures/heap/heap.ts +149 -19
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
  56. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  57. package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
  58. package/src/data-structures/matrix/matrix.ts +56 -0
  59. package/src/data-structures/queue/deque.ts +187 -0
  60. package/src/data-structures/queue/queue.ts +109 -0
  61. package/src/data-structures/stack/stack.ts +75 -5
  62. package/src/data-structures/trie/trie.ts +84 -0
  63. package/src/interfaces/binary-tree.ts +1 -9
@@ -432,6 +432,35 @@ var undirectedGraphTyped = (() => {
432
432
  for (const ele of this) if (ele === element) return true;
433
433
  return false;
434
434
  }
435
+ /**
436
+ * Check whether a value exists (Array-compatible alias for `has`).
437
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
438
+ * @param element - Element to search for (uses `===`).
439
+ * @returns `true` if found.
440
+ */
441
+ includes(element) {
442
+ return this.has(element);
443
+ }
444
+ /**
445
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
446
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
447
+ */
448
+ *entries() {
449
+ let index = 0;
450
+ for (const value of this) {
451
+ yield [index++, value];
452
+ }
453
+ }
454
+ /**
455
+ * Return an iterator of numeric indices (Array-compatible).
456
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
457
+ */
458
+ *keys() {
459
+ let index = 0;
460
+ for (const _ of this) {
461
+ yield index++;
462
+ }
463
+ }
435
464
  /**
436
465
  * Reduces all elements to a single accumulated value.
437
466
  *
@@ -691,6 +720,16 @@ var undirectedGraphTyped = (() => {
691
720
  }
692
721
  return this;
693
722
  }
723
+ /**
724
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
725
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
726
+ * @returns A new reversed instance.
727
+ */
728
+ toReversed() {
729
+ const cloned = this.clone();
730
+ cloned.reverse();
731
+ return cloned;
732
+ }
694
733
  };
695
734
 
696
735
  // src/data-structures/heap/heap.ts
@@ -760,6 +799,13 @@ var undirectedGraphTyped = (() => {
760
799
 
761
800
 
762
801
 
802
+
803
+
804
+
805
+
806
+
807
+
808
+
763
809
 
764
810
 
765
811
 
@@ -817,7 +863,7 @@ var undirectedGraphTyped = (() => {
817
863
  }
818
864
  /**
819
865
  * Insert an element.
820
- * @remarks Time O(1) amortized, Space O(1)
866
+ * @remarks Time O(log N) amortized, Space O(1)
821
867
  * @param element - Element to insert.
822
868
  * @returns True.
823
869
 
@@ -847,6 +893,13 @@ var undirectedGraphTyped = (() => {
847
893
 
848
894
 
849
895
 
896
+
897
+
898
+
899
+
900
+
901
+
902
+
850
903
 
851
904
 
852
905
 
@@ -904,6 +957,13 @@ var undirectedGraphTyped = (() => {
904
957
 
905
958
 
906
959
 
960
+
961
+
962
+
963
+
964
+
965
+
966
+
907
967
 
908
968
 
909
969
 
@@ -968,6 +1028,40 @@ var undirectedGraphTyped = (() => {
968
1028
 
969
1029
 
970
1030
 
1031
+
1032
+
1033
+
1034
+
1035
+
1036
+
1037
+ * @example
1038
+ * // Heap with custom comparator (MaxHeap behavior)
1039
+ * interface Task {
1040
+ * id: number;
1041
+ * priority: number;
1042
+ * name: string;
1043
+ * }
1044
+ *
1045
+ * // Custom comparator for max heap behavior (higher priority first)
1046
+ * const tasks: Task[] = [
1047
+ * { id: 1, priority: 5, name: 'Email' },
1048
+ * { id: 2, priority: 3, name: 'Chat' },
1049
+ * { id: 3, priority: 8, name: 'Alert' }
1050
+ * ];
1051
+ *
1052
+ * const maxHeap = new Heap(tasks, {
1053
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
1054
+ * });
1055
+ *
1056
+ * console.log(maxHeap.size); // 3;
1057
+ *
1058
+ * // Peek returns highest priority task
1059
+ * const topTask = maxHeap.peek();
1060
+ * console.log(topTask?.priority); // 8;
1061
+ * console.log(topTask?.name); // 'Alert';
1062
+ */
1063
+ /**
1064
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
971
1065
 
972
1066
 
973
1067
 
@@ -998,6 +1092,14 @@ var undirectedGraphTyped = (() => {
998
1092
  * console.log(topTask?.name); // 'Alert';
999
1093
  */
1000
1094
  poll() {
1095
+ return this.pop();
1096
+ }
1097
+ /**
1098
+ * Remove and return the top element (min or max depending on comparator).
1099
+ * @remarks Time O(log N) amortized, Space O(1)
1100
+ * @returns The removed top element, or undefined if empty.
1101
+ */
1102
+ pop() {
1001
1103
  if (this.elements.length === 0) return;
1002
1104
  const value = this.elements[0];
1003
1105
  const last = this.elements.pop();
@@ -1038,6 +1140,13 @@ var undirectedGraphTyped = (() => {
1038
1140
 
1039
1141
 
1040
1142
 
1143
+
1144
+
1145
+
1146
+
1147
+
1148
+
1149
+
1041
1150
 
1042
1151
 
1043
1152
 
@@ -1138,6 +1247,13 @@ var undirectedGraphTyped = (() => {
1138
1247
 
1139
1248
 
1140
1249
 
1250
+
1251
+
1252
+
1253
+
1254
+
1255
+
1256
+
1141
1257
 
1142
1258
 
1143
1259
 
@@ -1185,6 +1301,13 @@ var undirectedGraphTyped = (() => {
1185
1301
 
1186
1302
 
1187
1303
 
1304
+
1305
+
1306
+
1307
+
1308
+
1309
+
1310
+
1188
1311
 
1189
1312
 
1190
1313
 
@@ -1202,16 +1325,6 @@ var undirectedGraphTyped = (() => {
1202
1325
  clear() {
1203
1326
  this._elements = [];
1204
1327
  }
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
1328
  /**
1216
1329
  * Check if an equal element exists in the heap.
1217
1330
  * @remarks Time O(N), Space O(1)
@@ -1235,6 +1348,13 @@ var undirectedGraphTyped = (() => {
1235
1348
 
1236
1349
 
1237
1350
 
1351
+
1352
+
1353
+
1354
+
1355
+
1356
+
1357
+
1238
1358
 
1239
1359
 
1240
1360
 
@@ -1282,6 +1402,13 @@ var undirectedGraphTyped = (() => {
1282
1402
 
1283
1403
 
1284
1404
 
1405
+
1406
+
1407
+
1408
+
1409
+
1410
+
1411
+
1285
1412
 
1286
1413
 
1287
1414
 
@@ -1306,7 +1433,7 @@ var undirectedGraphTyped = (() => {
1306
1433
  }
1307
1434
  if (index < 0) return false;
1308
1435
  if (index === 0) {
1309
- this.poll();
1436
+ this.pop();
1310
1437
  } else if (index === this.elements.length - 1) {
1311
1438
  this.elements.pop();
1312
1439
  } else {
@@ -1316,13 +1443,19 @@ var undirectedGraphTyped = (() => {
1316
1443
  }
1317
1444
  return true;
1318
1445
  }
1446
+ /**
1447
+ * @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
1448
+ */
1449
+ deleteBy(predicate) {
1450
+ return this.deleteWhere(predicate);
1451
+ }
1319
1452
  /**
1320
1453
  * Delete the first element that matches a predicate.
1321
1454
  * @remarks Time O(N), Space O(1)
1322
1455
  * @param predicate - Function (element, index, heap) → boolean.
1323
1456
  * @returns True if an element was removed.
1324
1457
  */
1325
- deleteBy(predicate) {
1458
+ deleteWhere(predicate) {
1326
1459
  let idx = -1;
1327
1460
  for (let i = 0; i < this.elements.length; i++) {
1328
1461
  if (predicate(this.elements[i], i, this)) {
@@ -1332,7 +1465,7 @@ var undirectedGraphTyped = (() => {
1332
1465
  }
1333
1466
  if (idx < 0) return false;
1334
1467
  if (idx === 0) {
1335
- this.poll();
1468
+ this.pop();
1336
1469
  } else if (idx === this.elements.length - 1) {
1337
1470
  this.elements.pop();
1338
1471
  } else {
@@ -1375,6 +1508,13 @@ var undirectedGraphTyped = (() => {
1375
1508
 
1376
1509
 
1377
1510
 
1511
+
1512
+
1513
+
1514
+
1515
+
1516
+
1517
+
1378
1518
 
1379
1519
 
1380
1520
 
@@ -1455,6 +1595,13 @@ var undirectedGraphTyped = (() => {
1455
1595
 
1456
1596
 
1457
1597
 
1598
+
1599
+
1600
+
1601
+
1602
+
1603
+
1604
+
1458
1605
 
1459
1606
 
1460
1607
 
@@ -1508,6 +1655,13 @@ var undirectedGraphTyped = (() => {
1508
1655
 
1509
1656
 
1510
1657
 
1658
+
1659
+
1660
+
1661
+
1662
+
1663
+
1664
+
1511
1665
 
1512
1666
 
1513
1667
 
@@ -1560,6 +1714,13 @@ var undirectedGraphTyped = (() => {
1560
1714
 
1561
1715
 
1562
1716
 
1717
+
1718
+
1719
+
1720
+
1721
+
1722
+
1723
+
1563
1724
 
1564
1725
 
1565
1726
 
@@ -1619,6 +1780,13 @@ var undirectedGraphTyped = (() => {
1619
1780
 
1620
1781
 
1621
1782
 
1783
+
1784
+
1785
+
1786
+
1787
+
1788
+
1789
+
1622
1790
 
1623
1791
 
1624
1792
 
@@ -1820,6 +1988,13 @@ var undirectedGraphTyped = (() => {
1820
1988
 
1821
1989
 
1822
1990
 
1991
+
1992
+
1993
+
1994
+
1995
+
1996
+
1997
+
1823
1998
 
1824
1999
 
1825
2000
 
@@ -1870,6 +2045,13 @@ var undirectedGraphTyped = (() => {
1870
2045
 
1871
2046
 
1872
2047
 
2048
+
2049
+
2050
+
2051
+
2052
+
2053
+
2054
+
1873
2055
 
1874
2056
 
1875
2057
 
@@ -1887,6 +2069,14 @@ var undirectedGraphTyped = (() => {
1887
2069
  get first() {
1888
2070
  return this.length > 0 ? this.elements[this._offset] : void 0;
1889
2071
  }
2072
+ /**
2073
+ * Peek at the front element without removing it (alias for `first`).
2074
+ * @remarks Time O(1), Space O(1)
2075
+ * @returns Front element or undefined.
2076
+ */
2077
+ peek() {
2078
+ return this.first;
2079
+ }
1890
2080
  /**
1891
2081
  * Get the last element (back) without removing it.
1892
2082
  * @remarks Time O(1), Space O(1)
@@ -1936,6 +2126,13 @@ var undirectedGraphTyped = (() => {
1936
2126
 
1937
2127
 
1938
2128
 
2129
+
2130
+
2131
+
2132
+
2133
+
2134
+
2135
+
1939
2136
 
1940
2137
 
1941
2138
 
@@ -1998,6 +2195,13 @@ var undirectedGraphTyped = (() => {
1998
2195
 
1999
2196
 
2000
2197
 
2198
+
2199
+
2200
+
2201
+
2202
+
2203
+
2204
+
2001
2205
 
2002
2206
 
2003
2207
 
@@ -2067,6 +2271,13 @@ var undirectedGraphTyped = (() => {
2067
2271
 
2068
2272
 
2069
2273
 
2274
+
2275
+
2276
+
2277
+
2278
+
2279
+
2280
+
2070
2281
 
2071
2282
 
2072
2283
 
@@ -2126,6 +2337,13 @@ var undirectedGraphTyped = (() => {
2126
2337
 
2127
2338
 
2128
2339
 
2340
+
2341
+
2342
+
2343
+
2344
+
2345
+
2346
+
2129
2347
 
2130
2348
 
2131
2349
 
@@ -2178,6 +2396,13 @@ var undirectedGraphTyped = (() => {
2178
2396
 
2179
2397
 
2180
2398
 
2399
+
2400
+
2401
+
2402
+
2403
+
2404
+
2405
+
2181
2406
 
2182
2407
 
2183
2408
 
@@ -2232,6 +2457,21 @@ var undirectedGraphTyped = (() => {
2232
2457
  this._elements[this._offset + index] = newElement;
2233
2458
  return true;
2234
2459
  }
2460
+ /**
2461
+ * Delete the first element that satisfies a predicate.
2462
+ * @remarks Time O(N), Space O(N)
2463
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
2464
+ * @returns True if a match was removed.
2465
+ */
2466
+ deleteWhere(predicate) {
2467
+ for (let i = 0; i < this.length; i++) {
2468
+ if (predicate(this._elements[this._offset + i], i, this)) {
2469
+ this.deleteAt(i);
2470
+ return true;
2471
+ }
2472
+ }
2473
+ return false;
2474
+ }
2235
2475
  /**
2236
2476
  * Reverse the queue in-place by compacting then reversing.
2237
2477
  * @remarks Time O(N), Space O(N)
@@ -2271,6 +2511,13 @@ var undirectedGraphTyped = (() => {
2271
2511
 
2272
2512
 
2273
2513
 
2514
+
2515
+
2516
+
2517
+
2518
+
2519
+
2520
+
2274
2521
 
2275
2522
 
2276
2523
 
@@ -2317,6 +2564,13 @@ var undirectedGraphTyped = (() => {
2317
2564
 
2318
2565
 
2319
2566
 
2567
+
2568
+
2569
+
2570
+
2571
+
2572
+
2573
+
2320
2574
 
2321
2575
 
2322
2576
 
@@ -2386,6 +2640,13 @@ var undirectedGraphTyped = (() => {
2386
2640
 
2387
2641
 
2388
2642
 
2643
+
2644
+
2645
+
2646
+
2647
+
2648
+
2649
+
2389
2650
 
2390
2651
 
2391
2652
 
@@ -2439,6 +2700,13 @@ var undirectedGraphTyped = (() => {
2439
2700
 
2440
2701
 
2441
2702
 
2703
+
2704
+
2705
+
2706
+
2707
+
2708
+
2709
+
2442
2710
 
2443
2711
 
2444
2712
 
@@ -2496,6 +2764,13 @@ var undirectedGraphTyped = (() => {
2496
2764
 
2497
2765
 
2498
2766
 
2767
+
2768
+
2769
+
2770
+
2771
+
2772
+
2773
+
2499
2774
 
2500
2775
 
2501
2776
 
@@ -3615,6 +3890,13 @@ var undirectedGraphTyped = (() => {
3615
3890
 
3616
3891
 
3617
3892
 
3893
+
3894
+
3895
+
3896
+
3897
+
3898
+
3899
+
3618
3900
 
3619
3901
 
3620
3902
 
@@ -3700,6 +3982,13 @@ var undirectedGraphTyped = (() => {
3700
3982
 
3701
3983
 
3702
3984
 
3985
+
3986
+
3987
+
3988
+
3989
+
3990
+
3991
+
3703
3992
 
3704
3993
 
3705
3994
 
@@ -3784,6 +4073,13 @@ var undirectedGraphTyped = (() => {
3784
4073
 
3785
4074
 
3786
4075
 
4076
+
4077
+
4078
+
4079
+
4080
+
4081
+
4082
+
3787
4083
 
3788
4084
 
3789
4085
 
@@ -3883,6 +4179,13 @@ var undirectedGraphTyped = (() => {
3883
4179
 
3884
4180
 
3885
4181
 
4182
+
4183
+
4184
+
4185
+
4186
+
4187
+
4188
+
3886
4189
 
3887
4190
 
3888
4191
 
@@ -3937,6 +4240,13 @@ var undirectedGraphTyped = (() => {
3937
4240
 
3938
4241
 
3939
4242
 
4243
+
4244
+
4245
+
4246
+
4247
+
4248
+
4249
+
3940
4250
 
3941
4251
 
3942
4252
 
@@ -4061,6 +4371,13 @@ var undirectedGraphTyped = (() => {
4061
4371
 
4062
4372
 
4063
4373
 
4374
+
4375
+
4376
+
4377
+
4378
+
4379
+
4380
+
4064
4381
 
4065
4382
 
4066
4383
 
@@ -4207,6 +4524,13 @@ var undirectedGraphTyped = (() => {
4207
4524
 
4208
4525
 
4209
4526
 
4527
+
4528
+
4529
+
4530
+
4531
+
4532
+
4533
+
4210
4534
 
4211
4535
 
4212
4536
 
@@ -4275,6 +4599,13 @@ var undirectedGraphTyped = (() => {
4275
4599
 
4276
4600
 
4277
4601
 
4602
+
4603
+
4604
+
4605
+
4606
+
4607
+
4608
+
4278
4609
 
4279
4610
 
4280
4611
 
@@ -4325,6 +4656,13 @@ var undirectedGraphTyped = (() => {
4325
4656
 
4326
4657
 
4327
4658
 
4659
+
4660
+
4661
+
4662
+
4663
+
4664
+
4665
+
4328
4666
 
4329
4667
 
4330
4668