--- /dev/null
+INCLUDE "utils.ml"
+module type S =
+sig
+ type data
+ type t
+ val make : data -> t
+ val node : t -> data
+ val hash : t -> int
+ val uid : t -> int
+ val equal : t -> t -> bool
+end
+module Make (H : Hashtbl.HashedType) : S with type data = H.t =
+struct
+ type data = H.t
+ type t = { id : int;
+ key : int; (* hash *)
+ node : data;
+ }
+
+ let node t = t.node
+ let hash t = t.key
+ let uid t = t.id
+ let gen_uid =
+ let id = ref ~-1 in
+ fun () -> incr id;!id
+ let equal t1 t2 = t1 == t2 || t1.id == t2.id
+ module WH = Weak.Make( struct
+ type _t = t
+ type t = _t
+ let hash = hash
+ let equal a b = H.equal a.node b.node
+ end)
+ let pool = WH.create MED_H_SIZE
+ let make x =
+ let cell = { id = gen_uid(); key = H.hash x; node = x } in
+ WH.merge pool cell
+end