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
@@ -253,6 +253,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
253
253
 
254
254
 
255
255
 
256
+
257
+
258
+
256
259
 
257
260
 
258
261
 
@@ -311,6 +314,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
311
314
 
312
315
 
313
316
 
317
+
318
+
319
+
314
320
 
315
321
 
316
322
 
@@ -364,6 +370,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
364
370
 
365
371
 
366
372
 
373
+
374
+
375
+
367
376
 
368
377
 
369
378
 
@@ -413,6 +422,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
413
422
 
414
423
 
415
424
 
425
+
426
+
427
+
416
428
 
417
429
 
418
430
 
@@ -461,6 +473,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
461
473
 
462
474
 
463
475
 
476
+
477
+
478
+
464
479
 
465
480
 
466
481
 
@@ -512,6 +527,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
512
527
 
513
528
 
514
529
 
530
+
531
+
532
+
515
533
 
516
534
 
517
535
 
@@ -588,6 +606,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
588
606
 
589
607
 
590
608
 
609
+
610
+
611
+
591
612
 
592
613
 
593
614
 
@@ -647,6 +668,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
647
668
 
648
669
 
649
670
 
671
+
672
+
673
+
650
674
 
651
675
 
652
676
 
@@ -700,6 +724,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
700
724
 
701
725
 
702
726
 
727
+
728
+
729
+
703
730
 
704
731
 
705
732
 
@@ -753,6 +780,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
753
780
 
754
781
 
755
782
 
783
+
784
+
785
+
756
786
 
757
787
 
758
788
 
@@ -803,6 +833,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
803
833
 
804
834
 
805
835
 
836
+
837
+
838
+
806
839
 
807
840
 
808
841
 
@@ -848,6 +881,9 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
848
881
 
849
882
 
850
883
 
884
+
885
+
886
+
851
887
 
852
888
 
853
889
 
@@ -232,6 +232,35 @@ var queueTyped = (() => {
232
232
  for (const ele of this) if (ele === element) return true;
233
233
  return false;
234
234
  }
235
+ /**
236
+ * Check whether a value exists (Array-compatible alias for `has`).
237
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
238
+ * @param element - Element to search for (uses `===`).
239
+ * @returns `true` if found.
240
+ */
241
+ includes(element) {
242
+ return this.has(element);
243
+ }
244
+ /**
245
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
246
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
247
+ */
248
+ *entries() {
249
+ let index = 0;
250
+ for (const value of this) {
251
+ yield [index++, value];
252
+ }
253
+ }
254
+ /**
255
+ * Return an iterator of numeric indices (Array-compatible).
256
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
257
+ */
258
+ *keys() {
259
+ let index = 0;
260
+ for (const _ of this) {
261
+ yield index++;
262
+ }
263
+ }
235
264
  /**
236
265
  * Reduces all elements to a single accumulated value.
237
266
  *
@@ -536,6 +565,16 @@ var queueTyped = (() => {
536
565
  }
537
566
  return this;
538
567
  }
568
+ /**
569
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
570
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
571
+ * @returns A new reversed instance.
572
+ */
573
+ toReversed() {
574
+ const cloned = this.clone();
575
+ cloned.reverse();
576
+ return cloned;
577
+ }
539
578
  };
540
579
  var LinearLinkedBase = class extends LinearBase {
541
580
  constructor(options) {
@@ -828,6 +867,9 @@ var queueTyped = (() => {
828
867
 
829
868
 
830
869
 
870
+
871
+
872
+
831
873
 
832
874
 
833
875
 
@@ -899,6 +941,9 @@ var queueTyped = (() => {
899
941
 
900
942
 
901
943
 
944
+
945
+
946
+
902
947
 
903
948
 
904
949
 
@@ -976,6 +1021,9 @@ var queueTyped = (() => {
976
1021
 
977
1022
 
978
1023
 
1024
+
1025
+
1026
+
979
1027
 
980
1028
 
981
1029
 
@@ -1034,6 +1082,9 @@ var queueTyped = (() => {
1034
1082
 
1035
1083
 
1036
1084
 
1085
+
1086
+
1087
+
1037
1088
 
1038
1089
 
1039
1090
 
@@ -1153,6 +1204,9 @@ var queueTyped = (() => {
1153
1204
 
1154
1205
 
1155
1206
 
1207
+
1208
+
1209
+
1156
1210
 
1157
1211
 
1158
1212
 
@@ -1216,6 +1270,9 @@ var queueTyped = (() => {
1216
1270
 
1217
1271
 
1218
1272
 
1273
+
1274
+
1275
+
1219
1276
 
1220
1277
 
1221
1278
 
@@ -1268,6 +1325,9 @@ var queueTyped = (() => {
1268
1325
 
1269
1326
 
1270
1327
 
1328
+
1329
+
1330
+
1271
1331
 
1272
1332
 
1273
1333
 
@@ -1326,6 +1386,9 @@ var queueTyped = (() => {
1326
1386
 
1327
1387
 
1328
1388
 
1389
+
1390
+
1391
+
1329
1392
 
1330
1393
 
1331
1394
 
@@ -1389,6 +1452,9 @@ var queueTyped = (() => {
1389
1452
 
1390
1453
 
1391
1454
 
1455
+
1456
+
1457
+
1392
1458
 
1393
1459
 
1394
1460
 
@@ -1460,6 +1526,9 @@ var queueTyped = (() => {
1460
1526
 
1461
1527
 
1462
1528
 
1529
+
1530
+
1531
+
1463
1532
 
1464
1533
 
1465
1534
 
@@ -1508,6 +1577,9 @@ var queueTyped = (() => {
1508
1577
 
1509
1578
 
1510
1579
 
1580
+
1581
+
1582
+
1511
1583
 
1512
1584
 
1513
1585
 
@@ -1562,6 +1634,9 @@ var queueTyped = (() => {
1562
1634
 
1563
1635
 
1564
1636
 
1637
+
1638
+
1639
+
1565
1640
 
1566
1641
 
1567
1642
 
@@ -1782,6 +1857,9 @@ var queueTyped = (() => {
1782
1857
 
1783
1858
 
1784
1859
 
1860
+
1861
+
1862
+
1785
1863
 
1786
1864
 
1787
1865
 
@@ -1840,6 +1918,9 @@ var queueTyped = (() => {
1840
1918
 
1841
1919
 
1842
1920
 
1921
+
1922
+
1923
+
1843
1924
 
1844
1925
 
1845
1926
 
@@ -1926,6 +2007,9 @@ var queueTyped = (() => {
1926
2007
 
1927
2008
 
1928
2009
 
2010
+
2011
+
2012
+
1929
2013
 
1930
2014
 
1931
2015
 
@@ -2161,6 +2245,9 @@ var queueTyped = (() => {
2161
2245
 
2162
2246
 
2163
2247
 
2248
+
2249
+
2250
+
2164
2251
 
2165
2252
 
2166
2253
 
@@ -2215,6 +2302,9 @@ var queueTyped = (() => {
2215
2302
 
2216
2303
 
2217
2304
 
2305
+
2306
+
2307
+
2218
2308
 
2219
2309
 
2220
2310
 
@@ -2293,6 +2383,9 @@ var queueTyped = (() => {
2293
2383
 
2294
2384
 
2295
2385
 
2386
+
2387
+
2388
+
2296
2389
 
2297
2390
 
2298
2391
 
@@ -2359,6 +2452,9 @@ var queueTyped = (() => {
2359
2452
 
2360
2453
 
2361
2454
 
2455
+
2456
+
2457
+
2362
2458
 
2363
2459
 
2364
2460
 
@@ -2432,6 +2528,9 @@ var queueTyped = (() => {
2432
2528
 
2433
2529
 
2434
2530
 
2531
+
2532
+
2533
+
2435
2534
 
2436
2535
 
2437
2536
 
@@ -2495,6 +2594,9 @@ var queueTyped = (() => {
2495
2594
 
2496
2595
 
2497
2596
 
2597
+
2598
+
2599
+
2498
2600
 
2499
2601
 
2500
2602
 
@@ -2551,6 +2653,9 @@ var queueTyped = (() => {
2551
2653
 
2552
2654
 
2553
2655
 
2656
+
2657
+
2658
+
2554
2659
 
2555
2660
 
2556
2661
 
@@ -2663,6 +2768,9 @@ var queueTyped = (() => {
2663
2768
 
2664
2769
 
2665
2770
 
2771
+
2772
+
2773
+
2666
2774
 
2667
2775
 
2668
2776
 
@@ -2713,6 +2821,9 @@ var queueTyped = (() => {
2713
2821
 
2714
2822
 
2715
2823
 
2824
+
2825
+
2826
+
2716
2827
 
2717
2828
 
2718
2829
 
@@ -2786,6 +2897,9 @@ var queueTyped = (() => {
2786
2897
 
2787
2898
 
2788
2899
 
2900
+
2901
+
2902
+
2789
2903
 
2790
2904
 
2791
2905
 
@@ -2843,6 +2957,9 @@ var queueTyped = (() => {
2843
2957
 
2844
2958
 
2845
2959
 
2960
+
2961
+
2962
+
2846
2963
 
2847
2964
 
2848
2965
 
@@ -2904,6 +3021,9 @@ var queueTyped = (() => {
2904
3021
 
2905
3022
 
2906
3023
 
3024
+
3025
+
3026
+
2907
3027
 
2908
3028
 
2909
3029
 
@@ -3210,7 +3330,10 @@ var queueTyped = (() => {
3210
3330
  }
3211
3331
  /**
3212
3332
  * Deque peek at both ends
3213
- * @example
3333
+
3334
+
3335
+
3336
+ * @example
3214
3337
  * // Deque peek at both ends
3215
3338
  * const deque = new Deque<number>([10, 20, 30, 40, 50]);
3216
3339
  *
@@ -3268,6 +3391,9 @@ var queueTyped = (() => {
3268
3391
 
3269
3392
 
3270
3393
 
3394
+
3395
+
3396
+
3271
3397
 
3272
3398
 
3273
3399
 
@@ -3335,6 +3461,9 @@ var queueTyped = (() => {
3335
3461
 
3336
3462
 
3337
3463
 
3464
+
3465
+
3466
+
3338
3467
 
3339
3468
 
3340
3469
 
@@ -3415,6 +3544,9 @@ var queueTyped = (() => {
3415
3544
 
3416
3545
 
3417
3546
 
3547
+
3548
+
3549
+
3418
3550
 
3419
3551
 
3420
3552
 
@@ -3482,6 +3614,9 @@ var queueTyped = (() => {
3482
3614
 
3483
3615
 
3484
3616
 
3617
+
3618
+
3619
+
3485
3620
 
3486
3621
 
3487
3622
 
@@ -3550,6 +3685,9 @@ var queueTyped = (() => {
3550
3685
 
3551
3686
 
3552
3687
 
3688
+
3689
+
3690
+
3553
3691
 
3554
3692
 
3555
3693
 
@@ -3659,6 +3797,9 @@ var queueTyped = (() => {
3659
3797
 
3660
3798
 
3661
3799
 
3800
+
3801
+
3802
+
3662
3803
 
3663
3804
 
3664
3805
 
@@ -3708,6 +3849,9 @@ var queueTyped = (() => {
3708
3849
 
3709
3850
 
3710
3851
 
3852
+
3853
+
3854
+
3711
3855
 
3712
3856
 
3713
3857
 
@@ -3761,6 +3905,9 @@ var queueTyped = (() => {
3761
3905
 
3762
3906
 
3763
3907
 
3908
+
3909
+
3910
+
3764
3911
 
3765
3912
 
3766
3913
 
@@ -3965,6 +4112,9 @@ var queueTyped = (() => {
3965
4112
 
3966
4113
 
3967
4114
 
4115
+
4116
+
4117
+
3968
4118
 
3969
4119
 
3970
4120
 
@@ -4059,6 +4209,64 @@ var queueTyped = (() => {
4059
4209
 
4060
4210
 
4061
4211
 
4212
+
4213
+ * @example
4214
+ * // Deque for...of iteration and reverse
4215
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
4216
+ *
4217
+ * // Iterate forward
4218
+ * const forward: string[] = [];
4219
+ * for (const item of deque) {
4220
+ * forward.push(item);
4221
+ * }
4222
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
4223
+ *
4224
+ * // Reverse the deque
4225
+ * deque.reverse();
4226
+ * const backward: string[] = [];
4227
+ * for (const item of deque) {
4228
+ * backward.push(item);
4229
+ * }
4230
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
4231
+ */
4232
+ /**
4233
+ * Find the last value matching a predicate (scans back-to-front).
4234
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
4235
+ * @param predicate - Function called with (value, index, deque).
4236
+ * @returns Matching value or undefined.
4237
+ * @example
4238
+ * // Find last matching value
4239
+ * const d = new Deque([1, 2, 3, 4, 5]);
4240
+ * console.log(d.findLast(v => v > 2)); // 5;
4241
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
4242
+ */
4243
+ findLast(predicate) {
4244
+ for (let i = this.length - 1; i >= 0; i--) {
4245
+ const val = this.at(i);
4246
+ if (predicate(val, i, this)) return val;
4247
+ }
4248
+ return void 0;
4249
+ }
4250
+ /**
4251
+ * Find the index of the last value matching a predicate (scans back-to-front).
4252
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
4253
+ * @param predicate - Function called with (value, index, deque).
4254
+ * @returns Matching index, or -1 if not found.
4255
+ * @example
4256
+ * // Find last matching index
4257
+ * const d = new Deque([10, 20, 30, 20, 10]);
4258
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
4259
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
4260
+ */
4261
+ findLastIndex(predicate) {
4262
+ for (let i = this.length - 1; i >= 0; i--) {
4263
+ if (predicate(this.at(i), i, this)) return i;
4264
+ }
4265
+ return -1;
4266
+ }
4267
+ /**
4268
+ * Deque for...of iteration and reverse
4269
+
4062
4270
 
4063
4271
  * @example
4064
4272
  * // Deque for...of iteration and reverse
@@ -4172,6 +4380,9 @@ var queueTyped = (() => {
4172
4380
 
4173
4381
 
4174
4382
 
4383
+
4384
+
4385
+
4175
4386
 
4176
4387
 
4177
4388
 
@@ -4247,6 +4458,9 @@ var queueTyped = (() => {
4247
4458
 
4248
4459
 
4249
4460
 
4461
+
4462
+
4463
+
4250
4464
 
4251
4465
 
4252
4466
 
@@ -4305,6 +4519,9 @@ var queueTyped = (() => {
4305
4519
 
4306
4520
 
4307
4521
 
4522
+
4523
+
4524
+
4308
4525
 
4309
4526
 
4310
4527
 
@@ -4383,6 +4600,9 @@ var queueTyped = (() => {
4383
4600
 
4384
4601
 
4385
4602
 
4603
+
4604
+
4605
+
4386
4606
 
4387
4607
 
4388
4608