Skip to content
This repository
Newer
Older
100644 48 lines (43 sloc) 1.637 kb
fccc6851 » MLstate
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (* CF mi *)
19
20 type ('a, 'b) t = ('a, ('b, unit) Hashtbl.t) Hashtbl.t
21 let create = Hashtbl.create
22 let clear = Hashtbl.clear
23 let copy = Hashtbl.copy
24 let remove = Hashtbl.remove
25 let mem = Hashtbl.mem
26 let iter = Hashtbl.iter
27 let fold = Hashtbl.fold
28 let length = Hashtbl.length
29 let add t k v =
30 let all = try Hashtbl.find t k with | Not_found -> Hashtbl.create 10 in
31 Hashtbl.replace all v (); Hashtbl.replace t k all
32 let find t k = try Hashtbl.find t k with | Not_found -> Hashtbl.create 10
33 let mem_cp t (k, v) = Hashtbl.mem (find t k) v
34 let gen_to_list f t =
35 let fold k v acc = (f k v)::acc in
36 Hashtbl.fold fold t []
37 let to_list t = gen_to_list (fun a b -> a, gen_to_list (fun a _ -> a) b) t
38 let find_list t k =
39 try
40 gen_to_list (fun a _ -> a) (Hashtbl.find t k)
41 with
42 | Not_found -> []
43 let iter_list f =
44 let iter k v = f k (gen_to_list (fun a _ -> a) v) in
45 Hashtbl.iter iter
46 let fold_list f =
47 let fold k v ac = f k (gen_to_list (fun a _ -> a) v) ac in
48 Hashtbl.fold fold
Something went wrong with that request. Please try again.