Function pasture_core::util::sort_untyped_slice_by_permutation[][src]

pub fn sort_untyped_slice_by_permutation(
    slice: &mut [u8],
    permutation: &[usize],
    stride: usize
)

Sorts a slice containing binary untyped data as if it did contain typed data. Sorting is performed using the given permutation. stride defines the offset between two consecutive elements within slice.

Example

let mut typed_vec : Vec<u32> = vec![10,20,30,40,50,60];
let mut untyped_vec = unsafe { std::slice::from_raw_parts_mut(typed_vec.as_mut_ptr() as *mut u8, std::mem::size_of::<u32>() * typed_vec.len())};
let permutation = vec![1,0,3,2,5,4];

sort_untyped_slice_by_permutation(untyped_vec, permutation.as_slice(), std::mem::size_of::<u32>());
assert_eq!(vec![20,10,40,30,60,50], typed_vec);

Safety

Make sure that stride matches the size of the typed data that slice refers to, otherwise the binary layout will get scrambled!

Panics

If the number of entries in permutation times the stride does not equal the number of entries in slice. If permutation contains any entry that is >= slice.len() / stride