pub fn partition_index<T, P>(data: &mut [T], predicate: P) -> usizeExpand description
partition a mutable slice in-place so that it contains all elements for
which predicate(e) is true, followed by all elements for which
predicate(e) is false.
Returns the index of the first element which returned false.
Returns 0 if all elements returned false.
Returns data.len() if all elements returned true.
Examples
let mut even_odd = [0u8, 1, 2, 3, 4, 5, 6];
let first_odd = partition_index(&mut even_odd, |x| x & 1 == 0);
assert_eq!(first_odd, 4, "expected an index of 4, got {:?}", first_odd);
for (idx, &e) in even_odd.iter().enumerate() {
if idx < first_odd {
assert!(e & 1 == 0, "expected elements before first_odd to be even, found {:?}", e);
} else {
assert!(e & 1 == 1, "expected elements after first_odd to be odd, found {:?}", e);
}
}