queue-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 +221 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +221 -1
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +221 -1
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +221 -1
  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/queue-typed.js +221 -1
  34. package/dist/umd/queue-typed.js.map +1 -1
  35. package/dist/umd/queue-typed.min.js +1 -1
  36. package/dist/umd/queue-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
@@ -206,6 +206,35 @@ var _IterableElementBase = class _IterableElementBase {
206
206
  for (const ele of this) if (ele === element) return true;
207
207
  return false;
208
208
  }
209
+ /**
210
+ * Check whether a value exists (Array-compatible alias for `has`).
211
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
212
+ * @param element - Element to search for (uses `===`).
213
+ * @returns `true` if found.
214
+ */
215
+ includes(element) {
216
+ return this.has(element);
217
+ }
218
+ /**
219
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
220
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
221
+ */
222
+ *entries() {
223
+ let index = 0;
224
+ for (const value of this) {
225
+ yield [index++, value];
226
+ }
227
+ }
228
+ /**
229
+ * Return an iterator of numeric indices (Array-compatible).
230
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
231
+ */
232
+ *keys() {
233
+ let index = 0;
234
+ for (const _ of this) {
235
+ yield index++;
236
+ }
237
+ }
209
238
  /**
210
239
  * Reduces all elements to a single accumulated value.
211
240
  *
@@ -514,6 +543,16 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
514
543
  }
515
544
  return this;
516
545
  }
546
+ /**
547
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
548
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
549
+ * @returns A new reversed instance.
550
+ */
551
+ toReversed() {
552
+ const cloned = this.clone();
553
+ cloned.reverse();
554
+ return cloned;
555
+ }
517
556
  };
518
557
  __name(_LinearBase, "LinearBase");
519
558
  var LinearBase = _LinearBase;
@@ -812,6 +851,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
812
851
 
813
852
 
814
853
 
854
+
855
+
856
+
815
857
 
816
858
 
817
859
 
@@ -883,6 +925,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
883
925
 
884
926
 
885
927
 
928
+
929
+
930
+
886
931
 
887
932
 
888
933
 
@@ -960,6 +1005,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
960
1005
 
961
1006
 
962
1007
 
1008
+
1009
+
1010
+
963
1011
 
964
1012
 
965
1013
 
@@ -1018,6 +1066,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1018
1066
 
1019
1067
 
1020
1068
 
1069
+
1070
+
1071
+
1021
1072
 
1022
1073
 
1023
1074
 
@@ -1137,6 +1188,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1137
1188
 
1138
1189
 
1139
1190
 
1191
+
1192
+
1193
+
1140
1194
 
1141
1195
 
1142
1196
 
@@ -1200,6 +1254,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1200
1254
 
1201
1255
 
1202
1256
 
1257
+
1258
+
1259
+
1203
1260
 
1204
1261
 
1205
1262
 
@@ -1252,6 +1309,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1252
1309
 
1253
1310
 
1254
1311
 
1312
+
1313
+
1314
+
1255
1315
 
1256
1316
 
1257
1317
 
@@ -1310,6 +1370,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1310
1370
 
1311
1371
 
1312
1372
 
1373
+
1374
+
1375
+
1313
1376
 
1314
1377
 
1315
1378
 
@@ -1373,6 +1436,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1373
1436
 
1374
1437
 
1375
1438
 
1439
+
1440
+
1441
+
1376
1442
 
1377
1443
 
1378
1444
 
@@ -1444,6 +1510,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1444
1510
 
1445
1511
 
1446
1512
 
1513
+
1514
+
1515
+
1447
1516
 
1448
1517
 
1449
1518
 
@@ -1492,6 +1561,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1492
1561
 
1493
1562
 
1494
1563
 
1564
+
1565
+
1566
+
1495
1567
 
1496
1568
 
1497
1569
 
@@ -1546,6 +1618,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1546
1618
 
1547
1619
 
1548
1620
 
1621
+
1622
+
1623
+
1549
1624
 
1550
1625
 
1551
1626
 
@@ -1766,6 +1841,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1766
1841
 
1767
1842
 
1768
1843
 
1844
+
1845
+
1846
+
1769
1847
 
1770
1848
 
1771
1849
 
@@ -1824,6 +1902,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1824
1902
 
1825
1903
 
1826
1904
 
1905
+
1906
+
1907
+
1827
1908
 
1828
1909
 
1829
1910
 
@@ -1910,6 +1991,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1910
1991
 
1911
1992
 
1912
1993
 
1994
+
1995
+
1996
+
1913
1997
 
1914
1998
 
1915
1999
 
@@ -2148,6 +2232,9 @@ var _Queue = class _Queue extends LinearBase {
2148
2232
 
2149
2233
 
2150
2234
 
2235
+
2236
+
2237
+
2151
2238
 
2152
2239
 
2153
2240
 
@@ -2202,6 +2289,9 @@ var _Queue = class _Queue extends LinearBase {
2202
2289
 
2203
2290
 
2204
2291
 
2292
+
2293
+
2294
+
2205
2295
 
2206
2296
 
2207
2297
 
@@ -2280,6 +2370,9 @@ var _Queue = class _Queue extends LinearBase {
2280
2370
 
2281
2371
 
2282
2372
 
2373
+
2374
+
2375
+
2283
2376
 
2284
2377
 
2285
2378
 
@@ -2346,6 +2439,9 @@ var _Queue = class _Queue extends LinearBase {
2346
2439
 
2347
2440
 
2348
2441
 
2442
+
2443
+
2444
+
2349
2445
 
2350
2446
 
2351
2447
 
@@ -2419,6 +2515,9 @@ var _Queue = class _Queue extends LinearBase {
2419
2515
 
2420
2516
 
2421
2517
 
2518
+
2519
+
2520
+
2422
2521
 
2423
2522
 
2424
2523
 
@@ -2482,6 +2581,9 @@ var _Queue = class _Queue extends LinearBase {
2482
2581
 
2483
2582
 
2484
2583
 
2584
+
2585
+
2586
+
2485
2587
 
2486
2588
 
2487
2589
 
@@ -2538,6 +2640,9 @@ var _Queue = class _Queue extends LinearBase {
2538
2640
 
2539
2641
 
2540
2642
 
2643
+
2644
+
2645
+
2541
2646
 
2542
2647
 
2543
2648
 
@@ -2650,6 +2755,9 @@ var _Queue = class _Queue extends LinearBase {
2650
2755
 
2651
2756
 
2652
2757
 
2758
+
2759
+
2760
+
2653
2761
 
2654
2762
 
2655
2763
 
@@ -2700,6 +2808,9 @@ var _Queue = class _Queue extends LinearBase {
2700
2808
 
2701
2809
 
2702
2810
 
2811
+
2812
+
2813
+
2703
2814
 
2704
2815
 
2705
2816
 
@@ -2773,6 +2884,9 @@ var _Queue = class _Queue extends LinearBase {
2773
2884
 
2774
2885
 
2775
2886
 
2887
+
2888
+
2889
+
2776
2890
 
2777
2891
 
2778
2892
 
@@ -2830,6 +2944,9 @@ var _Queue = class _Queue extends LinearBase {
2830
2944
 
2831
2945
 
2832
2946
 
2947
+
2948
+
2949
+
2833
2950
 
2834
2951
 
2835
2952
 
@@ -2891,6 +3008,9 @@ var _Queue = class _Queue extends LinearBase {
2891
3008
 
2892
3009
 
2893
3010
 
3011
+
3012
+
3013
+
2894
3014
 
2895
3015
 
2896
3016
 
@@ -3201,7 +3321,10 @@ var _Deque = class _Deque extends LinearBase {
3201
3321
  }
3202
3322
  /**
3203
3323
  * Deque peek at both ends
3204
- * @example
3324
+
3325
+
3326
+
3327
+ * @example
3205
3328
  * // Deque peek at both ends
3206
3329
  * const deque = new Deque<number>([10, 20, 30, 40, 50]);
3207
3330
  *
@@ -3259,6 +3382,9 @@ var _Deque = class _Deque extends LinearBase {
3259
3382
 
3260
3383
 
3261
3384
 
3385
+
3386
+
3387
+
3262
3388
 
3263
3389
 
3264
3390
 
@@ -3326,6 +3452,9 @@ var _Deque = class _Deque extends LinearBase {
3326
3452
 
3327
3453
 
3328
3454
 
3455
+
3456
+
3457
+
3329
3458
 
3330
3459
 
3331
3460
 
@@ -3406,6 +3535,9 @@ var _Deque = class _Deque extends LinearBase {
3406
3535
 
3407
3536
 
3408
3537
 
3538
+
3539
+
3540
+
3409
3541
 
3410
3542
 
3411
3543
 
@@ -3473,6 +3605,9 @@ var _Deque = class _Deque extends LinearBase {
3473
3605
 
3474
3606
 
3475
3607
 
3608
+
3609
+
3610
+
3476
3611
 
3477
3612
 
3478
3613
 
@@ -3541,6 +3676,9 @@ var _Deque = class _Deque extends LinearBase {
3541
3676
 
3542
3677
 
3543
3678
 
3679
+
3680
+
3681
+
3544
3682
 
3545
3683
 
3546
3684
 
@@ -3650,6 +3788,9 @@ var _Deque = class _Deque extends LinearBase {
3650
3788
 
3651
3789
 
3652
3790
 
3791
+
3792
+
3793
+
3653
3794
 
3654
3795
 
3655
3796
 
@@ -3699,6 +3840,9 @@ var _Deque = class _Deque extends LinearBase {
3699
3840
 
3700
3841
 
3701
3842
 
3843
+
3844
+
3845
+
3702
3846
 
3703
3847
 
3704
3848
 
@@ -3752,6 +3896,9 @@ var _Deque = class _Deque extends LinearBase {
3752
3896
 
3753
3897
 
3754
3898
 
3899
+
3900
+
3901
+
3755
3902
 
3756
3903
 
3757
3904
 
@@ -3956,6 +4103,9 @@ var _Deque = class _Deque extends LinearBase {
3956
4103
 
3957
4104
 
3958
4105
 
4106
+
4107
+
4108
+
3959
4109
 
3960
4110
 
3961
4111
 
@@ -4050,6 +4200,64 @@ var _Deque = class _Deque extends LinearBase {
4050
4200
 
4051
4201
 
4052
4202
 
4203
+
4204
+ * @example
4205
+ * // Deque for...of iteration and reverse
4206
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
4207
+ *
4208
+ * // Iterate forward
4209
+ * const forward: string[] = [];
4210
+ * for (const item of deque) {
4211
+ * forward.push(item);
4212
+ * }
4213
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
4214
+ *
4215
+ * // Reverse the deque
4216
+ * deque.reverse();
4217
+ * const backward: string[] = [];
4218
+ * for (const item of deque) {
4219
+ * backward.push(item);
4220
+ * }
4221
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
4222
+ */
4223
+ /**
4224
+ * Find the last value matching a predicate (scans back-to-front).
4225
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
4226
+ * @param predicate - Function called with (value, index, deque).
4227
+ * @returns Matching value or undefined.
4228
+ * @example
4229
+ * // Find last matching value
4230
+ * const d = new Deque([1, 2, 3, 4, 5]);
4231
+ * console.log(d.findLast(v => v > 2)); // 5;
4232
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
4233
+ */
4234
+ findLast(predicate) {
4235
+ for (let i = this.length - 1; i >= 0; i--) {
4236
+ const val = this.at(i);
4237
+ if (predicate(val, i, this)) return val;
4238
+ }
4239
+ return void 0;
4240
+ }
4241
+ /**
4242
+ * Find the index of the last value matching a predicate (scans back-to-front).
4243
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
4244
+ * @param predicate - Function called with (value, index, deque).
4245
+ * @returns Matching index, or -1 if not found.
4246
+ * @example
4247
+ * // Find last matching index
4248
+ * const d = new Deque([10, 20, 30, 20, 10]);
4249
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
4250
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
4251
+ */
4252
+ findLastIndex(predicate) {
4253
+ for (let i = this.length - 1; i >= 0; i--) {
4254
+ if (predicate(this.at(i), i, this)) return i;
4255
+ }
4256
+ return -1;
4257
+ }
4258
+ /**
4259
+ * Deque for...of iteration and reverse
4260
+
4053
4261
 
4054
4262
  * @example
4055
4263
  * // Deque for...of iteration and reverse
@@ -4163,6 +4371,9 @@ var _Deque = class _Deque extends LinearBase {
4163
4371
 
4164
4372
 
4165
4373
 
4374
+
4375
+
4376
+
4166
4377
 
4167
4378
 
4168
4379
 
@@ -4238,6 +4449,9 @@ var _Deque = class _Deque extends LinearBase {
4238
4449
 
4239
4450
 
4240
4451
 
4452
+
4453
+
4454
+
4241
4455
 
4242
4456
 
4243
4457
 
@@ -4296,6 +4510,9 @@ var _Deque = class _Deque extends LinearBase {
4296
4510
 
4297
4511
 
4298
4512
 
4513
+
4514
+
4515
+
4299
4516
 
4300
4517
 
4301
4518
 
@@ -4374,6 +4591,9 @@ var _Deque = class _Deque extends LinearBase {
4374
4591
 
4375
4592
 
4376
4593
 
4594
+
4595
+
4596
+
4377
4597
 
4378
4598
 
4379
4599