Commits

camlspotter committed 877b3a0

Hashset has now find for hashconsing

Comments (0)

Files changed (2)

 (* poorman's hash set by hashtbl *)
-type 'a t = ('a, unit) Hashtbl.t
+type 'a t = ('a, 'a) Hashtbl.t
 
 let create = Hashtbl.create
-let add set x = Hashtbl.replace set x ()
+let add set x = Hashtbl.replace set x x
 let remove = Hashtbl.remove
 let mem = Hashtbl.mem
-let iter f = Hashtbl.iter (fun v () -> f v)
-let fold f = Hashtbl.fold (fun v () st -> f v st)
+let find = Hashtbl.find
+let find_opt t k = try Some (Hashtbl.find t k) with Not_found -> None
+let iter f = Hashtbl.iter (fun v _ -> f v)
+let fold f = Hashtbl.fold (fun v _ st -> f v st)
 let elements = Hashtbl.length
 let clear = Hashtbl.clear
 
 val add : 'a t -> 'a -> unit
 val remove : 'a t -> 'a -> unit
 val mem : 'a t -> 'a -> bool
+val find : 'a t -> 'a -> 'a (** good for hash consing *)
+val find_opt : 'a t -> 'a -> 'a option (** good for hash consing *)
 val iter : ('a -> unit) -> 'a t -> unit
 val fold : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
 val elements : 'a t -> int