permute

Crates.iopermute
lib.rspermute
version0.2.1
sourcesrc
created_at2019-08-07 17:18:02.041991
updated_at2022-06-05 20:38:47.509577
descriptionGenerate permutations of vectors and slices in a memory-efficient and deterministic manner, using Heap's algorithm.
homepage
repositoryhttps://github.com/NoraCodes/permute-rs
max_upload_size
id154832
size11,011
Leonora Tindall (NoraCodes)

documentation

README

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.

Commit count: 5

cargo fmt