pub fn heap_recursive<T, F, C>(xs: &mut [T], f: F) -> C
Expand description
Heap’s algorithm for generating permutations, recursive version.
The recursive algorithm supports slices of any size (even though only a small number of elements is practical), and is generally a bit faster than the iterative version.
The closure f
may return either ()
to simply run through all
permutations, or a Control
value that permits breaking the
iteration early.
use permutohedron::heap_recursive;
let mut data = [1, 2, 3, 4, 5, 6];
let mut permutations = Vec::new();
heap_recursive(&mut data, |permutation| {
permutations.push(permutation.to_vec())
});
assert_eq!(permutations.len(), 720);