Crates.io | permute |
lib.rs | permute |
version | 0.2.1 |
source | src |
created_at | 2019-08-07 17:18:02.041991 |
updated_at | 2022-06-05 20:38:47.509577 |
description | Generate permutations of vectors and slices in a memory-efficient and deterministic manner, using Heap's algorithm. |
homepage | |
repository | https://github.com/NoraCodes/permute-rs |
max_upload_size | |
id | 154832 |
size | 11,011 |
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.