Skip to content

Commit

Permalink
Rename MAX_LEN_SMALL_SORT -> SMALL_SORT_THRESHOLD
Browse files Browse the repository at this point in the history
  • Loading branch information
Voultapher committed Oct 2, 2023
1 parent 334be51 commit 9237364
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/drift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub fn sort<T, F: FnMut(&T, &T) -> bool>(
// as our threshold, as we will call small_sort on any runs smaller than this.
const MIN_MERGE_SLICE_LEN: usize = 32;
let min_good_run_len = if eager_sort {
T::MAX_LEN_SMALL_SORT
T::SMALL_SORT_THRESHOLD
} else if len <= (MIN_MERGE_SLICE_LEN * MIN_MERGE_SLICE_LEN) {
MIN_MERGE_SLICE_LEN
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/quicksort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn stable_quicksort<T, F: FnMut(&T, &T) -> bool>(
loop {
let len = v.len();

if len <= T::MAX_LEN_SMALL_SORT {
if len <= T::SMALL_SORT_THRESHOLD {
T::sort_small(v, scratch, is_less);
return;
}
Expand Down
12 changes: 6 additions & 6 deletions src/smallsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use core::ptr;
// Use a trait to focus code-gen on only the parts actually relevant for the type. Avoid generating
// LLVM-IR for the sorting-network and median-networks for types that don't qualify.
pub trait SmallSortTypeImpl: Sized {
const MAX_LEN_SMALL_SORT: usize;
const SMALL_SORT_THRESHOLD: usize;

/// Sorts `v` using strategies optimized for small sizes.
fn sort_small<F: FnMut(&Self, &Self) -> bool>(
Expand All @@ -23,7 +23,7 @@ pub trait SmallSortTypeImpl: Sized {
}

impl<T> SmallSortTypeImpl for T {
default const MAX_LEN_SMALL_SORT: usize = 16;
default const SMALL_SORT_THRESHOLD: usize = 16;

default fn sort_small<F: FnMut(&T, &T) -> bool>(
v: &mut [T],
Expand All @@ -36,14 +36,14 @@ impl<T> SmallSortTypeImpl for T {
}
}

pub const MIN_SMALL_SORT_SCRATCH_LEN: usize = i32::MAX_LEN_SMALL_SORT + 16;
pub const MIN_SMALL_SORT_SCRATCH_LEN: usize = i32::SMALL_SORT_THRESHOLD + 16;

impl<T> SmallSortTypeImpl for T
where
T: crate::Freeze,
(): crate::IsTrue<{ mem::size_of::<T>() <= 96 }>,
{
const MAX_LEN_SMALL_SORT: usize = 20;
const SMALL_SORT_THRESHOLD: usize = 20;

fn sort_small<F: FnMut(&T, &T) -> bool>(
v: &mut [T],
Expand All @@ -70,14 +70,14 @@ where
// SAFETY: scratch_base is valid and has enough space.
sort8_stable(
v_base,
scratch_base.add(T::MAX_LEN_SMALL_SORT),
scratch_base.add(T::SMALL_SORT_THRESHOLD),
scratch_base,
is_less,
);

sort8_stable(
v_base.add(len_div_2),
scratch_base.add(T::MAX_LEN_SMALL_SORT + 8),
scratch_base.add(T::SMALL_SORT_THRESHOLD + 8),
scratch_base.add(len_div_2),
is_less,
);
Expand Down

0 comments on commit 9237364

Please sign in to comment.