fn sample_efraimidis_spirakis<R, F, X, N>(
rng: &mut R,
length: N,
weight: F,
amount: N,
) -> Result<IndexVec, WeightError>Expand description
Randomly sample amount distinct indices from 0..length
The result may contain less than amount indices if insufficient non-zero
weights are available. Results are returned in an arbitrary order (there is
no guarantee of shuffling or ordering).
Function weight is called once for each index to provide weights.
This implementation is based on the algorithm A-ExpJ as found in
Efraimidis and Spirakis, 2005.
It uses O(length + amount) space and O(length) time.
Error cases:
WeightError::InvalidWeightwhen a weight is not-a-number or negative, or when infinite weights fill the reservoir before all elements have been processed (this always happens with more thanamountinfinite weights, and may also happen with exactlyamount, depending on order).