sample_single_excluding_l_reservoir

Function sample_single_excluding_l_reservoir 

Source
pub fn sample_single_excluding_l_reservoir<I, R, T, E>(
    rng: &mut R,
    iterable: I,
    excluded: E,
) -> Option<T>
where R: Rng, T: PartialEq, I: IntoIterator<Item = T>, E: Borrow<T>,
Expand description

Sample one element uniformly from an iterator, excluding any element equal to excluded. Returns None if the iterator is empty or every element equals excluded.

This is the iterator counterpart to sample_single_excluding. It runs in O(n) time and is correct even when the iterator does not report an exact length. Prefer sample_single_excluding for slices, which can dispatch to a faster rejection-sampling strategy backed by random access.