Function malachite_base::vecs::exhaustive::lex_ordered_unique_vecs
source · pub fn lex_ordered_unique_vecs<I: Clone + Iterator>(
xs: I,
) -> LexOrderedUniqueCollections<I, Vec<I::Item>> ⓘ
Expand description
Generates Vec
s with elements from a single iterator, such that each Vec
has no repeated
elements, and the elements in each Vec
are ordered the same way as they are in the source
iterator.
The Vec
s 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, only prefixes of the iterator will 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 Vec
.
§Examples
use itertools::Itertools;
use malachite_base::vecs::exhaustive::lex_ordered_unique_vecs;
let xss = lex_ordered_unique_vecs(1..=4).collect_vec();
assert_eq!(
xss.iter().map(Vec::as_slice).collect_vec().as_slice(),
&[
&[][..],
&[1],
&[1, 2],
&[1, 2, 3],
&[1, 2, 3, 4],
&[1, 2, 4],
&[1, 3],
&[1, 3, 4],
&[1, 4],
&[2],
&[2, 3],
&[2, 3, 4],
&[2, 4],
&[3],
&[3, 4],
&[4]
]
);