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