Function malachite_base::vecs::exhaustive::shortlex_vecs_length_range
source · pub fn shortlex_vecs_length_range<I: Clone + Iterator>(
a: u64,
b: u64,
xs: I,
) -> ShortlexVecs<I::Item, PrimitiveIntIncreasingRange<u64>, I> ⓘ
Expand description
Generates all Vec
s with lengths in $[a, b)$ and with elements from a specified iterator, in
shortlex order.
Shortlex order means that the Vec
s are output from shortest to longest, and Vec
s of the
same length are output in lexicographic order with respect to the ordering of the Vec
elements specified by the input iterator.
xs
must be finite; if it’s infinite and $a < b$, only Vec
s of length a
(or 0 and 1, if
a
is 0) are ever produced.
The output length is
$$
\sum_{k=a}^{b-1} n^k,
$$
where $k$ is xs.count()
.
The lengths of the output Vec
s grow logarithmically.
§Examples
use itertools::Itertools;
use malachite_base::bools::exhaustive::exhaustive_bools;
use malachite_base::vecs::exhaustive::shortlex_vecs_length_range;
let bss = shortlex_vecs_length_range(2, 4, exhaustive_bools()).collect_vec();
assert_eq!(
bss.iter().map(Vec::as_slice).collect_vec().as_slice(),
&[
&[false, false][..],
&[false, true],
&[true, false],
&[true, true],
&[false, false, false],
&[false, false, true],
&[false, true, false],
&[false, true, true],
&[true, false, false],
&[true, false, true],
&[true, true, false],
&[true, true, true]
]
);