Skip to main content

random_b_tree_sets_fixed_length

Function random_b_tree_sets_fixed_length 

Source
pub fn random_b_tree_sets_fixed_length<I: Iterator>(
    len: u64,
    xs: I,
) -> RandomBTreeSetsFixedLength<I> 
where I::Item: Ord,
Expand description

Randomly generates BTreeSets of a given length.

The input iterator must generate at least len distinct elements; otherwise, this iterator will hang.

$$ P((x_i)_{i=0}^{n-1}) = n!\prod_{i=0}^{n-1}P(x_i). $$

If len is 0, the output consists of the empty set, repeated.

xs must be infinite.

§Expected complexity per iteration

$T(i) = O(\ell \log \ell \cdot T^\prime(i))$

$M(i) = O(\ell M^\prime(i))$

where $T$ is time, $M$ is additional memory, $i$ is the iteration number, $T^\prime$ and $M^\prime$ are the time and memory functions of xs, and $\ell$ is len.

If xs can repeat values, extra draws are needed to reach the required number of distinct elements, and an iteration fails to terminate if fewer distinct values are reachable than the requested length.

§Expected complexity per iteration

$T(i) = O(m \log m \cdot T^\prime(i))$

$M(i) = O(m M^\prime(i))$

where $T$ is time, $M$ is additional memory, $i$ is the iteration number, $T^\prime$ and $M^\prime$ are the time and memory functions of the iterators produced by xs_gen, and $m$ is mean_length_numerator / mean_length_denominator.

If xs can repeat values, extra draws are needed to reach the required number of distinct elements, and an iteration fails to terminate if fewer distinct values are reachable than the requested length.

§Examples

use itertools::Itertools;
use malachite_base::num::random::random_unsigned_inclusive_range;
use malachite_base::random::EXAMPLE_SEED;
use malachite_base::sets::random::random_b_tree_sets_fixed_length;
use maplit::btreeset;

let xss = random_b_tree_sets_fixed_length(
    2,
    random_unsigned_inclusive_range::<u32>(EXAMPLE_SEED, 1, 100),
)
.take(10)
.collect_vec();
assert_eq!(
    xss,
    &[
        btreeset! {24, 95},
        btreeset! {71, 99},
        btreeset! {53, 93},
        btreeset! {34, 85},
        btreeset! {2, 48},
        btreeset! {11, 55},
        btreeset! {18, 48},
        btreeset! {90, 93},
        btreeset! {67, 93},
        btreeset! {93, 95}
    ]
);