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
@@ -210,6 +210,35 @@ var IterableElementBase = class {
210
210
  for (const ele of this) if (ele === element) return true;
211
211
  return false;
212
212
  }
213
+ /**
214
+ * Check whether a value exists (Array-compatible alias for `has`).
215
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
216
+ * @param element - Element to search for (uses `===`).
217
+ * @returns `true` if found.
218
+ */
219
+ includes(element) {
220
+ return this.has(element);
221
+ }
222
+ /**
223
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
224
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
225
+ */
226
+ *entries() {
227
+ let index = 0;
228
+ for (const value of this) {
229
+ yield [index++, value];
230
+ }
231
+ }
232
+ /**
233
+ * Return an iterator of numeric indices (Array-compatible).
234
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
235
+ */
236
+ *keys() {
237
+ let index = 0;
238
+ for (const _ of this) {
239
+ yield index++;
240
+ }
241
+ }
213
242
  /**
214
243
  * Reduces all elements to a single accumulated value.
215
244
  *
@@ -520,6 +549,16 @@ var LinearBase = class _LinearBase extends IterableElementBase {
520
549
  }
521
550
  return this;
522
551
  }
552
+ /**
553
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
554
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
555
+ * @returns A new reversed instance.
556
+ */
557
+ toReversed() {
558
+ const cloned = this.clone();
559
+ cloned.reverse();
560
+ return cloned;
561
+ }
523
562
  };
524
563
  var LinearLinkedBase = class extends LinearBase {
525
564
  static {
@@ -819,6 +858,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
819
858
 
820
859
 
821
860
 
861
+
862
+
863
+
822
864
 
823
865
 
824
866
 
@@ -890,6 +932,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
890
932
 
891
933
 
892
934
 
935
+
936
+
937
+
893
938
 
894
939
 
895
940
 
@@ -966,6 +1011,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
966
1011
 
967
1012
 
968
1013
 
1014
+
1015
+
1016
+
969
1017
 
970
1018
 
971
1019
 
@@ -1024,6 +1072,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1024
1072
 
1025
1073
 
1026
1074
 
1075
+
1076
+
1077
+
1027
1078
 
1028
1079
 
1029
1080
 
@@ -1143,6 +1194,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1143
1194
 
1144
1195
 
1145
1196
 
1197
+
1198
+
1199
+
1146
1200
 
1147
1201
 
1148
1202
 
@@ -1206,6 +1260,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1206
1260
 
1207
1261
 
1208
1262
 
1263
+
1264
+
1265
+
1209
1266
 
1210
1267
 
1211
1268
 
@@ -1258,6 +1315,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1258
1315
 
1259
1316
 
1260
1317
 
1318
+
1319
+
1320
+
1261
1321
 
1262
1322
 
1263
1323
 
@@ -1316,6 +1376,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1316
1376
 
1317
1377
 
1318
1378
 
1379
+
1380
+
1381
+
1319
1382
 
1320
1383
 
1321
1384
 
@@ -1379,6 +1442,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1379
1442
 
1380
1443
 
1381
1444
 
1445
+
1446
+
1447
+
1382
1448
 
1383
1449
 
1384
1450
 
@@ -1450,6 +1516,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1450
1516
 
1451
1517
 
1452
1518
 
1519
+
1520
+
1521
+
1453
1522
 
1454
1523
 
1455
1524
 
@@ -1498,6 +1567,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1498
1567
 
1499
1568
 
1500
1569
 
1570
+
1571
+
1572
+
1501
1573
 
1502
1574
 
1503
1575
 
@@ -1552,6 +1624,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1552
1624
 
1553
1625
 
1554
1626
 
1627
+
1628
+
1629
+
1555
1630
 
1556
1631
 
1557
1632
 
@@ -1772,6 +1847,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1772
1847
 
1773
1848
 
1774
1849
 
1850
+
1851
+
1852
+
1775
1853
 
1776
1854
 
1777
1855
 
@@ -1830,6 +1908,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1830
1908
 
1831
1909
 
1832
1910
 
1911
+
1912
+
1913
+
1833
1914
 
1834
1915
 
1835
1916
 
@@ -1916,6 +1997,9 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1916
1997
 
1917
1998
 
1918
1999
 
2000
+
2001
+
2002
+
1919
2003
 
1920
2004
 
1921
2005
 
@@ -2240,6 +2324,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2240
2324
 
2241
2325
 
2242
2326
 
2327
+
2328
+
2329
+
2243
2330
 
2244
2331
 
2245
2332
 
@@ -2313,6 +2400,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2313
2400
 
2314
2401
 
2315
2402
 
2403
+
2404
+
2405
+
2316
2406
 
2317
2407
 
2318
2408
 
@@ -2385,6 +2475,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2385
2475
 
2386
2476
 
2387
2477
 
2478
+
2479
+
2480
+
2388
2481
 
2389
2482
 
2390
2483
 
@@ -2448,6 +2541,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2448
2541
 
2449
2542
 
2450
2543
 
2544
+
2545
+
2546
+
2451
2547
 
2452
2548
 
2453
2549
 
@@ -2540,6 +2636,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2540
2636
 
2541
2637
 
2542
2638
 
2639
+
2640
+
2641
+
2543
2642
 
2544
2643
 
2545
2644
 
@@ -2593,6 +2692,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2593
2692
 
2594
2693
 
2595
2694
 
2695
+
2696
+
2697
+
2596
2698
 
2597
2699
 
2598
2700
 
@@ -2677,6 +2779,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2677
2779
 
2678
2780
 
2679
2781
 
2782
+
2783
+
2784
+
2680
2785
 
2681
2786
 
2682
2787
 
@@ -2789,6 +2894,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2789
2894
 
2790
2895
 
2791
2896
 
2897
+
2898
+
2899
+
2792
2900
 
2793
2901
 
2794
2902
 
@@ -2848,6 +2956,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2848
2956
 
2849
2957
 
2850
2958
 
2959
+
2960
+
2961
+
2851
2962
 
2852
2963
 
2853
2964
 
@@ -2909,6 +3020,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2909
3020
 
2910
3021
 
2911
3022
 
3023
+
3024
+
3025
+
2912
3026
 
2913
3027
 
2914
3028
 
@@ -2957,6 +3071,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
2957
3071
 
2958
3072
 
2959
3073
 
3074
+
3075
+
3076
+
2960
3077
 
2961
3078
 
2962
3079
 
@@ -3009,6 +3126,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3009
3126
 
3010
3127
 
3011
3128
 
3129
+
3130
+
3131
+
3012
3132
 
3013
3133
 
3014
3134
 
@@ -3072,11 +3192,31 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3072
3192
  * @example
3073
3193
  * // Find value scanning from tail
3074
3194
  * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
3075
- * // getBackward scans from tail to head, returns first match
3076
- * const found = list.getBackward(node => node.value < 4);
3195
+ * // findLast scans from tail to head, returns first match
3196
+ * const found = list.findLast(node => node.value < 4);
3077
3197
  * console.log(found); // 3;
3078
3198
  */
3199
+ /**
3200
+ * @deprecated Use `findLast` instead. Will be removed in a future major version.
3201
+ */
3079
3202
  getBackward(elementNodeOrPredicate) {
3203
+ return this.findLast(elementNodeOrPredicate);
3204
+ }
3205
+ /**
3206
+ * Find the first value matching a predicate scanning backward (tail → head).
3207
+ * @remarks Time O(N), Space O(1)
3208
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
3209
+ * @returns Matching value or undefined.
3210
+
3211
+
3212
+ * @example
3213
+ * // Find value scanning from tail
3214
+ * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
3215
+ * // findLast scans from tail to head, returns first match
3216
+ * const found = list.findLast(node => node.value < 4);
3217
+ * console.log(found); // 3;
3218
+ */
3219
+ findLast(elementNodeOrPredicate) {
3080
3220
  const predicate = this._ensurePredicate(elementNodeOrPredicate);
3081
3221
  let current = this.tail;
3082
3222
  while (current) {
@@ -3085,6 +3225,22 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3085
3225
  }
3086
3226
  return void 0;
3087
3227
  }
3228
+ /**
3229
+ * Find the index of the last value matching a predicate (scans tail → head).
3230
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
3231
+ * @param predicate - Function called with (value, index, list).
3232
+ * @returns Matching index, or -1 if not found.
3233
+ */
3234
+ findLastIndex(predicate) {
3235
+ let current = this.tail;
3236
+ let index = this.length - 1;
3237
+ while (current) {
3238
+ if (predicate(current.value, index, this)) return index;
3239
+ current = current.prev;
3240
+ index--;
3241
+ }
3242
+ return -1;
3243
+ }
3088
3244
  /**
3089
3245
  * Reverse the list in place.
3090
3246
  * @remarks Time O(N), Space O(1)
@@ -3124,6 +3280,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3124
3280
 
3125
3281
 
3126
3282
 
3283
+
3284
+
3285
+
3127
3286
 
3128
3287
 
3129
3288
 
@@ -3210,6 +3369,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3210
3369
 
3211
3370
 
3212
3371
 
3372
+
3373
+
3374
+
3213
3375
 
3214
3376
 
3215
3377
 
@@ -3267,6 +3429,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3267
3429
 
3268
3430
 
3269
3431
 
3432
+
3433
+
3434
+
3270
3435
 
3271
3436
 
3272
3437
 
@@ -3343,6 +3508,9 @@ var DoublyLinkedList = class extends LinearLinkedBase {
3343
3508
 
3344
3509
 
3345
3510
 
3511
+
3512
+
3513
+
3346
3514
 
3347
3515
 
3348
3516
 
@@ -3750,6 +3918,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
3750
3918
 
3751
3919
 
3752
3920
 
3921
+
3922
+
3923
+
3753
3924
 
3754
3925
 
3755
3926
 
@@ -3796,6 +3967,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
3796
3967
 
3797
3968
 
3798
3969
 
3970
+
3971
+
3972
+
3799
3973
 
3800
3974
 
3801
3975
 
@@ -3845,6 +4019,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
3845
4019
 
3846
4020
 
3847
4021
 
4022
+
4023
+
4024
+
3848
4025
 
3849
4026
 
3850
4027
 
@@ -3902,6 +4079,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
3902
4079
 
3903
4080
 
3904
4081
 
4082
+
4083
+
4084
+
3905
4085
 
3906
4086
 
3907
4087
 
@@ -3984,6 +4164,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
3984
4164
 
3985
4165
 
3986
4166
 
4167
+
4168
+
4169
+
3987
4170
 
3988
4171
 
3989
4172
 
@@ -4051,6 +4234,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4051
4234
 
4052
4235
 
4053
4236
 
4237
+
4238
+
4239
+
4054
4240
 
4055
4241
 
4056
4242
 
@@ -4101,6 +4287,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4101
4287
 
4102
4288
 
4103
4289
 
4290
+
4291
+
4292
+
4104
4293
 
4105
4294
 
4106
4295
 
@@ -4171,6 +4360,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4171
4360
 
4172
4361
 
4173
4362
 
4363
+
4364
+
4365
+
4174
4366
 
4175
4367
 
4176
4368
 
@@ -4221,6 +4413,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4221
4413
 
4222
4414
 
4223
4415
 
4416
+
4417
+
4418
+
4224
4419
 
4225
4420
 
4226
4421
 
@@ -4273,6 +4468,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4273
4468
 
4274
4469
 
4275
4470
 
4471
+
4472
+
4473
+
4276
4474
 
4277
4475
 
4278
4476
 
@@ -4323,6 +4521,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4323
4521
 
4324
4522
 
4325
4523
 
4524
+
4525
+
4526
+
4326
4527
 
4327
4528
 
4328
4529
 
@@ -4376,6 +4577,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4376
4577
 
4377
4578
 
4378
4579
 
4580
+
4581
+
4582
+
4379
4583
 
4380
4584
 
4381
4585
 
@@ -4434,6 +4638,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4434
4638
 
4435
4639
 
4436
4640
 
4641
+
4642
+
4643
+
4437
4644
 
4438
4645
 
4439
4646
 
@@ -4490,6 +4697,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4490
4697
 
4491
4698
 
4492
4699
 
4700
+
4701
+
4702
+
4493
4703
 
4494
4704
 
4495
4705
 
@@ -4545,6 +4755,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4545
4755
 
4546
4756
 
4547
4757
 
4758
+
4759
+
4760
+
4548
4761
 
4549
4762
 
4550
4763
 
@@ -4606,6 +4819,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4606
4819
 
4607
4820
 
4608
4821
 
4822
+
4823
+
4824
+
4609
4825
 
4610
4826
 
4611
4827
 
@@ -4675,6 +4891,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4675
4891
 
4676
4892
 
4677
4893
 
4894
+
4895
+
4896
+
4678
4897
 
4679
4898
 
4680
4899
 
@@ -4728,6 +4947,9 @@ var SkipList = class _SkipList extends IterableEntryBase {
4728
4947
 
4729
4948
 
4730
4949
 
4950
+
4951
+
4952
+
4731
4953
 
4732
4954
 
4733
4955