Function rudac::algo::transform::partition_with [−][src]
pub fn partition_with<T, F>(
slice: &mut [T],
pivot_index: usize,
compare: &F
) -> usize where
F: Fn(&T, &T) -> Ordering,
Expand description
Partitions the slice around the element at pivot_index
.
Returns index of pivot after partitioning
Arguments
slice
: slice of data to be partitionedpivot_index
: index of the pivot. slice will be partitioned around item at this indexcompare
: custom comparing closure
Examples
use rudac::algo::transform::partition_with;
let mut vec = vec![(1, 10), (2,6), (3,1), (3,4), (4,2), (5,3), (6,7), (8,9), (9,8), (10,5)];
partition_with(&mut vec, 3, &|x1,x2| {x1.1.cmp(&x2.1)});
// pivot
// '
assert_eq!(vec, vec![(3, 1), (4, 2), (5, 3), (3, 4), (2, 6), (1, 10), (6, 7), (8, 9), (9, 8), (10, 5)]);