File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
library/alloc/src/collections Expand file tree Collapse file tree 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> {
630630 // and about 2 * (len1 + len2) comparisons in the worst case
631631 // while `extend` takes O(len2 * log(len1)) operations
632632 // 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.
634635 #[ inline]
635636 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+ }
637643 }
638644
639645 if better_to_rebuild ( self . len ( ) , other. len ( ) ) {
You can’t perform that action at this time.
0 commit comments