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
@@ -208,6 +208,35 @@ var _IterableElementBase = class _IterableElementBase {
208
208
  for (const ele of this) if (ele === element) return true;
209
209
  return false;
210
210
  }
211
+ /**
212
+ * Check whether a value exists (Array-compatible alias for `has`).
213
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
214
+ * @param element - Element to search for (uses `===`).
215
+ * @returns `true` if found.
216
+ */
217
+ includes(element) {
218
+ return this.has(element);
219
+ }
220
+ /**
221
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
222
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
223
+ */
224
+ *entries() {
225
+ let index = 0;
226
+ for (const value of this) {
227
+ yield [index++, value];
228
+ }
229
+ }
230
+ /**
231
+ * Return an iterator of numeric indices (Array-compatible).
232
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
233
+ */
234
+ *keys() {
235
+ let index = 0;
236
+ for (const _ of this) {
237
+ yield index++;
238
+ }
239
+ }
211
240
  /**
212
241
  * Reduces all elements to a single accumulated value.
213
242
  *
@@ -516,6 +545,16 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
516
545
  }
517
546
  return this;
518
547
  }
548
+ /**
549
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
550
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
551
+ * @returns A new reversed instance.
552
+ */
553
+ toReversed() {
554
+ const cloned = this.clone();
555
+ cloned.reverse();
556
+ return cloned;
557
+ }
519
558
  };
520
559
  __name(_LinearBase, "LinearBase");
521
560
  var LinearBase = _LinearBase;
@@ -806,6 +845,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
806
845
 
807
846
 
808
847
 
848
+
849
+
850
+
851
+
852
+
853
+
854
+
809
855
 
810
856
 
811
857
 
@@ -873,6 +919,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
873
919
 
874
920
 
875
921
 
922
+
923
+
924
+
925
+
926
+
927
+
928
+
876
929
 
877
930
 
878
931
 
@@ -946,6 +999,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
946
999
 
947
1000
 
948
1001
 
1002
+
1003
+
1004
+
1005
+
1006
+
1007
+
1008
+
949
1009
 
950
1010
 
951
1011
 
@@ -1000,6 +1060,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1000
1060
 
1001
1061
 
1002
1062
 
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+
1003
1070
 
1004
1071
 
1005
1072
 
@@ -1115,6 +1182,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1115
1182
 
1116
1183
 
1117
1184
 
1185
+
1186
+
1187
+
1188
+
1189
+
1190
+
1191
+
1118
1192
 
1119
1193
 
1120
1194
 
@@ -1174,6 +1248,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1174
1248
 
1175
1249
 
1176
1250
 
1251
+
1252
+
1253
+
1254
+
1255
+
1256
+
1257
+
1177
1258
 
1178
1259
 
1179
1260
 
@@ -1222,6 +1303,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1222
1303
 
1223
1304
 
1224
1305
 
1306
+
1307
+
1308
+
1309
+
1310
+
1311
+
1312
+
1225
1313
 
1226
1314
 
1227
1315
 
@@ -1276,6 +1364,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1276
1364
 
1277
1365
 
1278
1366
 
1367
+
1368
+
1369
+
1370
+
1371
+
1372
+
1373
+
1279
1374
 
1280
1375
 
1281
1376
 
@@ -1335,6 +1430,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1335
1430
 
1336
1431
 
1337
1432
 
1433
+
1434
+
1435
+
1436
+
1437
+
1438
+
1439
+
1338
1440
 
1339
1441
 
1340
1442
 
@@ -1402,6 +1504,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1402
1504
 
1403
1505
 
1404
1506
 
1507
+
1508
+
1509
+
1510
+
1511
+
1512
+
1513
+
1405
1514
 
1406
1515
 
1407
1516
 
@@ -1446,6 +1555,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1446
1555
 
1447
1556
 
1448
1557
 
1558
+
1559
+
1560
+
1561
+
1562
+
1563
+
1564
+
1449
1565
 
1450
1566
 
1451
1567
 
@@ -1496,6 +1612,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1496
1612
 
1497
1613
 
1498
1614
 
1615
+
1616
+
1617
+
1618
+
1619
+
1620
+
1621
+
1499
1622
 
1500
1623
 
1501
1624
 
@@ -1712,6 +1835,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1712
1835
 
1713
1836
 
1714
1837
 
1838
+
1839
+
1840
+
1841
+
1842
+
1843
+
1844
+
1715
1845
 
1716
1846
 
1717
1847
 
@@ -1766,6 +1896,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1766
1896
 
1767
1897
 
1768
1898
 
1899
+
1900
+
1901
+
1902
+
1903
+
1904
+
1905
+
1769
1906
 
1770
1907
 
1771
1908
 
@@ -1848,6 +1985,13 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1848
1985
 
1849
1986
 
1850
1987
 
1988
+
1989
+
1990
+
1991
+
1992
+
1993
+
1994
+
1851
1995
 
1852
1996
 
1853
1997
 
@@ -2082,6 +2226,13 @@ var _Queue = class _Queue extends LinearBase {
2082
2226
 
2083
2227
 
2084
2228
 
2229
+
2230
+
2231
+
2232
+
2233
+
2234
+
2235
+
2085
2236
 
2086
2237
 
2087
2238
 
@@ -2132,6 +2283,13 @@ var _Queue = class _Queue extends LinearBase {
2132
2283
 
2133
2284
 
2134
2285
 
2286
+
2287
+
2288
+
2289
+
2290
+
2291
+
2292
+
2135
2293
 
2136
2294
 
2137
2295
 
@@ -2149,6 +2307,14 @@ var _Queue = class _Queue extends LinearBase {
2149
2307
  get first() {
2150
2308
  return this.length > 0 ? this.elements[this._offset] : void 0;
2151
2309
  }
2310
+ /**
2311
+ * Peek at the front element without removing it (alias for `first`).
2312
+ * @remarks Time O(1), Space O(1)
2313
+ * @returns Front element or undefined.
2314
+ */
2315
+ peek() {
2316
+ return this.first;
2317
+ }
2152
2318
  /**
2153
2319
  * Get the last element (back) without removing it.
2154
2320
  * @remarks Time O(1), Space O(1)
@@ -2198,6 +2364,13 @@ var _Queue = class _Queue extends LinearBase {
2198
2364
 
2199
2365
 
2200
2366
 
2367
+
2368
+
2369
+
2370
+
2371
+
2372
+
2373
+
2201
2374
 
2202
2375
 
2203
2376
 
@@ -2260,6 +2433,13 @@ var _Queue = class _Queue extends LinearBase {
2260
2433
 
2261
2434
 
2262
2435
 
2436
+
2437
+
2438
+
2439
+
2440
+
2441
+
2442
+
2263
2443
 
2264
2444
 
2265
2445
 
@@ -2329,6 +2509,13 @@ var _Queue = class _Queue extends LinearBase {
2329
2509
 
2330
2510
 
2331
2511
 
2512
+
2513
+
2514
+
2515
+
2516
+
2517
+
2518
+
2332
2519
 
2333
2520
 
2334
2521
 
@@ -2388,6 +2575,13 @@ var _Queue = class _Queue extends LinearBase {
2388
2575
 
2389
2576
 
2390
2577
 
2578
+
2579
+
2580
+
2581
+
2582
+
2583
+
2584
+
2391
2585
 
2392
2586
 
2393
2587
 
@@ -2440,6 +2634,13 @@ var _Queue = class _Queue extends LinearBase {
2440
2634
 
2441
2635
 
2442
2636
 
2637
+
2638
+
2639
+
2640
+
2641
+
2642
+
2643
+
2443
2644
 
2444
2645
 
2445
2646
 
@@ -2494,6 +2695,21 @@ var _Queue = class _Queue extends LinearBase {
2494
2695
  this._elements[this._offset + index] = newElement;
2495
2696
  return true;
2496
2697
  }
2698
+ /**
2699
+ * Delete the first element that satisfies a predicate.
2700
+ * @remarks Time O(N), Space O(N)
2701
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
2702
+ * @returns True if a match was removed.
2703
+ */
2704
+ deleteWhere(predicate) {
2705
+ for (let i = 0; i < this.length; i++) {
2706
+ if (predicate(this._elements[this._offset + i], i, this)) {
2707
+ this.deleteAt(i);
2708
+ return true;
2709
+ }
2710
+ }
2711
+ return false;
2712
+ }
2497
2713
  /**
2498
2714
  * Reverse the queue in-place by compacting then reversing.
2499
2715
  * @remarks Time O(N), Space O(N)
@@ -2533,6 +2749,13 @@ var _Queue = class _Queue extends LinearBase {
2533
2749
 
2534
2750
 
2535
2751
 
2752
+
2753
+
2754
+
2755
+
2756
+
2757
+
2758
+
2536
2759
 
2537
2760
 
2538
2761
 
@@ -2579,6 +2802,13 @@ var _Queue = class _Queue extends LinearBase {
2579
2802
 
2580
2803
 
2581
2804
 
2805
+
2806
+
2807
+
2808
+
2809
+
2810
+
2811
+
2582
2812
 
2583
2813
 
2584
2814
 
@@ -2648,6 +2878,13 @@ var _Queue = class _Queue extends LinearBase {
2648
2878
 
2649
2879
 
2650
2880
 
2881
+
2882
+
2883
+
2884
+
2885
+
2886
+
2887
+
2651
2888
 
2652
2889
 
2653
2890
 
@@ -2701,6 +2938,13 @@ var _Queue = class _Queue extends LinearBase {
2701
2938
 
2702
2939
 
2703
2940
 
2941
+
2942
+
2943
+
2944
+
2945
+
2946
+
2947
+
2704
2948
 
2705
2949
 
2706
2950
 
@@ -2758,6 +3002,13 @@ var _Queue = class _Queue extends LinearBase {
2758
3002
 
2759
3003
 
2760
3004
 
3005
+
3006
+
3007
+
3008
+
3009
+
3010
+
3011
+
2761
3012
 
2762
3013
 
2763
3014
 
@@ -3042,6 +3293,37 @@ var _Deque = class _Deque extends LinearBase {
3042
3293
 
3043
3294
 
3044
3295
 
3296
+
3297
+
3298
+
3299
+
3300
+
3301
+ * @example
3302
+ * // Deque peek at both ends
3303
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
3304
+ *
3305
+ * // Get first element without removing
3306
+ * const first = deque.at(0);
3307
+ * console.log(first); // 10;
3308
+ *
3309
+ * // Get last element without removing
3310
+ * const last = deque.at(deque.length - 1);
3311
+ * console.log(last); // 50;
3312
+ *
3313
+ * // Length unchanged
3314
+ * console.log(deque.length); // 5;
3315
+ */
3316
+ /**
3317
+ * Peek at the front element without removing it (alias for `first`).
3318
+ * @remarks Time O(1), Space O(1)
3319
+ * @returns Front element or undefined.
3320
+ */
3321
+ peek() {
3322
+ return this.first;
3323
+ }
3324
+ /**
3325
+ * Deque peek at both ends
3326
+
3045
3327
 
3046
3328
 
3047
3329
  * @example
@@ -3094,6 +3376,13 @@ var _Deque = class _Deque extends LinearBase {
3094
3376
 
3095
3377
 
3096
3378
 
3379
+
3380
+
3381
+
3382
+
3383
+
3384
+
3385
+
3097
3386
 
3098
3387
 
3099
3388
 
@@ -3157,6 +3446,13 @@ var _Deque = class _Deque extends LinearBase {
3157
3446
 
3158
3447
 
3159
3448
 
3449
+
3450
+
3451
+
3452
+
3453
+
3454
+
3455
+
3160
3456
 
3161
3457
 
3162
3458
 
@@ -3233,6 +3529,13 @@ var _Deque = class _Deque extends LinearBase {
3233
3529
 
3234
3530
 
3235
3531
 
3532
+
3533
+
3534
+
3535
+
3536
+
3537
+
3538
+
3236
3539
 
3237
3540
 
3238
3541
 
@@ -3296,6 +3599,13 @@ var _Deque = class _Deque extends LinearBase {
3296
3599
 
3297
3600
 
3298
3601
 
3602
+
3603
+
3604
+
3605
+
3606
+
3607
+
3608
+
3299
3609
 
3300
3610
 
3301
3611
 
@@ -3360,6 +3670,13 @@ var _Deque = class _Deque extends LinearBase {
3360
3670
 
3361
3671
 
3362
3672
 
3673
+
3674
+
3675
+
3676
+
3677
+
3678
+
3679
+
3363
3680
 
3364
3681
 
3365
3682
 
@@ -3465,6 +3782,13 @@ var _Deque = class _Deque extends LinearBase {
3465
3782
 
3466
3783
 
3467
3784
 
3785
+
3786
+
3787
+
3788
+
3789
+
3790
+
3791
+
3468
3792
 
3469
3793
 
3470
3794
 
@@ -3510,6 +3834,13 @@ var _Deque = class _Deque extends LinearBase {
3510
3834
 
3511
3835
 
3512
3836
 
3837
+
3838
+
3839
+
3840
+
3841
+
3842
+
3843
+
3513
3844
 
3514
3845
 
3515
3846
 
@@ -3559,6 +3890,13 @@ var _Deque = class _Deque extends LinearBase {
3559
3890
 
3560
3891
 
3561
3892
 
3893
+
3894
+
3895
+
3896
+
3897
+
3898
+
3899
+
3562
3900
 
3563
3901
 
3564
3902
 
@@ -3759,6 +4097,13 @@ var _Deque = class _Deque extends LinearBase {
3759
4097
 
3760
4098
 
3761
4099
 
4100
+
4101
+
4102
+
4103
+
4104
+
4105
+
4106
+
3762
4107
 
3763
4108
 
3764
4109
 
@@ -3853,6 +4198,68 @@ var _Deque = class _Deque extends LinearBase {
3853
4198
 
3854
4199
 
3855
4200
 
4201
+
4202
+
4203
+
4204
+
4205
+
4206
+ * @example
4207
+ * // Deque for...of iteration and reverse
4208
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
4209
+ *
4210
+ * // Iterate forward
4211
+ * const forward: string[] = [];
4212
+ * for (const item of deque) {
4213
+ * forward.push(item);
4214
+ * }
4215
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
4216
+ *
4217
+ * // Reverse the deque
4218
+ * deque.reverse();
4219
+ * const backward: string[] = [];
4220
+ * for (const item of deque) {
4221
+ * backward.push(item);
4222
+ * }
4223
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
4224
+ */
4225
+ /**
4226
+ * Find the last value matching a predicate (scans back-to-front).
4227
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
4228
+ * @param predicate - Function called with (value, index, deque).
4229
+ * @returns Matching value or undefined.
4230
+ * @example
4231
+ * // Find last matching value
4232
+ * const d = new Deque([1, 2, 3, 4, 5]);
4233
+ * console.log(d.findLast(v => v > 2)); // 5;
4234
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
4235
+ */
4236
+ findLast(predicate) {
4237
+ for (let i = this.length - 1; i >= 0; i--) {
4238
+ const val = this.at(i);
4239
+ if (predicate(val, i, this)) return val;
4240
+ }
4241
+ return void 0;
4242
+ }
4243
+ /**
4244
+ * Find the index of the last value matching a predicate (scans back-to-front).
4245
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
4246
+ * @param predicate - Function called with (value, index, deque).
4247
+ * @returns Matching index, or -1 if not found.
4248
+ * @example
4249
+ * // Find last matching index
4250
+ * const d = new Deque([10, 20, 30, 20, 10]);
4251
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
4252
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
4253
+ */
4254
+ findLastIndex(predicate) {
4255
+ for (let i = this.length - 1; i >= 0; i--) {
4256
+ if (predicate(this.at(i), i, this)) return i;
4257
+ }
4258
+ return -1;
4259
+ }
4260
+ /**
4261
+ * Deque for...of iteration and reverse
4262
+
3856
4263
 
3857
4264
  * @example
3858
4265
  * // Deque for...of iteration and reverse
@@ -3958,6 +4365,13 @@ var _Deque = class _Deque extends LinearBase {
3958
4365
 
3959
4366
 
3960
4367
 
4368
+
4369
+
4370
+
4371
+
4372
+
4373
+
4374
+
3961
4375
 
3962
4376
 
3963
4377
 
@@ -4029,6 +4443,13 @@ var _Deque = class _Deque extends LinearBase {
4029
4443
 
4030
4444
 
4031
4445
 
4446
+
4447
+
4448
+
4449
+
4450
+
4451
+
4452
+
4032
4453
 
4033
4454
 
4034
4455
 
@@ -4083,6 +4504,13 @@ var _Deque = class _Deque extends LinearBase {
4083
4504
 
4084
4505
 
4085
4506
 
4507
+
4508
+
4509
+
4510
+
4511
+
4512
+
4513
+
4086
4514
 
4087
4515
 
4088
4516
 
@@ -4157,6 +4585,13 @@ var _Deque = class _Deque extends LinearBase {
4157
4585
 
4158
4586
 
4159
4587
 
4588
+
4589
+
4590
+
4591
+
4592
+
4593
+
4594
+
4160
4595
 
4161
4596
 
4162
4597