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 {
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
  *
@@ -518,6 +547,16 @@ var LinearBase = class _LinearBase extends IterableElementBase {
518
547
  }
519
548
  return this;
520
549
  }
550
+ /**
551
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
552
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
553
+ * @returns A new reversed instance.
554
+ */
555
+ toReversed() {
556
+ const cloned = this.clone();
557
+ cloned.reverse();
558
+ return cloned;
559
+ }
521
560
  };
522
561
  var LinearLinkedBase = class extends LinearBase {
523
562
  static {
@@ -809,6 +848,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
809
848
 
810
849
 
811
850
 
851
+
852
+
853
+
854
+
855
+
856
+
857
+
812
858
 
813
859
 
814
860
 
@@ -876,6 +922,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
876
922
 
877
923
 
878
924
 
925
+
926
+
927
+
928
+
929
+
930
+
931
+
879
932
 
880
933
 
881
934
 
@@ -948,6 +1001,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
948
1001
 
949
1002
 
950
1003
 
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
951
1011
 
952
1012
 
953
1013
 
@@ -1002,6 +1062,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1002
1062
 
1003
1063
 
1004
1064
 
1065
+
1066
+
1067
+
1068
+
1069
+
1070
+
1071
+
1005
1072
 
1006
1073
 
1007
1074
 
@@ -1117,6 +1184,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1117
1184
 
1118
1185
 
1119
1186
 
1187
+
1188
+
1189
+
1190
+
1191
+
1192
+
1193
+
1120
1194
 
1121
1195
 
1122
1196
 
@@ -1176,6 +1250,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1176
1250
 
1177
1251
 
1178
1252
 
1253
+
1254
+
1255
+
1256
+
1257
+
1258
+
1259
+
1179
1260
 
1180
1261
 
1181
1262
 
@@ -1224,6 +1305,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1224
1305
 
1225
1306
 
1226
1307
 
1308
+
1309
+
1310
+
1311
+
1312
+
1313
+
1314
+
1227
1315
 
1228
1316
 
1229
1317
 
@@ -1278,6 +1366,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1278
1366
 
1279
1367
 
1280
1368
 
1369
+
1370
+
1371
+
1372
+
1373
+
1374
+
1375
+
1281
1376
 
1282
1377
 
1283
1378
 
@@ -1337,6 +1432,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1337
1432
 
1338
1433
 
1339
1434
 
1435
+
1436
+
1437
+
1438
+
1439
+
1440
+
1441
+
1340
1442
 
1341
1443
 
1342
1444
 
@@ -1404,6 +1506,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1404
1506
 
1405
1507
 
1406
1508
 
1509
+
1510
+
1511
+
1512
+
1513
+
1514
+
1515
+
1407
1516
 
1408
1517
 
1409
1518
 
@@ -1448,6 +1557,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1448
1557
 
1449
1558
 
1450
1559
 
1560
+
1561
+
1562
+
1563
+
1564
+
1565
+
1566
+
1451
1567
 
1452
1568
 
1453
1569
 
@@ -1498,6 +1614,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1498
1614
 
1499
1615
 
1500
1616
 
1617
+
1618
+
1619
+
1620
+
1621
+
1622
+
1623
+
1501
1624
 
1502
1625
 
1503
1626
 
@@ -1714,6 +1837,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1714
1837
 
1715
1838
 
1716
1839
 
1840
+
1841
+
1842
+
1843
+
1844
+
1845
+
1846
+
1717
1847
 
1718
1848
 
1719
1849
 
@@ -1768,6 +1898,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1768
1898
 
1769
1899
 
1770
1900
 
1901
+
1902
+
1903
+
1904
+
1905
+
1906
+
1907
+
1771
1908
 
1772
1909
 
1773
1910
 
@@ -1850,6 +1987,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1850
1987
 
1851
1988
 
1852
1989
 
1990
+
1991
+
1992
+
1993
+
1994
+
1995
+
1996
+
1853
1997
 
1854
1998
 
1855
1999
 
@@ -2085,6 +2229,13 @@ var Queue = class _Queue extends LinearBase {
2085
2229
 
2086
2230
 
2087
2231
 
2232
+
2233
+
2234
+
2235
+
2236
+
2237
+
2238
+
2088
2239
 
2089
2240
 
2090
2241
 
@@ -2135,6 +2286,13 @@ var Queue = class _Queue extends LinearBase {
2135
2286
 
2136
2287
 
2137
2288
 
2289
+
2290
+
2291
+
2292
+
2293
+
2294
+
2295
+
2138
2296
 
2139
2297
 
2140
2298
 
@@ -2152,6 +2310,14 @@ var Queue = class _Queue extends LinearBase {
2152
2310
  get first() {
2153
2311
  return this.length > 0 ? this.elements[this._offset] : void 0;
2154
2312
  }
2313
+ /**
2314
+ * Peek at the front element without removing it (alias for `first`).
2315
+ * @remarks Time O(1), Space O(1)
2316
+ * @returns Front element or undefined.
2317
+ */
2318
+ peek() {
2319
+ return this.first;
2320
+ }
2155
2321
  /**
2156
2322
  * Get the last element (back) without removing it.
2157
2323
  * @remarks Time O(1), Space O(1)
@@ -2201,6 +2367,13 @@ var Queue = class _Queue extends LinearBase {
2201
2367
 
2202
2368
 
2203
2369
 
2370
+
2371
+
2372
+
2373
+
2374
+
2375
+
2376
+
2204
2377
 
2205
2378
 
2206
2379
 
@@ -2263,6 +2436,13 @@ var Queue = class _Queue extends LinearBase {
2263
2436
 
2264
2437
 
2265
2438
 
2439
+
2440
+
2441
+
2442
+
2443
+
2444
+
2445
+
2266
2446
 
2267
2447
 
2268
2448
 
@@ -2332,6 +2512,13 @@ var Queue = class _Queue extends LinearBase {
2332
2512
 
2333
2513
 
2334
2514
 
2515
+
2516
+
2517
+
2518
+
2519
+
2520
+
2521
+
2335
2522
 
2336
2523
 
2337
2524
 
@@ -2391,6 +2578,13 @@ var Queue = class _Queue extends LinearBase {
2391
2578
 
2392
2579
 
2393
2580
 
2581
+
2582
+
2583
+
2584
+
2585
+
2586
+
2587
+
2394
2588
 
2395
2589
 
2396
2590
 
@@ -2443,6 +2637,13 @@ var Queue = class _Queue extends LinearBase {
2443
2637
 
2444
2638
 
2445
2639
 
2640
+
2641
+
2642
+
2643
+
2644
+
2645
+
2646
+
2446
2647
 
2447
2648
 
2448
2649
 
@@ -2497,6 +2698,21 @@ var Queue = class _Queue extends LinearBase {
2497
2698
  this._elements[this._offset + index] = newElement;
2498
2699
  return true;
2499
2700
  }
2701
+ /**
2702
+ * Delete the first element that satisfies a predicate.
2703
+ * @remarks Time O(N), Space O(N)
2704
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
2705
+ * @returns True if a match was removed.
2706
+ */
2707
+ deleteWhere(predicate) {
2708
+ for (let i = 0; i < this.length; i++) {
2709
+ if (predicate(this._elements[this._offset + i], i, this)) {
2710
+ this.deleteAt(i);
2711
+ return true;
2712
+ }
2713
+ }
2714
+ return false;
2715
+ }
2500
2716
  /**
2501
2717
  * Reverse the queue in-place by compacting then reversing.
2502
2718
  * @remarks Time O(N), Space O(N)
@@ -2536,6 +2752,13 @@ var Queue = class _Queue extends LinearBase {
2536
2752
 
2537
2753
 
2538
2754
 
2755
+
2756
+
2757
+
2758
+
2759
+
2760
+
2761
+
2539
2762
 
2540
2763
 
2541
2764
 
@@ -2582,6 +2805,13 @@ var Queue = class _Queue extends LinearBase {
2582
2805
 
2583
2806
 
2584
2807
 
2808
+
2809
+
2810
+
2811
+
2812
+
2813
+
2814
+
2585
2815
 
2586
2816
 
2587
2817
 
@@ -2651,6 +2881,13 @@ var Queue = class _Queue extends LinearBase {
2651
2881
 
2652
2882
 
2653
2883
 
2884
+
2885
+
2886
+
2887
+
2888
+
2889
+
2890
+
2654
2891
 
2655
2892
 
2656
2893
 
@@ -2704,6 +2941,13 @@ var Queue = class _Queue extends LinearBase {
2704
2941
 
2705
2942
 
2706
2943
 
2944
+
2945
+
2946
+
2947
+
2948
+
2949
+
2950
+
2707
2951
 
2708
2952
 
2709
2953
 
@@ -2761,6 +3005,13 @@ var Queue = class _Queue extends LinearBase {
2761
3005
 
2762
3006
 
2763
3007
 
3008
+
3009
+
3010
+
3011
+
3012
+
3013
+
3014
+
2764
3015
 
2765
3016
 
2766
3017
 
@@ -3045,6 +3296,37 @@ var Deque = class extends LinearBase {
3045
3296
 
3046
3297
 
3047
3298
 
3299
+
3300
+
3301
+
3302
+
3303
+
3304
+ * @example
3305
+ * // Deque peek at both ends
3306
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
3307
+ *
3308
+ * // Get first element without removing
3309
+ * const first = deque.at(0);
3310
+ * console.log(first); // 10;
3311
+ *
3312
+ * // Get last element without removing
3313
+ * const last = deque.at(deque.length - 1);
3314
+ * console.log(last); // 50;
3315
+ *
3316
+ * // Length unchanged
3317
+ * console.log(deque.length); // 5;
3318
+ */
3319
+ /**
3320
+ * Peek at the front element without removing it (alias for `first`).
3321
+ * @remarks Time O(1), Space O(1)
3322
+ * @returns Front element or undefined.
3323
+ */
3324
+ peek() {
3325
+ return this.first;
3326
+ }
3327
+ /**
3328
+ * Deque peek at both ends
3329
+
3048
3330
 
3049
3331
 
3050
3332
  * @example
@@ -3097,6 +3379,13 @@ var Deque = class extends LinearBase {
3097
3379
 
3098
3380
 
3099
3381
 
3382
+
3383
+
3384
+
3385
+
3386
+
3387
+
3388
+
3100
3389
 
3101
3390
 
3102
3391
 
@@ -3160,6 +3449,13 @@ var Deque = class extends LinearBase {
3160
3449
 
3161
3450
 
3162
3451
 
3452
+
3453
+
3454
+
3455
+
3456
+
3457
+
3458
+
3163
3459
 
3164
3460
 
3165
3461
 
@@ -3236,6 +3532,13 @@ var Deque = class extends LinearBase {
3236
3532
 
3237
3533
 
3238
3534
 
3535
+
3536
+
3537
+
3538
+
3539
+
3540
+
3541
+
3239
3542
 
3240
3543
 
3241
3544
 
@@ -3299,6 +3602,13 @@ var Deque = class extends LinearBase {
3299
3602
 
3300
3603
 
3301
3604
 
3605
+
3606
+
3607
+
3608
+
3609
+
3610
+
3611
+
3302
3612
 
3303
3613
 
3304
3614
 
@@ -3363,6 +3673,13 @@ var Deque = class extends LinearBase {
3363
3673
 
3364
3674
 
3365
3675
 
3676
+
3677
+
3678
+
3679
+
3680
+
3681
+
3682
+
3366
3683
 
3367
3684
 
3368
3685
 
@@ -3468,6 +3785,13 @@ var Deque = class extends LinearBase {
3468
3785
 
3469
3786
 
3470
3787
 
3788
+
3789
+
3790
+
3791
+
3792
+
3793
+
3794
+
3471
3795
 
3472
3796
 
3473
3797
 
@@ -3513,6 +3837,13 @@ var Deque = class extends LinearBase {
3513
3837
 
3514
3838
 
3515
3839
 
3840
+
3841
+
3842
+
3843
+
3844
+
3845
+
3846
+
3516
3847
 
3517
3848
 
3518
3849
 
@@ -3562,6 +3893,13 @@ var Deque = class extends LinearBase {
3562
3893
 
3563
3894
 
3564
3895
 
3896
+
3897
+
3898
+
3899
+
3900
+
3901
+
3902
+
3565
3903
 
3566
3904
 
3567
3905
 
@@ -3762,6 +4100,13 @@ var Deque = class extends LinearBase {
3762
4100
 
3763
4101
 
3764
4102
 
4103
+
4104
+
4105
+
4106
+
4107
+
4108
+
4109
+
3765
4110
 
3766
4111
 
3767
4112
 
@@ -3856,6 +4201,68 @@ var Deque = class extends LinearBase {
3856
4201
 
3857
4202
 
3858
4203
 
4204
+
4205
+
4206
+
4207
+
4208
+
4209
+ * @example
4210
+ * // Deque for...of iteration and reverse
4211
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
4212
+ *
4213
+ * // Iterate forward
4214
+ * const forward: string[] = [];
4215
+ * for (const item of deque) {
4216
+ * forward.push(item);
4217
+ * }
4218
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
4219
+ *
4220
+ * // Reverse the deque
4221
+ * deque.reverse();
4222
+ * const backward: string[] = [];
4223
+ * for (const item of deque) {
4224
+ * backward.push(item);
4225
+ * }
4226
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
4227
+ */
4228
+ /**
4229
+ * Find the last value matching a predicate (scans back-to-front).
4230
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
4231
+ * @param predicate - Function called with (value, index, deque).
4232
+ * @returns Matching value or undefined.
4233
+ * @example
4234
+ * // Find last matching value
4235
+ * const d = new Deque([1, 2, 3, 4, 5]);
4236
+ * console.log(d.findLast(v => v > 2)); // 5;
4237
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
4238
+ */
4239
+ findLast(predicate) {
4240
+ for (let i = this.length - 1; i >= 0; i--) {
4241
+ const val = this.at(i);
4242
+ if (predicate(val, i, this)) return val;
4243
+ }
4244
+ return void 0;
4245
+ }
4246
+ /**
4247
+ * Find the index of the last value matching a predicate (scans back-to-front).
4248
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
4249
+ * @param predicate - Function called with (value, index, deque).
4250
+ * @returns Matching index, or -1 if not found.
4251
+ * @example
4252
+ * // Find last matching index
4253
+ * const d = new Deque([10, 20, 30, 20, 10]);
4254
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
4255
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
4256
+ */
4257
+ findLastIndex(predicate) {
4258
+ for (let i = this.length - 1; i >= 0; i--) {
4259
+ if (predicate(this.at(i), i, this)) return i;
4260
+ }
4261
+ return -1;
4262
+ }
4263
+ /**
4264
+ * Deque for...of iteration and reverse
4265
+
3859
4266
 
3860
4267
  * @example
3861
4268
  * // Deque for...of iteration and reverse
@@ -3961,6 +4368,13 @@ var Deque = class extends LinearBase {
3961
4368
 
3962
4369
 
3963
4370
 
4371
+
4372
+
4373
+
4374
+
4375
+
4376
+
4377
+
3964
4378
 
3965
4379
 
3966
4380
 
@@ -4032,6 +4446,13 @@ var Deque = class extends LinearBase {
4032
4446
 
4033
4447
 
4034
4448
 
4449
+
4450
+
4451
+
4452
+
4453
+
4454
+
4455
+
4035
4456
 
4036
4457
 
4037
4458
 
@@ -4086,6 +4507,13 @@ var Deque = class extends LinearBase {
4086
4507
 
4087
4508
 
4088
4509
 
4510
+
4511
+
4512
+
4513
+
4514
+
4515
+
4516
+
4089
4517
 
4090
4518
 
4091
4519
 
@@ -4160,6 +4588,13 @@ var Deque = class extends LinearBase {
4160
4588
 
4161
4589
 
4162
4590
 
4591
+
4592
+
4593
+
4594
+
4595
+
4596
+
4597
+
4163
4598
 
4164
4599
 
4165
4600