Function malachite_base::sets::exhaustive::shortlex_hash_sets
source · pub fn shortlex_hash_sets<I: Clone + Iterator>(
xs: I,
) -> ShortlexOrderedUniqueCollections<I, HashSet<I::Item>> ⓘ
Expand description
Generates HashSet
s with elements from a single iterator.
The HashSet
s are generated in order of increasing length, and within each length they are
ordered lexicographically with respect to the order of the element iterator.
The source iterator should not repeat any elements, but this is not enforced.
The iterator should be finite; if it is infinite, HashSet
s of length 2 and above will never
be generated.
If the input iterator is infinite, the output length is also infinite.
If the input iterator length is $n$, the output length is $2^n$.
If xs
is empty, the output consists of a single empty HashSet
.
§Examples
use itertools::Itertools;
use malachite_base::sets::exhaustive::shortlex_hash_sets;
use maplit::hashset;
let xss = shortlex_hash_sets(1..=4).collect_vec();
assert_eq!(
xss,
&[
hashset! {},
hashset! {1},
hashset! {2},
hashset! {3},
hashset! {4},
hashset! {1, 2},
hashset! {1, 3},
hashset! {1, 4},
hashset! {2, 3},
hashset! {2, 4},
hashset! {3, 4},
hashset! {1, 2, 3},
hashset! {1, 2, 4},
hashset! {1, 3, 4},
hashset! {2, 3, 4},
hashset! {1, 2, 3, 4}
]
);