Trait permutohedron::LexicalPermutation [] [src]

pub trait LexicalPermutation {
    fn next_permutation(&mut self) -> bool;
fn prev_permutation(&mut self) -> bool; }

Permute a slice into its next or previous permutation (in lexical order).

use permutohedron::LexicalPermutation;

let mut data = [1, 2, 3];
let mut permutations = Vec::new();

loop {
    permutations.push(data.to_vec());
    if !data.next_permutation() {
        break;
    }
}

assert_eq!(permutations, &[&[1, 2, 3], &[1, 3, 2],
                           &[2, 1, 3], &[2, 3, 1],
                           &[3, 1, 2], &[3, 2, 1]]);

// `data` has been mutated in-place:
assert_eq!(data, [3, 2, 1]);

Required Methods

Return true if the slice was permuted, false if it is already at the last ordered permutation.

Return true if the slice was permuted, false if it is already at the first ordered permutation.

Implementations on Foreign Types

impl<T> LexicalPermutation for [T] where
    T: Ord
[src]

[src]

Original author in Rust: Thomas Backman serenity@exscape.org

[src]

Implementors