Version 0.3.0.
[virt-dmesg.git] / src / counter.mli
1 (* Basic counting module.
2  * (C) Copyright 2003-2006 Merjis Inc.
3  *
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.
8  *
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.
13  *
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
18  *)
19
20 (** Basic counting module. *)
21
22 type 'a t
23 (** Count items of type ['a]. *)
24
25 val create : unit -> 'a t
26 (** Create a new counter. *)
27
28 val incr : 'a t -> 'a -> unit
29 (** [incr counter thing] adds one to the count of [thing]s in [counter]. *)
30
31 val decr : 'a t -> 'a -> unit
32 (** [decr counter thing] subtracts one to the count of [thing]s in [counter]. *)
33
34 val add : 'a t -> 'a -> int -> unit
35 (** [add counter thing n] adds [n] to the count of [thing]s in [counter]. *)
36
37 val sub : 'a t -> 'a -> int -> unit
38 (** [sub counter thing n] subtracts [n] to the count of [thing]s in [counter]. *)
39
40 val set : 'a t -> 'a -> int -> unit
41 (** [set counter thing n] sets the count of [thing]s to [n]. *)
42
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.
46   *)
47
48 val incr_get : 'a t -> 'a -> int
49 (** Faster form of {!Counter.incr} followed by {!Counter.get}. *)
50
51 val zero : 'a t -> 'a -> unit
52 (** [zero counter thing] sets the count of [thing]s to 0.
53   * See also {!Counter.clear}.
54   *)
55
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.
60   *)
61
62 val length : 'a t -> int
63 (** Return the number of distinct things. See also {!Counter.total} *)
64
65 val total : 'a t -> int
66 (** Return the number of things counted (the total number of counts).
67   * See also {!Counter.length}
68   *)
69
70 val clear : 'a t -> unit
71 (** [clear counter] zeroes all counts. *)