Tools for analyzing and reverse engineering hive files.
[libguestfs.git] / hivex / tools / counter.mli
1 (** Basic counting module.
2
3     Copyright (C) 2006 Merjis Ltd.
4
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.
9
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.
14
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
18 *)
19
20 type 'a t
21 (** Count items of type ['a]. *)
22
23 val create : unit -> 'a t
24 (** Create a new counter. *)
25
26 val incr : 'a t -> 'a -> unit
27 (** [incr counter thing] adds one to the count of [thing]s in [counter]. *)
28
29 val decr : 'a t -> 'a -> unit
30 (** [decr counter thing] subtracts one to the count of [thing]s in [counter]. *)
31
32 val add : 'a t -> 'a -> int -> unit
33 (** [add counter thing n] adds [n] to the count of [thing]s in [counter]. *)
34
35 val sub : 'a t -> 'a -> int -> unit
36 (** [sub counter thing n] subtracts [n] to the count of [thing]s in [counter]. *)
37
38 val set : 'a t -> 'a -> int -> unit
39 (** [set counter thing n] sets the count of [thing]s to [n]. *)
40
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.
44   *)
45
46 val incr_get : 'a t -> 'a -> int
47 (** Faster form of {!Counter.incr} followed by {!Counter.get}. *)
48
49 val zero : 'a t -> 'a -> unit
50 (** [zero counter thing] sets the count of [thing]s to 0.
51   * See also {!Counter.clear}.
52   *)
53
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.
58   *)
59
60 val length : 'a t -> int
61 (** Return the number of distinct things. See also {!Counter.total} *)
62
63 val total : 'a t -> int
64 (** Return the number of things counted (the total number of counts).
65   * See also {!Counter.length}
66   *)
67
68 val clear : 'a t -> unit
69 (** [clear counter] zeroes all counts. *)