binary-tree-typed 2.4.5 → 2.5.1

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 (94) hide show
  1. package/README.md +0 -84
  2. package/dist/cjs/index.cjs +1476 -404
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +1473 -401
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +1476 -404
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +1473 -401
  9. package/dist/esm-legacy/index.mjs.map +1 -1
  10. package/dist/types/data-structures/base/index.d.ts +1 -0
  11. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  12. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  13. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  14. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +380 -51
  15. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +487 -147
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +956 -80
  17. package/dist/types/data-structures/binary-tree/bst.d.ts +816 -29
  18. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +610 -31
  19. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +326 -135
  20. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3781 -6
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3607 -201
  22. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2874 -65
  23. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3528 -6
  24. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  25. package/dist/types/data-structures/graph/directed-graph.d.ts +429 -47
  26. package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
  27. package/dist/types/data-structures/graph/undirected-graph.d.ts +393 -59
  28. package/dist/types/data-structures/hash/hash-map.d.ts +473 -89
  29. package/dist/types/data-structures/heap/heap.d.ts +581 -99
  30. package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
  31. package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
  32. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +646 -47
  33. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +596 -68
  34. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +793 -12
  35. package/dist/types/data-structures/matrix/matrix.d.ts +499 -0
  36. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
  37. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
  38. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
  39. package/dist/types/data-structures/queue/deque.d.ts +593 -71
  40. package/dist/types/data-structures/queue/queue.d.ts +463 -42
  41. package/dist/types/data-structures/stack/stack.d.ts +384 -32
  42. package/dist/types/data-structures/trie/trie.d.ts +470 -48
  43. package/dist/types/interfaces/graph.d.ts +1 -1
  44. package/dist/types/types/common.d.ts +2 -2
  45. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
  46. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  47. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
  48. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  49. package/dist/types/types/utils/validate-type.d.ts +4 -4
  50. package/dist/umd/binary-tree-typed.js +1469 -397
  51. package/dist/umd/binary-tree-typed.js.map +1 -1
  52. package/dist/umd/binary-tree-typed.min.js +5 -5
  53. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/data-structures/base/index.ts +1 -0
  56. package/src/data-structures/base/iterable-element-base.ts +4 -5
  57. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  58. package/src/data-structures/base/linear-base.ts +3 -3
  59. package/src/data-structures/binary-tree/avl-tree.ts +386 -51
  60. package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
  61. package/src/data-structures/binary-tree/binary-tree.ts +956 -81
  62. package/src/data-structures/binary-tree/bst.ts +840 -35
  63. package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
  64. package/src/data-structures/binary-tree/segment-tree.ts +498 -249
  65. package/src/data-structures/binary-tree/tree-map.ts +3784 -7
  66. package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
  67. package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
  68. package/src/data-structures/binary-tree/tree-set.ts +3531 -10
  69. package/src/data-structures/graph/abstract-graph.ts +4 -4
  70. package/src/data-structures/graph/directed-graph.ts +429 -47
  71. package/src/data-structures/graph/map-graph.ts +59 -1
  72. package/src/data-structures/graph/undirected-graph.ts +393 -59
  73. package/src/data-structures/hash/hash-map.ts +476 -92
  74. package/src/data-structures/heap/heap.ts +581 -99
  75. package/src/data-structures/heap/max-heap.ts +46 -0
  76. package/src/data-structures/heap/min-heap.ts +59 -0
  77. package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
  78. package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
  79. package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
  80. package/src/data-structures/matrix/matrix.ts +584 -12
  81. package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
  82. package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
  83. package/src/data-structures/priority-queue/priority-queue.ts +60 -0
  84. package/src/data-structures/queue/deque.ts +592 -70
  85. package/src/data-structures/queue/queue.ts +463 -42
  86. package/src/data-structures/stack/stack.ts +384 -32
  87. package/src/data-structures/trie/trie.ts +470 -48
  88. package/src/interfaces/graph.ts +1 -1
  89. package/src/types/common.ts +2 -2
  90. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
  91. package/src/types/data-structures/heap/heap.ts +1 -0
  92. package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
  93. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  94. package/src/types/utils/validate-type.ts +4 -4
@@ -84,6 +84,35 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
84
84
  /**
85
85
  * Number of distinct keys.
86
86
  * @remarks Time O(1), Space O(1)
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ * @example
111
+ * // Unique key count
112
+ * const ms = new TreeMultiSet<number>();
113
+ * ms.add(1, 3);
114
+ * ms.add(2, 2);
115
+ * console.log(ms.distinctSize); // 2;
87
116
  */
88
117
  get distinctSize(): number {
89
118
  return this.#core.size;
@@ -92,6 +121,152 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
92
121
  /**
93
122
  * Whether the multiset is empty.
94
123
  * @remarks Time O(1), Space O(1)
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+ * @example
268
+ * // Check empty
269
+ * console.log(new TreeMultiSet().isEmpty()); // true;
95
270
  */
96
271
  isEmpty(): boolean {
97
272
  return this.size === 0;
@@ -100,6 +275,158 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
100
275
  /**
101
276
  * Whether the multiset contains the given key.
102
277
  * @remarks Time O(log n), Space O(1)
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+ * @example
425
+ * // Check existence
426
+ * const ms = new TreeMultiSet<number>();
427
+ * ms.add(1);
428
+ * console.log(ms.has(1)); // true;
429
+ * console.log(ms.has(2)); // false;
103
430
  */
104
431
  has(key: K): boolean {
105
432
  this._validateKey(key);
@@ -109,6 +436,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
109
436
  /**
110
437
  * Returns the count of occurrences for the given key.
111
438
  * @remarks Time O(log n), Space O(1)
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+ * @example
463
+ * // Get occurrence count
464
+ * const ms = new TreeMultiSet<number>();
465
+ * ms.add(1, 5);
466
+ * console.log(ms.count(1)); // 5;
112
467
  */
113
468
  count(key: K): number {
114
469
  this._validateKey(key);
@@ -119,6 +474,151 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
119
474
  * Add `n` occurrences of `key`.
120
475
  * @returns True if the multiset changed.
121
476
  * @remarks Time O(log n), Space O(1)
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
584
+
585
+
586
+
587
+
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+
602
+
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+
611
+
612
+
613
+
614
+ * @example
615
+ * // Add elements
616
+ * const ms = new TreeMultiSet<number>();
617
+ * ms.add(1);
618
+ * ms.add(1);
619
+ * ms.add(2);
620
+ * console.log(ms.count(1)); // 2;
621
+ * console.log(ms.size); // 3;
122
622
  */
123
623
  add(key: K, n = 1): boolean {
124
624
  this._validateKey(key);
@@ -136,6 +636,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
136
636
  * Set count for `key` to exactly `n`.
137
637
  * @returns True if changed.
138
638
  * @remarks Time O(log n), Space O(1)
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+ * @example
663
+ * // Set occurrence count
664
+ * const ms = new TreeMultiSet<number>();
665
+ * ms.setCount(1, 3);
666
+ * console.log(ms.count(1)); // 3;
139
667
  */
140
668
  setCount(key: K, n: number): boolean {
141
669
  this._validateKey(key);
@@ -158,6 +686,158 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
158
686
  * Delete `n` occurrences of `key` (default 1).
159
687
  * @returns True if any occurrence was removed.
160
688
  * @remarks Time O(log n), Space O(1)
689
+
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+
796
+
797
+
798
+
799
+
800
+
801
+
802
+
803
+
804
+
805
+
806
+
807
+
808
+
809
+
810
+
811
+
812
+
813
+
814
+
815
+
816
+
817
+
818
+
819
+
820
+
821
+
822
+
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+
834
+
835
+ * @example
836
+ * // Remove one occurrence
837
+ * const ms = new TreeMultiSet<number>();
838
+ * ms.add(1, 3);
839
+ * ms.delete(1);
840
+ * console.log(ms.count(1)); // 2;
161
841
  */
162
842
  delete(key: K, n = 1): boolean {
163
843
  this._validateKey(key);
@@ -181,6 +861,35 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
181
861
  * Delete all occurrences of the given key.
182
862
  * @returns True if any occurrence was removed.
183
863
  * @remarks Time O(log n), Space O(1)
864
+
865
+
866
+
867
+
868
+
869
+
870
+
871
+
872
+
873
+
874
+
875
+
876
+
877
+
878
+
879
+
880
+
881
+
882
+
883
+
884
+
885
+
886
+
887
+ * @example
888
+ * // Remove all occurrences
889
+ * const ms = new TreeMultiSet<number>();
890
+ * ms.add(1, 3);
891
+ * ms.deleteAll(1);
892
+ * console.log(ms.has(1)); // false;
184
893
  */
185
894
  deleteAll(key: K): boolean {
186
895
  this._validateKey(key);
@@ -194,6 +903,35 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
194
903
  /**
195
904
  * Iterates over distinct keys (each key yielded once).
196
905
  * @remarks Time O(n), Space O(1)
906
+
907
+
908
+
909
+
910
+
911
+
912
+
913
+
914
+
915
+
916
+
917
+
918
+
919
+
920
+
921
+
922
+
923
+
924
+
925
+
926
+
927
+
928
+
929
+ * @example
930
+ * // Iterate unique keys
931
+ * const ms = new TreeMultiSet<number>();
932
+ * ms.add(1, 2);
933
+ * ms.add(2);
934
+ * console.log([...ms.keysDistinct()]); // [1, 2];
197
935
  */
198
936
  *keysDistinct(): IterableIterator<K> {
199
937
  yield* this.#core.keys();
@@ -202,6 +940,154 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
202
940
  /**
203
941
  * Iterates over entries as [key, count] pairs.
204
942
  * @remarks Time O(n), Space O(1)
943
+
944
+
945
+
946
+
947
+
948
+
949
+
950
+
951
+
952
+
953
+
954
+
955
+
956
+
957
+
958
+
959
+
960
+
961
+
962
+
963
+
964
+
965
+
966
+
967
+
968
+
969
+
970
+
971
+
972
+
973
+
974
+
975
+
976
+
977
+
978
+
979
+
980
+
981
+
982
+
983
+
984
+
985
+
986
+
987
+
988
+
989
+
990
+
991
+
992
+
993
+
994
+
995
+
996
+
997
+
998
+
999
+
1000
+
1001
+
1002
+
1003
+
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+
1023
+
1024
+
1025
+
1026
+
1027
+
1028
+
1029
+
1030
+
1031
+
1032
+
1033
+
1034
+
1035
+
1036
+
1037
+
1038
+
1039
+
1040
+
1041
+
1042
+
1043
+
1044
+
1045
+
1046
+
1047
+
1048
+
1049
+
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+
1070
+
1071
+
1072
+
1073
+
1074
+
1075
+
1076
+
1077
+
1078
+
1079
+
1080
+
1081
+
1082
+
1083
+
1084
+
1085
+
1086
+ * @example
1087
+ * // Iterate entries
1088
+ * const ms = new TreeMultiSet<number>();
1089
+ * ms.add(1, 2);
1090
+ * console.log([...ms.entries()].length); // > 0;
205
1091
  */
206
1092
  *entries(): IterableIterator<[K, number]> {
207
1093
  for (const [k, v] of this.#core) {
@@ -222,6 +1108,155 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
222
1108
  /**
223
1109
  * Returns an array with all elements (expanded).
224
1110
  * @remarks Time O(size), Space O(size)
1111
+
1112
+
1113
+
1114
+
1115
+
1116
+
1117
+
1118
+
1119
+
1120
+
1121
+
1122
+
1123
+
1124
+
1125
+
1126
+
1127
+
1128
+
1129
+
1130
+
1131
+
1132
+
1133
+
1134
+
1135
+
1136
+
1137
+
1138
+
1139
+
1140
+
1141
+
1142
+
1143
+
1144
+
1145
+
1146
+
1147
+
1148
+
1149
+
1150
+
1151
+
1152
+
1153
+
1154
+
1155
+
1156
+
1157
+
1158
+
1159
+
1160
+
1161
+
1162
+
1163
+
1164
+
1165
+
1166
+
1167
+
1168
+
1169
+
1170
+
1171
+
1172
+
1173
+
1174
+
1175
+
1176
+
1177
+
1178
+
1179
+
1180
+
1181
+
1182
+
1183
+
1184
+
1185
+
1186
+
1187
+
1188
+
1189
+
1190
+
1191
+
1192
+
1193
+
1194
+
1195
+
1196
+
1197
+
1198
+
1199
+
1200
+
1201
+
1202
+
1203
+
1204
+
1205
+
1206
+
1207
+
1208
+
1209
+
1210
+
1211
+
1212
+
1213
+
1214
+
1215
+
1216
+
1217
+
1218
+
1219
+
1220
+
1221
+
1222
+
1223
+
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+
1230
+
1231
+
1232
+
1233
+
1234
+
1235
+
1236
+
1237
+
1238
+
1239
+
1240
+
1241
+
1242
+
1243
+
1244
+
1245
+
1246
+
1247
+
1248
+
1249
+
1250
+
1251
+
1252
+
1253
+
1254
+ * @example
1255
+ * // All elements (with duplicates)
1256
+ * const ms = new TreeMultiSet<number>();
1257
+ * ms.add(1, 2);
1258
+ * ms.add(2);
1259
+ * console.log(ms.toArray()); // [1, 1, 2];
225
1260
  */
226
1261
  toArray(): K[] {
227
1262
  return [...this];
@@ -230,6 +1265,35 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
230
1265
  /**
231
1266
  * Returns an array with distinct keys only.
232
1267
  * @remarks Time O(n), Space O(n)
1268
+
1269
+
1270
+
1271
+
1272
+
1273
+
1274
+
1275
+
1276
+
1277
+
1278
+
1279
+
1280
+
1281
+
1282
+
1283
+
1284
+
1285
+
1286
+
1287
+
1288
+
1289
+
1290
+
1291
+ * @example
1292
+ * // Unique keys only
1293
+ * const ms = new TreeMultiSet<number>();
1294
+ * ms.add(1, 3);
1295
+ * ms.add(2);
1296
+ * console.log(ms.toDistinctArray()); // [1, 2];
233
1297
  */
234
1298
  toDistinctArray(): K[] {
235
1299
  return [...this.keysDistinct()];
@@ -238,6 +1302,35 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
238
1302
  /**
239
1303
  * Returns an array of [key, count] entries.
240
1304
  * @remarks Time O(n), Space O(n)
1305
+
1306
+
1307
+
1308
+
1309
+
1310
+
1311
+
1312
+
1313
+
1314
+
1315
+
1316
+
1317
+
1318
+
1319
+
1320
+
1321
+
1322
+
1323
+
1324
+
1325
+
1326
+
1327
+
1328
+ * @example
1329
+ * // Key-count pairs
1330
+ * const ms = new TreeMultiSet<number>();
1331
+ * ms.add(1, 2);
1332
+ * ms.add(3);
1333
+ * console.log(ms.toEntries()); // [[1, 2], [3, 1]];
241
1334
  */
242
1335
  toEntries(): Array<[K, number]> {
243
1336
  return [...this.entries()];
@@ -256,10 +1349,156 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
256
1349
  /**
257
1350
  * Remove all elements from the multiset.
258
1351
  * @remarks Time O(1), Space O(1)
259
- * @example
260
- * const ms = new TreeMultiSet([1, 2, 2, 3]);
261
- * ms.clear();
262
- * ms.size; // 0
1352
+
1353
+
1354
+
1355
+
1356
+
1357
+
1358
+
1359
+
1360
+
1361
+
1362
+
1363
+
1364
+
1365
+
1366
+
1367
+
1368
+
1369
+
1370
+
1371
+
1372
+
1373
+
1374
+
1375
+
1376
+
1377
+
1378
+
1379
+
1380
+
1381
+
1382
+
1383
+
1384
+
1385
+
1386
+
1387
+
1388
+
1389
+
1390
+
1391
+
1392
+
1393
+
1394
+
1395
+
1396
+
1397
+
1398
+
1399
+
1400
+
1401
+
1402
+
1403
+
1404
+
1405
+
1406
+
1407
+
1408
+
1409
+
1410
+
1411
+
1412
+
1413
+
1414
+
1415
+
1416
+
1417
+
1418
+
1419
+
1420
+
1421
+
1422
+
1423
+
1424
+
1425
+
1426
+
1427
+
1428
+
1429
+
1430
+
1431
+
1432
+
1433
+
1434
+
1435
+
1436
+
1437
+
1438
+
1439
+
1440
+
1441
+
1442
+
1443
+
1444
+
1445
+
1446
+
1447
+
1448
+
1449
+
1450
+
1451
+
1452
+
1453
+
1454
+
1455
+
1456
+
1457
+
1458
+
1459
+
1460
+
1461
+
1462
+
1463
+
1464
+
1465
+
1466
+
1467
+
1468
+
1469
+
1470
+
1471
+
1472
+
1473
+
1474
+
1475
+
1476
+
1477
+
1478
+
1479
+
1480
+
1481
+
1482
+
1483
+
1484
+
1485
+
1486
+
1487
+
1488
+
1489
+
1490
+
1491
+
1492
+
1493
+
1494
+
1495
+
1496
+ * @example
1497
+ * // Remove all
1498
+ * const ms = new TreeMultiSet<number>();
1499
+ * ms.add(1);
1500
+ * ms.clear();
1501
+ * console.log(ms.isEmpty()); // true;
263
1502
  */
264
1503
  clear(): void {
265
1504
  this.#core.clear();
@@ -271,9 +1510,36 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
271
1510
  /**
272
1511
  * Returns the smallest key, or undefined if empty.
273
1512
  * @remarks Time O(log n), Space O(1)
274
- * @example
275
- * const ms = new TreeMultiSet([3, 1, 4]);
276
- * ms.first(); // 1
1513
+
1514
+
1515
+
1516
+
1517
+
1518
+
1519
+
1520
+
1521
+
1522
+
1523
+
1524
+
1525
+
1526
+
1527
+
1528
+
1529
+
1530
+
1531
+
1532
+
1533
+
1534
+
1535
+
1536
+
1537
+ * @example
1538
+ * // Smallest element
1539
+ * const ms = new TreeMultiSet<number>();
1540
+ * ms.add(3);
1541
+ * ms.add(1);
1542
+ * console.log(ms.first()); // 1;
277
1543
  */
278
1544
  first(): K | undefined {
279
1545
  return this.#core.getLeftMost();
@@ -282,9 +1548,36 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
282
1548
  /**
283
1549
  * Returns the largest key, or undefined if empty.
284
1550
  * @remarks Time O(log n), Space O(1)
285
- * @example
286
- * const ms = new TreeMultiSet([3, 1, 4]);
287
- * ms.last(); // 4
1551
+
1552
+
1553
+
1554
+
1555
+
1556
+
1557
+
1558
+
1559
+
1560
+
1561
+
1562
+
1563
+
1564
+
1565
+
1566
+
1567
+
1568
+
1569
+
1570
+
1571
+
1572
+
1573
+
1574
+
1575
+ * @example
1576
+ * // Largest element
1577
+ * const ms = new TreeMultiSet<number>();
1578
+ * ms.add(1);
1579
+ * ms.add(3);
1580
+ * console.log(ms.last()); // 3;
288
1581
  */
289
1582
  last(): K | undefined {
290
1583
  return this.#core.getRightMost();
@@ -293,10 +1586,37 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
293
1586
  /**
294
1587
  * Removes all occurrences of the smallest key and returns it.
295
1588
  * @remarks Time O(log n), Space O(1)
296
- * @example
297
- * const ms = new TreeMultiSet([1, 1, 2, 3]);
298
- * ms.pollFirst(); // 1
299
- * ms.has(1); // false
1589
+
1590
+
1591
+
1592
+
1593
+
1594
+
1595
+
1596
+
1597
+
1598
+
1599
+
1600
+
1601
+
1602
+
1603
+
1604
+
1605
+
1606
+
1607
+
1608
+
1609
+
1610
+
1611
+
1612
+
1613
+ * @example
1614
+ * // Remove and return smallest
1615
+ * const ms = new TreeMultiSet<number>();
1616
+ * ms.add(2);
1617
+ * ms.add(1);
1618
+ * console.log(ms.pollFirst()); // 1;
1619
+ * console.log(ms.has(1)); // false;
300
1620
  */
301
1621
  pollFirst(): K | undefined {
302
1622
  const key = this.first();
@@ -308,10 +1628,36 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
308
1628
  /**
309
1629
  * Removes all occurrences of the largest key and returns it.
310
1630
  * @remarks Time O(log n), Space O(1)
311
- * @example
312
- * const ms = new TreeMultiSet([1, 2, 3, 3]);
313
- * ms.pollLast(); // 3
314
- * ms.has(3); // false
1631
+
1632
+
1633
+
1634
+
1635
+
1636
+
1637
+
1638
+
1639
+
1640
+
1641
+
1642
+
1643
+
1644
+
1645
+
1646
+
1647
+
1648
+
1649
+
1650
+
1651
+
1652
+
1653
+
1654
+
1655
+ * @example
1656
+ * // Remove and return largest
1657
+ * const ms = new TreeMultiSet<number>();
1658
+ * ms.add(1);
1659
+ * ms.add(3);
1660
+ * console.log(ms.pollLast()); // 3;
315
1661
  */
316
1662
  pollLast(): K | undefined {
317
1663
  const key = this.last();
@@ -323,10 +1669,127 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
323
1669
  /**
324
1670
  * Returns the smallest key >= given key, or undefined.
325
1671
  * @remarks Time O(log n), Space O(1)
326
- * @example
327
- * const ms = new TreeMultiSet([10, 20, 30]);
328
- * ms.ceiling(15); // 20
329
- * ms.ceiling(20); // 20
1672
+
1673
+
1674
+
1675
+
1676
+
1677
+
1678
+
1679
+
1680
+
1681
+
1682
+
1683
+
1684
+
1685
+
1686
+
1687
+
1688
+
1689
+
1690
+
1691
+
1692
+
1693
+
1694
+
1695
+
1696
+
1697
+
1698
+
1699
+
1700
+
1701
+
1702
+
1703
+
1704
+
1705
+
1706
+
1707
+
1708
+
1709
+
1710
+
1711
+
1712
+
1713
+
1714
+
1715
+
1716
+
1717
+
1718
+
1719
+
1720
+
1721
+
1722
+
1723
+
1724
+
1725
+
1726
+
1727
+
1728
+
1729
+
1730
+
1731
+
1732
+
1733
+
1734
+
1735
+
1736
+
1737
+
1738
+
1739
+
1740
+
1741
+
1742
+
1743
+
1744
+
1745
+
1746
+
1747
+
1748
+
1749
+
1750
+
1751
+
1752
+
1753
+
1754
+
1755
+
1756
+
1757
+
1758
+
1759
+
1760
+
1761
+
1762
+
1763
+
1764
+
1765
+
1766
+
1767
+
1768
+
1769
+
1770
+
1771
+
1772
+
1773
+
1774
+
1775
+
1776
+
1777
+
1778
+
1779
+
1780
+
1781
+
1782
+
1783
+
1784
+
1785
+
1786
+ * @example
1787
+ * // Least key ≥ target
1788
+ * const ms = new TreeMultiSet<number>();
1789
+ * ms.add(10);
1790
+ * ms.add(20);
1791
+ * ms.add(30);
1792
+ * console.log(ms.ceiling(15)); // 20;
330
1793
  */
331
1794
  ceiling(key: K): K | undefined {
332
1795
  this._validateKey(key);
@@ -336,10 +1799,127 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
336
1799
  /**
337
1800
  * Returns the largest key <= given key, or undefined.
338
1801
  * @remarks Time O(log n), Space O(1)
339
- * @example
340
- * const ms = new TreeMultiSet([10, 20, 30]);
341
- * ms.floor(25); // 20
342
- * ms.floor(20); // 20
1802
+
1803
+
1804
+
1805
+
1806
+
1807
+
1808
+
1809
+
1810
+
1811
+
1812
+
1813
+
1814
+
1815
+
1816
+
1817
+
1818
+
1819
+
1820
+
1821
+
1822
+
1823
+
1824
+
1825
+
1826
+
1827
+
1828
+
1829
+
1830
+
1831
+
1832
+
1833
+
1834
+
1835
+
1836
+
1837
+
1838
+
1839
+
1840
+
1841
+
1842
+
1843
+
1844
+
1845
+
1846
+
1847
+
1848
+
1849
+
1850
+
1851
+
1852
+
1853
+
1854
+
1855
+
1856
+
1857
+
1858
+
1859
+
1860
+
1861
+
1862
+
1863
+
1864
+
1865
+
1866
+
1867
+
1868
+
1869
+
1870
+
1871
+
1872
+
1873
+
1874
+
1875
+
1876
+
1877
+
1878
+
1879
+
1880
+
1881
+
1882
+
1883
+
1884
+
1885
+
1886
+
1887
+
1888
+
1889
+
1890
+
1891
+
1892
+
1893
+
1894
+
1895
+
1896
+
1897
+
1898
+
1899
+
1900
+
1901
+
1902
+
1903
+
1904
+
1905
+
1906
+
1907
+
1908
+
1909
+
1910
+
1911
+
1912
+
1913
+
1914
+
1915
+
1916
+ * @example
1917
+ * // Greatest key ≤ target
1918
+ * const ms = new TreeMultiSet<number>();
1919
+ * ms.add(10);
1920
+ * ms.add(20);
1921
+ * ms.add(30);
1922
+ * console.log(ms.floor(25)); // 20;
343
1923
  */
344
1924
  floor(key: K): K | undefined {
345
1925
  this._validateKey(key);
@@ -349,10 +1929,126 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
349
1929
  /**
350
1930
  * Returns the smallest key > given key, or undefined.
351
1931
  * @remarks Time O(log n), Space O(1)
352
- * @example
353
- * const ms = new TreeMultiSet([10, 20, 30]);
354
- * ms.higher(10); // 20
355
- * ms.higher(15); // 20
1932
+
1933
+
1934
+
1935
+
1936
+
1937
+
1938
+
1939
+
1940
+
1941
+
1942
+
1943
+
1944
+
1945
+
1946
+
1947
+
1948
+
1949
+
1950
+
1951
+
1952
+
1953
+
1954
+
1955
+
1956
+
1957
+
1958
+
1959
+
1960
+
1961
+
1962
+
1963
+
1964
+
1965
+
1966
+
1967
+
1968
+
1969
+
1970
+
1971
+
1972
+
1973
+
1974
+
1975
+
1976
+
1977
+
1978
+
1979
+
1980
+
1981
+
1982
+
1983
+
1984
+
1985
+
1986
+
1987
+
1988
+
1989
+
1990
+
1991
+
1992
+
1993
+
1994
+
1995
+
1996
+
1997
+
1998
+
1999
+
2000
+
2001
+
2002
+
2003
+
2004
+
2005
+
2006
+
2007
+
2008
+
2009
+
2010
+
2011
+
2012
+
2013
+
2014
+
2015
+
2016
+
2017
+
2018
+
2019
+
2020
+
2021
+
2022
+
2023
+
2024
+
2025
+
2026
+
2027
+
2028
+
2029
+
2030
+
2031
+
2032
+
2033
+
2034
+
2035
+
2036
+
2037
+
2038
+
2039
+
2040
+
2041
+
2042
+
2043
+
2044
+
2045
+
2046
+ * @example
2047
+ * // Least key > target
2048
+ * const ms = new TreeMultiSet<number>();
2049
+ * ms.add(10);
2050
+ * ms.add(20);
2051
+ * console.log(ms.higher(10)); // 20;
356
2052
  */
357
2053
  higher(key: K): K | undefined {
358
2054
  this._validateKey(key);
@@ -362,10 +2058,126 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
362
2058
  /**
363
2059
  * Returns the largest key < given key, or undefined.
364
2060
  * @remarks Time O(log n), Space O(1)
365
- * @example
366
- * const ms = new TreeMultiSet([10, 20, 30]);
367
- * ms.lower(20); // 10
368
- * ms.lower(15); // 10
2061
+
2062
+
2063
+
2064
+
2065
+
2066
+
2067
+
2068
+
2069
+
2070
+
2071
+
2072
+
2073
+
2074
+
2075
+
2076
+
2077
+
2078
+
2079
+
2080
+
2081
+
2082
+
2083
+
2084
+
2085
+
2086
+
2087
+
2088
+
2089
+
2090
+
2091
+
2092
+
2093
+
2094
+
2095
+
2096
+
2097
+
2098
+
2099
+
2100
+
2101
+
2102
+
2103
+
2104
+
2105
+
2106
+
2107
+
2108
+
2109
+
2110
+
2111
+
2112
+
2113
+
2114
+
2115
+
2116
+
2117
+
2118
+
2119
+
2120
+
2121
+
2122
+
2123
+
2124
+
2125
+
2126
+
2127
+
2128
+
2129
+
2130
+
2131
+
2132
+
2133
+
2134
+
2135
+
2136
+
2137
+
2138
+
2139
+
2140
+
2141
+
2142
+
2143
+
2144
+
2145
+
2146
+
2147
+
2148
+
2149
+
2150
+
2151
+
2152
+
2153
+
2154
+
2155
+
2156
+
2157
+
2158
+
2159
+
2160
+
2161
+
2162
+
2163
+
2164
+
2165
+
2166
+
2167
+
2168
+
2169
+
2170
+
2171
+
2172
+
2173
+
2174
+
2175
+ * @example
2176
+ * // Greatest key < target
2177
+ * const ms = new TreeMultiSet<number>();
2178
+ * ms.add(10);
2179
+ * ms.add(20);
2180
+ * console.log(ms.lower(20)); // 10;
369
2181
  */
370
2182
  lower(key: K): K | undefined {
371
2183
  this._validateKey(key);
@@ -377,10 +2189,158 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
377
2189
  /**
378
2190
  * Iterates over distinct keys with their counts.
379
2191
  * @remarks Time O(n), Space O(1)
380
- * @example
381
- * const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
382
- * ms.forEach((key, count) => console.log(`${key}: ${count}`));
383
- * // 1: 2, 2: 1, 3: 3
2192
+
2193
+
2194
+
2195
+
2196
+
2197
+
2198
+
2199
+
2200
+
2201
+
2202
+
2203
+
2204
+
2205
+
2206
+
2207
+
2208
+
2209
+
2210
+
2211
+
2212
+
2213
+
2214
+
2215
+
2216
+
2217
+
2218
+
2219
+
2220
+
2221
+
2222
+
2223
+
2224
+
2225
+
2226
+
2227
+
2228
+
2229
+
2230
+
2231
+
2232
+
2233
+
2234
+
2235
+
2236
+
2237
+
2238
+
2239
+
2240
+
2241
+
2242
+
2243
+
2244
+
2245
+
2246
+
2247
+
2248
+
2249
+
2250
+
2251
+
2252
+
2253
+
2254
+
2255
+
2256
+
2257
+
2258
+
2259
+
2260
+
2261
+
2262
+
2263
+
2264
+
2265
+
2266
+
2267
+
2268
+
2269
+
2270
+
2271
+
2272
+
2273
+
2274
+
2275
+
2276
+
2277
+
2278
+
2279
+
2280
+
2281
+
2282
+
2283
+
2284
+
2285
+
2286
+
2287
+
2288
+
2289
+
2290
+
2291
+
2292
+
2293
+
2294
+
2295
+
2296
+
2297
+
2298
+
2299
+
2300
+
2301
+
2302
+
2303
+
2304
+
2305
+
2306
+
2307
+
2308
+
2309
+
2310
+
2311
+
2312
+
2313
+
2314
+
2315
+
2316
+
2317
+
2318
+
2319
+
2320
+
2321
+
2322
+
2323
+
2324
+
2325
+
2326
+
2327
+
2328
+
2329
+
2330
+
2331
+
2332
+
2333
+
2334
+
2335
+
2336
+ * @example
2337
+ * // Iterate
2338
+ * const ms = new TreeMultiSet<number>();
2339
+ * ms.add(1, 2);
2340
+ * ms.add(2);
2341
+ * const pairs: [number, number][] = [];
2342
+ * ms.forEach((k, c) => pairs.push([k, c]));
2343
+ * console.log(pairs); // [[1, 2], [2, 1]];
384
2344
  */
385
2345
  forEach(callback: (key: K, count: number) => void): void {
386
2346
  for (const [k, c] of this.entries()) {
@@ -391,10 +2351,158 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
391
2351
  /**
392
2352
  * Creates a new TreeMultiSet with entries that match the predicate.
393
2353
  * @remarks Time O(n log n), Space O(n)
394
- * @example
395
- * const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
396
- * const filtered = ms.filter((key, count) => count >= 2);
397
- * // TreeMultiSet { 1: 2, 3: 3 }
2354
+
2355
+
2356
+
2357
+
2358
+
2359
+
2360
+
2361
+
2362
+
2363
+
2364
+
2365
+
2366
+
2367
+
2368
+
2369
+
2370
+
2371
+
2372
+
2373
+
2374
+
2375
+
2376
+
2377
+
2378
+
2379
+
2380
+
2381
+
2382
+
2383
+
2384
+
2385
+
2386
+
2387
+
2388
+
2389
+
2390
+
2391
+
2392
+
2393
+
2394
+
2395
+
2396
+
2397
+
2398
+
2399
+
2400
+
2401
+
2402
+
2403
+
2404
+
2405
+
2406
+
2407
+
2408
+
2409
+
2410
+
2411
+
2412
+
2413
+
2414
+
2415
+
2416
+
2417
+
2418
+
2419
+
2420
+
2421
+
2422
+
2423
+
2424
+
2425
+
2426
+
2427
+
2428
+
2429
+
2430
+
2431
+
2432
+
2433
+
2434
+
2435
+
2436
+
2437
+
2438
+
2439
+
2440
+
2441
+
2442
+
2443
+
2444
+
2445
+
2446
+
2447
+
2448
+
2449
+
2450
+
2451
+
2452
+
2453
+
2454
+
2455
+
2456
+
2457
+
2458
+
2459
+
2460
+
2461
+
2462
+
2463
+
2464
+
2465
+
2466
+
2467
+
2468
+
2469
+
2470
+
2471
+
2472
+
2473
+
2474
+
2475
+
2476
+
2477
+
2478
+
2479
+
2480
+
2481
+
2482
+
2483
+
2484
+
2485
+
2486
+
2487
+
2488
+
2489
+
2490
+
2491
+
2492
+
2493
+
2494
+
2495
+
2496
+
2497
+
2498
+ * @example
2499
+ * // Filter
2500
+ * const ms = new TreeMultiSet<number>();
2501
+ * ms.add(1, 3);
2502
+ * ms.add(2, 1);
2503
+ * ms.add(3, 2);
2504
+ * const filtered = ms.filter((k, c) => c > 1);
2505
+ * console.log([...filtered.keysDistinct()]); // [1, 3];
398
2506
  */
399
2507
  filter(predicate: (key: K, count: number) => boolean): TreeMultiSet<K> {
400
2508
  const result = new TreeMultiSet<K>([], {
@@ -412,9 +2520,157 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
412
2520
  /**
413
2521
  * Reduces the multiset to a single value.
414
2522
  * @remarks Time O(n), Space O(1)
415
- * @example
416
- * const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
417
- * const total = ms.reduce((acc, key, count) => acc + count, 0); // 6
2523
+
2524
+
2525
+
2526
+
2527
+
2528
+
2529
+
2530
+
2531
+
2532
+
2533
+
2534
+
2535
+
2536
+
2537
+
2538
+
2539
+
2540
+
2541
+
2542
+
2543
+
2544
+
2545
+
2546
+
2547
+
2548
+
2549
+
2550
+
2551
+
2552
+
2553
+
2554
+
2555
+
2556
+
2557
+
2558
+
2559
+
2560
+
2561
+
2562
+
2563
+
2564
+
2565
+
2566
+
2567
+
2568
+
2569
+
2570
+
2571
+
2572
+
2573
+
2574
+
2575
+
2576
+
2577
+
2578
+
2579
+
2580
+
2581
+
2582
+
2583
+
2584
+
2585
+
2586
+
2587
+
2588
+
2589
+
2590
+
2591
+
2592
+
2593
+
2594
+
2595
+
2596
+
2597
+
2598
+
2599
+
2600
+
2601
+
2602
+
2603
+
2604
+
2605
+
2606
+
2607
+
2608
+
2609
+
2610
+
2611
+
2612
+
2613
+
2614
+
2615
+
2616
+
2617
+
2618
+
2619
+
2620
+
2621
+
2622
+
2623
+
2624
+
2625
+
2626
+
2627
+
2628
+
2629
+
2630
+
2631
+
2632
+
2633
+
2634
+
2635
+
2636
+
2637
+
2638
+
2639
+
2640
+
2641
+
2642
+
2643
+
2644
+
2645
+
2646
+
2647
+
2648
+
2649
+
2650
+
2651
+
2652
+
2653
+
2654
+
2655
+
2656
+
2657
+
2658
+
2659
+
2660
+
2661
+
2662
+
2663
+
2664
+
2665
+
2666
+
2667
+ * @example
2668
+ * // Aggregate
2669
+ * const ms = new TreeMultiSet<number>();
2670
+ * ms.add(1, 2);
2671
+ * ms.add(2, 3);
2672
+ * const sum = ms.reduce((acc, k, c) => acc + k * c, 0);
2673
+ * console.log(sum); // 8;
418
2674
  */
419
2675
  reduce<U>(callback: (accumulator: U, key: K, count: number) => U, initialValue: U): U {
420
2676
  let acc = initialValue;
@@ -428,15 +2684,157 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
428
2684
  * Maps keys and counts to a new TreeMultiSet.
429
2685
  * When multiple keys map to the same new key, counts are merged (added).
430
2686
  * @remarks Time O(n log n), Space O(n)
431
- * @example
432
- * const ms = new TreeMultiSet([1, 1, 2, 3, 3, 3]);
433
- * const mapped = ms.map((key, count) => [key * 10, count]);
434
- * // TreeMultiSet { 10: 2, 20: 1, 30: 3 }
435
- * @example
436
- * // Collision: counts merge
437
- * const ms = new TreeMultiSet([1, 2, 3]);
438
- * const merged = ms.map((key, count) => [key % 2, count]);
439
- * // { 0: 1, 1: 2 } (1 and 3 both map to 1, counts add)
2687
+
2688
+
2689
+
2690
+
2691
+
2692
+
2693
+
2694
+
2695
+
2696
+
2697
+
2698
+
2699
+
2700
+
2701
+
2702
+
2703
+
2704
+
2705
+
2706
+
2707
+
2708
+
2709
+
2710
+
2711
+
2712
+
2713
+
2714
+
2715
+
2716
+
2717
+
2718
+
2719
+
2720
+
2721
+
2722
+
2723
+
2724
+
2725
+
2726
+
2727
+
2728
+
2729
+
2730
+
2731
+
2732
+
2733
+
2734
+
2735
+
2736
+
2737
+
2738
+
2739
+
2740
+
2741
+
2742
+
2743
+
2744
+
2745
+
2746
+
2747
+
2748
+
2749
+
2750
+
2751
+
2752
+
2753
+
2754
+
2755
+
2756
+
2757
+
2758
+
2759
+
2760
+
2761
+
2762
+
2763
+
2764
+
2765
+
2766
+
2767
+
2768
+
2769
+
2770
+
2771
+
2772
+
2773
+
2774
+
2775
+
2776
+
2777
+
2778
+
2779
+
2780
+
2781
+
2782
+
2783
+
2784
+
2785
+
2786
+
2787
+
2788
+
2789
+
2790
+
2791
+
2792
+
2793
+
2794
+
2795
+
2796
+
2797
+
2798
+
2799
+
2800
+
2801
+
2802
+
2803
+
2804
+
2805
+
2806
+
2807
+
2808
+
2809
+
2810
+
2811
+
2812
+
2813
+
2814
+
2815
+
2816
+
2817
+
2818
+
2819
+
2820
+
2821
+
2822
+
2823
+
2824
+
2825
+
2826
+
2827
+
2828
+
2829
+
2830
+
2831
+ * @example
2832
+ * // Transform
2833
+ * const ms = new TreeMultiSet<number>();
2834
+ * ms.add(1, 2);
2835
+ * ms.add(2, 3);
2836
+ * const doubled = ms.map((k, c) => [k * 10, c] as [number, number]);
2837
+ * console.log([...doubled.keysDistinct()]); // [10, 20];
440
2838
  */
441
2839
  map<K2>(
442
2840
  mapper: (key: K, count: number) => [K2, number],
@@ -456,11 +2854,157 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
456
2854
  /**
457
2855
  * Creates an independent copy of this multiset.
458
2856
  * @remarks Time O(n log n), Space O(n)
459
- * @example
460
- * const ms = new TreeMultiSet([1, 1, 2]);
461
- * const copy = ms.clone();
462
- * copy.add(3);
463
- * ms.has(3); // false (original unchanged)
2857
+
2858
+
2859
+
2860
+
2861
+
2862
+
2863
+
2864
+
2865
+
2866
+
2867
+
2868
+
2869
+
2870
+
2871
+
2872
+
2873
+
2874
+
2875
+
2876
+
2877
+
2878
+
2879
+
2880
+
2881
+
2882
+
2883
+
2884
+
2885
+
2886
+
2887
+
2888
+
2889
+
2890
+
2891
+
2892
+
2893
+
2894
+
2895
+
2896
+
2897
+
2898
+
2899
+
2900
+
2901
+
2902
+
2903
+
2904
+
2905
+
2906
+
2907
+
2908
+
2909
+
2910
+
2911
+
2912
+
2913
+
2914
+
2915
+
2916
+
2917
+
2918
+
2919
+
2920
+
2921
+
2922
+
2923
+
2924
+
2925
+
2926
+
2927
+
2928
+
2929
+
2930
+
2931
+
2932
+
2933
+
2934
+
2935
+
2936
+
2937
+
2938
+
2939
+
2940
+
2941
+
2942
+
2943
+
2944
+
2945
+
2946
+
2947
+
2948
+
2949
+
2950
+
2951
+
2952
+
2953
+
2954
+
2955
+
2956
+
2957
+
2958
+
2959
+
2960
+
2961
+
2962
+
2963
+
2964
+
2965
+
2966
+
2967
+
2968
+
2969
+
2970
+
2971
+
2972
+
2973
+
2974
+
2975
+
2976
+
2977
+
2978
+
2979
+
2980
+
2981
+
2982
+
2983
+
2984
+
2985
+
2986
+
2987
+
2988
+
2989
+
2990
+
2991
+
2992
+
2993
+
2994
+
2995
+
2996
+
2997
+
2998
+
2999
+
3000
+
3001
+ * @example
3002
+ * // Deep clone
3003
+ * const ms = new TreeMultiSet<number>();
3004
+ * ms.add(1, 3);
3005
+ * const copy = ms.clone();
3006
+ * copy.deleteAll(1);
3007
+ * console.log(ms.has(1)); // true;
464
3008
  */
465
3009
  clone(): TreeMultiSet<K> {
466
3010
  const result = new TreeMultiSet<K>([], {
@@ -478,9 +3022,128 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
478
3022
  /**
479
3023
  * Returns keys within the given range.
480
3024
  * @remarks Time O(log n + k), Space O(k) where k is result size
481
- * @example
482
- * const ms = new TreeMultiSet([10, 20, 30, 40, 50]);
483
- * ms.rangeSearch([15, 45]); // [20, 30, 40]
3025
+
3026
+
3027
+
3028
+
3029
+
3030
+
3031
+
3032
+
3033
+
3034
+
3035
+
3036
+
3037
+
3038
+
3039
+
3040
+
3041
+
3042
+
3043
+
3044
+
3045
+
3046
+
3047
+
3048
+
3049
+
3050
+
3051
+
3052
+
3053
+
3054
+
3055
+
3056
+
3057
+
3058
+
3059
+
3060
+
3061
+
3062
+
3063
+
3064
+
3065
+
3066
+
3067
+
3068
+
3069
+
3070
+
3071
+
3072
+
3073
+
3074
+
3075
+
3076
+
3077
+
3078
+
3079
+
3080
+
3081
+
3082
+
3083
+
3084
+
3085
+
3086
+
3087
+
3088
+
3089
+
3090
+
3091
+
3092
+
3093
+
3094
+
3095
+
3096
+
3097
+
3098
+
3099
+
3100
+
3101
+
3102
+
3103
+
3104
+
3105
+
3106
+
3107
+
3108
+
3109
+
3110
+
3111
+
3112
+
3113
+
3114
+
3115
+
3116
+
3117
+
3118
+
3119
+
3120
+
3121
+
3122
+
3123
+
3124
+
3125
+
3126
+
3127
+
3128
+
3129
+
3130
+
3131
+
3132
+
3133
+
3134
+
3135
+
3136
+
3137
+
3138
+
3139
+ * @example
3140
+ * // Find in range
3141
+ * const ms = new TreeMultiSet<number>();
3142
+ * ms.add(10);
3143
+ * ms.add(20);
3144
+ * ms.add(30);
3145
+ * const result = ms.rangeSearch([15, 25]);
3146
+ * console.log(result.length); // 1;
484
3147
  */
485
3148
  rangeSearch<C extends (key: K) => any>(
486
3149
  range: [K, K],
@@ -493,9 +3156,155 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
493
3156
  /**
494
3157
  * Prints the internal tree structure (for debugging).
495
3158
  * @remarks Time O(n), Space O(n)
496
- * @example
497
- * const ms = new TreeMultiSet([1, 2, 3]);
498
- * ms.print();
3159
+
3160
+
3161
+
3162
+
3163
+
3164
+
3165
+
3166
+
3167
+
3168
+
3169
+
3170
+
3171
+
3172
+
3173
+
3174
+
3175
+
3176
+
3177
+
3178
+
3179
+
3180
+
3181
+
3182
+
3183
+
3184
+
3185
+
3186
+
3187
+
3188
+
3189
+
3190
+
3191
+
3192
+
3193
+
3194
+
3195
+
3196
+
3197
+
3198
+
3199
+
3200
+
3201
+
3202
+
3203
+
3204
+
3205
+
3206
+
3207
+
3208
+
3209
+
3210
+
3211
+
3212
+
3213
+
3214
+
3215
+
3216
+
3217
+
3218
+
3219
+
3220
+
3221
+
3222
+
3223
+
3224
+
3225
+
3226
+
3227
+
3228
+
3229
+
3230
+
3231
+
3232
+
3233
+
3234
+
3235
+
3236
+
3237
+
3238
+
3239
+
3240
+
3241
+
3242
+
3243
+
3244
+
3245
+
3246
+
3247
+
3248
+
3249
+
3250
+
3251
+
3252
+
3253
+
3254
+
3255
+
3256
+
3257
+
3258
+
3259
+
3260
+
3261
+
3262
+
3263
+
3264
+
3265
+
3266
+
3267
+
3268
+
3269
+
3270
+
3271
+
3272
+
3273
+
3274
+
3275
+
3276
+
3277
+
3278
+
3279
+
3280
+
3281
+
3282
+
3283
+
3284
+
3285
+
3286
+
3287
+
3288
+
3289
+
3290
+
3291
+
3292
+
3293
+
3294
+
3295
+
3296
+
3297
+
3298
+
3299
+
3300
+
3301
+
3302
+
3303
+ * @example
3304
+ * // Display
3305
+ * const ms = new TreeMultiSet<number>();
3306
+ * ms.add(1);
3307
+ * expect(() => ms.print()).not.toThrow();
499
3308
  */
500
3309
  print(): void {
501
3310
  this.#core.print();