reservoir sampling
val create : ?random_state:Core.Random.State.t ‑> int ‑> 'a t
create ~random_state desired_sample_size
creates an empty sample of 'a
values.
The sample will grow no larger than desired_sample_size
when presented with more
values by calling add
.
val maybe_add : 'a t ‑> 'a ‑> unit
maybe_add t x
will randomly either add x
to t
or ignore it. If adding x
would grow the sample larger than desired_sample_size t
, some previously selected
value will be discarded.
val to_list : 'a t ‑> 'a list
the current selection from values previously seen by t
. Of all previously seen
values, each subset of size desired_sample_size t
is equally likely to have
been selected.
val select : ?random_state:Core.Random.State.t ‑> next:(unit ‑> 'a option) ‑> int ‑> 'a list
randomly select a subset of size sample_size
from a stream of unknown length.
Each possible subset is chosen with equal probability.
val num_seen : _ t ‑> int
number of things maybe_add
ed so far, no matter they're actually added or ignored
val clear : _ t ‑> unit
clear t
clears contents of t
and resets num_seen
. It doesn not reset random
state