Usable version:
[tatoo.git] / src / utils.ml
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                               TAToo                                 *)
4 (*                                                                     *)
5 (*                     Kim Nguyen, LRI UMR8623                         *)
6 (*                   Université Paris-Sud & CNRS                       *)
7 (*                                                                     *)
8 (*  Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
9 (*  Recherche Scientifique. All rights reserved.  This file is         *)
10 (*  distributed under the terms of the GNU Lesser General Public       *)
11 (*  License, with the special exception on linking described in file   *)
12 (*  ../LICENSE.                                                        *)
13 (*                                                                     *)
14 (***********************************************************************)
15
16 (** Various generic signatures and generic module and functor definitions
17 *)
18 INCLUDE "utils.ml"
19
20
21 module HashSet (H : Hashtbl.HashedType) :
22   Sigs.HashSet with type data = H.t =
23 struct
24   module T = Hashtbl.Make(H)
25   type data = H.t
26   type t = data T.t
27   let create = T.create
28   let add h v = T.add h v v
29   let find = T.find
30   let remove = T.remove
31   let find_all = T.find_all
32   let clear = T.clear
33   let mem = T.mem
34 end
35
36 module Pair (X : Sigs.Type) (Y : Sigs.Type) :
37   Sigs.Type with type t = X.t * Y.t =
38 struct
39   type t = X.t * Y.t
40   let hash (x, y) = HASHINT2(X.hash x, Y.hash y)
41   let compare (x1, y1) (x2, y2) =
42     let r = X.compare x1 x2 in
43     if r != 0 then r else Y.compare y1 y2
44   let equal p1 p2 =
45     p1 == p2 ||
46       let x1, y1 = p1
47       and x2, y2 = p2 in X.equal x1 x2 && Y.equal y1 y2
48 end