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
fn next_permutation(&mut self) -> bool
Return true
if the slice was permuted, false
if it is already
at the last ordered permutation.
fn prev_permutation(&mut self) -> bool
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]
T: Ord,
fn next_permutation(&mut self) -> bool
[src]
Original author in Rust: Thomas Backman serenity@exscape.org