linked-list-typed 2.5.3 → 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 (61) hide show
  1. package/dist/cjs/index.cjs +224 -2
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +224 -2
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +224 -2
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +224 -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 +36 -0
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  24. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +90 -1
  30. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  32. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  33. package/dist/umd/linked-list-typed.js +224 -2
  34. package/dist/umd/linked-list-typed.js.map +1 -1
  35. package/dist/umd/linked-list-typed.min.js +1 -1
  36. package/dist/umd/linked-list-typed.min.js.map +1 -1
  37. package/package.json +2 -2
  38. package/src/data-structures/base/iterable-element-base.ts +32 -0
  39. package/src/data-structures/base/linear-base.ts +11 -0
  40. package/src/data-structures/binary-tree/avl-tree.ts +36 -0
  41. package/src/data-structures/binary-tree/binary-indexed-tree.ts +42 -0
  42. package/src/data-structures/binary-tree/binary-tree.ts +75 -0
  43. package/src/data-structures/binary-tree/bst.ts +72 -0
  44. package/src/data-structures/binary-tree/red-black-tree.ts +57 -0
  45. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  46. package/src/data-structures/binary-tree/tree-map.ts +375 -0
  47. package/src/data-structures/binary-tree/tree-multi-map.ts +392 -0
  48. package/src/data-structures/binary-tree/tree-multi-set.ts +336 -0
  49. package/src/data-structures/binary-tree/tree-set.ts +492 -0
  50. package/src/data-structures/graph/directed-graph.ts +30 -0
  51. package/src/data-structures/graph/undirected-graph.ts +27 -0
  52. package/src/data-structures/hash/hash-map.ts +33 -0
  53. package/src/data-structures/heap/heap.ts +42 -0
  54. package/src/data-structures/linked-list/doubly-linked-list.ts +90 -2
  55. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  56. package/src/data-structures/linked-list/skip-linked-list.ts +54 -0
  57. package/src/data-structures/matrix/matrix.ts +24 -0
  58. package/src/data-structures/queue/deque.ts +103 -1
  59. package/src/data-structures/queue/queue.ts +36 -0
  60. package/src/data-structures/stack/stack.ts +30 -0
  61. package/src/data-structures/trie/trie.ts +36 -0
@@ -253,6 +253,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
253
253
 
254
254
 
255
255
 
256
+
257
+
258
+
256
259
 
257
260
 
258
261
 
@@ -311,6 +314,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
311
314
 
312
315
 
313
316
 
317
+
318
+
319
+
314
320
 
315
321
 
316
322
 
@@ -364,6 +370,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
364
370
 
365
371
 
366
372
 
373
+
374
+
375
+
367
376
 
368
377
 
369
378
 
@@ -413,6 +422,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
413
422
 
414
423
 
415
424
 
425
+
426
+
427
+
416
428
 
417
429
 
418
430
 
@@ -461,6 +473,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
461
473
 
462
474
 
463
475
 
476
+
477
+
478
+
464
479
 
465
480
 
466
481
 
@@ -512,6 +527,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
512
527
 
513
528
 
514
529
 
530
+
531
+
532
+
515
533
 
516
534
 
517
535
 
@@ -588,6 +606,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
588
606
 
589
607
 
590
608
 
609
+
610
+
611
+
591
612
 
592
613
 
593
614
 
@@ -647,6 +668,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
647
668
 
648
669
 
649
670
 
671
+
672
+
673
+
650
674
 
651
675
 
652
676
 
@@ -700,6 +724,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
700
724
 
701
725
 
702
726
 
727
+
728
+
729
+
703
730
 
704
731
 
705
732
 
@@ -753,6 +780,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
753
780
 
754
781
 
755
782
 
783
+
784
+
785
+
756
786
 
757
787
 
758
788
 
@@ -803,6 +833,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
803
833
 
804
834
 
805
835
 
836
+
837
+
838
+
806
839
 
807
840
 
808
841
 
@@ -848,6 +881,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
848
881
 
849
882
 
850
883
 
884
+
885
+
886
+
851
887
 
852
888
 
853
889
 
@@ -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) {
@@ -838,6 +877,9 @@ var linkedListTyped = (() => {
838
877
 
839
878
 
840
879
 
880
+
881
+
882
+
841
883
 
842
884
 
843
885
 
@@ -909,6 +951,9 @@ var linkedListTyped = (() => {
909
951
 
910
952
 
911
953
 
954
+
955
+
956
+
912
957
 
913
958
 
914
959
 
@@ -986,6 +1031,9 @@ var linkedListTyped = (() => {
986
1031
 
987
1032
 
988
1033
 
1034
+
1035
+
1036
+
989
1037
 
990
1038
 
991
1039
 
@@ -1044,6 +1092,9 @@ var linkedListTyped = (() => {
1044
1092
 
1045
1093
 
1046
1094
 
1095
+
1096
+
1097
+
1047
1098
 
1048
1099
 
1049
1100
 
@@ -1163,6 +1214,9 @@ var linkedListTyped = (() => {
1163
1214
 
1164
1215
 
1165
1216
 
1217
+
1218
+
1219
+
1166
1220
 
1167
1221
 
1168
1222
 
@@ -1226,6 +1280,9 @@ var linkedListTyped = (() => {
1226
1280
 
1227
1281
 
1228
1282
 
1283
+
1284
+
1285
+
1229
1286
 
1230
1287
 
1231
1288
 
@@ -1278,6 +1335,9 @@ var linkedListTyped = (() => {
1278
1335
 
1279
1336
 
1280
1337
 
1338
+
1339
+
1340
+
1281
1341
 
1282
1342
 
1283
1343
 
@@ -1336,6 +1396,9 @@ var linkedListTyped = (() => {
1336
1396
 
1337
1397
 
1338
1398
 
1399
+
1400
+
1401
+
1339
1402
 
1340
1403
 
1341
1404
 
@@ -1399,6 +1462,9 @@ var linkedListTyped = (() => {
1399
1462
 
1400
1463
 
1401
1464
 
1465
+
1466
+
1467
+
1402
1468
 
1403
1469
 
1404
1470
 
@@ -1470,6 +1536,9 @@ var linkedListTyped = (() => {
1470
1536
 
1471
1537
 
1472
1538
 
1539
+
1540
+
1541
+
1473
1542
 
1474
1543
 
1475
1544
 
@@ -1518,6 +1587,9 @@ var linkedListTyped = (() => {
1518
1587
 
1519
1588
 
1520
1589
 
1590
+
1591
+
1592
+
1521
1593
 
1522
1594
 
1523
1595
 
@@ -1572,6 +1644,9 @@ var linkedListTyped = (() => {
1572
1644
 
1573
1645
 
1574
1646
 
1647
+
1648
+
1649
+
1575
1650
 
1576
1651
 
1577
1652
 
@@ -1792,6 +1867,9 @@ var linkedListTyped = (() => {
1792
1867
 
1793
1868
 
1794
1869
 
1870
+
1871
+
1872
+
1795
1873
 
1796
1874
 
1797
1875
 
@@ -1850,6 +1928,9 @@ var linkedListTyped = (() => {
1850
1928
 
1851
1929
 
1852
1930
 
1931
+
1932
+
1933
+
1853
1934
 
1854
1935
 
1855
1936
 
@@ -1936,6 +2017,9 @@ var linkedListTyped = (() => {
1936
2017
 
1937
2018
 
1938
2019
 
2020
+
2021
+
2022
+
1939
2023
 
1940
2024
 
1941
2025
 
@@ -2255,6 +2339,9 @@ var linkedListTyped = (() => {
2255
2339
 
2256
2340
 
2257
2341
 
2342
+
2343
+
2344
+
2258
2345
 
2259
2346
 
2260
2347
 
@@ -2328,6 +2415,9 @@ var linkedListTyped = (() => {
2328
2415
 
2329
2416
 
2330
2417
 
2418
+
2419
+
2420
+
2331
2421
 
2332
2422
 
2333
2423
 
@@ -2400,6 +2490,9 @@ var linkedListTyped = (() => {
2400
2490
 
2401
2491
 
2402
2492
 
2493
+
2494
+
2495
+
2403
2496
 
2404
2497
 
2405
2498
 
@@ -2463,6 +2556,9 @@ var linkedListTyped = (() => {
2463
2556
 
2464
2557
 
2465
2558
 
2559
+
2560
+
2561
+
2466
2562
 
2467
2563
 
2468
2564
 
@@ -2555,6 +2651,9 @@ var linkedListTyped = (() => {
2555
2651
 
2556
2652
 
2557
2653
 
2654
+
2655
+
2656
+
2558
2657
 
2559
2658
 
2560
2659
 
@@ -2608,6 +2707,9 @@ var linkedListTyped = (() => {
2608
2707
 
2609
2708
 
2610
2709
 
2710
+
2711
+
2712
+
2611
2713
 
2612
2714
 
2613
2715
 
@@ -2692,6 +2794,9 @@ var linkedListTyped = (() => {
2692
2794
 
2693
2795
 
2694
2796
 
2797
+
2798
+
2799
+
2695
2800
 
2696
2801
 
2697
2802
 
@@ -2804,6 +2909,9 @@ var linkedListTyped = (() => {
2804
2909
 
2805
2910
 
2806
2911
 
2912
+
2913
+
2914
+
2807
2915
 
2808
2916
 
2809
2917
 
@@ -2863,6 +2971,9 @@ var linkedListTyped = (() => {
2863
2971
 
2864
2972
 
2865
2973
 
2974
+
2975
+
2976
+
2866
2977
 
2867
2978
 
2868
2979
 
@@ -2924,6 +3035,9 @@ var linkedListTyped = (() => {
2924
3035
 
2925
3036
 
2926
3037
 
3038
+
3039
+
3040
+
2927
3041
 
2928
3042
 
2929
3043
 
@@ -2972,6 +3086,9 @@ var linkedListTyped = (() => {
2972
3086
 
2973
3087
 
2974
3088
 
3089
+
3090
+
3091
+
2975
3092
 
2976
3093
 
2977
3094
 
@@ -3024,6 +3141,9 @@ var linkedListTyped = (() => {
3024
3141
 
3025
3142
 
3026
3143
 
3144
+
3145
+
3146
+
3027
3147
 
3028
3148
 
3029
3149
 
@@ -3087,11 +3207,31 @@ var linkedListTyped = (() => {
3087
3207
  * @example
3088
3208
  * // Find value scanning from tail
3089
3209
  * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
3090
- * // getBackward scans from tail to head, returns first match
3091
- * 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);
3092
3212
  * console.log(found); // 3;
3093
3213
  */
3214
+ /**
3215
+ * @deprecated Use `findLast` instead. Will be removed in a future major version.
3216
+ */
3094
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) {
3095
3235
  const predicate = this._ensurePredicate(elementNodeOrPredicate);
3096
3236
  let current = this.tail;
3097
3237
  while (current) {
@@ -3100,6 +3240,22 @@ var linkedListTyped = (() => {
3100
3240
  }
3101
3241
  return void 0;
3102
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
+ }
3103
3259
  /**
3104
3260
  * Reverse the list in place.
3105
3261
  * @remarks Time O(N), Space O(1)
@@ -3139,6 +3295,9 @@ var linkedListTyped = (() => {
3139
3295
 
3140
3296
 
3141
3297
 
3298
+
3299
+
3300
+
3142
3301
 
3143
3302
 
3144
3303
 
@@ -3225,6 +3384,9 @@ var linkedListTyped = (() => {
3225
3384
 
3226
3385
 
3227
3386
 
3387
+
3388
+
3389
+
3228
3390
 
3229
3391
 
3230
3392
 
@@ -3282,6 +3444,9 @@ var linkedListTyped = (() => {
3282
3444
 
3283
3445
 
3284
3446
 
3447
+
3448
+
3449
+
3285
3450
 
3286
3451
 
3287
3452
 
@@ -3358,6 +3523,9 @@ var linkedListTyped = (() => {
3358
3523
 
3359
3524
 
3360
3525
 
3526
+
3527
+
3528
+
3361
3529
 
3362
3530
 
3363
3531
 
@@ -3757,6 +3925,9 @@ var linkedListTyped = (() => {
3757
3925
 
3758
3926
 
3759
3927
 
3928
+
3929
+
3930
+
3760
3931
 
3761
3932
 
3762
3933
 
@@ -3803,6 +3974,9 @@ var linkedListTyped = (() => {
3803
3974
 
3804
3975
 
3805
3976
 
3977
+
3978
+
3979
+
3806
3980
 
3807
3981
 
3808
3982
 
@@ -3852,6 +4026,9 @@ var linkedListTyped = (() => {
3852
4026
 
3853
4027
 
3854
4028
 
4029
+
4030
+
4031
+
3855
4032
 
3856
4033
 
3857
4034
 
@@ -3909,6 +4086,9 @@ var linkedListTyped = (() => {
3909
4086
 
3910
4087
 
3911
4088
 
4089
+
4090
+
4091
+
3912
4092
 
3913
4093
 
3914
4094
 
@@ -3991,6 +4171,9 @@ var linkedListTyped = (() => {
3991
4171
 
3992
4172
 
3993
4173
 
4174
+
4175
+
4176
+
3994
4177
 
3995
4178
 
3996
4179
 
@@ -4058,6 +4241,9 @@ var linkedListTyped = (() => {
4058
4241
 
4059
4242
 
4060
4243
 
4244
+
4245
+
4246
+
4061
4247
 
4062
4248
 
4063
4249
 
@@ -4108,6 +4294,9 @@ var linkedListTyped = (() => {
4108
4294
 
4109
4295
 
4110
4296
 
4297
+
4298
+
4299
+
4111
4300
 
4112
4301
 
4113
4302
 
@@ -4178,6 +4367,9 @@ var linkedListTyped = (() => {
4178
4367
 
4179
4368
 
4180
4369
 
4370
+
4371
+
4372
+
4181
4373
 
4182
4374
 
4183
4375
 
@@ -4228,6 +4420,9 @@ var linkedListTyped = (() => {
4228
4420
 
4229
4421
 
4230
4422
 
4423
+
4424
+
4425
+
4231
4426
 
4232
4427
 
4233
4428
 
@@ -4280,6 +4475,9 @@ var linkedListTyped = (() => {
4280
4475
 
4281
4476
 
4282
4477
 
4478
+
4479
+
4480
+
4283
4481
 
4284
4482
 
4285
4483
 
@@ -4330,6 +4528,9 @@ var linkedListTyped = (() => {
4330
4528
 
4331
4529
 
4332
4530
 
4531
+
4532
+
4533
+
4333
4534
 
4334
4535
 
4335
4536
 
@@ -4383,6 +4584,9 @@ var linkedListTyped = (() => {
4383
4584
 
4384
4585
 
4385
4586
 
4587
+
4588
+
4589
+
4386
4590
 
4387
4591
 
4388
4592
 
@@ -4441,6 +4645,9 @@ var linkedListTyped = (() => {
4441
4645
 
4442
4646
 
4443
4647
 
4648
+
4649
+
4650
+
4444
4651
 
4445
4652
 
4446
4653
 
@@ -4497,6 +4704,9 @@ var linkedListTyped = (() => {
4497
4704
 
4498
4705
 
4499
4706
 
4707
+
4708
+
4709
+
4500
4710
 
4501
4711
 
4502
4712
 
@@ -4552,6 +4762,9 @@ var linkedListTyped = (() => {
4552
4762
 
4553
4763
 
4554
4764
 
4765
+
4766
+
4767
+
4555
4768
 
4556
4769
 
4557
4770
 
@@ -4613,6 +4826,9 @@ var linkedListTyped = (() => {
4613
4826
 
4614
4827
 
4615
4828
 
4829
+
4830
+
4831
+
4616
4832
 
4617
4833
 
4618
4834
 
@@ -4682,6 +4898,9 @@ var linkedListTyped = (() => {
4682
4898
 
4683
4899
 
4684
4900
 
4901
+
4902
+
4903
+
4685
4904
 
4686
4905
 
4687
4906
 
@@ -4735,6 +4954,9 @@ var linkedListTyped = (() => {
4735
4954
 
4736
4955
 
4737
4956
 
4957
+
4958
+
4959
+
4738
4960
 
4739
4961
 
4740
4962