queue-typed 2.5.2 → 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 (63) hide show
  1. package/dist/cjs/index.cjs +435 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +435 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +435 -0
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +435 -0
  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 +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +171 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/umd/queue-typed.js +435 -0
  35. package/dist/umd/queue-typed.js.map +1 -1
  36. package/dist/umd/queue-typed.min.js +1 -1
  37. package/dist/umd/queue-typed.min.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/data-structures/base/iterable-element-base.ts +32 -0
  40. package/src/data-structures/base/linear-base.ts +11 -0
  41. package/src/data-structures/binary-tree/avl-tree.ts +88 -5
  42. package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
  43. package/src/data-structures/binary-tree/binary-tree.ts +242 -81
  44. package/src/data-structures/binary-tree/bst.ts +173 -7
  45. package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
  46. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  47. package/src/data-structures/binary-tree/tree-map.ts +948 -36
  48. package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
  49. package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
  50. package/src/data-structures/binary-tree/tree-set.ts +1260 -251
  51. package/src/data-structures/graph/directed-graph.ts +71 -1
  52. package/src/data-structures/graph/undirected-graph.ts +64 -1
  53. package/src/data-structures/hash/hash-map.ts +100 -12
  54. package/src/data-structures/heap/heap.ts +149 -19
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
  56. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  57. package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
  58. package/src/data-structures/matrix/matrix.ts +56 -0
  59. package/src/data-structures/queue/deque.ts +187 -0
  60. package/src/data-structures/queue/queue.ts +109 -0
  61. package/src/data-structures/stack/stack.ts +75 -5
  62. package/src/data-structures/trie/trie.ts +84 -0
  63. package/src/interfaces/binary-tree.ts +1 -9
@@ -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;
@@ -804,6 +843,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
804
843
 
805
844
 
806
845
 
846
+
847
+
848
+
849
+
850
+
851
+
852
+
807
853
 
808
854
 
809
855
 
@@ -871,6 +917,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
871
917
 
872
918
 
873
919
 
920
+
921
+
922
+
923
+
924
+
925
+
926
+
874
927
 
875
928
 
876
929
 
@@ -944,6 +997,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
944
997
 
945
998
 
946
999
 
1000
+
1001
+
1002
+
1003
+
1004
+
1005
+
1006
+
947
1007
 
948
1008
 
949
1009
 
@@ -998,6 +1058,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
998
1058
 
999
1059
 
1000
1060
 
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1001
1068
 
1002
1069
 
1003
1070
 
@@ -1113,6 +1180,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1113
1180
 
1114
1181
 
1115
1182
 
1183
+
1184
+
1185
+
1186
+
1187
+
1188
+
1189
+
1116
1190
 
1117
1191
 
1118
1192
 
@@ -1172,6 +1246,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1172
1246
 
1173
1247
 
1174
1248
 
1249
+
1250
+
1251
+
1252
+
1253
+
1254
+
1255
+
1175
1256
 
1176
1257
 
1177
1258
 
@@ -1220,6 +1301,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1220
1301
 
1221
1302
 
1222
1303
 
1304
+
1305
+
1306
+
1307
+
1308
+
1309
+
1310
+
1223
1311
 
1224
1312
 
1225
1313
 
@@ -1274,6 +1362,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1274
1362
 
1275
1363
 
1276
1364
 
1365
+
1366
+
1367
+
1368
+
1369
+
1370
+
1371
+
1277
1372
 
1278
1373
 
1279
1374
 
@@ -1333,6 +1428,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1333
1428
 
1334
1429
 
1335
1430
 
1431
+
1432
+
1433
+
1434
+
1435
+
1436
+
1437
+
1336
1438
 
1337
1439
 
1338
1440
 
@@ -1400,6 +1502,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1400
1502
 
1401
1503
 
1402
1504
 
1505
+
1506
+
1507
+
1508
+
1509
+
1510
+
1511
+
1403
1512
 
1404
1513
 
1405
1514
 
@@ -1444,6 +1553,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1444
1553
 
1445
1554
 
1446
1555
 
1556
+
1557
+
1558
+
1559
+
1560
+
1561
+
1562
+
1447
1563
 
1448
1564
 
1449
1565
 
@@ -1494,6 +1610,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1494
1610
 
1495
1611
 
1496
1612
 
1613
+
1614
+
1615
+
1616
+
1617
+
1618
+
1619
+
1497
1620
 
1498
1621
 
1499
1622
 
@@ -1710,6 +1833,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1710
1833
 
1711
1834
 
1712
1835
 
1836
+
1837
+
1838
+
1839
+
1840
+
1841
+
1842
+
1713
1843
 
1714
1844
 
1715
1845
 
@@ -1764,6 +1894,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1764
1894
 
1765
1895
 
1766
1896
 
1897
+
1898
+
1899
+
1900
+
1901
+
1902
+
1903
+
1767
1904
 
1768
1905
 
1769
1906
 
@@ -1846,6 +1983,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1846
1983
 
1847
1984
 
1848
1985
 
1986
+
1987
+
1988
+
1989
+
1990
+
1991
+
1992
+
1849
1993
 
1850
1994
 
1851
1995
 
@@ -2080,6 +2224,13 @@ var _Queue = class _Queue extends LinearBase {
2080
2224
 
2081
2225
 
2082
2226
 
2227
+
2228
+
2229
+
2230
+
2231
+
2232
+
2233
+
2083
2234
 
2084
2235
 
2085
2236
 
@@ -2130,6 +2281,13 @@ var _Queue = class _Queue extends LinearBase {
2130
2281
 
2131
2282
 
2132
2283
 
2284
+
2285
+
2286
+
2287
+
2288
+
2289
+
2290
+
2133
2291
 
2134
2292
 
2135
2293
 
@@ -2147,6 +2305,14 @@ var _Queue = class _Queue extends LinearBase {
2147
2305
  get first() {
2148
2306
  return this.length > 0 ? this.elements[this._offset] : void 0;
2149
2307
  }
2308
+ /**
2309
+ * Peek at the front element without removing it (alias for `first`).
2310
+ * @remarks Time O(1), Space O(1)
2311
+ * @returns Front element or undefined.
2312
+ */
2313
+ peek() {
2314
+ return this.first;
2315
+ }
2150
2316
  /**
2151
2317
  * Get the last element (back) without removing it.
2152
2318
  * @remarks Time O(1), Space O(1)
@@ -2196,6 +2362,13 @@ var _Queue = class _Queue extends LinearBase {
2196
2362
 
2197
2363
 
2198
2364
 
2365
+
2366
+
2367
+
2368
+
2369
+
2370
+
2371
+
2199
2372
 
2200
2373
 
2201
2374
 
@@ -2258,6 +2431,13 @@ var _Queue = class _Queue extends LinearBase {
2258
2431
 
2259
2432
 
2260
2433
 
2434
+
2435
+
2436
+
2437
+
2438
+
2439
+
2440
+
2261
2441
 
2262
2442
 
2263
2443
 
@@ -2327,6 +2507,13 @@ var _Queue = class _Queue extends LinearBase {
2327
2507
 
2328
2508
 
2329
2509
 
2510
+
2511
+
2512
+
2513
+
2514
+
2515
+
2516
+
2330
2517
 
2331
2518
 
2332
2519
 
@@ -2386,6 +2573,13 @@ var _Queue = class _Queue extends LinearBase {
2386
2573
 
2387
2574
 
2388
2575
 
2576
+
2577
+
2578
+
2579
+
2580
+
2581
+
2582
+
2389
2583
 
2390
2584
 
2391
2585
 
@@ -2438,6 +2632,13 @@ var _Queue = class _Queue extends LinearBase {
2438
2632
 
2439
2633
 
2440
2634
 
2635
+
2636
+
2637
+
2638
+
2639
+
2640
+
2641
+
2441
2642
 
2442
2643
 
2443
2644
 
@@ -2492,6 +2693,21 @@ var _Queue = class _Queue extends LinearBase {
2492
2693
  this._elements[this._offset + index] = newElement;
2493
2694
  return true;
2494
2695
  }
2696
+ /**
2697
+ * Delete the first element that satisfies a predicate.
2698
+ * @remarks Time O(N), Space O(N)
2699
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
2700
+ * @returns True if a match was removed.
2701
+ */
2702
+ deleteWhere(predicate) {
2703
+ for (let i = 0; i < this.length; i++) {
2704
+ if (predicate(this._elements[this._offset + i], i, this)) {
2705
+ this.deleteAt(i);
2706
+ return true;
2707
+ }
2708
+ }
2709
+ return false;
2710
+ }
2495
2711
  /**
2496
2712
  * Reverse the queue in-place by compacting then reversing.
2497
2713
  * @remarks Time O(N), Space O(N)
@@ -2531,6 +2747,13 @@ var _Queue = class _Queue extends LinearBase {
2531
2747
 
2532
2748
 
2533
2749
 
2750
+
2751
+
2752
+
2753
+
2754
+
2755
+
2756
+
2534
2757
 
2535
2758
 
2536
2759
 
@@ -2577,6 +2800,13 @@ var _Queue = class _Queue extends LinearBase {
2577
2800
 
2578
2801
 
2579
2802
 
2803
+
2804
+
2805
+
2806
+
2807
+
2808
+
2809
+
2580
2810
 
2581
2811
 
2582
2812
 
@@ -2646,6 +2876,13 @@ var _Queue = class _Queue extends LinearBase {
2646
2876
 
2647
2877
 
2648
2878
 
2879
+
2880
+
2881
+
2882
+
2883
+
2884
+
2885
+
2649
2886
 
2650
2887
 
2651
2888
 
@@ -2699,6 +2936,13 @@ var _Queue = class _Queue extends LinearBase {
2699
2936
 
2700
2937
 
2701
2938
 
2939
+
2940
+
2941
+
2942
+
2943
+
2944
+
2945
+
2702
2946
 
2703
2947
 
2704
2948
 
@@ -2756,6 +3000,13 @@ var _Queue = class _Queue extends LinearBase {
2756
3000
 
2757
3001
 
2758
3002
 
3003
+
3004
+
3005
+
3006
+
3007
+
3008
+
3009
+
2759
3010
 
2760
3011
 
2761
3012
 
@@ -3040,6 +3291,37 @@ var _Deque = class _Deque extends LinearBase {
3040
3291
 
3041
3292
 
3042
3293
 
3294
+
3295
+
3296
+
3297
+
3298
+
3299
+ * @example
3300
+ * // Deque peek at both ends
3301
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
3302
+ *
3303
+ * // Get first element without removing
3304
+ * const first = deque.at(0);
3305
+ * console.log(first); // 10;
3306
+ *
3307
+ * // Get last element without removing
3308
+ * const last = deque.at(deque.length - 1);
3309
+ * console.log(last); // 50;
3310
+ *
3311
+ * // Length unchanged
3312
+ * console.log(deque.length); // 5;
3313
+ */
3314
+ /**
3315
+ * Peek at the front element without removing it (alias for `first`).
3316
+ * @remarks Time O(1), Space O(1)
3317
+ * @returns Front element or undefined.
3318
+ */
3319
+ peek() {
3320
+ return this.first;
3321
+ }
3322
+ /**
3323
+ * Deque peek at both ends
3324
+
3043
3325
 
3044
3326
 
3045
3327
  * @example
@@ -3092,6 +3374,13 @@ var _Deque = class _Deque extends LinearBase {
3092
3374
 
3093
3375
 
3094
3376
 
3377
+
3378
+
3379
+
3380
+
3381
+
3382
+
3383
+
3095
3384
 
3096
3385
 
3097
3386
 
@@ -3155,6 +3444,13 @@ var _Deque = class _Deque extends LinearBase {
3155
3444
 
3156
3445
 
3157
3446
 
3447
+
3448
+
3449
+
3450
+
3451
+
3452
+
3453
+
3158
3454
 
3159
3455
 
3160
3456
 
@@ -3231,6 +3527,13 @@ var _Deque = class _Deque extends LinearBase {
3231
3527
 
3232
3528
 
3233
3529
 
3530
+
3531
+
3532
+
3533
+
3534
+
3535
+
3536
+
3234
3537
 
3235
3538
 
3236
3539
 
@@ -3294,6 +3597,13 @@ var _Deque = class _Deque extends LinearBase {
3294
3597
 
3295
3598
 
3296
3599
 
3600
+
3601
+
3602
+
3603
+
3604
+
3605
+
3606
+
3297
3607
 
3298
3608
 
3299
3609
 
@@ -3358,6 +3668,13 @@ var _Deque = class _Deque extends LinearBase {
3358
3668
 
3359
3669
 
3360
3670
 
3671
+
3672
+
3673
+
3674
+
3675
+
3676
+
3677
+
3361
3678
 
3362
3679
 
3363
3680
 
@@ -3463,6 +3780,13 @@ var _Deque = class _Deque extends LinearBase {
3463
3780
 
3464
3781
 
3465
3782
 
3783
+
3784
+
3785
+
3786
+
3787
+
3788
+
3789
+
3466
3790
 
3467
3791
 
3468
3792
 
@@ -3508,6 +3832,13 @@ var _Deque = class _Deque extends LinearBase {
3508
3832
 
3509
3833
 
3510
3834
 
3835
+
3836
+
3837
+
3838
+
3839
+
3840
+
3841
+
3511
3842
 
3512
3843
 
3513
3844
 
@@ -3557,6 +3888,13 @@ var _Deque = class _Deque extends LinearBase {
3557
3888
 
3558
3889
 
3559
3890
 
3891
+
3892
+
3893
+
3894
+
3895
+
3896
+
3897
+
3560
3898
 
3561
3899
 
3562
3900
 
@@ -3757,6 +4095,13 @@ var _Deque = class _Deque extends LinearBase {
3757
4095
 
3758
4096
 
3759
4097
 
4098
+
4099
+
4100
+
4101
+
4102
+
4103
+
4104
+
3760
4105
 
3761
4106
 
3762
4107
 
@@ -3851,6 +4196,68 @@ var _Deque = class _Deque extends LinearBase {
3851
4196
 
3852
4197
 
3853
4198
 
4199
+
4200
+
4201
+
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
+
3854
4261
 
3855
4262
  * @example
3856
4263
  * // Deque for...of iteration and reverse
@@ -3956,6 +4363,13 @@ var _Deque = class _Deque extends LinearBase {
3956
4363
 
3957
4364
 
3958
4365
 
4366
+
4367
+
4368
+
4369
+
4370
+
4371
+
4372
+
3959
4373
 
3960
4374
 
3961
4375
 
@@ -4027,6 +4441,13 @@ var _Deque = class _Deque extends LinearBase {
4027
4441
 
4028
4442
 
4029
4443
 
4444
+
4445
+
4446
+
4447
+
4448
+
4449
+
4450
+
4030
4451
 
4031
4452
 
4032
4453
 
@@ -4081,6 +4502,13 @@ var _Deque = class _Deque extends LinearBase {
4081
4502
 
4082
4503
 
4083
4504
 
4505
+
4506
+
4507
+
4508
+
4509
+
4510
+
4511
+
4084
4512
 
4085
4513
 
4086
4514
 
@@ -4155,6 +4583,13 @@ var _Deque = class _Deque extends LinearBase {
4155
4583
 
4156
4584
 
4157
4585
 
4586
+
4587
+
4588
+
4589
+
4590
+
4591
+
4592
+
4158
4593
 
4159
4594
 
4160
4595