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
@@ -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;
@@ -814,6 +853,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
814
853
 
815
854
 
816
855
 
856
+
857
+
858
+
817
859
 
818
860
 
819
861
 
@@ -885,6 +927,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
885
927
 
886
928
 
887
929
 
930
+
931
+
932
+
888
933
 
889
934
 
890
935
 
@@ -962,6 +1007,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
962
1007
 
963
1008
 
964
1009
 
1010
+
1011
+
1012
+
965
1013
 
966
1014
 
967
1015
 
@@ -1020,6 +1068,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1020
1068
 
1021
1069
 
1022
1070
 
1071
+
1072
+
1073
+
1023
1074
 
1024
1075
 
1025
1076
 
@@ -1139,6 +1190,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1139
1190
 
1140
1191
 
1141
1192
 
1193
+
1194
+
1195
+
1142
1196
 
1143
1197
 
1144
1198
 
@@ -1202,6 +1256,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1202
1256
 
1203
1257
 
1204
1258
 
1259
+
1260
+
1261
+
1205
1262
 
1206
1263
 
1207
1264
 
@@ -1254,6 +1311,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1254
1311
 
1255
1312
 
1256
1313
 
1314
+
1315
+
1316
+
1257
1317
 
1258
1318
 
1259
1319
 
@@ -1312,6 +1372,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1312
1372
 
1313
1373
 
1314
1374
 
1375
+
1376
+
1377
+
1315
1378
 
1316
1379
 
1317
1380
 
@@ -1375,6 +1438,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1375
1438
 
1376
1439
 
1377
1440
 
1441
+
1442
+
1443
+
1378
1444
 
1379
1445
 
1380
1446
 
@@ -1446,6 +1512,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1446
1512
 
1447
1513
 
1448
1514
 
1515
+
1516
+
1517
+
1449
1518
 
1450
1519
 
1451
1520
 
@@ -1494,6 +1563,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1494
1563
 
1495
1564
 
1496
1565
 
1566
+
1567
+
1568
+
1497
1569
 
1498
1570
 
1499
1571
 
@@ -1548,6 +1620,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1548
1620
 
1549
1621
 
1550
1622
 
1623
+
1624
+
1625
+
1551
1626
 
1552
1627
 
1553
1628
 
@@ -1768,6 +1843,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1768
1843
 
1769
1844
 
1770
1845
 
1846
+
1847
+
1848
+
1771
1849
 
1772
1850
 
1773
1851
 
@@ -1826,6 +1904,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1826
1904
 
1827
1905
 
1828
1906
 
1907
+
1908
+
1909
+
1829
1910
 
1830
1911
 
1831
1912
 
@@ -1912,6 +1993,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1912
1993
 
1913
1994
 
1914
1995
 
1996
+
1997
+
1998
+
1915
1999
 
1916
2000
 
1917
2001
 
@@ -2150,6 +2234,9 @@ var _Queue = class _Queue extends LinearBase {
2150
2234
 
2151
2235
 
2152
2236
 
2237
+
2238
+
2239
+
2153
2240
 
2154
2241
 
2155
2242
 
@@ -2204,6 +2291,9 @@ var _Queue = class _Queue extends LinearBase {
2204
2291
 
2205
2292
 
2206
2293
 
2294
+
2295
+
2296
+
2207
2297
 
2208
2298
 
2209
2299
 
@@ -2282,6 +2372,9 @@ var _Queue = class _Queue extends LinearBase {
2282
2372
 
2283
2373
 
2284
2374
 
2375
+
2376
+
2377
+
2285
2378
 
2286
2379
 
2287
2380
 
@@ -2348,6 +2441,9 @@ var _Queue = class _Queue extends LinearBase {
2348
2441
 
2349
2442
 
2350
2443
 
2444
+
2445
+
2446
+
2351
2447
 
2352
2448
 
2353
2449
 
@@ -2421,6 +2517,9 @@ var _Queue = class _Queue extends LinearBase {
2421
2517
 
2422
2518
 
2423
2519
 
2520
+
2521
+
2522
+
2424
2523
 
2425
2524
 
2426
2525
 
@@ -2484,6 +2583,9 @@ var _Queue = class _Queue extends LinearBase {
2484
2583
 
2485
2584
 
2486
2585
 
2586
+
2587
+
2588
+
2487
2589
 
2488
2590
 
2489
2591
 
@@ -2540,6 +2642,9 @@ var _Queue = class _Queue extends LinearBase {
2540
2642
 
2541
2643
 
2542
2644
 
2645
+
2646
+
2647
+
2543
2648
 
2544
2649
 
2545
2650
 
@@ -2652,6 +2757,9 @@ var _Queue = class _Queue extends LinearBase {
2652
2757
 
2653
2758
 
2654
2759
 
2760
+
2761
+
2762
+
2655
2763
 
2656
2764
 
2657
2765
 
@@ -2702,6 +2810,9 @@ var _Queue = class _Queue extends LinearBase {
2702
2810
 
2703
2811
 
2704
2812
 
2813
+
2814
+
2815
+
2705
2816
 
2706
2817
 
2707
2818
 
@@ -2775,6 +2886,9 @@ var _Queue = class _Queue extends LinearBase {
2775
2886
 
2776
2887
 
2777
2888
 
2889
+
2890
+
2891
+
2778
2892
 
2779
2893
 
2780
2894
 
@@ -2832,6 +2946,9 @@ var _Queue = class _Queue extends LinearBase {
2832
2946
 
2833
2947
 
2834
2948
 
2949
+
2950
+
2951
+
2835
2952
 
2836
2953
 
2837
2954
 
@@ -2893,6 +3010,9 @@ var _Queue = class _Queue extends LinearBase {
2893
3010
 
2894
3011
 
2895
3012
 
3013
+
3014
+
3015
+
2896
3016
 
2897
3017
 
2898
3018
 
@@ -3203,7 +3323,10 @@ var _Deque = class _Deque extends LinearBase {
3203
3323
  }
3204
3324
  /**
3205
3325
  * Deque peek at both ends
3206
- * @example
3326
+
3327
+
3328
+
3329
+ * @example
3207
3330
  * // Deque peek at both ends
3208
3331
  * const deque = new Deque<number>([10, 20, 30, 40, 50]);
3209
3332
  *
@@ -3261,6 +3384,9 @@ var _Deque = class _Deque extends LinearBase {
3261
3384
 
3262
3385
 
3263
3386
 
3387
+
3388
+
3389
+
3264
3390
 
3265
3391
 
3266
3392
 
@@ -3328,6 +3454,9 @@ var _Deque = class _Deque extends LinearBase {
3328
3454
 
3329
3455
 
3330
3456
 
3457
+
3458
+
3459
+
3331
3460
 
3332
3461
 
3333
3462
 
@@ -3408,6 +3537,9 @@ var _Deque = class _Deque extends LinearBase {
3408
3537
 
3409
3538
 
3410
3539
 
3540
+
3541
+
3542
+
3411
3543
 
3412
3544
 
3413
3545
 
@@ -3475,6 +3607,9 @@ var _Deque = class _Deque extends LinearBase {
3475
3607
 
3476
3608
 
3477
3609
 
3610
+
3611
+
3612
+
3478
3613
 
3479
3614
 
3480
3615
 
@@ -3543,6 +3678,9 @@ var _Deque = class _Deque extends LinearBase {
3543
3678
 
3544
3679
 
3545
3680
 
3681
+
3682
+
3683
+
3546
3684
 
3547
3685
 
3548
3686
 
@@ -3652,6 +3790,9 @@ var _Deque = class _Deque extends LinearBase {
3652
3790
 
3653
3791
 
3654
3792
 
3793
+
3794
+
3795
+
3655
3796
 
3656
3797
 
3657
3798
 
@@ -3701,6 +3842,9 @@ var _Deque = class _Deque extends LinearBase {
3701
3842
 
3702
3843
 
3703
3844
 
3845
+
3846
+
3847
+
3704
3848
 
3705
3849
 
3706
3850
 
@@ -3754,6 +3898,9 @@ var _Deque = class _Deque extends LinearBase {
3754
3898
 
3755
3899
 
3756
3900
 
3901
+
3902
+
3903
+
3757
3904
 
3758
3905
 
3759
3906
 
@@ -3958,6 +4105,9 @@ var _Deque = class _Deque extends LinearBase {
3958
4105
 
3959
4106
 
3960
4107
 
4108
+
4109
+
4110
+
3961
4111
 
3962
4112
 
3963
4113
 
@@ -4052,6 +4202,64 @@ var _Deque = class _Deque extends LinearBase {
4052
4202
 
4053
4203
 
4054
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
+
4055
4263
 
4056
4264
  * @example
4057
4265
  * // Deque for...of iteration and reverse
@@ -4165,6 +4373,9 @@ var _Deque = class _Deque extends LinearBase {
4165
4373
 
4166
4374
 
4167
4375
 
4376
+
4377
+
4378
+
4168
4379
 
4169
4380
 
4170
4381
 
@@ -4240,6 +4451,9 @@ var _Deque = class _Deque extends LinearBase {
4240
4451
 
4241
4452
 
4242
4453
 
4454
+
4455
+
4456
+
4243
4457
 
4244
4458
 
4245
4459
 
@@ -4298,6 +4512,9 @@ var _Deque = class _Deque extends LinearBase {
4298
4512
 
4299
4513
 
4300
4514
 
4515
+
4516
+
4517
+
4301
4518
 
4302
4519
 
4303
4520
 
@@ -4376,6 +4593,9 @@ var _Deque = class _Deque extends LinearBase {
4376
4593
 
4377
4594
 
4378
4595
 
4596
+
4597
+
4598
+
4379
4599
 
4380
4600
 
4381
4601