mirror of
https://github.com/openharmony/third_party_rust_env_logger.git
synced 2026-07-01 21:24:04 -04:00
4310a6da20
Co-authored-by: TilCreator <tilcreator@tc-j.de>
31 lines
611 B
Rust
31 lines
611 B
Rust
use std::collections::BTreeSet;
|
|
|
|
pub fn all<T>(input: &[T]) -> BTreeSet<BTreeSet<T>>
|
|
where
|
|
T: Ord + Eq + Clone,
|
|
{
|
|
let mut permutations = BTreeSet::new();
|
|
|
|
if input.is_empty() {
|
|
return permutations;
|
|
}
|
|
|
|
permutations.insert(input.iter().cloned().collect());
|
|
|
|
if input.len() > 1 {
|
|
for t in input {
|
|
let p = input
|
|
.iter()
|
|
.filter(|pt| *pt != t)
|
|
.cloned()
|
|
.collect::<Vec<_>>();
|
|
|
|
for pt in all(&p) {
|
|
permutations.insert(pt);
|
|
}
|
|
}
|
|
}
|
|
|
|
permutations
|
|
}
|