Function malachite_base::vecs::exhaustive::lex_vecs_fixed_length_from_single
source · [−]pub fn lex_vecs_fixed_length_from_single<I: Iterator>(
len: u64,
xs: I
) -> LexFixedLengthVecsFromSingle<I>ⓘNotable traits for LexFixedLengthVecsFromSingle<I>impl<I: Iterator> Iterator for LexFixedLengthVecsFromSingle<I> where
I::Item: Clone, type Item = Vec<I::Item>;
where
I::Item: Clone,
Expand description
Generates all Vec
s of a given length with elements from a single iterator, in lexicographic
order.
The order is lexicographic with respect to the order of the element iterator.
xs
must be finite.
The output length is $k^n$, where $k$ is xs.count()
and $n$ is len
.
If len
is 0, the output consists of one empty Vec
.
If xs
is empty, the output is also empty, unless len
is 0.
Examples
extern crate itertools;
use itertools::Itertools;
use malachite_base::vecs::exhaustive::lex_vecs_fixed_length_from_single;
let xss = lex_vecs_fixed_length_from_single(2, 0..4).collect_vec();
assert_eq!(
xss.iter().map(Vec::as_slice).collect_vec().as_slice(),
&[
&[0, 0],
&[0, 1],
&[0, 2],
&[0, 3],
&[1, 0],
&[1, 1],
&[1, 2],
&[1, 3],
&[2, 0],
&[2, 1],
&[2, 2],
&[2, 3],
&[3, 0],
&[3, 1],
&[3, 2],
&[3, 3]
]
);