1 (** Basic counting module.
3 Copyright (C) 2006 Merjis Ltd.
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 (** Count items of type ['a]. *)
23 val create : unit -> 'a t
24 (** Create a new counter. *)
26 val incr : 'a t -> 'a -> unit
27 (** [incr counter thing] adds one to the count of [thing]s in [counter]. *)
29 val decr : 'a t -> 'a -> unit
30 (** [decr counter thing] subtracts one to the count of [thing]s in [counter]. *)
32 val add : 'a t -> 'a -> int -> unit
33 (** [add counter thing n] adds [n] to the count of [thing]s in [counter]. *)
35 val sub : 'a t -> 'a -> int -> unit
36 (** [sub counter thing n] subtracts [n] to the count of [thing]s in [counter]. *)
38 val set : 'a t -> 'a -> int -> unit
39 (** [set counter thing n] sets the count of [thing]s to [n]. *)
41 val get : 'a t -> 'a -> int
42 (** [get counter thing] returns the count of [thing]s. (Returns 0 for
43 * [thing]s which have not been added.
46 val incr_get : 'a t -> 'a -> int
47 (** Faster form of {!Counter.incr} followed by {!Counter.get}. *)
49 val zero : 'a t -> 'a -> unit
50 (** [zero counter thing] sets the count of [thing]s to 0.
51 * See also {!Counter.clear}.
54 val read : 'a t -> (int * 'a) list
55 (** [read counter] reads the frequency of each thing. They are sorted
56 * with the thing appearing most frequently first. Only things occurring
57 * non-zero times are returned.
60 val length : 'a t -> int
61 (** Return the number of distinct things. See also {!Counter.total} *)
63 val total : 'a t -> int
64 (** Return the number of things counted (the total number of counts).
65 * See also {!Counter.length}
68 val clear : 'a t -> unit
69 (** [clear counter] zeroes all counts. *)