package core_extended

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

reservoir sampling

type 'a t

a random sample of 'a values

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 desired_sample_size : 'a t -> int

the desired sample size

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_added 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

OCaml

Innovation. Community. Security.