Function malachite_base::vecs::exhaustive::shortlex_vecs
source · pub fn shortlex_vecs<I: Clone + Iterator>(
xs: I,
) -> ShortlexVecs<I::Item, PrimitiveIntIncreasingRange<u64>, I> ⓘ
Expand description
Generates Vec
s 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, only Vec
s of length 0 and 1 are ever produced.
If xs
is empty, the output length is 1; otherwise, the output is infinite.
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;
let bss = shortlex_vecs(exhaustive_bools()).take(20).collect_vec();
assert_eq!(
bss.iter().map(Vec::as_slice).collect_vec().as_slice(),
&[
&[][..],
&[false],
&[true],
&[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],
&[false, false, false, false],
&[false, false, false, true],
&[false, false, true, false],
&[false, false, true, true],
&[false, true, false, false]
]
);