diff options
| author | blake2-ppc <blake2-ppc> | 2013-09-09 01:29:07 +0200 |
|---|---|---|
| committer | blake2-ppc <blake2-ppc> | 2013-09-10 05:50:06 +0200 |
| commit | de9546a3f8c3153983a7b6069a9f2aee28f2e296 (patch) | |
| tree | e47a777ac41654cc0ba72c3c754e3f911e84ad3c /src/rustllvm/RustWrapper.cpp | |
| parent | 6212729315be2ac80785ffcecfe0a80c9955c4cf (diff) | |
| download | rust-de9546a3f8c3153983a7b6069a9f2aee28f2e296.tar.gz rust-de9546a3f8c3153983a7b6069a9f2aee28f2e296.zip | |
std::vec: Replace each_permutation with a new Permutations iterator
Introduce ElementSwaps and Permutations. ElementSwaps is an iterator
that for a given sequence length yields the element swaps needed
to visit each possible permutation of the sequence in turn.
We use an algorithm that generates a sequence such that each permutation
is only one swap apart.
let mut v = [1, 2, 3];
for perm in v.permutations_iter() {
// yields 1 2 3 | 1 3 2 | 3 1 2 | 3 2 1 | 2 3 1 | 2 1 3
}
The `.permutations_iter()` yields clones of the input vector for each
permutation.
If a copyless traversal is needed, it can be constructed with
`ElementSwaps`:
for (a, b) in ElementSwaps::new(3) {
// yields (2, 1), (1, 0), (2, 1) ...
v.swap(a, b);
// ..
}
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
