pub fn heap_permutation<'a, T>(d: &'a mut [T], cb: impl FnMut(&[T]) + 'a)
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 [1, 2, 3], [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.

Breaking change from 0.3.x to 0.4

Since version 0.4.0, the first result return by this iterator will be the original value