Expand description
§Description
This crate provides functions for sorting arrays and slices of primitives in const contexts.
Arrays and slices of bools, u8s, and i8s are sorted with counting sort while arrays of other types
are sorted with quicksort.
Functions with the naming convention into_sorted_*_array take an array by value,
and functions with the naming convention sort_*_slice take a mutable reference to a slice.
§Examples
Sort an array by value:
use compile_time_sort::into_sorted_i32_array;
const ARRAY: [i32; 5] = [-3, 3, 2, i32::MAX, 0];
const SORTED_ARRAY: [i32; 5] = into_sorted_i32_array(ARRAY);
assert_eq!(SORTED_ARRAY, [-3, 0, 2, 3, i32::MAX]);Sort an array by reference:
use compile_time_sort::sort_i32_slice;
const SORTED_ARRAY: [i32; 5] = {
let mut arr = [5, i32::MIN, 0, -2, 0];
sort_i32_slice(&mut arr);
arr
};
assert_eq!(SORTED_ARRAY, [i32::MIN, -2, 0, 0, 5]);§Features
sort_slices: enables the sort_*_slice functions and raises the MSRV of the crate to 1.83.0.
Functions§
- Sorts the given array of
bools using the counting sort algorithm. - Sorts the given array of
chars using the quicksort algorithm - Sorts the given array of
i8s using the counting sort algorithm. - Sorts the given array of
i16s using the quicksort algorithm - Sorts the given array of
i32s using the quicksort algorithm - Sorts the given array of
i64s using the quicksort algorithm - Sorts the given array of
i128s using the quicksort algorithm - Sorts the given array of
isizes using the quicksort algorithm - Sorts the given array of
u8s using the counting sort algorithm. - Sorts the given array of
u16s using the quicksort algorithm - Sorts the given array of
u32s using the quicksort algorithm - Sorts the given array of
u64s using the quicksort algorithm - Sorts the given array of
u128s using the quicksort algorithm - Sorts the given array of
usizes using the quicksort algorithm - sort_
bool_ slice sort_slicesSorts the given slice ofbools using the counting sort algorithm. - sort_
char_ slice sort_slicesSorts the given slice ofchars using the quicksort algorithm - sort_
i8_ slice sort_slicesSorts the given slice ofi8s using the counting sort algorithm. - sort_
i16_ slice sort_slicesSorts the given slice ofi16s using the quicksort algorithm - sort_
i32_ slice sort_slicesSorts the given slice ofi32s using the quicksort algorithm - sort_
i64_ slice sort_slicesSorts the given slice ofi64s using the quicksort algorithm - sort_
i128_ slice sort_slicesSorts the given slice ofi128s using the quicksort algorithm - sort_
isize_ slice sort_slicesSorts the given slice ofisizes using the quicksort algorithm - sort_
u8_ slice sort_slicesSorts the given slice ofu8s using the counting sort algorithm. - sort_
u16_ slice sort_slicesSorts the given slice ofu16s using the quicksort algorithm - sort_
u32_ slice sort_slicesSorts the given slice ofu32s using the quicksort algorithm - sort_
u64_ slice sort_slicesSorts the given slice ofu64s using the quicksort algorithm - sort_
u128_ slice sort_slicesSorts the given slice ofu128s using the quicksort algorithm - sort_
usize_ slice sort_slicesSorts the given slice ofusizes using the quicksort algorithm