rostl_sort/utils.rs
1//! Some generic utils that should probably be in another module
2
3/// Returns the smallest power of two that is strictly greater than the given size.
4#[inline]
5pub const fn get_strictly_bigger_power_of_two(size: usize) -> usize {
6 // Using this hand-optimized version is slower:
7 // 1 << (usize::BITS - size.leading_zeros()) as usize
8 //
9 let mut n = 1;
10 while n <= size {
11 n *= 2;
12 }
13 n
14}
15
16/// Syntactic sugar for `arr.cswap(i,i,a[i]>a[j])`
17#[macro_export]
18macro_rules! CSWAP {
19 ($arr:expr, $i:expr, $j:expr) => {
20 $arr.cswap($i, $j, $arr[$i] > $arr[$j]);
21 };
22}