pub fn heap_permutation<'a, T>(d: &'a mut [T], cb: impl FnMut(&'a [T]))
Expand description

Heap permutation which permutate variable d in place and call cb function for each permutation done on d.

Parameter

  • d a data to be permuted.
  • cb a callback function that will be called several times for each permuted value.

Example

use permutator::heap_permutation;
heap_permutation(&mut [1, 2, 3], |p| {
    // call multiple times. It'll print [2, 1, 3], [3, 1, 2], 
    // [1, 3, 2], [2, 3, 1], and [3, 2, 1] respectively.
    println!("{:?}", p);
});

See

Warning

The permutation is done in place which mean the parameter d will be mutated.

Notes

  1. The value passed to callback function will equals to value inside parameter d.