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
|
@@ -136,7 +136,7 @@ export declare class BinaryTreeNode<K = any, V = any> {
|
|
|
136
136
|
* node?: BinaryTreeNode<string> | null,
|
|
137
137
|
* conditions?: { [key: string]: boolean }
|
|
138
138
|
* ): string {
|
|
139
|
-
* if (!node)
|
|
139
|
+
* if (!node) raise(Error, 'Invalid node');
|
|
140
140
|
*
|
|
141
141
|
* // If it's a leaf node, return the decision result
|
|
142
142
|
* if (!node.left && !node.right) return node.key;
|
|
@@ -181,7 +181,7 @@ export declare class BinaryTreeNode<K = any, V = any> {
|
|
|
181
181
|
* case '/':
|
|
182
182
|
* return rightValue !== 0 ? leftValue / rightValue : 0; // Handle division by zero
|
|
183
183
|
* default:
|
|
184
|
-
*
|
|
184
|
+
* raise(Error, `Unsupported operator: ${node.key}`);
|
|
185
185
|
* }
|
|
186
186
|
* }
|
|
187
187
|
*
|
|
@@ -350,7 +350,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
350
350
|
* @param key - The key to validate.
|
|
351
351
|
* @returns True if the key is valid, false otherwise.
|
|
352
352
|
*/
|
|
353
|
-
isValidKey(key:
|
|
353
|
+
isValidKey(key: unknown): key is K;
|
|
354
354
|
/**
|
|
355
355
|
* Adds a new node to the tree.
|
|
356
356
|
* @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation adds the node at the first available position in a level-order (BFS) traversal. This is NOT a Binary Search Tree insertion. Time O(N), where N is the number of nodes. It must traverse level-by-level to find an empty slot. Space O(N) in the worst case for the BFS queue (e.g., a full last level).
|
|
@@ -363,6 +363,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
363
363
|
|
|
364
364
|
|
|
365
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
|
+
|
|
366
390
|
* @example
|
|
367
391
|
* // Add a single node
|
|
368
392
|
* const tree = new BinaryTree<number>();
|
|
@@ -391,6 +415,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
391
415
|
|
|
392
416
|
|
|
393
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
|
+
|
|
394
442
|
* @example
|
|
395
443
|
* // basic BinaryTree creation and insertion
|
|
396
444
|
* // Create a BinaryTree with entries
|
|
@@ -431,6 +479,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
431
479
|
|
|
432
480
|
|
|
433
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
|
+
|
|
434
506
|
* @example
|
|
435
507
|
* // Bulk add
|
|
436
508
|
* const tree = new BinaryTree<number>();
|
|
@@ -447,6 +519,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
447
519
|
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
448
520
|
|
|
449
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
|
+
|
|
450
546
|
* @example
|
|
451
547
|
* // Set multiple entries
|
|
452
548
|
* const tree = new BinaryTree<number, string>();
|
|
@@ -468,6 +564,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
468
564
|
|
|
469
565
|
|
|
470
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
|
+
|
|
471
591
|
* @example
|
|
472
592
|
* // Combine trees
|
|
473
593
|
* const t1 = new BinaryTree<number>([1, 2]);
|
|
@@ -501,6 +621,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
501
621
|
|
|
502
622
|
|
|
503
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
|
+
|
|
504
648
|
* @example
|
|
505
649
|
* // Remove a node
|
|
506
650
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -513,6 +657,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
513
657
|
* Search by predicate
|
|
514
658
|
|
|
515
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
|
+
|
|
516
684
|
* @example
|
|
517
685
|
* // Search by predicate
|
|
518
686
|
* const tree = new BinaryTree<number>([5, 3, 7, 1, 9]);
|
|
@@ -538,6 +706,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
538
706
|
|
|
539
707
|
|
|
540
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
|
+
|
|
541
733
|
* @example
|
|
542
734
|
* // Get nodes by condition
|
|
543
735
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -562,6 +754,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
562
754
|
|
|
563
755
|
|
|
564
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
|
+
|
|
565
781
|
* @example
|
|
566
782
|
* // Get node by key
|
|
567
783
|
* const tree = new BinaryTree<number, string>([[1, 'root'], [2, 'child']]);
|
|
@@ -587,6 +803,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
587
803
|
|
|
588
804
|
|
|
589
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
|
+
|
|
590
830
|
* @example
|
|
591
831
|
* // Retrieve value by key
|
|
592
832
|
* const tree = new BinaryTree<number, string>([[1, 'root'], [2, 'left'], [3, 'right']]);
|
|
@@ -613,6 +853,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
613
853
|
|
|
614
854
|
|
|
615
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
|
+
|
|
616
880
|
* @example
|
|
617
881
|
* // BinaryTree get and has operations
|
|
618
882
|
* const tree = new BinaryTree(
|
|
@@ -655,6 +919,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
655
919
|
|
|
656
920
|
|
|
657
921
|
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
658
946
|
* @example
|
|
659
947
|
* // Remove all nodes
|
|
660
948
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -676,6 +964,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
676
964
|
|
|
677
965
|
|
|
678
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
|
+
|
|
679
991
|
* @example
|
|
680
992
|
* // Check empty
|
|
681
993
|
* console.log(new BinaryTree().isEmpty()); // true;
|
|
@@ -705,20 +1017,68 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
705
1017
|
|
|
706
1018
|
|
|
707
1019
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
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
|
+
* @example
|
|
1045
|
+
* // Check BST property
|
|
1046
|
+
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
1047
|
+
* // BinaryTree doesn't guarantee BST order
|
|
1048
|
+
* console.log(typeof tree.isBST()); // 'boolean';
|
|
1049
|
+
*/
|
|
1050
|
+
isBST(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
|
|
1051
|
+
/**
|
|
1052
|
+
* Gets the depth of a node (distance from `startNode`).
|
|
1053
|
+
* @remarks Time O(H), where H is the depth of the `dist` node relative to `startNode`. O(N) worst-case. Space O(1).
|
|
1054
|
+
*
|
|
1055
|
+
* @param dist - The node to find the depth of.
|
|
1056
|
+
* @param [startNode=this._root] - The node to measure depth from (defaults to root).
|
|
1057
|
+
* @returns The depth (0 if `dist` is `startNode`).
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
|
|
722
1082
|
|
|
723
1083
|
|
|
724
1084
|
|
|
@@ -755,6 +1115,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
755
1115
|
|
|
756
1116
|
|
|
757
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
|
+
|
|
758
1142
|
* @example
|
|
759
1143
|
* // Get tree height
|
|
760
1144
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -805,6 +1189,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
805
1189
|
|
|
806
1190
|
|
|
807
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
|
+
|
|
808
1216
|
* @example
|
|
809
1217
|
* // Depth-first search traversal
|
|
810
1218
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -827,6 +1235,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
827
1235
|
|
|
828
1236
|
|
|
829
1237
|
|
|
1238
|
+
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
830
1262
|
* @example
|
|
831
1263
|
* // BinaryTree level-order traversal
|
|
832
1264
|
* const tree = new BinaryTree([
|
|
@@ -869,6 +1301,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
869
1301
|
|
|
870
1302
|
|
|
871
1303
|
|
|
1304
|
+
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
|
|
1325
|
+
|
|
1326
|
+
|
|
1327
|
+
|
|
872
1328
|
* @example
|
|
873
1329
|
* // Get leaf nodes
|
|
874
1330
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -887,6 +1343,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
887
1343
|
|
|
888
1344
|
|
|
889
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
|
+
|
|
890
1370
|
* @example
|
|
891
1371
|
* // Level-order grouping
|
|
892
1372
|
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
@@ -907,6 +1387,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
907
1387
|
|
|
908
1388
|
|
|
909
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
|
+
|
|
910
1414
|
* @example
|
|
911
1415
|
* // Morris traversal (O(1) space)
|
|
912
1416
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -929,6 +1433,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
929
1433
|
|
|
930
1434
|
|
|
931
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
|
+
|
|
932
1460
|
* @example
|
|
933
1461
|
* // Deep copy
|
|
934
1462
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -953,6 +1481,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
953
1481
|
|
|
954
1482
|
|
|
955
1483
|
|
|
1484
|
+
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
|
|
1495
|
+
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
|
|
1503
|
+
|
|
1504
|
+
|
|
1505
|
+
|
|
1506
|
+
|
|
1507
|
+
|
|
956
1508
|
* @example
|
|
957
1509
|
* // Filter nodes by condition
|
|
958
1510
|
* const tree = new BinaryTree<number>([1, 2, 3, 4]);
|
|
@@ -980,6 +1532,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
980
1532
|
|
|
981
1533
|
|
|
982
1534
|
|
|
1535
|
+
|
|
1536
|
+
|
|
1537
|
+
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
|
|
1555
|
+
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
|
|
983
1559
|
* @example
|
|
984
1560
|
* // Transform to new tree
|
|
985
1561
|
* const tree = new BinaryTree<number, number>([[1, 10], [2, 20]]);
|
|
@@ -1011,6 +1587,30 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1011
1587
|
|
|
1012
1588
|
|
|
1013
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
|
+
|
|
1014
1614
|
* @example
|
|
1015
1615
|
* // Display tree
|
|
1016
1616
|
* const tree = new BinaryTree<number>([1, 2, 3]);
|
|
@@ -1136,7 +1736,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1136
1736
|
* @param p - The item to check.
|
|
1137
1737
|
* @returns True if it's a function.
|
|
1138
1738
|
*/
|
|
1139
|
-
protected _isPredicate(p:
|
|
1739
|
+
protected _isPredicate(p: unknown): p is NodePredicate<BinaryTreeNode<K, V>>;
|
|
1140
1740
|
/**
|
|
1141
1741
|
* (Protected) Extracts the key from a key, node, or entry.
|
|
1142
1742
|
* @remarks Time O(1)
|