binary-tree-typed 2.5.0 → 2.5.2
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.
- package/dist/cjs/index.cjs +771 -68
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +771 -68
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +771 -69
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +771 -69
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/binary-tree-typed.js +773 -71
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +5 -5
- package/dist/umd/binary-tree-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +299 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
- package/src/data-structures/binary-tree/binary-tree.ts +606 -6
- package/src/data-structures/binary-tree/bst.ts +946 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
- package/src/data-structures/binary-tree/segment-tree.ts +145 -2
- package/src/data-structures/binary-tree/tree-map.ts +3423 -499
- package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
- package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
- package/src/data-structures/binary-tree/tree-set.ts +3209 -413
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +240 -0
- package/src/data-structures/graph/undirected-graph.ts +216 -0
- package/src/data-structures/hash/hash-map.ts +281 -19
- package/src/data-structures/heap/heap.ts +340 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
- package/src/data-structures/matrix/matrix.ts +202 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +365 -5
- package/src/data-structures/queue/queue.ts +288 -0
- package/src/data-structures/stack/stack.ts +240 -0
- package/src/data-structures/trie/trie.ts +295 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -254,6 +254,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
254
254
|
*/
|
|
255
255
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | BSTNode | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BSTOptions<K, V, R>);
|
|
256
256
|
protected _root?: BSTNode<K, V>;
|
|
257
|
+
protected _enableOrderStatistic: boolean;
|
|
257
258
|
/**
|
|
258
259
|
* Gets the root node of the tree.
|
|
259
260
|
* @remarks Time O(1)
|
|
@@ -307,7 +308,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
307
308
|
* @param key - The key to validate.
|
|
308
309
|
* @returns True if the key is valid, false otherwise.
|
|
309
310
|
*/
|
|
310
|
-
isValidKey(key:
|
|
311
|
+
isValidKey(key: unknown): key is K;
|
|
311
312
|
/**
|
|
312
313
|
* Depth-first search traversal
|
|
313
314
|
|
|
@@ -330,6 +331,54 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
330
331
|
|
|
331
332
|
|
|
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
|
+
|
|
333
382
|
|
|
334
383
|
|
|
335
384
|
* @example
|
|
@@ -356,6 +405,54 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
356
405
|
|
|
357
406
|
|
|
358
407
|
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
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
|
+
|
|
359
456
|
* @example
|
|
360
457
|
* // Breadth-first traversal
|
|
361
458
|
* const bst = new BST<number>([5, 3, 7]);
|
|
@@ -383,6 +480,54 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
383
480
|
|
|
384
481
|
|
|
385
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
|
+
|
|
386
531
|
* @example
|
|
387
532
|
* // Level-order grouping
|
|
388
533
|
* const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
@@ -421,6 +566,54 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
421
566
|
|
|
422
567
|
|
|
423
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
|
+
|
|
615
|
+
|
|
616
|
+
|
|
424
617
|
* @example
|
|
425
618
|
* // Get node object by key
|
|
426
619
|
* const bst = new BST<number, string>([[5, 'root'], [3, 'left'], [7, 'right']]);
|
|
@@ -443,6 +636,54 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
443
636
|
|
|
444
637
|
|
|
445
638
|
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
446
687
|
* @example
|
|
447
688
|
* // Search nodes by predicate
|
|
448
689
|
* const bst = new BST<number, string>([[1, 'a'], [2, 'b'], [3, 'c'], [4, 'd']]);
|
|
@@ -464,6 +705,30 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
464
705
|
|
|
465
706
|
|
|
466
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
|
+
|
|
467
732
|
* @example
|
|
468
733
|
* // Find all keys in a range
|
|
469
734
|
* const bst = new BST<number>([10, 20, 30, 40, 50]);
|
|
@@ -471,6 +736,69 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
471
736
|
*/
|
|
472
737
|
rangeSearch(range: Range<K> | [K, K]): (K | undefined)[];
|
|
473
738
|
rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
739
|
+
/**
|
|
740
|
+
* Returns the element at the k-th position in tree order (0-indexed).
|
|
741
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
742
|
+
* Tree order is defined by the comparator — ascending by default, but respects custom comparators (e.g. descending).
|
|
743
|
+
*
|
|
744
|
+
* @param k - The 0-based position in tree order (0 = first element).
|
|
745
|
+
* @returns The key at position k, or `undefined` if out of bounds.
|
|
746
|
+
* @example
|
|
747
|
+
* // Order-statistic on BST
|
|
748
|
+
* const tree = new BST<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
749
|
+
* console.log(tree.getByRank(0)); // 10;
|
|
750
|
+
* console.log(tree.getByRank(4)); // 50;
|
|
751
|
+
* console.log(tree.getRank(30)); // 2;
|
|
752
|
+
*/
|
|
753
|
+
getByRank(k: number): K | undefined;
|
|
754
|
+
/**
|
|
755
|
+
* Returns the element at the k-th position in tree order and applies a callback.
|
|
756
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
757
|
+
*
|
|
758
|
+
* @param k - The 0-based position in tree order (0 = first element).
|
|
759
|
+
* @param callback - Callback to apply to the found node.
|
|
760
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
761
|
+
* @returns The callback result, or `undefined` if out of bounds.
|
|
762
|
+
*/
|
|
763
|
+
getByRank<C extends NodeCallback<BSTNode<K, V>>>(k: number, callback: C, iterationType?: IterationType): ReturnType<C> | undefined;
|
|
764
|
+
/**
|
|
765
|
+
* Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
766
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
767
|
+
* Tree order is defined by the comparator. When the key is not found, returns the insertion position.
|
|
768
|
+
*
|
|
769
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry `[K, V]`, or predicate to find.
|
|
770
|
+
* @returns The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
771
|
+
*/
|
|
772
|
+
getRank(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): number;
|
|
773
|
+
/**
|
|
774
|
+
* Returns the 0-based rank (number of preceding elements in tree order) with explicit iteration type.
|
|
775
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
776
|
+
*
|
|
777
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate to find.
|
|
778
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
779
|
+
* @returns The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
780
|
+
*/
|
|
781
|
+
getRank(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, iterationType: IterationType): number;
|
|
782
|
+
/**
|
|
783
|
+
* Returns elements by position range in tree order (0-indexed, inclusive on both ends).
|
|
784
|
+
* @remarks Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
785
|
+
*
|
|
786
|
+
* @param start - Start position (inclusive, 0-indexed). Clamped to 0 if negative.
|
|
787
|
+
* @param end - End position (inclusive, 0-indexed). Clamped to size-1 if too large.
|
|
788
|
+
* @returns Array of keys in tree order within the specified range.
|
|
789
|
+
*/
|
|
790
|
+
rangeByRank(start: number, end: number): (K | undefined)[];
|
|
791
|
+
/**
|
|
792
|
+
* Returns elements by position range in tree order with callback and optional iteration type.
|
|
793
|
+
* @remarks Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
794
|
+
*
|
|
795
|
+
* @param start - Start rank (inclusive, 0-indexed).
|
|
796
|
+
* @param end - End rank (inclusive, 0-indexed).
|
|
797
|
+
* @param callback - Callback to apply to each node in the range.
|
|
798
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
799
|
+
* @returns Array of callback results for nodes in the rank range.
|
|
800
|
+
*/
|
|
801
|
+
rangeByRank<C extends NodeCallback<BSTNode<K, V>>>(start: number, end: number, callback: C, iterationType?: IterationType): ReturnType<C>[];
|
|
474
802
|
/**
|
|
475
803
|
* Adds a new node to the BST based on key comparison.
|
|
476
804
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -498,6 +826,78 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
498
826
|
|
|
499
827
|
|
|
500
828
|
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
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
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
501
901
|
|
|
502
902
|
|
|
503
903
|
|
|
@@ -533,6 +933,54 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
533
933
|
|
|
534
934
|
|
|
535
935
|
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
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
|
+
|
|
536
984
|
* @example
|
|
537
985
|
* // Set multiple key-value pairs
|
|
538
986
|
* const bst = new BST<number, string>();
|
|
@@ -557,6 +1005,30 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
557
1005
|
|
|
558
1006
|
|
|
559
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
|
+
|
|
560
1032
|
* @example
|
|
561
1033
|
* // Find the least key ≥ target
|
|
562
1034
|
* const bst = new BST<number>([10, 20, 30, 40, 50]);
|
|
@@ -587,6 +1059,30 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
587
1059
|
|
|
588
1060
|
|
|
589
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
|
+
|
|
590
1086
|
* @example
|
|
591
1087
|
* // Find the least key strictly > target
|
|
592
1088
|
* const bst = new BST<number>([10, 20, 30, 40]);
|
|
@@ -616,6 +1112,30 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
616
1112
|
|
|
617
1113
|
|
|
618
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
|
+
|
|
619
1139
|
* @example
|
|
620
1140
|
* // Find the greatest key ≤ target
|
|
621
1141
|
* const bst = new BST<number>([10, 20, 30, 40, 50]);
|
|
@@ -646,6 +1166,30 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
646
1166
|
|
|
647
1167
|
|
|
648
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
|
+
|
|
649
1193
|
* @example
|
|
650
1194
|
* // Find the greatest key strictly < target
|
|
651
1195
|
* const bst = new BST<number>([10, 20, 30, 40]);
|
|
@@ -676,6 +1220,30 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
676
1220
|
|
|
677
1221
|
|
|
678
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
|
+
|
|
679
1247
|
* @example
|
|
680
1248
|
* // Rebalance the tree
|
|
681
1249
|
* const bst = new BST<number>();
|
|
@@ -701,6 +1269,30 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
701
1269
|
|
|
702
1270
|
|
|
703
1271
|
|
|
1272
|
+
|
|
1273
|
+
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
|
|
1280
|
+
|
|
1281
|
+
|
|
1282
|
+
|
|
1283
|
+
|
|
1284
|
+
|
|
1285
|
+
|
|
1286
|
+
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
|
|
1290
|
+
|
|
1291
|
+
|
|
1292
|
+
|
|
1293
|
+
|
|
1294
|
+
|
|
1295
|
+
|
|
704
1296
|
* @example
|
|
705
1297
|
* // Check if tree is height-balanced
|
|
706
1298
|
* const bst = new BST<number>([3, 1, 5, 2, 4]);
|
|
@@ -738,6 +1330,54 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
738
1330
|
|
|
739
1331
|
|
|
740
1332
|
|
|
1333
|
+
|
|
1334
|
+
|
|
1335
|
+
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
|
|
1339
|
+
|
|
1340
|
+
|
|
1341
|
+
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
|
|
1345
|
+
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
|
|
1350
|
+
|
|
1351
|
+
|
|
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
|
+
|
|
741
1381
|
* @example
|
|
742
1382
|
* // Transform to new tree
|
|
743
1383
|
* const bst = new BST<number, number>([[1, 10], [2, 20], [3, 30]]);
|
|
@@ -908,6 +1548,41 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
908
1548
|
*
|
|
909
1549
|
* @param v - The node to set as root.
|
|
910
1550
|
*/
|
|
1551
|
+
/**
|
|
1552
|
+
* (Protected) Recalculates the subtree count for a single node.
|
|
1553
|
+
* @remarks Time O(1). Only active when enableOrderStatistic is true.
|
|
1554
|
+
*/
|
|
1555
|
+
protected _updateCount(node: BSTNode<K, V>): void;
|
|
1556
|
+
/**
|
|
1557
|
+
* (Protected) Updates subtree counts from a node up to the root.
|
|
1558
|
+
* @remarks Time O(log n). Only active when enableOrderStatistic is true.
|
|
1559
|
+
*/
|
|
1560
|
+
protected _updateCountAlongPath(node: OptNode<BSTNode<K, V>>): void;
|
|
1561
|
+
/**
|
|
1562
|
+
* (Protected) Finds the node at position k in tree order (iterative).
|
|
1563
|
+
* @remarks Time O(log n), Space O(1)
|
|
1564
|
+
*/
|
|
1565
|
+
protected _getByRankIterative(node: OptNode<BSTNode<K, V>>, k: number): BSTNode<K, V> | undefined;
|
|
1566
|
+
/**
|
|
1567
|
+
* (Protected) Finds the node at position k in tree order (recursive).
|
|
1568
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
1569
|
+
*/
|
|
1570
|
+
protected _getByRankRecursive(node: OptNode<BSTNode<K, V>>, k: number): BSTNode<K, V> | undefined;
|
|
1571
|
+
/**
|
|
1572
|
+
* (Protected) Computes the rank of a key iteratively.
|
|
1573
|
+
* @remarks Time O(log n), Space O(1)
|
|
1574
|
+
*/
|
|
1575
|
+
protected _getRankIterative(node: OptNode<BSTNode<K, V>>, key: K): number;
|
|
1576
|
+
/**
|
|
1577
|
+
* (Protected) Computes the rank of a key recursively.
|
|
1578
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
1579
|
+
*/
|
|
1580
|
+
protected _getRankRecursive(node: OptNode<BSTNode<K, V>>, key: K): number;
|
|
1581
|
+
/**
|
|
1582
|
+
* (Protected) Finds the in-order successor of a node.
|
|
1583
|
+
* @remarks Time O(log n), Space O(1)
|
|
1584
|
+
*/
|
|
1585
|
+
protected _next(node: BSTNode<K, V>): BSTNode<K, V> | undefined;
|
|
911
1586
|
protected _setRoot(v: OptNode<BSTNode<K, V>>): void;
|
|
912
1587
|
/**
|
|
913
1588
|
* (Protected) Compares two keys using the tree's comparator and reverse setting.
|