max-priority-queue-typed 2.5.2 → 2.5.3

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 (59) hide show
  1. package/dist/cjs/index.cjs +103 -16
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +103 -16
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +103 -16
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +103 -16
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +50 -2
  10. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
  11. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +116 -15
  12. package/dist/types/data-structures/binary-tree/bst.d.ts +99 -3
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +79 -8
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
  15. package/dist/types/data-structures/binary-tree/tree-map.d.ts +520 -1
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +489 -1
  17. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +393 -1
  18. package/dist/types/data-structures/binary-tree/tree-set.d.ts +500 -1
  19. package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
  20. package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
  21. package/dist/types/data-structures/hash/hash-map.d.ts +51 -6
  22. package/dist/types/data-structures/heap/heap.d.ts +98 -12
  23. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -0
  24. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +61 -1
  25. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
  26. package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
  27. package/dist/types/data-structures/queue/deque.d.ts +82 -0
  28. package/dist/types/data-structures/queue/queue.d.ts +61 -0
  29. package/dist/types/data-structures/stack/stack.d.ts +42 -2
  30. package/dist/types/data-structures/trie/trie.d.ts +48 -0
  31. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  32. package/dist/umd/max-priority-queue-typed.js +103 -16
  33. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  34. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  35. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  36. package/package.json +2 -2
  37. package/src/data-structures/binary-tree/avl-tree.ts +52 -5
  38. package/src/data-structures/binary-tree/binary-indexed-tree.ts +56 -0
  39. package/src/data-structures/binary-tree/binary-tree.ts +167 -81
  40. package/src/data-structures/binary-tree/bst.ts +101 -7
  41. package/src/data-structures/binary-tree/red-black-tree.ts +82 -15
  42. package/src/data-structures/binary-tree/segment-tree.ts +24 -0
  43. package/src/data-structures/binary-tree/tree-map.ts +540 -3
  44. package/src/data-structures/binary-tree/tree-multi-map.ts +490 -2
  45. package/src/data-structures/binary-tree/tree-multi-set.ts +393 -1
  46. package/src/data-structures/binary-tree/tree-set.ts +520 -3
  47. package/src/data-structures/graph/directed-graph.ts +41 -1
  48. package/src/data-structures/graph/undirected-graph.ts +37 -1
  49. package/src/data-structures/hash/hash-map.ts +67 -12
  50. package/src/data-structures/heap/heap.ts +107 -19
  51. package/src/data-structures/linked-list/doubly-linked-list.ts +88 -0
  52. package/src/data-structures/linked-list/singly-linked-list.ts +61 -1
  53. package/src/data-structures/linked-list/skip-linked-list.ts +72 -0
  54. package/src/data-structures/matrix/matrix.ts +32 -0
  55. package/src/data-structures/queue/deque.ts +85 -0
  56. package/src/data-structures/queue/queue.ts +73 -0
  57. package/src/data-structures/stack/stack.ts +45 -5
  58. package/src/data-structures/trie/trie.ts +48 -0
  59. package/src/interfaces/binary-tree.ts +1 -9
@@ -241,6 +241,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
241
241
 
242
242
 
243
243
 
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
244
264
 
245
265
 
246
266
 
@@ -432,6 +452,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
432
452
 
433
453
 
434
454
 
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+
435
475
 
436
476
 
437
477
 
@@ -472,6 +512,42 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
472
512
  return this;
473
513
  }
474
514
 
515
+ /**
516
+ * Add multiple keys at once.
517
+ * @remarks Expected time O(m log n), where m is the number of keys.
518
+ * @param keys - Iterable of keys to add.
519
+ * @returns Array of booleans indicating whether each key was newly added.
520
+
521
+
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+
536
+ * @example
537
+ * // Add multiple keys
538
+ * const ts = new TreeSet<number>();
539
+ * ts.addMany([5, 3, 7, 1, 9]);
540
+ * console.log(ts.size); // 5;
541
+ */
542
+ addMany(keys: Iterable<K>): boolean[] {
543
+ const results: boolean[] = [];
544
+ for (const key of keys) {
545
+ this._validateKey(key);
546
+ results.push(this.#core.set(key, undefined));
547
+ }
548
+ return results;
549
+ }
550
+
475
551
  /**
476
552
  * Test whether a key exists.
477
553
  * @remarks Expected time O(log n)
@@ -623,6 +699,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
623
699
 
624
700
 
625
701
 
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
626
722
 
627
723
 
628
724
 
@@ -808,6 +904,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
808
904
 
809
905
 
810
906
 
907
+
908
+
909
+
910
+
911
+
912
+
913
+
914
+
915
+
916
+
917
+
918
+
919
+
920
+
921
+
922
+
923
+
924
+
925
+
926
+
811
927
 
812
928
 
813
929
 
@@ -839,8 +955,25 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
839
955
  */
840
956
  delete(key: K): boolean {
841
957
  this._validateKey(key);
842
- const res = this.#core.delete(key);
843
- return Array.isArray(res) && res.length > 0 && !!res[0]?.deleted;
958
+ return this.#core.delete(key);
959
+ }
960
+
961
+ /**
962
+ * Delete all keys matching a predicate.
963
+ * @remarks Time O(N), Space O(N)
964
+ * @param predicate - Function (key, index, set) → boolean; return true to delete.
965
+ * @returns True if at least one key was deleted.
966
+ */
967
+ deleteWhere(predicate: (key: K, index: number, set: this) => boolean): boolean {
968
+ let deleted = false;
969
+ let index = 0;
970
+ for (const key of this) {
971
+ if (predicate(key, index++, this)) {
972
+ this.delete(key);
973
+ deleted = true;
974
+ }
975
+ }
976
+ return deleted;
844
977
  }
845
978
 
846
979
  /**
@@ -982,6 +1115,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
982
1115
 
983
1116
 
984
1117
 
1118
+
1119
+
1120
+
1121
+
1122
+
1123
+
1124
+
1125
+
1126
+
1127
+
1128
+
1129
+
1130
+
1131
+
1132
+
1133
+
1134
+
1135
+
1136
+
1137
+
985
1138
 
986
1139
 
987
1140
 
@@ -1152,6 +1305,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
1152
1305
 
1153
1306
 
1154
1307
 
1308
+
1309
+
1310
+
1311
+
1312
+
1313
+
1314
+
1315
+
1316
+
1317
+
1318
+
1319
+
1320
+
1321
+
1322
+
1323
+
1324
+
1325
+
1326
+
1327
+
1155
1328
 
1156
1329
 
1157
1330
 
@@ -1323,6 +1496,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
1323
1496
 
1324
1497
 
1325
1498
 
1499
+
1500
+
1501
+
1502
+
1503
+
1504
+
1505
+
1506
+
1507
+
1508
+
1509
+
1510
+
1511
+
1512
+
1513
+
1514
+
1515
+
1516
+
1517
+
1518
+
1326
1519
 
1327
1520
 
1328
1521
 
@@ -1494,6 +1687,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
1494
1687
 
1495
1688
 
1496
1689
 
1690
+
1691
+
1692
+
1693
+
1694
+
1695
+
1696
+
1697
+
1698
+
1699
+
1700
+
1701
+
1702
+
1703
+
1704
+
1705
+
1706
+
1707
+
1708
+
1709
+
1497
1710
 
1498
1711
 
1499
1712
 
@@ -1669,6 +1882,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
1669
1882
 
1670
1883
 
1671
1884
 
1885
+
1886
+
1887
+
1888
+
1889
+
1890
+
1891
+
1892
+
1893
+
1894
+
1895
+
1896
+
1897
+
1898
+
1899
+
1900
+
1901
+
1902
+
1903
+
1904
+
1672
1905
 
1673
1906
 
1674
1907
 
@@ -1843,6 +2076,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
1843
2076
 
1844
2077
 
1845
2078
 
2079
+
2080
+
2081
+
2082
+
2083
+
2084
+
2085
+
2086
+
2087
+
2088
+
2089
+
2090
+
2091
+
2092
+
2093
+
2094
+
2095
+
2096
+
2097
+
2098
+
1846
2099
 
1847
2100
 
1848
2101
 
@@ -2026,6 +2279,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2026
2279
 
2027
2280
 
2028
2281
 
2282
+
2283
+
2284
+
2285
+
2286
+
2287
+
2288
+
2289
+
2290
+
2291
+
2292
+
2293
+
2294
+
2295
+
2296
+
2297
+
2298
+
2299
+
2300
+
2301
+
2029
2302
 
2030
2303
 
2031
2304
 
@@ -2205,6 +2478,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2205
2478
 
2206
2479
 
2207
2480
 
2481
+
2482
+
2483
+
2484
+
2485
+
2486
+
2487
+
2488
+
2489
+
2490
+
2491
+
2492
+
2493
+
2494
+
2495
+
2496
+
2497
+
2498
+
2499
+
2500
+
2208
2501
 
2209
2502
 
2210
2503
 
@@ -2377,6 +2670,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2377
2670
 
2378
2671
 
2379
2672
 
2673
+
2674
+
2675
+
2676
+
2677
+
2678
+
2679
+
2680
+
2681
+
2682
+
2683
+
2684
+
2685
+
2686
+
2687
+
2688
+
2689
+
2690
+
2691
+
2692
+
2380
2693
 
2381
2694
 
2382
2695
 
@@ -2552,6 +2865,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2552
2865
 
2553
2866
 
2554
2867
 
2868
+
2869
+
2870
+
2871
+
2872
+
2873
+
2874
+
2875
+
2876
+
2877
+
2878
+
2879
+
2880
+
2881
+
2882
+
2883
+
2884
+
2885
+
2886
+
2887
+
2555
2888
 
2556
2889
 
2557
2890
 
@@ -2727,6 +3060,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2727
3060
 
2728
3061
 
2729
3062
 
3063
+
3064
+
3065
+
3066
+
3067
+
3068
+
3069
+
3070
+
3071
+
3072
+
3073
+
3074
+
3075
+
3076
+
3077
+
3078
+
3079
+
3080
+
3081
+
3082
+
2730
3083
 
2731
3084
 
2732
3085
 
@@ -2905,6 +3258,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
2905
3258
 
2906
3259
 
2907
3260
 
3261
+
3262
+
3263
+
3264
+
3265
+
3266
+
3267
+
3268
+
3269
+
3270
+
3271
+
3272
+
3273
+
3274
+
3275
+
3276
+
3277
+
3278
+
3279
+
3280
+
2908
3281
 
2909
3282
 
2910
3283
 
@@ -3075,6 +3448,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3075
3448
 
3076
3449
 
3077
3450
 
3451
+
3452
+
3453
+
3454
+
3455
+
3456
+
3457
+
3458
+
3459
+
3460
+
3461
+
3462
+
3463
+
3464
+
3465
+
3466
+
3467
+
3468
+
3469
+
3470
+
3078
3471
 
3079
3472
 
3080
3473
 
@@ -3140,6 +3533,10 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3140
3533
 
3141
3534
 
3142
3535
 
3536
+
3537
+
3538
+
3539
+
3143
3540
 
3144
3541
 
3145
3542
 
@@ -3209,6 +3606,10 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3209
3606
 
3210
3607
 
3211
3608
 
3609
+
3610
+
3611
+
3612
+
3212
3613
 
3213
3614
 
3214
3615
 
@@ -3256,6 +3657,10 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3256
3657
 
3257
3658
 
3258
3659
 
3660
+
3661
+
3662
+
3663
+
3259
3664
 
3260
3665
 
3261
3666
 
@@ -3308,6 +3713,10 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3308
3713
 
3309
3714
 
3310
3715
 
3716
+
3717
+
3718
+
3719
+
3311
3720
 
3312
3721
 
3313
3722
 
@@ -3446,6 +3855,22 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3446
3855
 
3447
3856
 
3448
3857
 
3858
+
3859
+
3860
+
3861
+
3862
+
3863
+
3864
+
3865
+
3866
+
3867
+
3868
+
3869
+
3870
+
3871
+
3872
+
3873
+
3449
3874
 
3450
3875
 
3451
3876
 
@@ -3604,6 +4029,22 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3604
4029
 
3605
4030
 
3606
4031
 
4032
+
4033
+
4034
+
4035
+
4036
+
4037
+
4038
+
4039
+
4040
+
4041
+
4042
+
4043
+
4044
+
4045
+
4046
+
4047
+
3607
4048
 
3608
4049
 
3609
4050
 
@@ -3754,6 +4195,22 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3754
4195
 
3755
4196
 
3756
4197
 
4198
+
4199
+
4200
+
4201
+
4202
+
4203
+
4204
+
4205
+
4206
+
4207
+
4208
+
4209
+
4210
+
4211
+
4212
+
4213
+
3757
4214
 
3758
4215
 
3759
4216
 
@@ -3902,6 +4359,22 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
3902
4359
 
3903
4360
 
3904
4361
 
4362
+
4363
+
4364
+
4365
+
4366
+
4367
+
4368
+
4369
+
4370
+
4371
+
4372
+
4373
+
4374
+
4375
+
4376
+
4377
+
3905
4378
 
3906
4379
 
3907
4380
 
@@ -4053,6 +4526,22 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
4053
4526
 
4054
4527
 
4055
4528
 
4529
+
4530
+
4531
+
4532
+
4533
+
4534
+
4535
+
4536
+
4537
+
4538
+
4539
+
4540
+
4541
+
4542
+
4543
+
4544
+
4056
4545
 
4057
4546
 
4058
4547
 
@@ -4150,8 +4639,16 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
4150
4639
  * Returns elements by rank range (0-indexed, inclusive on both ends).
4151
4640
  * @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
4152
4641
 
4642
+
4643
+
4644
+
4645
+
4646
+
4647
+
4648
+
4649
+
4153
4650
  * @example
4154
- * // Pagination with rangeByRank
4651
+ * // Pagination by position in tree order
4155
4652
  * const tree = new TreeSet<number>(
4156
4653
  * [10, 20, 30, 40, 50, 60, 70, 80, 90],
4157
4654
  * { enableOrderStatistic: true }
@@ -4310,6 +4807,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
4310
4807
 
4311
4808
 
4312
4809
 
4810
+
4811
+
4812
+
4813
+
4814
+
4815
+
4816
+
4817
+
4818
+
4819
+
4820
+
4821
+
4822
+
4823
+
4824
+
4825
+
4826
+
4827
+
4828
+
4829
+
4313
4830
 
4314
4831
 
4315
4832