binary-tree-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 +194 -55
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +194 -55
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +194 -55
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +194 -55
  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/binary-tree-typed.js +194 -55
  33. package/dist/umd/binary-tree-typed.js.map +1 -1
  34. package/dist/umd/binary-tree-typed.min.js +5 -5
  35. package/dist/umd/binary-tree-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
@@ -274,6 +274,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
274
274
 
275
275
 
276
276
 
277
+
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
277
297
 
278
298
 
279
299
 
@@ -452,6 +472,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
452
472
 
453
473
 
454
474
 
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
455
495
 
456
496
 
457
497
 
@@ -500,6 +540,42 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
500
540
  return this;
501
541
  }
502
542
 
543
+ /**
544
+ * Set multiple key-value pairs at once.
545
+ * @remarks Expected time O(m log n), where m is the number of entries.
546
+ * @param entries - Iterable of `[key, value]` tuples.
547
+ * @returns Array of booleans indicating whether each entry was successfully set.
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+ * @example
565
+ * // Set multiple key-value pairs
566
+ * const tm = new TreeMap<number, string>();
567
+ * tm.setMany([[1, 'a'], [2, 'b'], [3, 'c']]);
568
+ * console.log(tm.size); // 3;
569
+ */
570
+ setMany(entries: Iterable<[K, V | undefined]>): boolean[] {
571
+ const results: boolean[] = [];
572
+ for (const [key, value] of entries) {
573
+ this._validateKey(key);
574
+ results.push(this.#core.set(key, value as V));
575
+ }
576
+ return results;
577
+ }
578
+
503
579
  /**
504
580
  * Get the value under a key.
505
581
  * @remarks Expected time O(log n)
@@ -651,6 +727,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
651
727
 
652
728
 
653
729
 
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
654
750
 
655
751
 
656
752
 
@@ -840,6 +936,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
840
936
 
841
937
 
842
938
 
939
+
940
+
941
+
942
+
943
+
944
+
945
+
946
+
947
+
948
+
949
+
950
+
951
+
952
+
953
+
954
+
955
+
956
+
957
+
958
+
843
959
 
844
960
 
845
961
 
@@ -1029,6 +1145,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
1029
1145
 
1030
1146
 
1031
1147
 
1148
+
1149
+
1150
+
1151
+
1152
+
1153
+
1154
+
1155
+
1156
+
1157
+
1158
+
1159
+
1160
+
1161
+
1162
+
1163
+
1164
+
1165
+
1166
+
1167
+
1032
1168
 
1033
1169
 
1034
1170
 
@@ -1065,8 +1201,25 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
1065
1201
  */
1066
1202
  delete(key: K): boolean {
1067
1203
  this._validateKey(key);
1068
- const res = this.#core.delete(key);
1069
- return Array.isArray(res) && res.length > 0 && !!res[0]?.deleted;
1204
+ return this.#core.delete(key);
1205
+ }
1206
+
1207
+ /**
1208
+ * Delete all entries matching a predicate.
1209
+ * @remarks Time O(N), Space O(N)
1210
+ * @param predicate - Function (key, value, index, map) → boolean; return true to delete.
1211
+ * @returns True if at least one entry was deleted.
1212
+ */
1213
+ deleteWhere(predicate: (key: K, value: V | undefined, index: number, map: this) => boolean): boolean {
1214
+ let deleted = false;
1215
+ let index = 0;
1216
+ for (const [key, value] of this) {
1217
+ if (predicate(key, value, index++, this)) {
1218
+ this.delete(key);
1219
+ deleted = true;
1220
+ }
1221
+ }
1222
+ return deleted;
1070
1223
  }
1071
1224
 
1072
1225
  /**
@@ -1208,6 +1361,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
1208
1361
 
1209
1362
 
1210
1363
 
1364
+
1365
+
1366
+
1367
+
1368
+
1369
+
1370
+
1371
+
1372
+
1373
+
1374
+
1375
+
1376
+
1377
+
1378
+
1379
+
1380
+
1381
+
1382
+
1383
+
1211
1384
 
1212
1385
 
1213
1386
 
@@ -1378,6 +1551,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
1378
1551
 
1379
1552
 
1380
1553
 
1554
+
1555
+
1556
+
1557
+
1558
+
1559
+
1560
+
1561
+
1562
+
1563
+
1564
+
1565
+
1566
+
1567
+
1568
+
1569
+
1570
+
1571
+
1572
+
1573
+
1381
1574
 
1382
1575
 
1383
1576
 
@@ -1555,6 +1748,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
1555
1748
 
1556
1749
 
1557
1750
 
1751
+
1752
+
1753
+
1754
+
1755
+
1756
+
1757
+
1758
+
1759
+
1760
+
1761
+
1762
+
1763
+
1764
+
1765
+
1766
+
1767
+
1768
+
1769
+
1770
+
1558
1771
 
1559
1772
 
1560
1773
 
@@ -1726,6 +1939,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
1726
1939
 
1727
1940
 
1728
1941
 
1942
+
1943
+
1944
+
1945
+
1946
+
1947
+
1948
+
1949
+
1950
+
1951
+
1952
+
1953
+
1954
+
1955
+
1956
+
1957
+
1958
+
1959
+
1960
+
1961
+
1729
1962
 
1730
1963
 
1731
1964
 
@@ -1901,6 +2134,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
1901
2134
 
1902
2135
 
1903
2136
 
2137
+
2138
+
2139
+
2140
+
2141
+
2142
+
2143
+
2144
+
2145
+
2146
+
2147
+
2148
+
2149
+
2150
+
2151
+
2152
+
2153
+
2154
+
2155
+
2156
+
1904
2157
 
1905
2158
 
1906
2159
 
@@ -2075,6 +2328,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
2075
2328
 
2076
2329
 
2077
2330
 
2331
+
2332
+
2333
+
2334
+
2335
+
2336
+
2337
+
2338
+
2339
+
2340
+
2341
+
2342
+
2343
+
2344
+
2345
+
2346
+
2347
+
2348
+
2349
+
2350
+
2078
2351
 
2079
2352
 
2080
2353
 
@@ -2258,6 +2531,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
2258
2531
 
2259
2532
 
2260
2533
 
2534
+
2535
+
2536
+
2537
+
2538
+
2539
+
2540
+
2541
+
2542
+
2543
+
2544
+
2545
+
2546
+
2547
+
2548
+
2549
+
2550
+
2551
+
2552
+
2553
+
2261
2554
 
2262
2555
 
2263
2556
 
@@ -2437,6 +2730,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
2437
2730
 
2438
2731
 
2439
2732
 
2733
+
2734
+
2735
+
2736
+
2737
+
2738
+
2739
+
2740
+
2741
+
2742
+
2743
+
2744
+
2745
+
2746
+
2747
+
2748
+
2749
+
2750
+
2751
+
2752
+
2440
2753
 
2441
2754
 
2442
2755
 
@@ -2608,6 +2921,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
2608
2921
 
2609
2922
 
2610
2923
 
2924
+
2925
+
2926
+
2927
+
2928
+
2929
+
2930
+
2931
+
2932
+
2933
+
2934
+
2935
+
2936
+
2937
+
2938
+
2939
+
2940
+
2941
+
2942
+
2943
+
2611
2944
 
2612
2945
 
2613
2946
 
@@ -2783,6 +3116,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
2783
3116
 
2784
3117
 
2785
3118
 
3119
+
3120
+
3121
+
3122
+
3123
+
3124
+
3125
+
3126
+
3127
+
3128
+
3129
+
3130
+
3131
+
3132
+
3133
+
3134
+
3135
+
3136
+
3137
+
3138
+
2786
3139
 
2787
3140
 
2788
3141
 
@@ -2959,6 +3312,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
2959
3312
 
2960
3313
 
2961
3314
 
3315
+
3316
+
3317
+
3318
+
3319
+
3320
+
3321
+
3322
+
3323
+
3324
+
3325
+
3326
+
3327
+
3328
+
3329
+
3330
+
3331
+
3332
+
3333
+
3334
+
2962
3335
 
2963
3336
 
2964
3337
 
@@ -3136,6 +3509,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
3136
3509
 
3137
3510
 
3138
3511
 
3512
+
3513
+
3514
+
3515
+
3516
+
3517
+
3518
+
3519
+
3520
+
3521
+
3522
+
3523
+
3524
+
3525
+
3526
+
3527
+
3528
+
3529
+
3530
+
3531
+
3139
3532
 
3140
3533
 
3141
3534
 
@@ -3306,6 +3699,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
3306
3699
 
3307
3700
 
3308
3701
 
3702
+
3703
+
3704
+
3705
+
3706
+
3707
+
3708
+
3709
+
3710
+
3711
+
3712
+
3713
+
3714
+
3715
+
3716
+
3717
+
3718
+
3719
+
3720
+
3721
+
3309
3722
 
3310
3723
 
3311
3724
 
@@ -3372,6 +3785,10 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
3372
3785
 
3373
3786
 
3374
3787
 
3788
+
3789
+
3790
+
3791
+
3375
3792
 
3376
3793
 
3377
3794
 
@@ -3441,6 +3858,10 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
3441
3858
 
3442
3859
 
3443
3860
 
3861
+
3862
+
3863
+
3864
+
3444
3865
 
3445
3866
 
3446
3867
 
@@ -3494,6 +3915,10 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
3494
3915
 
3495
3916
 
3496
3917
 
3918
+
3919
+
3920
+
3921
+
3497
3922
 
3498
3923
 
3499
3924
 
@@ -3551,6 +3976,10 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
3551
3976
 
3552
3977
 
3553
3978
 
3979
+
3980
+
3981
+
3982
+
3554
3983
 
3555
3984
 
3556
3985
 
@@ -3695,6 +4124,22 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
3695
4124
 
3696
4125
 
3697
4126
 
4127
+
4128
+
4129
+
4130
+
4131
+
4132
+
4133
+
4134
+
4135
+
4136
+
4137
+
4138
+
4139
+
4140
+
4141
+
4142
+
3698
4143
 
3699
4144
 
3700
4145
 
@@ -3869,6 +4314,22 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
3869
4314
 
3870
4315
 
3871
4316
 
4317
+
4318
+
4319
+
4320
+
4321
+
4322
+
4323
+
4324
+
4325
+
4326
+
4327
+
4328
+
4329
+
4330
+
4331
+
4332
+
3872
4333
 
3873
4334
 
3874
4335
 
@@ -4027,6 +4488,22 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
4027
4488
 
4028
4489
 
4029
4490
 
4491
+
4492
+
4493
+
4494
+
4495
+
4496
+
4497
+
4498
+
4499
+
4500
+
4501
+
4502
+
4503
+
4504
+
4505
+
4506
+
4030
4507
 
4031
4508
 
4032
4509
 
@@ -4185,6 +4662,22 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
4185
4662
 
4186
4663
 
4187
4664
 
4665
+
4666
+
4667
+
4668
+
4669
+
4670
+
4671
+
4672
+
4673
+
4674
+
4675
+
4676
+
4677
+
4678
+
4679
+
4680
+
4188
4681
 
4189
4682
 
4190
4683
 
@@ -4344,6 +4837,22 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
4344
4837
 
4345
4838
 
4346
4839
 
4840
+
4841
+
4842
+
4843
+
4844
+
4845
+
4846
+
4847
+
4848
+
4849
+
4850
+
4851
+
4852
+
4853
+
4854
+
4855
+
4347
4856
 
4348
4857
 
4349
4858
 
@@ -4458,8 +4967,16 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
4458
4967
  * Returns keys by rank range (0-indexed, inclusive on both ends).
4459
4968
  * @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
4460
4969
 
4970
+
4971
+
4972
+
4973
+
4974
+
4975
+
4976
+
4977
+
4461
4978
  * @example
4462
- * // Pagination with rangeByRank
4979
+ * // Pagination by position in tree order
4463
4980
  * const tree = new TreeMap<number>(
4464
4981
  * [10, 20, 30, 40, 50, 60, 70, 80, 90],
4465
4982
  * { enableOrderStatistic: true }
@@ -4621,6 +5138,26 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
4621
5138
 
4622
5139
 
4623
5140
 
5141
+
5142
+
5143
+
5144
+
5145
+
5146
+
5147
+
5148
+
5149
+
5150
+
5151
+
5152
+
5153
+
5154
+
5155
+
5156
+
5157
+
5158
+
5159
+
5160
+
4624
5161
 
4625
5162
 
4626
5163