Commit 32a20f4 1 parent e48eb37 commit 32a20f4 Copy full SHA for 32a20f4
File tree 1 file changed +8
-2
lines changed
library/alloc/src/collections
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -630,10 +630,16 @@ impl<T: Ord> BinaryHeap<T> {
630
630
// and about 2 * (len1 + len2) comparisons in the worst case
631
631
// while `extend` takes O(len2 * log(len1)) operations
632
632
// and about 1 * len2 * log_2(len1) comparisons in the worst case,
633
- // assuming len1 >= len2.
633
+ // assuming len1 >= len2. For larger heaps, the crossover point
634
+ // no longer follows this reasoning and was determined empirically.
634
635
#[ inline]
635
636
fn better_to_rebuild ( len1 : usize , len2 : usize ) -> bool {
636
- 2 * ( len1 + len2) < len2 * log2_fast ( len1)
637
+ let tot_len = len1 + len2;
638
+ if tot_len <= 2048 {
639
+ 2 * tot_len < len2 * log2_fast ( len1)
640
+ } else {
641
+ 2 * tot_len < len2 * 11
642
+ }
637
643
}
638
644
639
645
if better_to_rebuild ( self . len ( ) , other. len ( ) ) {
You can’t perform that action at this time.
0 commit comments