permute 0.2.1

Generate permutations of vectors and slices in a memory-efficient and deterministic manner, using Heap's algorithm.
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented4 out of 4 items with examples
  • Size
  • Source code size: 10.66 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.25 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • NoraCodes/permute-rs
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • NoraCodes

permute

crate.io version badge docs.rs status badge github actions status badge

Generate permutations of a slice in a memory-efficient and deterministic manner, using Heap's algorithm.

For instance, printing all the permutations of the sequence ["red", "green", "blue"]:

use permute::permutations_of;

for permutation in permutations_of(&["red", "green", "blue"]) {
    for element in permutation {
        print!("{}, ", element);
    }
    println!("");
}

Based on the ordering provided by Heap’s algorithm, it’s guaranteed that this program will produce:

red, green, blue,
green, red, blue,
blue, red, green,
red, blue, green,
green, blue, red,
blue, green, red,

This crate also provides the ArbitraryTandemControlIter, which allows iterating over a slice using a slice of indices - that's how Heap's algorithm is implemented here.