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
@@ -215,6 +215,35 @@ var _IterableElementBase = class _IterableElementBase {
215
215
  for (const ele of this) if (ele === element) return true;
216
216
  return false;
217
217
  }
218
+ /**
219
+ * Check whether a value exists (Array-compatible alias for `has`).
220
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
221
+ * @param element - Element to search for (uses `===`).
222
+ * @returns `true` if found.
223
+ */
224
+ includes(element) {
225
+ return this.has(element);
226
+ }
227
+ /**
228
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
229
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
230
+ */
231
+ *entries() {
232
+ let index = 0;
233
+ for (const value of this) {
234
+ yield [index++, value];
235
+ }
236
+ }
237
+ /**
238
+ * Return an iterator of numeric indices (Array-compatible).
239
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
240
+ */
241
+ *keys() {
242
+ let index = 0;
243
+ for (const _ of this) {
244
+ yield index++;
245
+ }
246
+ }
218
247
  /**
219
248
  * Reduces all elements to a single accumulated value.
220
249
  *
@@ -523,6 +552,16 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
523
552
  }
524
553
  return this;
525
554
  }
555
+ /**
556
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
557
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
558
+ * @returns A new reversed instance.
559
+ */
560
+ toReversed() {
561
+ const cloned = this.clone();
562
+ cloned.reverse();
563
+ return cloned;
564
+ }
526
565
  };
527
566
  __name(_LinearBase, "LinearBase");
528
567
  var LinearBase = _LinearBase;
@@ -821,6 +860,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
821
860
 
822
861
 
823
862
 
863
+
864
+
865
+
824
866
 
825
867
 
826
868
 
@@ -892,6 +934,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
892
934
 
893
935
 
894
936
 
937
+
938
+
939
+
895
940
 
896
941
 
897
942
 
@@ -969,6 +1014,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
969
1014
 
970
1015
 
971
1016
 
1017
+
1018
+
1019
+
972
1020
 
973
1021
 
974
1022
 
@@ -1027,6 +1075,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1027
1075
 
1028
1076
 
1029
1077
 
1078
+
1079
+
1080
+
1030
1081
 
1031
1082
 
1032
1083
 
@@ -1146,6 +1197,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1146
1197
 
1147
1198
 
1148
1199
 
1200
+
1201
+
1202
+
1149
1203
 
1150
1204
 
1151
1205
 
@@ -1209,6 +1263,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1209
1263
 
1210
1264
 
1211
1265
 
1266
+
1267
+
1268
+
1212
1269
 
1213
1270
 
1214
1271
 
@@ -1261,6 +1318,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1261
1318
 
1262
1319
 
1263
1320
 
1321
+
1322
+
1323
+
1264
1324
 
1265
1325
 
1266
1326
 
@@ -1319,6 +1379,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1319
1379
 
1320
1380
 
1321
1381
 
1382
+
1383
+
1384
+
1322
1385
 
1323
1386
 
1324
1387
 
@@ -1382,6 +1445,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1382
1445
 
1383
1446
 
1384
1447
 
1448
+
1449
+
1450
+
1385
1451
 
1386
1452
 
1387
1453
 
@@ -1453,6 +1519,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1453
1519
 
1454
1520
 
1455
1521
 
1522
+
1523
+
1524
+
1456
1525
 
1457
1526
 
1458
1527
 
@@ -1501,6 +1570,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1501
1570
 
1502
1571
 
1503
1572
 
1573
+
1574
+
1575
+
1504
1576
 
1505
1577
 
1506
1578
 
@@ -1555,6 +1627,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1555
1627
 
1556
1628
 
1557
1629
 
1630
+
1631
+
1632
+
1558
1633
 
1559
1634
 
1560
1635
 
@@ -1775,6 +1850,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1775
1850
 
1776
1851
 
1777
1852
 
1853
+
1854
+
1855
+
1778
1856
 
1779
1857
 
1780
1858
 
@@ -1833,6 +1911,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1833
1911
 
1834
1912
 
1835
1913
 
1914
+
1915
+
1916
+
1836
1917
 
1837
1918
 
1838
1919
 
@@ -1919,6 +2000,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1919
2000
 
1920
2001
 
1921
2002
 
2003
+
2004
+
2005
+
1922
2006
 
1923
2007
 
1924
2008
 
@@ -2243,6 +2327,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2243
2327
 
2244
2328
 
2245
2329
 
2330
+
2331
+
2332
+
2246
2333
 
2247
2334
 
2248
2335
 
@@ -2316,6 +2403,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2316
2403
 
2317
2404
 
2318
2405
 
2406
+
2407
+
2408
+
2319
2409
 
2320
2410
 
2321
2411
 
@@ -2388,6 +2478,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2388
2478
 
2389
2479
 
2390
2480
 
2481
+
2482
+
2483
+
2391
2484
 
2392
2485
 
2393
2486
 
@@ -2451,6 +2544,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2451
2544
 
2452
2545
 
2453
2546
 
2547
+
2548
+
2549
+
2454
2550
 
2455
2551
 
2456
2552
 
@@ -2543,6 +2639,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2543
2639
 
2544
2640
 
2545
2641
 
2642
+
2643
+
2644
+
2546
2645
 
2547
2646
 
2548
2647
 
@@ -2596,6 +2695,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2596
2695
 
2597
2696
 
2598
2697
 
2698
+
2699
+
2700
+
2599
2701
 
2600
2702
 
2601
2703
 
@@ -2680,6 +2782,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2680
2782
 
2681
2783
 
2682
2784
 
2785
+
2786
+
2787
+
2683
2788
 
2684
2789
 
2685
2790
 
@@ -2792,6 +2897,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2792
2897
 
2793
2898
 
2794
2899
 
2900
+
2901
+
2902
+
2795
2903
 
2796
2904
 
2797
2905
 
@@ -2851,6 +2959,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2851
2959
 
2852
2960
 
2853
2961
 
2962
+
2963
+
2964
+
2854
2965
 
2855
2966
 
2856
2967
 
@@ -2912,6 +3023,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2912
3023
 
2913
3024
 
2914
3025
 
3026
+
3027
+
3028
+
2915
3029
 
2916
3030
 
2917
3031
 
@@ -2960,6 +3074,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2960
3074
 
2961
3075
 
2962
3076
 
3077
+
3078
+
3079
+
2963
3080
 
2964
3081
 
2965
3082
 
@@ -3012,6 +3129,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
3012
3129
 
3013
3130
 
3014
3131
 
3132
+
3133
+
3134
+
3015
3135
 
3016
3136
 
3017
3137
 
@@ -3075,11 +3195,31 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
3075
3195
  * @example
3076
3196
  * // Find value scanning from tail
3077
3197
  * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
3078
- * // getBackward scans from tail to head, returns first match
3079
- * const found = list.getBackward(node => node.value < 4);
3198
+ * // findLast scans from tail to head, returns first match
3199
+ * const found = list.findLast(node => node.value < 4);
3080
3200
  * console.log(found); // 3;
3081
3201
  */
3202
+ /**
3203
+ * @deprecated Use `findLast` instead. Will be removed in a future major version.
3204
+ */
3082
3205
  getBackward(elementNodeOrPredicate) {
3206
+ return this.findLast(elementNodeOrPredicate);
3207
+ }
3208
+ /**
3209
+ * Find the first value matching a predicate scanning backward (tail → head).
3210
+ * @remarks Time O(N), Space O(1)
3211
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
3212
+ * @returns Matching value or undefined.
3213
+
3214
+
3215
+ * @example
3216
+ * // Find value scanning from tail
3217
+ * const list = new DoublyLinkedList<number>([1, 2, 3, 4]);
3218
+ * // findLast scans from tail to head, returns first match
3219
+ * const found = list.findLast(node => node.value < 4);
3220
+ * console.log(found); // 3;
3221
+ */
3222
+ findLast(elementNodeOrPredicate) {
3083
3223
  const predicate = this._ensurePredicate(elementNodeOrPredicate);
3084
3224
  let current = this.tail;
3085
3225
  while (current) {
@@ -3088,6 +3228,22 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
3088
3228
  }
3089
3229
  return void 0;
3090
3230
  }
3231
+ /**
3232
+ * Find the index of the last value matching a predicate (scans tail → head).
3233
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
3234
+ * @param predicate - Function called with (value, index, list).
3235
+ * @returns Matching index, or -1 if not found.
3236
+ */
3237
+ findLastIndex(predicate) {
3238
+ let current = this.tail;
3239
+ let index = this.length - 1;
3240
+ while (current) {
3241
+ if (predicate(current.value, index, this)) return index;
3242
+ current = current.prev;
3243
+ index--;
3244
+ }
3245
+ return -1;
3246
+ }
3091
3247
  /**
3092
3248
  * Reverse the list in place.
3093
3249
  * @remarks Time O(N), Space O(1)
@@ -3127,6 +3283,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
3127
3283
 
3128
3284
 
3129
3285
 
3286
+
3287
+
3288
+
3130
3289
 
3131
3290
 
3132
3291
 
@@ -3213,6 +3372,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
3213
3372
 
3214
3373
 
3215
3374
 
3375
+
3376
+
3377
+
3216
3378
 
3217
3379
 
3218
3380
 
@@ -3270,6 +3432,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
3270
3432
 
3271
3433
 
3272
3434
 
3435
+
3436
+
3437
+
3273
3438
 
3274
3439
 
3275
3440
 
@@ -3346,6 +3511,9 @@ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
3346
3511
 
3347
3512
 
3348
3513
 
3514
+
3515
+
3516
+
3349
3517
 
3350
3518
 
3351
3519
 
@@ -3751,6 +3919,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
3751
3919
 
3752
3920
 
3753
3921
 
3922
+
3923
+
3924
+
3754
3925
 
3755
3926
 
3756
3927
 
@@ -3797,6 +3968,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
3797
3968
 
3798
3969
 
3799
3970
 
3971
+
3972
+
3973
+
3800
3974
 
3801
3975
 
3802
3976
 
@@ -3846,6 +4020,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
3846
4020
 
3847
4021
 
3848
4022
 
4023
+
4024
+
4025
+
3849
4026
 
3850
4027
 
3851
4028
 
@@ -3903,6 +4080,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
3903
4080
 
3904
4081
 
3905
4082
 
4083
+
4084
+
4085
+
3906
4086
 
3907
4087
 
3908
4088
 
@@ -3985,6 +4165,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
3985
4165
 
3986
4166
 
3987
4167
 
4168
+
4169
+
4170
+
3988
4171
 
3989
4172
 
3990
4173
 
@@ -4052,6 +4235,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4052
4235
 
4053
4236
 
4054
4237
 
4238
+
4239
+
4240
+
4055
4241
 
4056
4242
 
4057
4243
 
@@ -4102,6 +4288,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4102
4288
 
4103
4289
 
4104
4290
 
4291
+
4292
+
4293
+
4105
4294
 
4106
4295
 
4107
4296
 
@@ -4172,6 +4361,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4172
4361
 
4173
4362
 
4174
4363
 
4364
+
4365
+
4366
+
4175
4367
 
4176
4368
 
4177
4369
 
@@ -4222,6 +4414,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4222
4414
 
4223
4415
 
4224
4416
 
4417
+
4418
+
4419
+
4225
4420
 
4226
4421
 
4227
4422
 
@@ -4274,6 +4469,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4274
4469
 
4275
4470
 
4276
4471
 
4472
+
4473
+
4474
+
4277
4475
 
4278
4476
 
4279
4477
 
@@ -4324,6 +4522,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4324
4522
 
4325
4523
 
4326
4524
 
4525
+
4526
+
4527
+
4327
4528
 
4328
4529
 
4329
4530
 
@@ -4377,6 +4578,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4377
4578
 
4378
4579
 
4379
4580
 
4581
+
4582
+
4583
+
4380
4584
 
4381
4585
 
4382
4586
 
@@ -4435,6 +4639,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4435
4639
 
4436
4640
 
4437
4641
 
4642
+
4643
+
4644
+
4438
4645
 
4439
4646
 
4440
4647
 
@@ -4491,6 +4698,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4491
4698
 
4492
4699
 
4493
4700
 
4701
+
4702
+
4703
+
4494
4704
 
4495
4705
 
4496
4706
 
@@ -4546,6 +4756,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4546
4756
 
4547
4757
 
4548
4758
 
4759
+
4760
+
4761
+
4549
4762
 
4550
4763
 
4551
4764
 
@@ -4607,6 +4820,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4607
4820
 
4608
4821
 
4609
4822
 
4823
+
4824
+
4825
+
4610
4826
 
4611
4827
 
4612
4828
 
@@ -4676,6 +4892,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4676
4892
 
4677
4893
 
4678
4894
 
4895
+
4896
+
4897
+
4679
4898
 
4680
4899
 
4681
4900
 
@@ -4729,6 +4948,9 @@ var _SkipList = class _SkipList extends IterableEntryBase {
4729
4948
 
4730
4949
 
4731
4950
 
4951
+
4952
+
4953
+
4732
4954
 
4733
4955
 
4734
4956