Tweak the constants a bit
This commit is contained in:
parent
942173b38f
commit
c4454a5507
@ -1668,9 +1668,9 @@ fn merge_sort<T, F>(v: &mut [T], mut is_less: F)
|
|||||||
where F: FnMut(&T, &T) -> bool
|
where F: FnMut(&T, &T) -> bool
|
||||||
{
|
{
|
||||||
// Slices of up to this length get sorted using insertion sort.
|
// Slices of up to this length get sorted using insertion sort.
|
||||||
const MAX_INSERTION: usize = 16;
|
const MAX_INSERTION: usize = 20;
|
||||||
// Very short runs are extended using insertion sort to span at least this many elements.
|
// Very short runs are extended using insertion sort to span at least this many elements.
|
||||||
const MIN_RUN: usize = 8;
|
const MIN_RUN: usize = 10;
|
||||||
|
|
||||||
// Sorting has no meaningful behavior on zero-sized types.
|
// Sorting has no meaningful behavior on zero-sized types.
|
||||||
if size_of::<T>() == 0 {
|
if size_of::<T>() == 0 {
|
||||||
|
@ -355,7 +355,7 @@ fn partition<T, F>(v: &mut [T], pivot: usize, is_less: &mut F) -> (usize, bool)
|
|||||||
l += 1;
|
l += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the last element lesser that the pivot.
|
// Find the last element smaller that the pivot.
|
||||||
while l < r && !is_less(v.get_unchecked(r - 1), pivot) {
|
while l < r && !is_less(v.get_unchecked(r - 1), pivot) {
|
||||||
r -= 1;
|
r -= 1;
|
||||||
}
|
}
|
||||||
@ -472,7 +472,7 @@ fn choose_pivot<T, F>(v: &mut [T], is_less: &mut F) -> (usize, bool)
|
|||||||
{
|
{
|
||||||
// Minimal length to choose the median-of-medians method.
|
// Minimal length to choose the median-of-medians method.
|
||||||
// Shorter slices use the simple median-of-three method.
|
// Shorter slices use the simple median-of-three method.
|
||||||
const SHORTEST_MEDIAN_OF_MEDIANS: usize = 90;
|
const SHORTEST_MEDIAN_OF_MEDIANS: usize = 80;
|
||||||
// Maximal number of swaps that can be performed in this function.
|
// Maximal number of swaps that can be performed in this function.
|
||||||
const MAX_SWAPS: usize = 4 * 3;
|
const MAX_SWAPS: usize = 4 * 3;
|
||||||
|
|
||||||
@ -539,7 +539,7 @@ fn recurse<'a, T, F>(mut v: &'a mut [T], is_less: &mut F, mut pred: Option<&'a T
|
|||||||
where F: FnMut(&T, &T) -> bool
|
where F: FnMut(&T, &T) -> bool
|
||||||
{
|
{
|
||||||
// Slices of up to this length get sorted using insertion sort.
|
// Slices of up to this length get sorted using insertion sort.
|
||||||
const MAX_INSERTION: usize = 16;
|
const MAX_INSERTION: usize = 20;
|
||||||
|
|
||||||
// True if the last partitioning was reasonably balanced.
|
// True if the last partitioning was reasonably balanced.
|
||||||
let mut was_balanced = true;
|
let mut was_balanced = true;
|
||||||
@ -627,8 +627,8 @@ pub fn quicksort<T, F>(v: &mut [T], mut is_less: F)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit the number of imbalanced partitions to `floor(log2(len)) + 2`.
|
// Limit the number of imbalanced partitions to `floor(log2(len)) + 1`.
|
||||||
let limit = mem::size_of::<usize>() * 8 - v.len().leading_zeros() as usize + 1;
|
let limit = mem::size_of::<usize>() * 8 - v.len().leading_zeros() as usize;
|
||||||
|
|
||||||
recurse(v, &mut is_less, None, limit);
|
recurse(v, &mut is_less, None, limit);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user