Skip to main content

compact

Function compact 

Source
pub fn compact<T, F>(arr: &mut [T], is_dummy: F) -> usize
where F: Fn(&T) -> bool, T: Cmov + Copy,
Expand description

Stably compacts an array arr of length n using oblivious compaction. The payload array payload is the prefix sum of valid elements. Uses https://eprint.iacr.org/2022/1333.pdf

§Requires

§Behavior

  • returns ret - the number of non-dummy elements (new real length of the array).
  • first ret elements of arr are the non-dummy elements in the same order as they were in the original array.
  • the rest of the elements in arr are the dummy elements in no particular order.

§Oblivious

  • Fully data-independent memory access pattern.
  • Leaks: arr.len() - the full length of the original array

§Returns the number of non-dummy elements in the array after compaction.