X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=hcons.ml;h=35bc9427232d20ca68173b2c70bb589fca936afd;hb=cad5e2e2831477cba1f6211c57b9a4cc5b58bd55;hp=293b90f2e032dc02ae128f6ff383d0f6f40fd00f;hpb=f1da22caf34bc3367984228ace9e7e7aa0760f0a;p=SXSI%2Fxpathcomp.git diff --git a/hcons.ml b/hcons.ml index 293b90f..35bc942 100644 --- a/hcons.ml +++ b/hcons.ml @@ -1,34 +1,46 @@ 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 type SA = + 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 type S = + sig + type data + type t = private { id : int; + key : int; + node : data } + 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; - } - + type t = { id : int; + key : int; + 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 + let equal = (==) module WH = Weak.Make( struct type _t = t type t = _t let hash = hash - let equal a b = H.equal a.node b.node + let equal a b = a==b || H.equal a.node b.node end) let pool = WH.create MED_H_SIZE let make x =