Release coccinelle-0.1.2
[bpt/coccinelle.git] / commons / oassoch.ml
1 open Common
2
3 open Oassoc
4
5 (* !!take care!!: this class does side effect, not a pure oassoc *)
6 class ['a,'b] oassoch xs =
7 let h = Common.hash_of_list xs in
8 object(o)
9 inherit ['a,'b] oassoc
10
11 val data = h
12
13 method empty = {< data = Hashtbl.create 101 >}
14 method add (k,v) = (Hashtbl.replace data k v; o) (* not add cos add make iter sux *)
15
16 (* redefine replkey to be more efficient than default. With hash, don't need
17 to delkey before add, replace do both action directly.
18 *)
19 method replkey (k,v) = (Hashtbl.replace data k v; o)
20 method iter f = Hashtbl.iter (curry f) data
21 method view = raise Todo
22
23 method del (k,v) = (Hashtbl.remove data k; o)
24 method mem e = raise Todo
25 method null = (try (Hashtbl.iter (fun k v -> raise ReturnExn) data; false) with ReturnExn -> true)
26
27 method assoc k =
28 try
29 Hashtbl.find data k
30 with Not_found -> (log3 ("pb assoc with k = " ^ (Dumper.dump k)); raise Not_found)
31
32 method delkey k = (Hashtbl.remove data k; o)
33 end
34