2 stable releases
new 1.0.1 | Mar 5, 2025 |
---|---|
1.0.0 | Mar 3, 2025 |
#762 in Algorithms
266 downloads per month
Used in cphf
17KB
255 lines
sort-const
A macro for sorting arrays and slices at compile time.
Usage
Just use the const_quicksort
or const_shellsort
macros.
use sort_const::const_quicksort;
const fn lt(a: &u8, b: &u8) -> bool {
*a < *b
}
const A: &[u8] = &const_quicksort!([3, 1, 2]);
const B: &[u8] = &const_quicksort!([3, 1, 2], |a, b| *a < *b);
const C: &[u8] = &const_quicksort!([3, 1, 2], lt);
assert_eq!(A, [1, 2, 3]);
assert_eq!(B, [1, 2, 3]);
assert_eq!(C, [1, 2, 3]);
For now, this crate uses a custom const
y fork of arrayvec
. bluss/arrayvec#294 should fix this.
License
Licensed under
- MIT license (LICENSE or https://opensource.org/licenses/MIT)
Dependencies
~300KB