pub fn sort_by<T, D, F>(vec: D, mut compare: F) -> Permutation
where
    T: Ord,
    D: Deref<Target = [T]>,
    F: FnMut(&T, &T) -> Ordering,
{
    let mut permutation = Permutation::one(vec.len());
    //We use the reverse permutation form, because its more efficient for applying to indices.
    permutation
        .indices
        .sort_by(|&i, &j| compare(&vec[i], &vec[j]));
    return permutation;
}
/// Return the permutation that would sort a given slice by a comparator.
///
/// This is the same as `permutation::sort()` except that it allows you to specify
/// the comparator to use when sorting similar to `std::slice.sort_by()`
///
/// # Examples
///
/// ```
/// # use permutation::Permutation;
/// let mut vec = vec!['z','w','h','a','s','j'];
/// let permutation = permutation::sort_by(&vec[..], |a, b| b.cmp(a));
/// let permuted = permutation.apply_slice(&vec[..]);
/// vec.sort_by(|a,b| b.cmp(a));
/// assert!(vec == permuted);
/// ```
Return the permutation that would sort a given slice by a comparator.
This is the same as `permutation::sort()` except that it allows you to specify
the comparator to use when sorting similar to `std::slice.sort_by()`
Return the permutation that would sort a given slice by a comparator . This is the same as ` permutation :: sort () ` except that it allows you to specify the comparator to use when sorting similar to ` std :: slice . sort_by () `
pub fn sort_by<T, D, F>(vec: D, mut compare: F) -> Permutation
where
    T: Ord,
    D: Deref<Target = [T]>,
    F: FnMut(&T, &T) -> Ordering,
{
    let mut permutation = Permutation::one(vec.len());
    //We use the reverse permutation form, because its more efficient for applying to indices.
    permutation
        .indices
        .sort_by(|&i, &j| compare(&vec[i], &vec[j]));
    return permutation;
}
pub fn sort_by < T , D , F > ( vec : D , mut compare : F ) -> Permutation where T : Ord , D : Deref < Target = [ T ] > , F : FnMut ( & T , & T ) -> Ordering , { let mut permutation = Permutation :: one ( vec . len ( ) ) ; //We use the reverse permutation form, because its more efficient for applying to indices. permutation . indices . sort_by ( | & i , & j | compare ( & vec [ i ] , & vec [ j ] ) ) ; return permutation ; }
Return the permutation that would sort a given slice by a comparator.
Return the permutation that would sort a given slice by a comparator .
vec
D
compare
F
vec
D
compare
F
examples
None
use permutation::permutation;
None