max-priority-queue-typed 2.4.4 → 2.5.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 (85) hide show
  1. package/README.md +63 -0
  2. package/dist/cjs/index.cjs +403 -98
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +402 -97
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +403 -99
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +402 -98
  9. package/dist/esm-legacy/index.mjs.map +1 -1
  10. package/dist/types/common/error.d.ts +23 -0
  11. package/dist/types/common/index.d.ts +1 -0
  12. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  13. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +128 -51
  14. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +210 -164
  15. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +439 -78
  16. package/dist/types/data-structures/binary-tree/bst.d.ts +311 -28
  17. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +217 -31
  18. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +218 -152
  19. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1281 -5
  20. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1087 -201
  21. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +858 -65
  22. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1133 -5
  23. package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -0
  24. package/dist/types/data-structures/graph/directed-graph.d.ts +220 -47
  25. package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
  26. package/dist/types/data-structures/graph/undirected-graph.d.ts +218 -59
  27. package/dist/types/data-structures/hash/hash-map.d.ts +230 -77
  28. package/dist/types/data-structures/heap/heap.d.ts +287 -99
  29. package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
  30. package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
  31. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +286 -44
  32. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +278 -65
  33. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +415 -12
  34. package/dist/types/data-structures/matrix/matrix.d.ts +331 -0
  35. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
  36. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
  37. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
  38. package/dist/types/data-structures/queue/deque.d.ts +313 -66
  39. package/dist/types/data-structures/queue/queue.d.ts +211 -42
  40. package/dist/types/data-structures/stack/stack.d.ts +174 -32
  41. package/dist/types/data-structures/trie/trie.d.ts +213 -43
  42. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
  43. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
  44. package/dist/types/types/data-structures/queue/deque.d.ts +6 -0
  45. package/dist/umd/max-priority-queue-typed.js +400 -95
  46. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  47. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  48. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  49. package/package.json +2 -2
  50. package/src/common/error.ts +60 -0
  51. package/src/common/index.ts +2 -0
  52. package/src/data-structures/base/iterable-element-base.ts +2 -2
  53. package/src/data-structures/binary-tree/avl-tree.ts +134 -51
  54. package/src/data-structures/binary-tree/binary-indexed-tree.ts +303 -247
  55. package/src/data-structures/binary-tree/binary-tree.ts +542 -121
  56. package/src/data-structures/binary-tree/bst.ts +346 -37
  57. package/src/data-structures/binary-tree/red-black-tree.ts +309 -96
  58. package/src/data-structures/binary-tree/segment-tree.ts +372 -248
  59. package/src/data-structures/binary-tree/tree-map.ts +1292 -13
  60. package/src/data-structures/binary-tree/tree-multi-map.ts +1098 -215
  61. package/src/data-structures/binary-tree/tree-multi-set.ts +863 -69
  62. package/src/data-structures/binary-tree/tree-set.ts +1143 -15
  63. package/src/data-structures/graph/abstract-graph.ts +106 -1
  64. package/src/data-structures/graph/directed-graph.ts +223 -47
  65. package/src/data-structures/graph/map-graph.ts +59 -1
  66. package/src/data-structures/graph/undirected-graph.ts +299 -59
  67. package/src/data-structures/hash/hash-map.ts +243 -79
  68. package/src/data-structures/heap/heap.ts +291 -102
  69. package/src/data-structures/heap/max-heap.ts +48 -3
  70. package/src/data-structures/heap/min-heap.ts +59 -0
  71. package/src/data-structures/linked-list/doubly-linked-list.ts +286 -44
  72. package/src/data-structures/linked-list/singly-linked-list.ts +278 -65
  73. package/src/data-structures/linked-list/skip-linked-list.ts +689 -90
  74. package/src/data-structures/matrix/matrix.ts +425 -22
  75. package/src/data-structures/priority-queue/max-priority-queue.ts +59 -3
  76. package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
  77. package/src/data-structures/priority-queue/priority-queue.ts +60 -0
  78. package/src/data-structures/queue/deque.ts +343 -68
  79. package/src/data-structures/queue/queue.ts +211 -42
  80. package/src/data-structures/stack/stack.ts +174 -32
  81. package/src/data-structures/trie/trie.ts +215 -44
  82. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
  83. package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
  84. package/src/types/data-structures/queue/deque.ts +7 -0
  85. package/src/utils/utils.ts +4 -2
@@ -13,6 +13,11 @@ import type { TreeSetElementCallback, TreeSetOptions, TreeSetRangeOptions, TreeS
13
13
  *
14
14
  * - Iteration order is ascending by key.
15
15
  * - No node exposure: all APIs use keys only.
16
+ * @example
17
+ * // Set multiple key-value pairs
18
+ * const ts = new TreeSet<number, string>();
19
+ * ts.setMany([[1, 'a'], [2, 'b'], [3, 'c']]);
20
+ * console.log(ts.size); // 3;
16
21
  */
17
22
  export declare class TreeSet<K = any, R = K> implements Iterable<K> {
18
23
  #private;
@@ -49,43 +54,416 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
49
54
  get size(): number;
50
55
  /**
51
56
  * Whether the set is empty.
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+ * @example
96
+ * // Check empty
97
+ * console.log(new TreeSet().isEmpty()); // true;
52
98
  */
53
99
  isEmpty(): boolean;
54
100
  private _validateKey;
55
101
  /**
56
102
  * Add a key to the set (no-op if already present).
57
103
  * @remarks Expected time O(log n)
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ * @example
146
+ * // Unique tags with sorted order
147
+ * const tags = new TreeSet<string>(['javascript', 'typescript', 'react', 'typescript', 'node']);
148
+ *
149
+ * // Duplicates removed, sorted alphabetically
150
+ * console.log([...tags]); // ['javascript', 'node', 'react', 'typescript'];
151
+ * console.log(tags.size); // 4;
152
+ *
153
+ * tags.add('angular');
154
+ * console.log(tags.first()); // 'angular';
155
+ * console.log(tags.last()); // 'typescript';
58
156
  */
59
157
  add(key: K): this;
60
158
  /**
61
159
  * Test whether a key exists.
62
160
  * @remarks Expected time O(log n)
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
+ * @example
211
+ * // Checking membership in a sorted collection
212
+ * const allowed = new TreeSet<string>(['admin', 'editor', 'viewer']);
213
+ *
214
+ * console.log(allowed.has('admin')); // true;
215
+ * console.log(allowed.has('guest')); // false;
63
216
  */
64
217
  has(key: K): boolean;
65
218
  /**
66
219
  * Delete a key.
67
220
  * @returns `true` if the key existed; otherwise `false`.
68
221
  * @remarks Expected time O(log n)
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
+
268
+
269
+
270
+
271
+ * @example
272
+ * // Removing elements while maintaining order
273
+ * const nums = new TreeSet<number>([1, 3, 5, 7, 9]);
274
+ *
275
+ * console.log(nums.delete(5)); // true;
276
+ * console.log(nums.delete(5)); // false; // already gone
277
+ * console.log([...nums]); // [1, 3, 7, 9];
69
278
  */
70
279
  delete(key: K): boolean;
71
280
  /**
72
281
  * Remove all keys.
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
+ * @example
321
+ * // Remove all
322
+ * const ts = new TreeSet<number>([1, 2]);
323
+ * ts.clear();
324
+ * console.log(ts.isEmpty()); // true;
73
325
  */
74
326
  clear(): void;
75
327
  /**
76
328
  * Iterate over keys in ascending order.
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
+ * @example
368
+ * // Get sorted keys
369
+ * const ts = new TreeSet<number>([30, 10, 20]);
370
+ * console.log([...ts.keys()]); // [10, 20, 30];
77
371
  */
78
372
  keys(): IterableIterator<K>;
79
373
  /**
80
374
  * Iterate over values in ascending order.
81
375
  *
82
376
  * Note: for Set-like containers, `values()` is the same as `keys()`.
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
+ * @example
416
+ * // Get values (same as keys for Set)
417
+ * const ts = new TreeSet<number>([2, 1, 3]);
418
+ * console.log([...ts.values()]); // [1, 2, 3];
83
419
  */
84
420
  values(): IterableIterator<K>;
85
421
  /**
86
422
  * Iterate over `[value, value]` pairs (native Set convention).
87
423
  *
88
424
  * Note: TreeSet stores only keys internally; `[k, k]` is created on-the-fly during iteration.
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+ * @example
464
+ * // Iterate entries
465
+ * const ts = new TreeSet<number>([3, 1, 2]);
466
+ * console.log([...ts.entries()].map(([k]) => k)); // [1, 2, 3];
89
467
  */
90
468
  entries(): IterableIterator<[K, K]>;
91
469
  [Symbol.iterator](): IterableIterator<K>;
@@ -93,6 +471,50 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
93
471
  * Visit each value in ascending order.
94
472
  *
95
473
  * Callback follows native Set convention: `(value, value2, set)`.
474
+
475
+
476
+
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
+ * @example
513
+ * // Execute for each
514
+ * const ts = new TreeSet<number>([3, 1, 2]);
515
+ * const keys: number[] = [];
516
+ * ts.forEach(k => keys.push(k));
517
+ * console.log(keys); // [1, 2, 3];
96
518
  */
97
519
  forEach(cb: (value: K, value2: K, set: TreeSet<K>) => void, thisArg?: any): void;
98
520
  /**
@@ -100,6 +522,49 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
100
522
  *
101
523
  * This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
102
524
  * @remarks Time O(n log n) expected, Space O(n)
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
+ * @example
564
+ * // Transform
565
+ * const ts = new TreeSet<number>([1, 2, 3]);
566
+ * const doubled = ts.map(k => k * 2);
567
+ * console.log([...doubled]); // [2, 4, 6];
103
568
  */
104
569
  map<MK>(callbackfn: TreeSetElementCallback<K, MK, TreeSet<K>>, options?: Omit<TreeSetOptions<MK>, 'toElementFn'> & {
105
570
  comparator?: (a: MK, b: MK) => number;
@@ -107,68 +572,636 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
107
572
  /**
108
573
  * Create a new TreeSet containing only values that satisfy the predicate.
109
574
  * @remarks Time O(n log n) expected, Space O(n)
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
+ * @example
614
+ * // Filter
615
+ * const ts = new TreeSet<number>([1, 2, 3, 4, 5]);
616
+ * const evens = ts.filter(k => k % 2 === 0);
617
+ * console.log([...evens]); // [2, 4];
110
618
  */
111
619
  filter(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): TreeSet<K>;
112
620
  /**
113
621
  * Reduce values into a single accumulator.
114
622
  * @remarks Time O(n), Space O(1)
623
+
624
+
625
+
626
+
627
+
628
+
629
+
630
+
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+ * @example
662
+ * // Aggregate
663
+ * const ts = new TreeSet<number>([1, 2, 3]);
664
+ * const sum = ts.reduce((acc, k) => acc + k, 0);
665
+ * console.log(sum); // 6;
115
666
  */
116
667
  reduce<A>(callbackfn: TreeSetReduceCallback<K, A, TreeSet<K>>, initialValue: A): A;
117
668
  /**
118
669
  * Test whether all values satisfy a predicate.
119
670
  * @remarks Time O(n), Space O(1)
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+
684
+
685
+
686
+
687
+
688
+
689
+
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+ * @example
708
+ * // Test all
709
+ * const ts = new TreeSet<number>([2, 4, 6]);
710
+ * console.log(ts.every(k => k > 0)); // true;
120
711
  */
121
712
  every(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): boolean;
122
713
  /**
123
714
  * Test whether any value satisfies a predicate.
124
715
  * @remarks Time O(n), Space O(1)
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
+ * @example
753
+ * // Test any
754
+ * const ts = new TreeSet<number>([1, 3, 5]);
755
+ * console.log(ts.some(k => k === 3)); // true;
125
756
  */
126
757
  some(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): boolean;
127
758
  /**
128
759
  * Find the first value that satisfies a predicate.
129
760
  * @remarks Time O(n), Space O(1)
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
+ * @example
798
+ * // Find entry
799
+ * const ts = new TreeSet<number>([1, 2, 3]);
800
+ * const found = ts.find(k => k === 2);
801
+ * console.log(found); // 2;
130
802
  */
131
803
  find(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): K | undefined;
132
804
  /**
133
805
  * Materialize the set into an array of keys.
134
806
  * @remarks Time O(n), Space O(n)
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
+
836
+
837
+
838
+
839
+
840
+
841
+
842
+
843
+
844
+
845
+ * @example
846
+ * // Convert to array
847
+ * const ts = new TreeSet<number>([3, 1, 2]);
848
+ * console.log(ts.toArray()); // [1, 2, 3];
135
849
  */
136
850
  toArray(): K[];
137
851
  /**
138
852
  * Print a human-friendly representation.
139
853
  * @remarks Time O(n), Space O(n)
854
+
855
+
856
+
857
+
858
+
859
+
860
+
861
+
862
+
863
+
864
+
865
+
866
+
867
+
868
+
869
+
870
+
871
+
872
+
873
+
874
+
875
+
876
+
877
+
878
+
879
+
880
+
881
+
882
+
883
+
884
+
885
+
886
+
887
+
888
+
889
+
890
+
891
+
892
+ * @example
893
+ * // Display tree
894
+ * const ts = new TreeSet<number>([1, 2, 3]);
895
+ * expect(() => ts.print()).not.toThrow();
140
896
  */
141
897
  print(): void;
142
898
  /**
143
899
  * Smallest key in the set.
900
+
901
+
902
+
903
+
904
+
905
+
906
+
907
+
908
+
909
+
910
+
911
+ * @example
912
+ * // Student grade ranking with custom comparator
913
+ * interface Student {
914
+ * name: string;
915
+ * gpa: number;
916
+ * }
917
+ *
918
+ * const ranking = new TreeSet<Student>(
919
+ * [
920
+ * { name: 'Alice', gpa: 3.8 },
921
+ * { name: 'Bob', gpa: 3.5 },
922
+ * { name: 'Charlie', gpa: 3.9 },
923
+ * { name: 'Diana', gpa: 3.5 }
924
+ * ],
925
+ * { comparator: (a, b) => b.gpa - a.gpa || a.name.localeCompare(b.name) }
926
+ * );
927
+ *
928
+ * // Sorted by GPA descending, then name ascending
929
+ * const names = [...ranking].map(s => s.name);
930
+ * console.log(names); // ['Charlie', 'Alice', 'Bob', 'Diana'];
931
+ *
932
+ * // Top student
933
+ * console.log(ranking.first()?.name); // 'Charlie';
934
+ *
935
+ * // Filter students with GPA >= 3.8
936
+ * const honors = ranking.filter(s => s.gpa >= 3.8);
937
+ * console.log(honors.toArray().map(s => s.name)); // ['Charlie', 'Alice'];
144
938
  */
145
939
  first(): K | undefined;
146
940
  /**
147
941
  * Largest key in the set.
942
+
943
+
944
+
945
+
946
+
947
+
948
+
949
+
950
+
951
+
952
+
953
+ * @example
954
+ * // Get the maximum element
955
+ * const temps = new TreeSet<number>([18, 22, 15, 30, 25]);
956
+ * console.log(temps.last()); // 30;
957
+ * console.log(temps.first()); // 15;
148
958
  */
149
959
  last(): K | undefined;
150
960
  /**
151
961
  * Remove and return the smallest key.
962
+
963
+
964
+
965
+
966
+
967
+
968
+
969
+
970
+
971
+
972
+
973
+ * @example
974
+ * // Remove and return minimum
975
+ * const queue = new TreeSet<number>([5, 1, 8, 3]);
976
+ *
977
+ * console.log(queue.pollFirst()); // 1;
978
+ * console.log(queue.pollFirst()); // 3;
979
+ * console.log(queue.size); // 2;
152
980
  */
153
981
  pollFirst(): K | undefined;
154
982
  /**
155
983
  * Remove and return the largest key.
984
+
985
+
986
+
987
+
988
+
989
+
990
+
991
+
992
+
993
+
994
+
995
+ * @example
996
+ * // Remove and return maximum
997
+ * const stack = new TreeSet<number>([10, 20, 30]);
998
+ *
999
+ * console.log(stack.pollLast()); // 30;
1000
+ * console.log(stack.size); // 2;
156
1001
  */
157
1002
  pollLast(): K | undefined;
158
1003
  /**
159
1004
  * Smallest key that is >= the given key.
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
+ * @example
1044
+ * // Finding nearest available time slot
1045
+ * // Available appointment times (minutes from midnight)
1046
+ * const slots = new TreeSet<number>([540, 600, 660, 720, 840, 900]);
1047
+ *
1048
+ * // Customer wants something around 10:30 (630 min)
1049
+ * const nearest = slots.ceiling(630);
1050
+ * console.log(nearest); // 660; // 11:00 AM
1051
+ *
1052
+ * // What's the latest slot before 2:00 PM (840)?
1053
+ * const before2pm = slots.lower(840);
1054
+ * console.log(before2pm); // 720; // 12:00 PM
1055
+ *
1056
+ * // Book the 11:00 slot
1057
+ * slots.delete(660);
1058
+ * console.log(slots.ceiling(630)); // 720;
160
1059
  */
161
1060
  ceiling(key: K): K | undefined;
162
1061
  /**
163
1062
  * Largest key that is <= the given key.
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+
1070
+
1071
+
1072
+
1073
+
1074
+
1075
+
1076
+
1077
+
1078
+
1079
+
1080
+
1081
+
1082
+
1083
+
1084
+
1085
+
1086
+
1087
+
1088
+
1089
+
1090
+
1091
+
1092
+
1093
+
1094
+
1095
+
1096
+
1097
+
1098
+
1099
+
1100
+
1101
+ * @example
1102
+ * // Largest element ≤ target
1103
+ * const breakpoints = new TreeSet<number>([320, 768, 1024, 1280, 1920]);
1104
+ *
1105
+ * // Current width is 800 → which breakpoint applies?
1106
+ * console.log(breakpoints.floor(800)); // 768;
1107
+ * console.log(breakpoints.floor(1024)); // 1024; // exact match
1108
+ * console.log(breakpoints.floor(100)); // undefined;
164
1109
  */
165
1110
  floor(key: K): K | undefined;
166
1111
  /**
167
1112
  * Smallest key that is > the given key.
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
+ * @example
1152
+ * // Smallest element strictly > target
1153
+ * const levels = new TreeSet<number>([1, 5, 10, 25, 50, 100]);
1154
+ *
1155
+ * console.log(levels.higher(10)); // 25;
1156
+ * console.log(levels.higher(100)); // undefined;
168
1157
  */
169
1158
  higher(key: K): K | undefined;
170
1159
  /**
171
1160
  * Largest key that is < the given key.
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
+ * @example
1200
+ * // Largest element strictly < target
1201
+ * const tiers = new TreeSet<number>([100, 200, 500, 1000]);
1202
+ *
1203
+ * console.log(tiers.lower(500)); // 200;
1204
+ * console.log(tiers.lower(100)); // undefined;
172
1205
  */
173
1206
  lower(key: K): K | undefined;
174
1207
  /**
@@ -176,16 +1209,111 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
176
1209
  *
177
1210
  * @param range `[low, high]`
178
1211
  * @param options Inclusive/exclusive bounds (defaults to inclusive).
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
+ * @example
1251
+ * // IP address blocklist with range checking
1252
+ * // Simplified: use numeric IP representation
1253
+ * const blocklist = new TreeSet<number>([
1254
+ * 167772160, // 10.0.0.0
1255
+ * 167772416, // 10.0.1.0
1256
+ * 167772672, // 10.0.2.0
1257
+ * 167773184 // 10.0.4.0
1258
+ * ]);
1259
+ *
1260
+ * // Check if any blocked IP is in range 10.0.1.0 - 10.0.3.0
1261
+ * const inRange = blocklist.rangeSearch([167772416, 167772928]);
1262
+ * console.log(inRange); // [167772416, 167772672];
1263
+ *
1264
+ * // Quick membership check
1265
+ * console.log(blocklist.has(167772416)); // true;
1266
+ * console.log(blocklist.has(167772800)); // false;
179
1267
  */
180
1268
  rangeSearch(range: [K, K], options?: TreeSetRangeOptions): K[];
181
1269
  /**
182
1270
  * Creates a shallow clone of this set.
183
1271
  * @remarks Time O(n log n), Space O(n)
184
- * @example
185
- * const original = new TreeSet([1, 2, 3]);
186
- * const copy = original.clone();
187
- * copy.add(4);
188
- * original.has(4); // false (original unchanged)
1272
+
1273
+
1274
+
1275
+
1276
+
1277
+
1278
+
1279
+
1280
+
1281
+
1282
+
1283
+
1284
+
1285
+
1286
+
1287
+
1288
+
1289
+
1290
+
1291
+
1292
+
1293
+
1294
+
1295
+
1296
+
1297
+
1298
+
1299
+
1300
+
1301
+
1302
+
1303
+
1304
+
1305
+
1306
+
1307
+
1308
+
1309
+
1310
+
1311
+ * @example
1312
+ * // Deep clone
1313
+ * const ts = new TreeSet<number>([1, 2, 3]);
1314
+ * const copy = ts.clone();
1315
+ * copy.delete(1);
1316
+ * console.log(ts.has(1)); // true;
189
1317
  */
190
1318
  clone(): TreeSet<K>;
191
1319
  }