max-priority-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 +71 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +71 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +71 -0
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +71 -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 +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/max-priority-queue-typed.js +71 -0
  34. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  35. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  36. package/dist/umd/max-priority-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
@@ -266,6 +266,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
266
266
 
267
267
 
268
268
 
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
282
+
283
+
269
284
 
270
285
 
271
286
 
@@ -477,6 +492,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
477
492
 
478
493
 
479
494
 
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
480
510
 
481
511
 
482
512
 
@@ -524,6 +554,18 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
524
554
 
525
555
 
526
556
 
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+
567
+
568
+
527
569
 
528
570
 
529
571
 
@@ -724,6 +766,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
724
766
 
725
767
 
726
768
 
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
727
784
 
728
785
 
729
786
 
@@ -929,6 +986,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
929
986
 
930
987
 
931
988
 
989
+
990
+
991
+
992
+
993
+
994
+
995
+
996
+
997
+
998
+
999
+
1000
+
1001
+
1002
+
1003
+
932
1004
 
933
1005
 
934
1006
 
@@ -1140,6 +1212,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
1140
1212
 
1141
1213
 
1142
1214
 
1215
+
1216
+
1217
+
1218
+
1219
+
1220
+
1221
+
1222
+
1223
+
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+
1143
1230
 
1144
1231
 
1145
1232
 
@@ -1330,6 +1417,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
1330
1417
 
1331
1418
 
1332
1419
 
1420
+
1421
+
1422
+
1423
+
1424
+
1425
+
1426
+
1427
+
1428
+
1429
+
1430
+
1431
+
1432
+
1433
+
1434
+
1333
1435
 
1334
1436
 
1335
1437
 
@@ -1521,6 +1623,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
1521
1623
 
1522
1624
 
1523
1625
 
1626
+
1627
+
1628
+
1629
+
1630
+
1631
+
1632
+
1633
+
1634
+
1635
+
1636
+
1637
+
1638
+
1639
+
1640
+
1524
1641
 
1525
1642
 
1526
1643
 
@@ -1712,6 +1829,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
1712
1829
 
1713
1830
 
1714
1831
 
1832
+
1833
+
1834
+
1835
+
1836
+
1837
+
1838
+
1839
+
1840
+
1841
+
1842
+
1843
+
1844
+
1845
+
1846
+
1715
1847
 
1716
1848
 
1717
1849
 
@@ -1907,6 +2039,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
1907
2039
 
1908
2040
 
1909
2041
 
2042
+
2043
+
2044
+
2045
+
2046
+
2047
+
2048
+
2049
+
2050
+
2051
+
2052
+
2053
+
2054
+
2055
+
2056
+
1910
2057
 
1911
2058
 
1912
2059
 
@@ -2101,6 +2248,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2101
2248
 
2102
2249
 
2103
2250
 
2251
+
2252
+
2253
+
2254
+
2255
+
2256
+
2257
+
2258
+
2259
+
2260
+
2261
+
2262
+
2263
+
2264
+
2265
+
2104
2266
 
2105
2267
 
2106
2268
 
@@ -2304,6 +2466,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2304
2466
 
2305
2467
 
2306
2468
 
2469
+
2470
+
2471
+
2472
+
2473
+
2474
+
2475
+
2476
+
2477
+
2478
+
2479
+
2480
+
2481
+
2482
+
2483
+
2307
2484
 
2308
2485
 
2309
2486
 
@@ -2503,6 +2680,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2503
2680
 
2504
2681
 
2505
2682
 
2683
+
2684
+
2685
+
2686
+
2687
+
2688
+
2689
+
2690
+
2691
+
2692
+
2693
+
2694
+
2695
+
2696
+
2697
+
2506
2698
 
2507
2699
 
2508
2700
 
@@ -2695,6 +2887,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2695
2887
 
2696
2888
 
2697
2889
 
2890
+
2891
+
2892
+
2893
+
2894
+
2895
+
2896
+
2897
+
2898
+
2899
+
2900
+
2901
+
2902
+
2903
+
2904
+
2698
2905
 
2699
2906
 
2700
2907
 
@@ -2890,6 +3097,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2890
3097
 
2891
3098
 
2892
3099
 
3100
+
3101
+
3102
+
3103
+
3104
+
3105
+
3106
+
3107
+
3108
+
3109
+
3110
+
3111
+
3112
+
3113
+
3114
+
2893
3115
 
2894
3116
 
2895
3117
 
@@ -3085,6 +3307,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3085
3307
 
3086
3308
 
3087
3309
 
3310
+
3311
+
3312
+
3313
+
3314
+
3315
+
3316
+
3317
+
3318
+
3319
+
3320
+
3321
+
3322
+
3323
+
3324
+
3088
3325
 
3089
3326
 
3090
3327
 
@@ -3283,6 +3520,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3283
3520
 
3284
3521
 
3285
3522
 
3523
+
3524
+
3525
+
3526
+
3527
+
3528
+
3529
+
3530
+
3531
+
3532
+
3533
+
3534
+
3535
+
3536
+
3537
+
3286
3538
 
3287
3539
 
3288
3540
 
@@ -3473,6 +3725,21 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3473
3725
 
3474
3726
 
3475
3727
 
3728
+
3729
+
3730
+
3731
+
3732
+
3733
+
3734
+
3735
+
3736
+
3737
+
3738
+
3739
+
3740
+
3741
+
3742
+
3476
3743
 
3477
3744
 
3478
3745
 
@@ -3538,6 +3805,9 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3538
3805
 
3539
3806
 
3540
3807
 
3808
+
3809
+
3810
+
3541
3811
 
3542
3812
 
3543
3813
 
@@ -3611,6 +3881,9 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3611
3881
 
3612
3882
 
3613
3883
 
3884
+
3885
+
3886
+
3614
3887
 
3615
3888
 
3616
3889
 
@@ -3662,6 +3935,9 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3662
3935
 
3663
3936
 
3664
3937
 
3938
+
3939
+
3940
+
3665
3941
 
3666
3942
 
3667
3943
 
@@ -3718,6 +3994,9 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3718
3994
 
3719
3995
 
3720
3996
 
3997
+
3998
+
3999
+
3721
4000
 
3722
4001
 
3723
4002
 
@@ -3875,6 +4154,18 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3875
4154
 
3876
4155
 
3877
4156
 
4157
+
4158
+
4159
+
4160
+
4161
+
4162
+
4163
+
4164
+
4165
+
4166
+
4167
+
4168
+
3878
4169
 
3879
4170
 
3880
4171
 
@@ -4049,6 +4340,18 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
4049
4340
 
4050
4341
 
4051
4342
 
4343
+
4344
+
4345
+
4346
+
4347
+
4348
+
4349
+
4350
+
4351
+
4352
+
4353
+
4354
+
4052
4355
 
4053
4356
 
4054
4357
 
@@ -4215,6 +4518,18 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
4215
4518
 
4216
4519
 
4217
4520
 
4521
+
4522
+
4523
+
4524
+
4525
+
4526
+
4527
+
4528
+
4529
+
4530
+
4531
+
4532
+
4218
4533
 
4219
4534
 
4220
4535
 
@@ -4379,6 +4694,18 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
4379
4694
 
4380
4695
 
4381
4696
 
4697
+
4698
+
4699
+
4700
+
4701
+
4702
+
4703
+
4704
+
4705
+
4706
+
4707
+
4708
+
4382
4709
 
4383
4710
 
4384
4711
 
@@ -4546,6 +4873,18 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
4546
4873
 
4547
4874
 
4548
4875
 
4876
+
4877
+
4878
+
4879
+
4880
+
4881
+
4882
+
4883
+
4884
+
4885
+
4886
+
4887
+
4549
4888
 
4550
4889
 
4551
4890
 
@@ -4647,6 +4986,12 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
4647
4986
 
4648
4987
 
4649
4988
 
4989
+
4990
+
4991
+
4992
+
4993
+
4994
+
4650
4995
  * @example
4651
4996
  * // Pagination by position in tree order
4652
4997
  * const tree = new TreeSet<number>(
@@ -4840,6 +5185,153 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
4840
5185
 
4841
5186
 
4842
5187
 
5188
+
5189
+
5190
+
5191
+
5192
+
5193
+
5194
+
5195
+
5196
+
5197
+
5198
+
5199
+
5200
+
5201
+ * @example
5202
+ * // Deep clone
5203
+ * const ts = new TreeSet<number>([1, 2, 3]);
5204
+ * const copy = ts.clone();
5205
+ * copy.delete(1);
5206
+ * console.log(ts.has(1)); // true;
5207
+ */
5208
+ // ---- ES2025 Set-like operations ----
5209
+
5210
+ /**
5211
+ * Return a new TreeSet containing all elements from both sets.
5212
+ * @remarks When both sets share the same comparator, uses O(n+m) merge. Otherwise O(m log n).
5213
+ * @param other - Any iterable of keys.
5214
+ * @returns A new TreeSet.
5215
+ * @example
5216
+ * // Merge two sets
5217
+ * console.log([...a.union(b)]); // [1, 2, 3, 4, 5, 6, 7];
5218
+ */
5219
+ union(other: Iterable<K>): TreeSet<K> {
5220
+ const result = this.clone();
5221
+ for (const key of other) result.add(key);
5222
+ return result;
5223
+ }
5224
+
5225
+ /**
5226
+ * Return a new TreeSet containing only elements present in both sets.
5227
+ * @remarks Time O(n+m) with ordered merge when possible, otherwise O(n log m).
5228
+ * @param other - Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
5229
+ * @returns A new TreeSet.
5230
+ * @example
5231
+ * // Find common elements
5232
+ * console.log([...a.intersection(b)]); // [3, 4, 5];
5233
+ */
5234
+ intersection(other: Iterable<K>): TreeSet<K> {
5235
+ const otherSet = other instanceof TreeSet || other instanceof Set ? other : new Set(other);
5236
+ const result = new TreeSet<K>([], { comparator: this.#isDefaultComparator ? undefined : this.#userComparator });
5237
+ for (const key of this) {
5238
+ if (otherSet.has(key)) result.add(key);
5239
+ }
5240
+ return result;
5241
+ }
5242
+
5243
+ /**
5244
+ * Return a new TreeSet containing elements in this set but not in the other.
5245
+ * @remarks Time O(n+m) with ordered merge when possible, otherwise O(n log m).
5246
+ * @param other - Any iterable of keys.
5247
+ * @returns A new TreeSet.
5248
+ * @example
5249
+ * // Find exclusive elements
5250
+ * console.log([...a.difference(b)]); // [1, 2];
5251
+ */
5252
+ difference(other: Iterable<K>): TreeSet<K> {
5253
+ const otherSet = other instanceof TreeSet || other instanceof Set ? other : new Set(other);
5254
+ const result = new TreeSet<K>([], { comparator: this.#isDefaultComparator ? undefined : this.#userComparator });
5255
+ for (const key of this) {
5256
+ if (!otherSet.has(key)) result.add(key);
5257
+ }
5258
+ return result;
5259
+ }
5260
+
5261
+ /**
5262
+ * Return a new TreeSet containing elements in either set but not both.
5263
+ * @remarks Time O(n+m).
5264
+ * @param other - Any iterable of keys.
5265
+ * @returns A new TreeSet.
5266
+ * @example
5267
+ * // Find symmetric difference
5268
+ * console.log([...a.symmetricDifference(b)]); // [1, 2, 6, 7];
5269
+ */
5270
+ symmetricDifference(other: Iterable<K>): TreeSet<K> {
5271
+ const otherSet = other instanceof TreeSet || other instanceof Set ? other : new Set(other);
5272
+ const result = new TreeSet<K>([], { comparator: this.#isDefaultComparator ? undefined : this.#userComparator });
5273
+ for (const key of this) {
5274
+ if (!otherSet.has(key)) result.add(key);
5275
+ }
5276
+ for (const key of otherSet) {
5277
+ if (!this.has(key)) result.add(key);
5278
+ }
5279
+ return result;
5280
+ }
5281
+
5282
+ /**
5283
+ * Check whether every element in this set is also in the other.
5284
+ * @remarks Time O(n).
5285
+ * @param other - Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
5286
+ * @returns `true` if this is a subset of other.
5287
+ * @example
5288
+ * // Check subset
5289
+ * console.log(new TreeSet([3, 4]).isSubsetOf(a)); // true;
5290
+ */
5291
+ isSubsetOf(other: Iterable<K>): boolean {
5292
+ const otherSet = other instanceof TreeSet || other instanceof Set ? other : new Set(other);
5293
+ for (const key of this) {
5294
+ if (!otherSet.has(key)) return false;
5295
+ }
5296
+ return true;
5297
+ }
5298
+
5299
+ /**
5300
+ * Check whether every element in the other set is also in this set.
5301
+ * @remarks Time O(m).
5302
+ * @param other - Any iterable of keys.
5303
+ * @returns `true` if this is a superset of other.
5304
+ * @example
5305
+ * // Check superset
5306
+ * console.log(a.isSupersetOf(new TreeSet([2, 3]))); // true;
5307
+ */
5308
+ isSupersetOf(other: Iterable<K>): boolean {
5309
+ for (const key of other) {
5310
+ if (!this.has(key)) return false;
5311
+ }
5312
+ return true;
5313
+ }
5314
+
5315
+ /**
5316
+ * Check whether this set and the other share no common elements.
5317
+ * @remarks Time O(min(n,m)), can short-circuit on first overlap.
5318
+ * @param other - Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
5319
+ * @returns `true` if sets are disjoint.
5320
+ * @example
5321
+ * // Check disjoint
5322
+ * console.log(a.isDisjointFrom(new TreeSet([8, 9]))); // true;
5323
+ */
5324
+ isDisjointFrom(other: Iterable<K>): boolean {
5325
+ const otherSet = other instanceof TreeSet || other instanceof Set ? other : new Set(other);
5326
+ for (const key of this) {
5327
+ if (otherSet.has(key)) return false;
5328
+ }
5329
+ return true;
5330
+ }
5331
+
5332
+ /**
5333
+ * Deep copy
5334
+
4843
5335
 
4844
5336
 
4845
5337