Module Biocaml_accu (.ml)

module Biocaml_accu: sig .. end
A datastructure (based on Hashtbl) to accumulate values.

An Accu.t can be seen as a generalized histogram: values are mapped to bins, and each bin has a corresponding value which may be its size or its contents depending on the need.



Generic API

type ('instance, 'bin, 'increment, 'accu) t 
General type for accumulators: 'instances are mapped to 'bins, and the 'accumulated value for a 'bin is updated with an 'increment
val create : ?n:int ->
'd -> ('a -> 'b) -> ('c -> 'd -> 'd) -> ('a, 'b, 'c, 'd) t
create ~n e f op creates an accumulator, which maps instances to bins with f, uses e as a neutral element (that is the value associated to a bin before any value has been added to it) and updates the value of a bin with op. n is an estimation of the maximum number of bins.
val add : ('a, 'b, 'c, 'd) t -> 'a -> 'c -> unit
add accu x y updates the value in accu for the bin of x by an increment y
val stream : ('a, 'b, 'c, 'd) t -> ('b * 'd) Stream.t
val get : ('a, 'b, 'c, 'd) t -> 'b -> 'd option
get accu x returns the value associated to b in accu.

Counters and histograms

type 'instance counter = ('instance, 'instance, int, int) t 
The type of accumulators that count values
module Counter: sig .. end
val counts : ('a -> 'b) -> 'a Stream.t -> ('b * int) Stream.t
val product : ?filter:('a -> 'b -> bool) ->
('a -> 'b -> 'c) -> 'a list -> 'b list -> ('c * int) Stream.t
product filter f l1 l2 computes an histogram of values returned by f when it is applied for all combinations of elements in l1 and l2 such that the predicate filter is true

Relation

type ('a, 'b) relation = ('a, 'a, 'b, 'b list) t 
module Relation: sig .. end
val relation : ('a * 'b) Stream.t -> ('a * 'b list) Stream.t