module type COUNTER = sig
.. end
type
elt
Elements that are to be counted
type
t
val create : int -> t
A counter maps elements to natural numbers (the number of times this
element occurred)
val incr : t -> elt -> unit
Increment the counter for the given element
val incr_by : t -> int -> elt -> unit
Add or remove several occurrences at once. incr_by c x n
will add n
occurrences of x
if n>0
,
and remove abs n
occurrences if n<0
.
val get : t -> elt -> int
Number of occurrences for this element
val decr : t -> elt -> unit
Remove one occurrence of the element
Since 0.14
val length : t -> int
Number of distinct elements
Since 0.14
val add_seq : t -> elt CCHashtbl.sequence -> unit
Increment each element of the sequence
val of_seq : elt CCHashtbl.sequence -> t
of_seq s
is the same as add_seq (create ())
val to_seq : t -> (elt * int) CCHashtbl.sequence
to_seq tbl
returns elements of tbl
along with their multiplicity
Since 0.14
val add_list : t -> (elt * int) list -> unit
val of_list : (elt * int) list -> t
val to_list : t -> (elt * int) list
Since 0.14