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
@@ -208,6 +208,35 @@ var IterableElementBase = class {
208
208
  for (const ele of this) if (ele === element) return true;
209
209
  return false;
210
210
  }
211
+ /**
212
+ * Check whether a value exists (Array-compatible alias for `has`).
213
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
214
+ * @param element - Element to search for (uses `===`).
215
+ * @returns `true` if found.
216
+ */
217
+ includes(element) {
218
+ return this.has(element);
219
+ }
220
+ /**
221
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
222
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
223
+ */
224
+ *entries() {
225
+ let index = 0;
226
+ for (const value of this) {
227
+ yield [index++, value];
228
+ }
229
+ }
230
+ /**
231
+ * Return an iterator of numeric indices (Array-compatible).
232
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
233
+ */
234
+ *keys() {
235
+ let index = 0;
236
+ for (const _ of this) {
237
+ yield index++;
238
+ }
239
+ }
211
240
  /**
212
241
  * Reduces all elements to a single accumulated value.
213
242
  *
@@ -518,6 +547,16 @@ var LinearBase = class _LinearBase extends IterableElementBase {
518
547
  }
519
548
  return this;
520
549
  }
550
+ /**
551
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
552
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
553
+ * @returns A new reversed instance.
554
+ */
555
+ toReversed() {
556
+ const cloned = this.clone();
557
+ cloned.reverse();
558
+ return cloned;
559
+ }
521
560
  };
522
561
  var LinearLinkedBase = class extends LinearBase {
523
562
  static {
@@ -817,6 +856,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
817
856
 
818
857
 
819
858
 
859
+
860
+
861
+
820
862
 
821
863
 
822
864
 
@@ -888,6 +930,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
888
930
 
889
931
 
890
932
 
933
+
934
+
935
+
891
936
 
892
937
 
893
938
 
@@ -964,6 +1009,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
964
1009
 
965
1010
 
966
1011
 
1012
+
1013
+
1014
+
967
1015
 
968
1016
 
969
1017
 
@@ -1022,6 +1070,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1022
1070
 
1023
1071
 
1024
1072
 
1073
+
1074
+
1075
+
1025
1076
 
1026
1077
 
1027
1078
 
@@ -1141,6 +1192,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1141
1192
 
1142
1193
 
1143
1194
 
1195
+
1196
+
1197
+
1144
1198
 
1145
1199
 
1146
1200
 
@@ -1204,6 +1258,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1204
1258
 
1205
1259
 
1206
1260
 
1261
+
1262
+
1263
+
1207
1264
 
1208
1265
 
1209
1266
 
@@ -1256,6 +1313,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1256
1313
 
1257
1314
 
1258
1315
 
1316
+
1317
+
1318
+
1259
1319
 
1260
1320
 
1261
1321
 
@@ -1314,6 +1374,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1314
1374
 
1315
1375
 
1316
1376
 
1377
+
1378
+
1379
+
1317
1380
 
1318
1381
 
1319
1382
 
@@ -1377,6 +1440,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1377
1440
 
1378
1441
 
1379
1442
 
1443
+
1444
+
1445
+
1380
1446
 
1381
1447
 
1382
1448
 
@@ -1448,6 +1514,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1448
1514
 
1449
1515
 
1450
1516
 
1517
+
1518
+
1519
+
1451
1520
 
1452
1521
 
1453
1522
 
@@ -1496,6 +1565,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1496
1565
 
1497
1566
 
1498
1567
 
1568
+
1569
+
1570
+
1499
1571
 
1500
1572
 
1501
1573
 
@@ -1550,6 +1622,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1550
1622
 
1551
1623
 
1552
1624
 
1625
+
1626
+
1627
+
1553
1628
 
1554
1629
 
1555
1630
 
@@ -1770,6 +1845,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1770
1845
 
1771
1846
 
1772
1847
 
1848
+
1849
+
1850
+
1773
1851
 
1774
1852
 
1775
1853
 
@@ -1828,6 +1906,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1828
1906
 
1829
1907
 
1830
1908
 
1909
+
1910
+
1911
+
1831
1912
 
1832
1913
 
1833
1914
 
@@ -1914,6 +1995,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1914
1995
 
1915
1996
 
1916
1997
 
1998
+
1999
+
2000
+
1917
2001
 
1918
2002
 
1919
2003
 
@@ -2238,6 +2322,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2238
2322
 
2239
2323
 
2240
2324
 
2325
+
2326
+
2327
+
2241
2328
 
2242
2329
 
2243
2330
 
@@ -2311,6 +2398,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2311
2398
 
2312
2399
 
2313
2400
 
2401
+
2402
+
2403
+
2314
2404
 
2315
2405
 
2316
2406
 
@@ -2383,6 +2473,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2383
2473
 
2384
2474
 
2385
2475
 
2476
+
2477
+
2478
+
2386
2479
 
2387
2480
 
2388
2481
 
@@ -2446,6 +2539,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2446
2539
 
2447
2540
 
2448
2541
 
2542
+
2543
+
2544
+
2449
2545
 
2450
2546
 
2451
2547
 
@@ -2538,6 +2634,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2538
2634
 
2539
2635
 
2540
2636
 
2637
+
2638
+
2639
+
2541
2640
 
2542
2641
 
2543
2642
 
@@ -2591,6 +2690,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2591
2690
 
2592
2691
 
2593
2692
 
2693
+
2694
+
2695
+
2594
2696
 
2595
2697
 
2596
2698
 
@@ -2675,6 +2777,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2675
2777
 
2676
2778
 
2677
2779
 
2780
+
2781
+
2782
+
2678
2783
 
2679
2784
 
2680
2785
 
@@ -2787,6 +2892,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2787
2892
 
2788
2893
 
2789
2894
 
2895
+
2896
+
2897
+
2790
2898
 
2791
2899
 
2792
2900
 
@@ -2846,6 +2954,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2846
2954
 
2847
2955
 
2848
2956
 
2957
+
2958
+
2959
+
2849
2960
 
2850
2961
 
2851
2962
 
@@ -2907,6 +3018,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2907
3018
 
2908
3019
 
2909
3020
 
3021
+
3022
+
3023
+
2910
3024
 
2911
3025
 
2912
3026
 
@@ -2955,6 +3069,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2955
3069
 
2956
3070
 
2957
3071
 
3072
+
3073
+
3074
+
2958
3075
 
2959
3076
 
2960
3077
 
@@ -3007,6 +3124,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3007
3124
 
3008
3125
 
3009
3126
 
3127
+
3128
+
3129
+
3010
3130
 
3011
3131
 
3012
3132
 
@@ -3070,11 +3190,31 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3070
3190
  * @example
3071
3191
  * // Find value scanning from tail
3072
3192
  * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
3073
- * // getBackward scans from tail to head, returns first match
3074
- * const found = list.getBackward(node => node.value < 4);
3193
+ * // findLast scans from tail to head, returns first match
3194
+ * const found = list.findLast(node => node.value < 4);
3075
3195
  * console.log(found); // 3;
3076
3196
  */
3197
+ /**
3198
+ * @deprecated Use `findLast` instead. Will be removed in a future major version.
3199
+ */
3077
3200
  getBackward(elementNodeOrPredicate) {
3201
+ return this.findLast(elementNodeOrPredicate);
3202
+ }
3203
+ /**
3204
+ * Find the first value matching a predicate scanning backward (tail → head).
3205
+ * @remarks Time O(N), Space O(1)
3206
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
3207
+ * @returns Matching value or undefined.
3208
+
3209
+
3210
+ * @example
3211
+ * // Find value scanning from tail
3212
+ * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
3213
+ * // findLast scans from tail to head, returns first match
3214
+ * const found = list.findLast(node => node.value < 4);
3215
+ * console.log(found); // 3;
3216
+ */
3217
+ findLast(elementNodeOrPredicate) {
3078
3218
  const predicate = this._ensurePredicate(elementNodeOrPredicate);
3079
3219
  let current = this.tail;
3080
3220
  while (current) {
@@ -3083,6 +3223,22 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3083
3223
  }
3084
3224
  return void 0;
3085
3225
  }
3226
+ /**
3227
+ * Find the index of the last value matching a predicate (scans tail → head).
3228
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
3229
+ * @param predicate - Function called with (value, index, list).
3230
+ * @returns Matching index, or -1 if not found.
3231
+ */
3232
+ findLastIndex(predicate) {
3233
+ let current = this.tail;
3234
+ let index = this.length - 1;
3235
+ while (current) {
3236
+ if (predicate(current.value, index, this)) return index;
3237
+ current = current.prev;
3238
+ index--;
3239
+ }
3240
+ return -1;
3241
+ }
3086
3242
  /**
3087
3243
  * Reverse the list in place.
3088
3244
  * @remarks Time O(N), Space O(1)
@@ -3122,6 +3278,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3122
3278
 
3123
3279
 
3124
3280
 
3281
+
3282
+
3283
+
3125
3284
 
3126
3285
 
3127
3286
 
@@ -3208,6 +3367,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3208
3367
 
3209
3368
 
3210
3369
 
3370
+
3371
+
3372
+
3211
3373
 
3212
3374
 
3213
3375
 
@@ -3265,6 +3427,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3265
3427
 
3266
3428
 
3267
3429
 
3430
+
3431
+
3432
+
3268
3433
 
3269
3434
 
3270
3435
 
@@ -3341,6 +3506,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3341
3506
 
3342
3507
 
3343
3508
 
3509
+
3510
+
3511
+
3344
3512
 
3345
3513
 
3346
3514
 
@@ -3748,6 +3916,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
3748
3916
 
3749
3917
 
3750
3918
 
3919
+
3920
+
3921
+
3751
3922
 
3752
3923
 
3753
3924
 
@@ -3794,6 +3965,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
3794
3965
 
3795
3966
 
3796
3967
 
3968
+
3969
+
3970
+
3797
3971
 
3798
3972
 
3799
3973
 
@@ -3843,6 +4017,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
3843
4017
 
3844
4018
 
3845
4019
 
4020
+
4021
+
4022
+
3846
4023
 
3847
4024
 
3848
4025
 
@@ -3900,6 +4077,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
3900
4077
 
3901
4078
 
3902
4079
 
4080
+
4081
+
4082
+
3903
4083
 
3904
4084
 
3905
4085
 
@@ -3982,6 +4162,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
3982
4162
 
3983
4163
 
3984
4164
 
4165
+
4166
+
4167
+
3985
4168
 
3986
4169
 
3987
4170
 
@@ -4049,6 +4232,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4049
4232
 
4050
4233
 
4051
4234
 
4235
+
4236
+
4237
+
4052
4238
 
4053
4239
 
4054
4240
 
@@ -4099,6 +4285,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4099
4285
 
4100
4286
 
4101
4287
 
4288
+
4289
+
4290
+
4102
4291
 
4103
4292
 
4104
4293
 
@@ -4169,6 +4358,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4169
4358
 
4170
4359
 
4171
4360
 
4361
+
4362
+
4363
+
4172
4364
 
4173
4365
 
4174
4366
 
@@ -4219,6 +4411,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4219
4411
 
4220
4412
 
4221
4413
 
4414
+
4415
+
4416
+
4222
4417
 
4223
4418
 
4224
4419
 
@@ -4271,6 +4466,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4271
4466
 
4272
4467
 
4273
4468
 
4469
+
4470
+
4471
+
4274
4472
 
4275
4473
 
4276
4474
 
@@ -4321,6 +4519,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4321
4519
 
4322
4520
 
4323
4521
 
4522
+
4523
+
4524
+
4324
4525
 
4325
4526
 
4326
4527
 
@@ -4374,6 +4575,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4374
4575
 
4375
4576
 
4376
4577
 
4578
+
4579
+
4580
+
4377
4581
 
4378
4582
 
4379
4583
 
@@ -4432,6 +4636,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4432
4636
 
4433
4637
 
4434
4638
 
4639
+
4640
+
4641
+
4435
4642
 
4436
4643
 
4437
4644
 
@@ -4488,6 +4695,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4488
4695
 
4489
4696
 
4490
4697
 
4698
+
4699
+
4700
+
4491
4701
 
4492
4702
 
4493
4703
 
@@ -4543,6 +4753,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4543
4753
 
4544
4754
 
4545
4755
 
4756
+
4757
+
4758
+
4546
4759
 
4547
4760
 
4548
4761
 
@@ -4604,6 +4817,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4604
4817
 
4605
4818
 
4606
4819
 
4820
+
4821
+
4822
+
4607
4823
 
4608
4824
 
4609
4825
 
@@ -4673,6 +4889,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4673
4889
 
4674
4890
 
4675
4891
 
4892
+
4893
+
4894
+
4676
4895
 
4677
4896
 
4678
4897
 
@@ -4726,6 +4945,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4726
4945
 
4727
4946
 
4728
4947
 
4948
+
4949
+
4950
+
4729
4951
 
4730
4952
 
4731
4953