linked-list-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 +443 -2
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +443 -2
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +443 -2
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +443 -2
  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/linked-list-typed.js +443 -2
  35. package/dist/umd/linked-list-typed.js.map +1 -1
  36. package/dist/umd/linked-list-typed.min.js +1 -1
  37. package/dist/umd/linked-list-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
@@ -242,6 +242,35 @@ var linkedListTyped = (() => {
242
242
  for (const ele of this) if (ele === element) return true;
243
243
  return false;
244
244
  }
245
+ /**
246
+ * Check whether a value exists (Array-compatible alias for `has`).
247
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
248
+ * @param element - Element to search for (uses `===`).
249
+ * @returns `true` if found.
250
+ */
251
+ includes(element) {
252
+ return this.has(element);
253
+ }
254
+ /**
255
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
256
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
257
+ */
258
+ *entries() {
259
+ let index = 0;
260
+ for (const value of this) {
261
+ yield [index++, value];
262
+ }
263
+ }
264
+ /**
265
+ * Return an iterator of numeric indices (Array-compatible).
266
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
267
+ */
268
+ *keys() {
269
+ let index = 0;
270
+ for (const _ of this) {
271
+ yield index++;
272
+ }
273
+ }
245
274
  /**
246
275
  * Reduces all elements to a single accumulated value.
247
276
  *
@@ -546,6 +575,16 @@ var linkedListTyped = (() => {
546
575
  }
547
576
  return this;
548
577
  }
578
+ /**
579
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
580
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
581
+ * @returns A new reversed instance.
582
+ */
583
+ toReversed() {
584
+ const cloned = this.clone();
585
+ cloned.reverse();
586
+ return cloned;
587
+ }
549
588
  };
550
589
  var LinearLinkedBase = class extends LinearBase {
551
590
  constructor(options) {
@@ -830,6 +869,13 @@ var linkedListTyped = (() => {
830
869
 
831
870
 
832
871
 
872
+
873
+
874
+
875
+
876
+
877
+
878
+
833
879
 
834
880
 
835
881
 
@@ -897,6 +943,13 @@ var linkedListTyped = (() => {
897
943
 
898
944
 
899
945
 
946
+
947
+
948
+
949
+
950
+
951
+
952
+
900
953
 
901
954
 
902
955
 
@@ -970,6 +1023,13 @@ var linkedListTyped = (() => {
970
1023
 
971
1024
 
972
1025
 
1026
+
1027
+
1028
+
1029
+
1030
+
1031
+
1032
+
973
1033
 
974
1034
 
975
1035
 
@@ -1024,6 +1084,13 @@ var linkedListTyped = (() => {
1024
1084
 
1025
1085
 
1026
1086
 
1087
+
1088
+
1089
+
1090
+
1091
+
1092
+
1093
+
1027
1094
 
1028
1095
 
1029
1096
 
@@ -1139,6 +1206,13 @@ var linkedListTyped = (() => {
1139
1206
 
1140
1207
 
1141
1208
 
1209
+
1210
+
1211
+
1212
+
1213
+
1214
+
1215
+
1142
1216
 
1143
1217
 
1144
1218
 
@@ -1198,6 +1272,13 @@ var linkedListTyped = (() => {
1198
1272
 
1199
1273
 
1200
1274
 
1275
+
1276
+
1277
+
1278
+
1279
+
1280
+
1281
+
1201
1282
 
1202
1283
 
1203
1284
 
@@ -1246,6 +1327,13 @@ var linkedListTyped = (() => {
1246
1327
 
1247
1328
 
1248
1329
 
1330
+
1331
+
1332
+
1333
+
1334
+
1335
+
1336
+
1249
1337
 
1250
1338
 
1251
1339
 
@@ -1300,6 +1388,13 @@ var linkedListTyped = (() => {
1300
1388
 
1301
1389
 
1302
1390
 
1391
+
1392
+
1393
+
1394
+
1395
+
1396
+
1397
+
1303
1398
 
1304
1399
 
1305
1400
 
@@ -1359,6 +1454,13 @@ var linkedListTyped = (() => {
1359
1454
 
1360
1455
 
1361
1456
 
1457
+
1458
+
1459
+
1460
+
1461
+
1462
+
1463
+
1362
1464
 
1363
1465
 
1364
1466
 
@@ -1426,6 +1528,13 @@ var linkedListTyped = (() => {
1426
1528
 
1427
1529
 
1428
1530
 
1531
+
1532
+
1533
+
1534
+
1535
+
1536
+
1537
+
1429
1538
 
1430
1539
 
1431
1540
 
@@ -1470,6 +1579,13 @@ var linkedListTyped = (() => {
1470
1579
 
1471
1580
 
1472
1581
 
1582
+
1583
+
1584
+
1585
+
1586
+
1587
+
1588
+
1473
1589
 
1474
1590
 
1475
1591
 
@@ -1520,6 +1636,13 @@ var linkedListTyped = (() => {
1520
1636
 
1521
1637
 
1522
1638
 
1639
+
1640
+
1641
+
1642
+
1643
+
1644
+
1645
+
1523
1646
 
1524
1647
 
1525
1648
 
@@ -1736,6 +1859,13 @@ var linkedListTyped = (() => {
1736
1859
 
1737
1860
 
1738
1861
 
1862
+
1863
+
1864
+
1865
+
1866
+
1867
+
1868
+
1739
1869
 
1740
1870
 
1741
1871
 
@@ -1790,6 +1920,13 @@ var linkedListTyped = (() => {
1790
1920
 
1791
1921
 
1792
1922
 
1923
+
1924
+
1925
+
1926
+
1927
+
1928
+
1929
+
1793
1930
 
1794
1931
 
1795
1932
 
@@ -1872,6 +2009,13 @@ var linkedListTyped = (() => {
1872
2009
 
1873
2010
 
1874
2011
 
2012
+
2013
+
2014
+
2015
+
2016
+
2017
+
2018
+
1875
2019
 
1876
2020
 
1877
2021
 
@@ -2187,6 +2331,13 @@ var linkedListTyped = (() => {
2187
2331
 
2188
2332
 
2189
2333
 
2334
+
2335
+
2336
+
2337
+
2338
+
2339
+
2340
+
2190
2341
 
2191
2342
 
2192
2343
 
@@ -2256,6 +2407,13 @@ var linkedListTyped = (() => {
2256
2407
 
2257
2408
 
2258
2409
 
2410
+
2411
+
2412
+
2413
+
2414
+
2415
+
2416
+
2259
2417
 
2260
2418
 
2261
2419
 
@@ -2324,6 +2482,13 @@ var linkedListTyped = (() => {
2324
2482
 
2325
2483
 
2326
2484
 
2485
+
2486
+
2487
+
2488
+
2489
+
2490
+
2491
+
2327
2492
 
2328
2493
 
2329
2494
 
@@ -2383,6 +2548,13 @@ var linkedListTyped = (() => {
2383
2548
 
2384
2549
 
2385
2550
 
2551
+
2552
+
2553
+
2554
+
2555
+
2556
+
2557
+
2386
2558
 
2387
2559
 
2388
2560
 
@@ -2471,6 +2643,13 @@ var linkedListTyped = (() => {
2471
2643
 
2472
2644
 
2473
2645
 
2646
+
2647
+
2648
+
2649
+
2650
+
2651
+
2652
+
2474
2653
 
2475
2654
 
2476
2655
 
@@ -2520,6 +2699,13 @@ var linkedListTyped = (() => {
2520
2699
 
2521
2700
 
2522
2701
 
2702
+
2703
+
2704
+
2705
+
2706
+
2707
+
2708
+
2523
2709
 
2524
2710
 
2525
2711
 
@@ -2600,6 +2786,13 @@ var linkedListTyped = (() => {
2600
2786
 
2601
2787
 
2602
2788
 
2789
+
2790
+
2791
+
2792
+
2793
+
2794
+
2795
+
2603
2796
 
2604
2797
 
2605
2798
 
@@ -2708,6 +2901,13 @@ var linkedListTyped = (() => {
2708
2901
 
2709
2902
 
2710
2903
 
2904
+
2905
+
2906
+
2907
+
2908
+
2909
+
2910
+
2711
2911
 
2712
2912
 
2713
2913
 
@@ -2763,6 +2963,13 @@ var linkedListTyped = (() => {
2763
2963
 
2764
2964
 
2765
2965
 
2966
+
2967
+
2968
+
2969
+
2970
+
2971
+
2972
+
2766
2973
 
2767
2974
 
2768
2975
 
@@ -2820,6 +3027,13 @@ var linkedListTyped = (() => {
2820
3027
 
2821
3028
 
2822
3029
 
3030
+
3031
+
3032
+
3033
+
3034
+
3035
+
3036
+
2823
3037
 
2824
3038
 
2825
3039
 
@@ -2864,6 +3078,13 @@ var linkedListTyped = (() => {
2864
3078
 
2865
3079
 
2866
3080
 
3081
+
3082
+
3083
+
3084
+
3085
+
3086
+
3087
+
2867
3088
 
2868
3089
 
2869
3090
 
@@ -2912,6 +3133,13 @@ var linkedListTyped = (() => {
2912
3133
 
2913
3134
 
2914
3135
 
3136
+
3137
+
3138
+
3139
+
3140
+
3141
+
3142
+
2915
3143
 
2916
3144
 
2917
3145
 
@@ -2967,6 +3195,10 @@ var linkedListTyped = (() => {
2967
3195
 
2968
3196
 
2969
3197
 
3198
+
3199
+
3200
+
3201
+
2970
3202
 
2971
3203
 
2972
3204
 
@@ -2975,11 +3207,31 @@ var linkedListTyped = (() => {
2975
3207
  * @example
2976
3208
  * // Find value scanning from tail
2977
3209
  * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
2978
- * // getBackward scans from tail to head, returns first match
2979
- * const found = list.getBackward(node => node.value < 4);
3210
+ * // findLast scans from tail to head, returns first match
3211
+ * const found = list.findLast(node => node.value < 4);
2980
3212
  * console.log(found); // 3;
2981
3213
  */
3214
+ /**
3215
+ * @deprecated Use `findLast` instead. Will be removed in a future major version.
3216
+ */
2982
3217
  getBackward(elementNodeOrPredicate) {
3218
+ return this.findLast(elementNodeOrPredicate);
3219
+ }
3220
+ /**
3221
+ * Find the first value matching a predicate scanning backward (tail → head).
3222
+ * @remarks Time O(N), Space O(1)
3223
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
3224
+ * @returns Matching value or undefined.
3225
+
3226
+
3227
+ * @example
3228
+ * // Find value scanning from tail
3229
+ * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
3230
+ * // findLast scans from tail to head, returns first match
3231
+ * const found = list.findLast(node => node.value < 4);
3232
+ * console.log(found); // 3;
3233
+ */
3234
+ findLast(elementNodeOrPredicate) {
2983
3235
  const predicate = this._ensurePredicate(elementNodeOrPredicate);
2984
3236
  let current = this.tail;
2985
3237
  while (current) {
@@ -2988,6 +3240,22 @@ var linkedListTyped = (() => {
2988
3240
  }
2989
3241
  return void 0;
2990
3242
  }
3243
+ /**
3244
+ * Find the index of the last value matching a predicate (scans tail → head).
3245
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
3246
+ * @param predicate - Function called with (value, index, list).
3247
+ * @returns Matching index, or -1 if not found.
3248
+ */
3249
+ findLastIndex(predicate) {
3250
+ let current = this.tail;
3251
+ let index = this.length - 1;
3252
+ while (current) {
3253
+ if (predicate(current.value, index, this)) return index;
3254
+ current = current.prev;
3255
+ index--;
3256
+ }
3257
+ return -1;
3258
+ }
2991
3259
  /**
2992
3260
  * Reverse the list in place.
2993
3261
  * @remarks Time O(N), Space O(1)
@@ -3019,6 +3287,13 @@ var linkedListTyped = (() => {
3019
3287
 
3020
3288
 
3021
3289
 
3290
+
3291
+
3292
+
3293
+
3294
+
3295
+
3296
+
3022
3297
 
3023
3298
 
3024
3299
 
@@ -3043,6 +3318,25 @@ var linkedListTyped = (() => {
3043
3318
  }
3044
3319
  return this;
3045
3320
  }
3321
+ /**
3322
+ * Delete the first element that satisfies a predicate.
3323
+ * @remarks Time O(N), Space O(1)
3324
+ * @param predicate - Function (value, index, list) → boolean to decide deletion.
3325
+ * @returns True if a match was removed.
3326
+ */
3327
+ deleteWhere(predicate) {
3328
+ let current = this.head;
3329
+ let index = 0;
3330
+ while (current) {
3331
+ if (predicate(current.value, index, this)) {
3332
+ this.delete(current);
3333
+ return true;
3334
+ }
3335
+ current = current.next;
3336
+ index++;
3337
+ }
3338
+ return false;
3339
+ }
3046
3340
  /**
3047
3341
  * Set the equality comparator used to compare values.
3048
3342
  * @remarks Time O(1), Space O(1)
@@ -3082,6 +3376,13 @@ var linkedListTyped = (() => {
3082
3376
 
3083
3377
 
3084
3378
 
3379
+
3380
+
3381
+
3382
+
3383
+
3384
+
3385
+
3085
3386
 
3086
3387
 
3087
3388
 
@@ -3135,6 +3436,13 @@ var linkedListTyped = (() => {
3135
3436
 
3136
3437
 
3137
3438
 
3439
+
3440
+
3441
+
3442
+
3443
+
3444
+
3445
+
3138
3446
 
3139
3447
 
3140
3448
 
@@ -3207,6 +3515,13 @@ var linkedListTyped = (() => {
3207
3515
 
3208
3516
 
3209
3517
 
3518
+
3519
+
3520
+
3521
+
3522
+
3523
+
3524
+
3210
3525
 
3211
3526
 
3212
3527
 
@@ -3602,6 +3917,13 @@ var linkedListTyped = (() => {
3602
3917
 
3603
3918
 
3604
3919
 
3920
+
3921
+
3922
+
3923
+
3924
+
3925
+
3926
+
3605
3927
 
3606
3928
 
3607
3929
 
@@ -3644,6 +3966,13 @@ var linkedListTyped = (() => {
3644
3966
 
3645
3967
 
3646
3968
 
3969
+
3970
+
3971
+
3972
+
3973
+
3974
+
3975
+
3647
3976
 
3648
3977
 
3649
3978
 
@@ -3689,6 +4018,13 @@ var linkedListTyped = (() => {
3689
4018
 
3690
4019
 
3691
4020
 
4021
+
4022
+
4023
+
4024
+
4025
+
4026
+
4027
+
3692
4028
 
3693
4029
 
3694
4030
 
@@ -3742,6 +4078,13 @@ var linkedListTyped = (() => {
3742
4078
 
3743
4079
 
3744
4080
 
4081
+
4082
+
4083
+
4084
+
4085
+
4086
+
4087
+
3745
4088
 
3746
4089
 
3747
4090
 
@@ -3820,6 +4163,13 @@ var linkedListTyped = (() => {
3820
4163
 
3821
4164
 
3822
4165
 
4166
+
4167
+
4168
+
4169
+
4170
+
4171
+
4172
+
3823
4173
 
3824
4174
 
3825
4175
 
@@ -3883,6 +4233,13 @@ var linkedListTyped = (() => {
3883
4233
 
3884
4234
 
3885
4235
 
4236
+
4237
+
4238
+
4239
+
4240
+
4241
+
4242
+
3886
4243
 
3887
4244
 
3888
4245
 
@@ -3929,6 +4286,13 @@ var linkedListTyped = (() => {
3929
4286
 
3930
4287
 
3931
4288
 
4289
+
4290
+
4291
+
4292
+
4293
+
4294
+
4295
+
3932
4296
 
3933
4297
 
3934
4298
 
@@ -3995,6 +4359,13 @@ var linkedListTyped = (() => {
3995
4359
 
3996
4360
 
3997
4361
 
4362
+
4363
+
4364
+
4365
+
4366
+
4367
+
4368
+
3998
4369
 
3999
4370
 
4000
4371
 
@@ -4041,6 +4412,13 @@ var linkedListTyped = (() => {
4041
4412
 
4042
4413
 
4043
4414
 
4415
+
4416
+
4417
+
4418
+
4419
+
4420
+
4421
+
4044
4422
 
4045
4423
 
4046
4424
 
@@ -4089,6 +4467,13 @@ var linkedListTyped = (() => {
4089
4467
 
4090
4468
 
4091
4469
 
4470
+
4471
+
4472
+
4473
+
4474
+
4475
+
4476
+
4092
4477
 
4093
4478
 
4094
4479
 
@@ -4135,6 +4520,13 @@ var linkedListTyped = (() => {
4135
4520
 
4136
4521
 
4137
4522
 
4523
+
4524
+
4525
+
4526
+
4527
+
4528
+
4529
+
4138
4530
 
4139
4531
 
4140
4532
 
@@ -4184,6 +4576,13 @@ var linkedListTyped = (() => {
4184
4576
 
4185
4577
 
4186
4578
 
4579
+
4580
+
4581
+
4582
+
4583
+
4584
+
4585
+
4187
4586
 
4188
4587
 
4189
4588
 
@@ -4238,6 +4637,13 @@ var linkedListTyped = (() => {
4238
4637
 
4239
4638
 
4240
4639
 
4640
+
4641
+
4642
+
4643
+
4644
+
4645
+
4646
+
4241
4647
 
4242
4648
 
4243
4649
 
@@ -4290,6 +4696,13 @@ var linkedListTyped = (() => {
4290
4696
 
4291
4697
 
4292
4698
 
4699
+
4700
+
4701
+
4702
+
4703
+
4704
+
4705
+
4293
4706
 
4294
4707
 
4295
4708
 
@@ -4341,6 +4754,13 @@ var linkedListTyped = (() => {
4341
4754
 
4342
4755
 
4343
4756
 
4757
+
4758
+
4759
+
4760
+
4761
+
4762
+
4763
+
4344
4764
 
4345
4765
 
4346
4766
 
@@ -4398,6 +4818,13 @@ var linkedListTyped = (() => {
4398
4818
 
4399
4819
 
4400
4820
 
4821
+
4822
+
4823
+
4824
+
4825
+
4826
+
4827
+
4401
4828
 
4402
4829
 
4403
4830
 
@@ -4463,6 +4890,13 @@ var linkedListTyped = (() => {
4463
4890
 
4464
4891
 
4465
4892
 
4893
+
4894
+
4895
+
4896
+
4897
+
4898
+
4899
+
4466
4900
 
4467
4901
 
4468
4902
 
@@ -4512,6 +4946,13 @@ var linkedListTyped = (() => {
4512
4946
 
4513
4947
 
4514
4948
 
4949
+
4950
+
4951
+
4952
+
4953
+
4954
+
4955
+
4515
4956
 
4516
4957
 
4517
4958