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
@@ -210,6 +210,35 @@ var IterableElementBase = class {
210
210
  for (const ele of this) if (ele === element) return true;
211
211
  return false;
212
212
  }
213
+ /**
214
+ * Check whether a value exists (Array-compatible alias for `has`).
215
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
216
+ * @param element - Element to search for (uses `===`).
217
+ * @returns `true` if found.
218
+ */
219
+ includes(element) {
220
+ return this.has(element);
221
+ }
222
+ /**
223
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
224
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
225
+ */
226
+ *entries() {
227
+ let index = 0;
228
+ for (const value of this) {
229
+ yield [index++, value];
230
+ }
231
+ }
232
+ /**
233
+ * Return an iterator of numeric indices (Array-compatible).
234
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
235
+ */
236
+ *keys() {
237
+ let index = 0;
238
+ for (const _ of this) {
239
+ yield index++;
240
+ }
241
+ }
213
242
  /**
214
243
  * Reduces all elements to a single accumulated value.
215
244
  *
@@ -520,6 +549,16 @@ var LinearBase = class _LinearBase extends IterableElementBase {
520
549
  }
521
550
  return this;
522
551
  }
552
+ /**
553
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
554
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
555
+ * @returns A new reversed instance.
556
+ */
557
+ toReversed() {
558
+ const cloned = this.clone();
559
+ cloned.reverse();
560
+ return cloned;
561
+ }
523
562
  };
524
563
  var LinearLinkedBase = class extends LinearBase {
525
564
  static {
@@ -811,6 +850,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
811
850
 
812
851
 
813
852
 
853
+
854
+
855
+
856
+
857
+
858
+
859
+
814
860
 
815
861
 
816
862
 
@@ -878,6 +924,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
878
924
 
879
925
 
880
926
 
927
+
928
+
929
+
930
+
931
+
932
+
933
+
881
934
 
882
935
 
883
936
 
@@ -950,6 +1003,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
950
1003
 
951
1004
 
952
1005
 
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
953
1013
 
954
1014
 
955
1015
 
@@ -1004,6 +1064,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1004
1064
 
1005
1065
 
1006
1066
 
1067
+
1068
+
1069
+
1070
+
1071
+
1072
+
1073
+
1007
1074
 
1008
1075
 
1009
1076
 
@@ -1119,6 +1186,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1119
1186
 
1120
1187
 
1121
1188
 
1189
+
1190
+
1191
+
1192
+
1193
+
1194
+
1195
+
1122
1196
 
1123
1197
 
1124
1198
 
@@ -1178,6 +1252,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1178
1252
 
1179
1253
 
1180
1254
 
1255
+
1256
+
1257
+
1258
+
1259
+
1260
+
1261
+
1181
1262
 
1182
1263
 
1183
1264
 
@@ -1226,6 +1307,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1226
1307
 
1227
1308
 
1228
1309
 
1310
+
1311
+
1312
+
1313
+
1314
+
1315
+
1316
+
1229
1317
 
1230
1318
 
1231
1319
 
@@ -1280,6 +1368,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1280
1368
 
1281
1369
 
1282
1370
 
1371
+
1372
+
1373
+
1374
+
1375
+
1376
+
1377
+
1283
1378
 
1284
1379
 
1285
1380
 
@@ -1339,6 +1434,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1339
1434
 
1340
1435
 
1341
1436
 
1437
+
1438
+
1439
+
1440
+
1441
+
1442
+
1443
+
1342
1444
 
1343
1445
 
1344
1446
 
@@ -1406,6 +1508,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1406
1508
 
1407
1509
 
1408
1510
 
1511
+
1512
+
1513
+
1514
+
1515
+
1516
+
1517
+
1409
1518
 
1410
1519
 
1411
1520
 
@@ -1450,6 +1559,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1450
1559
 
1451
1560
 
1452
1561
 
1562
+
1563
+
1564
+
1565
+
1566
+
1567
+
1568
+
1453
1569
 
1454
1570
 
1455
1571
 
@@ -1500,6 +1616,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1500
1616
 
1501
1617
 
1502
1618
 
1619
+
1620
+
1621
+
1622
+
1623
+
1624
+
1625
+
1503
1626
 
1504
1627
 
1505
1628
 
@@ -1716,6 +1839,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1716
1839
 
1717
1840
 
1718
1841
 
1842
+
1843
+
1844
+
1845
+
1846
+
1847
+
1848
+
1719
1849
 
1720
1850
 
1721
1851
 
@@ -1770,6 +1900,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1770
1900
 
1771
1901
 
1772
1902
 
1903
+
1904
+
1905
+
1906
+
1907
+
1908
+
1909
+
1773
1910
 
1774
1911
 
1775
1912
 
@@ -1852,6 +1989,13 @@ var SinglyLinkedList = class extends LinearLinkedBase {
1852
1989
 
1853
1990
 
1854
1991
 
1992
+
1993
+
1994
+
1995
+
1996
+
1997
+
1998
+
1855
1999
 
1856
2000
 
1857
2001
 
@@ -2087,6 +2231,13 @@ var Queue = class _Queue extends LinearBase {
2087
2231
 
2088
2232
 
2089
2233
 
2234
+
2235
+
2236
+
2237
+
2238
+
2239
+
2240
+
2090
2241
 
2091
2242
 
2092
2243
 
@@ -2137,6 +2288,13 @@ var Queue = class _Queue extends LinearBase {
2137
2288
 
2138
2289
 
2139
2290
 
2291
+
2292
+
2293
+
2294
+
2295
+
2296
+
2297
+
2140
2298
 
2141
2299
 
2142
2300
 
@@ -2154,6 +2312,14 @@ var Queue = class _Queue extends LinearBase {
2154
2312
  get first() {
2155
2313
  return this.length > 0 ? this.elements[this._offset] : void 0;
2156
2314
  }
2315
+ /**
2316
+ * Peek at the front element without removing it (alias for `first`).
2317
+ * @remarks Time O(1), Space O(1)
2318
+ * @returns Front element or undefined.
2319
+ */
2320
+ peek() {
2321
+ return this.first;
2322
+ }
2157
2323
  /**
2158
2324
  * Get the last element (back) without removing it.
2159
2325
  * @remarks Time O(1), Space O(1)
@@ -2203,6 +2369,13 @@ var Queue = class _Queue extends LinearBase {
2203
2369
 
2204
2370
 
2205
2371
 
2372
+
2373
+
2374
+
2375
+
2376
+
2377
+
2378
+
2206
2379
 
2207
2380
 
2208
2381
 
@@ -2265,6 +2438,13 @@ var Queue = class _Queue extends LinearBase {
2265
2438
 
2266
2439
 
2267
2440
 
2441
+
2442
+
2443
+
2444
+
2445
+
2446
+
2447
+
2268
2448
 
2269
2449
 
2270
2450
 
@@ -2334,6 +2514,13 @@ var Queue = class _Queue extends LinearBase {
2334
2514
 
2335
2515
 
2336
2516
 
2517
+
2518
+
2519
+
2520
+
2521
+
2522
+
2523
+
2337
2524
 
2338
2525
 
2339
2526
 
@@ -2393,6 +2580,13 @@ var Queue = class _Queue extends LinearBase {
2393
2580
 
2394
2581
 
2395
2582
 
2583
+
2584
+
2585
+
2586
+
2587
+
2588
+
2589
+
2396
2590
 
2397
2591
 
2398
2592
 
@@ -2445,6 +2639,13 @@ var Queue = class _Queue extends LinearBase {
2445
2639
 
2446
2640
 
2447
2641
 
2642
+
2643
+
2644
+
2645
+
2646
+
2647
+
2648
+
2448
2649
 
2449
2650
 
2450
2651
 
@@ -2499,6 +2700,21 @@ var Queue = class _Queue extends LinearBase {
2499
2700
  this._elements[this._offset + index] = newElement;
2500
2701
  return true;
2501
2702
  }
2703
+ /**
2704
+ * Delete the first element that satisfies a predicate.
2705
+ * @remarks Time O(N), Space O(N)
2706
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
2707
+ * @returns True if a match was removed.
2708
+ */
2709
+ deleteWhere(predicate) {
2710
+ for (let i = 0; i < this.length; i++) {
2711
+ if (predicate(this._elements[this._offset + i], i, this)) {
2712
+ this.deleteAt(i);
2713
+ return true;
2714
+ }
2715
+ }
2716
+ return false;
2717
+ }
2502
2718
  /**
2503
2719
  * Reverse the queue in-place by compacting then reversing.
2504
2720
  * @remarks Time O(N), Space O(N)
@@ -2538,6 +2754,13 @@ var Queue = class _Queue extends LinearBase {
2538
2754
 
2539
2755
 
2540
2756
 
2757
+
2758
+
2759
+
2760
+
2761
+
2762
+
2763
+
2541
2764
 
2542
2765
 
2543
2766
 
@@ -2584,6 +2807,13 @@ var Queue = class _Queue extends LinearBase {
2584
2807
 
2585
2808
 
2586
2809
 
2810
+
2811
+
2812
+
2813
+
2814
+
2815
+
2816
+
2587
2817
 
2588
2818
 
2589
2819
 
@@ -2653,6 +2883,13 @@ var Queue = class _Queue extends LinearBase {
2653
2883
 
2654
2884
 
2655
2885
 
2886
+
2887
+
2888
+
2889
+
2890
+
2891
+
2892
+
2656
2893
 
2657
2894
 
2658
2895
 
@@ -2706,6 +2943,13 @@ var Queue = class _Queue extends LinearBase {
2706
2943
 
2707
2944
 
2708
2945
 
2946
+
2947
+
2948
+
2949
+
2950
+
2951
+
2952
+
2709
2953
 
2710
2954
 
2711
2955
 
@@ -2763,6 +3007,13 @@ var Queue = class _Queue extends LinearBase {
2763
3007
 
2764
3008
 
2765
3009
 
3010
+
3011
+
3012
+
3013
+
3014
+
3015
+
3016
+
2766
3017
 
2767
3018
 
2768
3019
 
@@ -3047,6 +3298,37 @@ var Deque = class extends LinearBase {
3047
3298
 
3048
3299
 
3049
3300
 
3301
+
3302
+
3303
+
3304
+
3305
+
3306
+ * @example
3307
+ * // Deque peek at both ends
3308
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
3309
+ *
3310
+ * // Get first element without removing
3311
+ * const first = deque.at(0);
3312
+ * console.log(first); // 10;
3313
+ *
3314
+ * // Get last element without removing
3315
+ * const last = deque.at(deque.length - 1);
3316
+ * console.log(last); // 50;
3317
+ *
3318
+ * // Length unchanged
3319
+ * console.log(deque.length); // 5;
3320
+ */
3321
+ /**
3322
+ * Peek at the front element without removing it (alias for `first`).
3323
+ * @remarks Time O(1), Space O(1)
3324
+ * @returns Front element or undefined.
3325
+ */
3326
+ peek() {
3327
+ return this.first;
3328
+ }
3329
+ /**
3330
+ * Deque peek at both ends
3331
+
3050
3332
 
3051
3333
 
3052
3334
  * @example
@@ -3099,6 +3381,13 @@ var Deque = class extends LinearBase {
3099
3381
 
3100
3382
 
3101
3383
 
3384
+
3385
+
3386
+
3387
+
3388
+
3389
+
3390
+
3102
3391
 
3103
3392
 
3104
3393
 
@@ -3162,6 +3451,13 @@ var Deque = class extends LinearBase {
3162
3451
 
3163
3452
 
3164
3453
 
3454
+
3455
+
3456
+
3457
+
3458
+
3459
+
3460
+
3165
3461
 
3166
3462
 
3167
3463
 
@@ -3238,6 +3534,13 @@ var Deque = class extends LinearBase {
3238
3534
 
3239
3535
 
3240
3536
 
3537
+
3538
+
3539
+
3540
+
3541
+
3542
+
3543
+
3241
3544
 
3242
3545
 
3243
3546
 
@@ -3301,6 +3604,13 @@ var Deque = class extends LinearBase {
3301
3604
 
3302
3605
 
3303
3606
 
3607
+
3608
+
3609
+
3610
+
3611
+
3612
+
3613
+
3304
3614
 
3305
3615
 
3306
3616
 
@@ -3365,6 +3675,13 @@ var Deque = class extends LinearBase {
3365
3675
 
3366
3676
 
3367
3677
 
3678
+
3679
+
3680
+
3681
+
3682
+
3683
+
3684
+
3368
3685
 
3369
3686
 
3370
3687
 
@@ -3470,6 +3787,13 @@ var Deque = class extends LinearBase {
3470
3787
 
3471
3788
 
3472
3789
 
3790
+
3791
+
3792
+
3793
+
3794
+
3795
+
3796
+
3473
3797
 
3474
3798
 
3475
3799
 
@@ -3515,6 +3839,13 @@ var Deque = class extends LinearBase {
3515
3839
 
3516
3840
 
3517
3841
 
3842
+
3843
+
3844
+
3845
+
3846
+
3847
+
3848
+
3518
3849
 
3519
3850
 
3520
3851
 
@@ -3564,6 +3895,13 @@ var Deque = class extends LinearBase {
3564
3895
 
3565
3896
 
3566
3897
 
3898
+
3899
+
3900
+
3901
+
3902
+
3903
+
3904
+
3567
3905
 
3568
3906
 
3569
3907
 
@@ -3764,6 +4102,13 @@ var Deque = class extends LinearBase {
3764
4102
 
3765
4103
 
3766
4104
 
4105
+
4106
+
4107
+
4108
+
4109
+
4110
+
4111
+
3767
4112
 
3768
4113
 
3769
4114
 
@@ -3858,6 +4203,68 @@ var Deque = class extends LinearBase {
3858
4203
 
3859
4204
 
3860
4205
 
4206
+
4207
+
4208
+
4209
+
4210
+
4211
+ * @example
4212
+ * // Deque for...of iteration and reverse
4213
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
4214
+ *
4215
+ * // Iterate forward
4216
+ * const forward: string[] = [];
4217
+ * for (const item of deque) {
4218
+ * forward.push(item);
4219
+ * }
4220
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
4221
+ *
4222
+ * // Reverse the deque
4223
+ * deque.reverse();
4224
+ * const backward: string[] = [];
4225
+ * for (const item of deque) {
4226
+ * backward.push(item);
4227
+ * }
4228
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
4229
+ */
4230
+ /**
4231
+ * Find the last value matching a predicate (scans back-to-front).
4232
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
4233
+ * @param predicate - Function called with (value, index, deque).
4234
+ * @returns Matching value or undefined.
4235
+ * @example
4236
+ * // Find last matching value
4237
+ * const d = new Deque([1, 2, 3, 4, 5]);
4238
+ * console.log(d.findLast(v => v > 2)); // 5;
4239
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
4240
+ */
4241
+ findLast(predicate) {
4242
+ for (let i = this.length - 1; i >= 0; i--) {
4243
+ const val = this.at(i);
4244
+ if (predicate(val, i, this)) return val;
4245
+ }
4246
+ return void 0;
4247
+ }
4248
+ /**
4249
+ * Find the index of the last value matching a predicate (scans back-to-front).
4250
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
4251
+ * @param predicate - Function called with (value, index, deque).
4252
+ * @returns Matching index, or -1 if not found.
4253
+ * @example
4254
+ * // Find last matching index
4255
+ * const d = new Deque([10, 20, 30, 20, 10]);
4256
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
4257
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
4258
+ */
4259
+ findLastIndex(predicate) {
4260
+ for (let i = this.length - 1; i >= 0; i--) {
4261
+ if (predicate(this.at(i), i, this)) return i;
4262
+ }
4263
+ return -1;
4264
+ }
4265
+ /**
4266
+ * Deque for...of iteration and reverse
4267
+
3861
4268
 
3862
4269
  * @example
3863
4270
  * // Deque for...of iteration and reverse
@@ -3963,6 +4370,13 @@ var Deque = class extends LinearBase {
3963
4370
 
3964
4371
 
3965
4372
 
4373
+
4374
+
4375
+
4376
+
4377
+
4378
+
4379
+
3966
4380
 
3967
4381
 
3968
4382
 
@@ -4034,6 +4448,13 @@ var Deque = class extends LinearBase {
4034
4448
 
4035
4449
 
4036
4450
 
4451
+
4452
+
4453
+
4454
+
4455
+
4456
+
4457
+
4037
4458
 
4038
4459
 
4039
4460
 
@@ -4088,6 +4509,13 @@ var Deque = class extends LinearBase {
4088
4509
 
4089
4510
 
4090
4511
 
4512
+
4513
+
4514
+
4515
+
4516
+
4517
+
4518
+
4091
4519
 
4092
4520
 
4093
4521
 
@@ -4162,6 +4590,13 @@ var Deque = class extends LinearBase {
4162
4590
 
4163
4591
 
4164
4592
 
4593
+
4594
+
4595
+
4596
+
4597
+
4598
+
4599
+
4165
4600
 
4166
4601
 
4167
4602