pub fn sort<T, D>(vec: D) -> Permutation
where
    T: Ord,
    D: Deref<Target = [T]>,
{
    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_key(|&i| &vec[i]);
    return permutation;
}
/// Return the permutation that would sort a given slice.
///
/// This calculates the permutation that if it were applied to the slice,
/// would put the elements in sorted order.
///
/// # Examples
///
/// ```
/// # use permutation::Permutation;
/// let mut vec = vec!['z','w','h','a','s','j'];
/// let permutation = permutation::sort(&vec[..]);
/// let permuted = permutation.apply_slice(&vec[..]);
/// vec.sort();
/// assert!(vec == permuted);
/// ```
///
/// You can also use it to sort multiple arrays based on the ordering of one.
///
/// ```
/// let names = vec!["Bob", "Steve", "Jane"];
/// let salary = vec![10, 5, 15];
/// let permutation = permutation::sort(&salary[..]);
/// let ordered_names = permutation.apply_slice(&names[..]);
/// let ordered_salaries = permutation.apply_slice(&salary[..]);
/// assert!(ordered_names == vec!["Steve", "Bob", "Jane"]);
/// assert!(ordered_salaries == vec![5, 10, 15]);
/// ```
Return the permutation that would sort a given slice.
This calculates the permutation that if it were applied to the slice,
would put the elements in sorted order.
Return the permutation that would sort a given slice . This calculates the permutation that if it were applied to the slice would put the elements in sorted order .
pub fn sort<T, D>(vec: D) -> Permutation
where
    T: Ord,
    D: Deref<Target = [T]>,
{
    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_key(|&i| &vec[i]);
    return permutation;
}
pub fn sort < T , D > ( vec : D ) -> Permutation where T : Ord , D : Deref < Target = [ T ] > , { 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_key ( | & i | & vec [ i ] ) ; return permutation ; }
Return the permutation that would sort a given slice.
Return the permutation that would sort a given slice .
vec
D
vec
D
examples
None
use permutation::permutation;
let mut vec = vec!['z','w','h','a','s','j'];
let permutation = permutation::sort(&vec[..]);
let permuted = permutation.apply_slice(&vec[..]);
vec.sort();
assert!(vec == permuted);
```

You can also use it to sort multiple arrays based on the ordering of one.

```
let names = vec!["Bob", "Steve", "Jane"];
let salary = vec![10, 5, 15];
let permutation = permutation::sort(&salary[..]);
let ordered_names = permutation.apply_slice(&names[..]);
let ordered_salaries = permutation.apply_slice(&salary[..]);
assert!(ordered_names == vec!["Steve", "Bob", "Jane"]);
assert!(ordered_salaries == vec![5, 10, 15]);
```
let mut vec = vec! [ ' z ' ' w ' ' h ' ' a ' ' s ' ' j ' ] ; let permutation = permutation :: sort ( &vec [ .. ] ) ; let permuted = permutation . apply_slice ( &vec [ .. ] ) ; vec . sort () ; assert! ( vec == permuted ) ; ` ` ` You can also use it to sort multiple arrays based on the ordering of one . ` ` ` let names = vec! [ " Bob " " Steve " " Jane " ] ; let salary = vec! [ 10 5 15 ] ; let permutation = permutation :: sort ( &salary [ .. ] ) ; let ordered_names = permutation . apply_slice ( &names [ .. ] ) ; let ordered_salaries = permutation . apply_slice ( &salary [ .. ] ) ; assert! ( ordered_names == vec! [ " Steve " " Bob " " Jane " ] ) ; assert! ( ordered_salaries == vec! [ 5 10 15 ] ) ; ` ` `