https://github.com/noracodes/permute-rs
Rust library for generating permutations of collections efficiently and deterministically.
https://github.com/noracodes/permute-rs
Last synced: 10 months ago
JSON representation
Rust library for generating permutations of collections efficiently and deterministically.
- Host: GitHub
- URL: https://github.com/noracodes/permute-rs
- Owner: NoraCodes
- Created: 2022-06-05T19:51:21.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-05T20:21:56.000Z (about 4 years ago)
- Last Synced: 2025-03-30T17:04:45.938Z (over 1 year ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# permute
[](https://crates.io/crate/permute)
[](https://docs.rs/permute)
[](https://github.com/noracodes/permute-rs/)
Generate permutations of a slice in a memory-efficient and deterministic manner, using
[Heap's algorithm](https://en.wikipedia.org/wiki/Heap%27s_algorithm).
For instance, printing all the permutations of the sequence ["red", "green",
"blue"]:
```rust
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:
```text
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.