X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=hlist.ml;h=e5a4aa54818e3da6cd5099440977f74f6b4315c4;hb=c5f06d325240c808a9be4d71e20fc01969420bb3;hp=4b836689099f5dfc81c2d1ec6259f39e09306002;hpb=451e60ad59e35344dff62da5ca27fcd5eec1bff9;p=SXSI%2Fxpathcomp.git diff --git a/hlist.ml b/hlist.ml index 4b83668..e5a4aa5 100644 --- a/hlist.ml +++ b/hlist.ml @@ -2,9 +2,19 @@ INCLUDE "utils.ml" module type S = sig type elt type 'a node = Nil | Cons of elt * 'a - type t + + module rec Node : + sig + include Hcons.S with type data = Data.t + end + and Data : sig + include Hashtbl.HashedType with type t = Node.t node + end + type data = Data.t + type t = Node.t val hash : t -> int val uid : t -> int + val make : data -> t val equal : t -> t -> bool val nil : t val node : t -> t node @@ -19,59 +29,51 @@ module type S = sig val length : t -> int end -module Make ( H : Hcons.S ) : S with type elt = H.t = +module Make ( H : Hcons.SA ) : S with type elt = H.t = struct type elt = H.t type 'a node = Nil | Cons of elt * 'a - module rec HNode : Hcons.S with type data = Node.t = Hcons.Make (Node) - and Node : Hashtbl.HashedType with type t = HNode.t node = + module rec Node : Hcons.S with type data = Data.t = Hcons.Make (Data) + and Data : Hashtbl.HashedType with type t = Node.t node = struct - type t = HNode.t node + type t = Node.t node let equal x y = match x,y with - | Nil,Nil -> true - | Cons (a,aa), Cons(b,bb) -> (H.equal a b) && (HNode.equal aa bb) + | _,_ when x==y -> true + | Cons (a,aa), Cons(b,bb) -> (aa==bb) && (H.equal a b) | _ -> false let hash = function | Nil -> 0 - | Cons(a,aa) -> HASHINT3(PRIME3,H.uid a, HNode.uid aa) + | Cons(a,aa) -> HASHINT3(PRIME3,H.uid a, aa.Node.id) end - ;; - - type t = HNode.t - let node = HNode.node - let hash = HNode.hash - let equal = HNode.equal - let uid = HNode.uid - let nil = HNode.make Nil - let cons a b = HNode.make (Cons(a,b)) - let hd a = - match HNode.node a with - | Nil -> failwith "hd" - | Cons(a,_) -> a - - let tl a = - match HNode.node a with - | Nil -> failwith "tl" - | Cons(_,a) -> a - + type data = Data.t + type t = Node.t + let make = Node.make + let node = Node.node + let hash = Node.hash + let equal = Node.equal + let uid = Node.uid + let nil = Node.make Nil + let cons a b = Node.make (Cons(a,b)) + let hd = function { Node.node = Cons(a,_) } -> a | _ -> failwith "hd" + let tl = function { Node.node = Cons(_,a) } -> a | _ -> failwith "tl" let fold f l acc = - let rec loop acc l = match HNode.node l with + let rec loop acc l = match l.Node.node with | Nil -> acc | Cons(a,aa) -> loop (f a acc) aa in loop acc l let map f l = - let rec loop l = match HNode.node l with + let rec loop l = match l.Node.node with | Nil -> nil | Cons(a,aa) -> cons (f a) (loop aa) in loop l let iter f l = - let rec loop l = match HNode.node l with + let rec loop l = match l.Node.node with | Nil -> () | Cons(a,aa) -> (f a);(loop aa) in