Expand description

Iterators that generate Vecs without repetition.

§lex_vecs_length_2

use itertools::Itertools;
use malachite_base::vecs::exhaustive::lex_vecs_length_2;

let xss = lex_vecs_length_2(
    ['a', 'b', 'c'].iter().cloned(),
    ['x', 'y', 'z'].iter().cloned(),
)
.collect_vec();
assert_eq!(
    xss.iter().map(Vec::as_slice).collect_vec().as_slice(),
    &[
        &['a', 'x'],
        &['a', 'y'],
        &['a', 'z'],
        &['b', 'x'],
        &['b', 'y'],
        &['b', 'z'],
        &['c', 'x'],
        &['c', 'y'],
        &['c', 'z']
    ]
);

§lex_vecs_fixed_length_2_inputs

use itertools::Itertools;
use malachite_base::chars::exhaustive::exhaustive_ascii_chars;
use malachite_base::iterators::bit_distributor::BitDistributorOutputType;
use malachite_base::vecs::exhaustive::lex_vecs_fixed_length_2_inputs;

// We are generating length-3 `Vec`s of `char`s using two input iterators. The first iterator
// (with index 0) produces all ASCII `char`s, and the second (index 1) produces the three
// `char`s `'x'`, `'y'`, and `'z'`. The elements of `output_types` are 0, 1, and 0, meaning that
// the first element of the output `Vec`s will be taken from iterator 0, the second element from
// iterator 1, and the third also from iterator 0.
let xss = lex_vecs_fixed_length_2_inputs(
    exhaustive_ascii_chars(),
    ['x', 'y', 'z'].iter().cloned(),
    &[0, 1, 0],
);
let xss_prefix = xss.take(20).collect_vec();
assert_eq!(
    xss_prefix
        .iter()
        .map(Vec::as_slice)
        .collect_vec()
        .as_slice(),
    &[
        &['a', 'x', 'a'],
        &['a', 'x', 'b'],
        &['a', 'x', 'c'],
        &['a', 'x', 'd'],
        &['a', 'x', 'e'],
        &['a', 'x', 'f'],
        &['a', 'x', 'g'],
        &['a', 'x', 'h'],
        &['a', 'x', 'i'],
        &['a', 'x', 'j'],
        &['a', 'x', 'k'],
        &['a', 'x', 'l'],
        &['a', 'x', 'm'],
        &['a', 'x', 'n'],
        &['a', 'x', 'o'],
        &['a', 'x', 'p'],
        &['a', 'x', 'q'],
        &['a', 'x', 'r'],
        &['a', 'x', 's'],
        &['a', 'x', 't']
    ]
);

§exhaustive_vecs_length_2

use itertools::Itertools;
use malachite_base::vecs::exhaustive::exhaustive_vecs_length_2;

let xss = exhaustive_vecs_length_2(
    ['a', 'b', 'c'].iter().cloned(),
    ['x', 'y', 'z'].iter().cloned(),
)
.collect_vec();
assert_eq!(
    xss.iter().map(Vec::as_slice).collect_vec().as_slice(),
    &[
        &['a', 'x'],
        &['a', 'y'],
        &['b', 'x'],
        &['b', 'y'],
        &['a', 'z'],
        &['b', 'z'],
        &['c', 'x'],
        &['c', 'y'],
        &['c', 'z']
    ]
);

§exhaustive_vecs_fixed_length_2_inputs

use itertools::Itertools;
use malachite_base::chars::exhaustive::exhaustive_ascii_chars;
use malachite_base::iterators::bit_distributor::BitDistributorOutputType;
use malachite_base::vecs::exhaustive::exhaustive_vecs_fixed_length_2_inputs;

// We are generating length-3 `Vec`s of `char`s using two input iterators. The first iterator
// (with index 0) produces all ASCII `char`s, and the second (index 1) produces the three
// `char`s `'x'`, `'y'`, and `'z'`. The elements of `output_types` have the indices 0, 1, and 0,
// meaning that the first element of the output `Vec`s will be taken from iterator 0, the second
// element from iterator 1, and the third also from iterator 0. The third element has a tiny
// output type, so it will grow more slowly than the other two elements (though it doesn't look
// that way from the first few `Vec`s).
let xss = exhaustive_vecs_fixed_length_2_inputs(
    exhaustive_ascii_chars(),
    ['x', 'y', 'z'].iter().cloned(),
    &[
        (BitDistributorOutputType::normal(1), 0),
        (BitDistributorOutputType::normal(1), 1),
        (BitDistributorOutputType::tiny(), 0),
    ],
);
let xss_prefix = xss.take(20).collect_vec();
assert_eq!(
    xss_prefix
        .iter()
        .map(Vec::as_slice)
        .collect_vec()
        .as_slice(),
    &[
        &['a', 'x', 'a'],
        &['a', 'x', 'b'],
        &['a', 'x', 'c'],
        &['a', 'x', 'd'],
        &['a', 'y', 'a'],
        &['a', 'y', 'b'],
        &['a', 'y', 'c'],
        &['a', 'y', 'd'],
        &['a', 'x', 'e'],
        &['a', 'x', 'f'],
        &['a', 'x', 'g'],
        &['a', 'x', 'h'],
        &['a', 'y', 'e'],
        &['a', 'y', 'f'],
        &['a', 'y', 'g'],
        &['a', 'y', 'h'],
        &['b', 'x', 'a'],
        &['b', 'x', 'b'],
        &['b', 'x', 'c'],
        &['b', 'x', 'd']
    ]
);

Structs§

  • Generates $k$-compositions of $n$ for all $n$ in a given range: all length-$k$ Vecs of positive usizes whose sum is in a given range.
  • This documentation applies not only to ExhaustiveFixedLengthVecs2Inputs, but also to ExhaustiveFixedLengthVecs3Inputs, ExhaustiveFixedLengthVecs4Inputs, and so on. See exhaustive_vecs_fixed_length for more information.
  • Generates all Vecs of elements from an iterator, where the Vecs have no repetitions and are ordered the same way as in the iterator.
  • Generates all Vecs with elements from a specified iterator and with lengths from another iterator.
  • Generates all collections of elements from an iterator, where the collections are of a fixed length, have no repetitions, and are ordered the same way as in the iterator.
  • This documentation applies not only to LexFixedLengthVecs2Inputs, but also to LexFixedLengthVecs3Inputs, LexFixedLengthVecs4Inputs, and so on. See lex_vecs_fixed_length for more information.
  • Generates all $k$-compositions of a number: all length-$k$ Vecs of positive usizes whose sum is a given number.
  • Generates all collections of elements from an iterator in lexicographic order, where the collections have no repetitions and are ordered the same way as in the iterator.
  • Generates all collections of elements from an iterator in lexicographic order, where the collections have no repetitions.
  • Generates all Vecs of elements from an iterator, where the Vecs are of a fixed length and have no repetitions.
  • Generates all collections of elements from an iterator in shortlex order, where the collections have no repetitions and are ordered the same way as in the iterator.
  • Generates all Vecs of elements from an iterator in shortlex order, where the Vecs have no repetitions.
  • Generates all Vecs with elements from a specified iterator and with lengths from another iterator.

Enums§

Functions§