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