Safety commit
[SXSI/xpathcomp.git] / ptset.ml
index 3185da4..68f7e2e 100644 (file)
--- a/ptset.ml
+++ b/ptset.ml
@@ -14,14 +14,14 @@ sig
   val is_singleton : t -> bool
   val mem_union : t -> t -> t
   val hash : t -> int
-  val uid : t -> int
+  val uid : t -> Uid.t
   val uncons : t -> elt*t
   val from_list : elt list -> t 
   val make : data -> t
   val node : t -> data
 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 =
@@ -44,8 +44,8 @@ struct
        | _ -> false
     let hash = function 
       | Empty -> 0
-      | Leaf i -> HASHINT2(HALF_MAX_INT,H.uid i)
-      | Branch (b,i,l,r) -> HASHINT4(b,i,HNode.uid l, HNode.uid r)
+      | Leaf i -> HASHINT2(HALF_MAX_INT,Uid.to_int (H.uid i))
+      | Branch (b,i,l,r) -> HASHINT4(b,i,Uid.to_int l.HNode.id, Uid.to_int r.HNode.id)
   end
  ;;
                             
@@ -79,7 +79,7 @@ struct
       | _ -> false
          
   let mem (k:elt) n = 
-    let kid = H.uid k in
+    let kid = Uid.to_int (H.uid k) in
     let rec loop n = match HNode.node n with
       | Empty -> false
       | Leaf j ->  k == j
@@ -142,10 +142,10 @@ END
   let match_prefix k p m = (mask k m) == p
     
   let add k t =
-    let kid = H.uid k in
+    let kid = Uid.to_int (H.uid k) in
     let rec ins n = match HNode.node n with
       | Empty -> leaf k
-      | Leaf j ->  if j == k then n else join kid (leaf k) (H.uid j) n
+      | Leaf j ->  if j == k then n else join kid (leaf k) (Uid.to_int (H.uid j)) n
       | Branch (p,m,t0,t1)  ->
          if match_prefix kid p m then
            if zero_bit kid m then 
@@ -158,7 +158,7 @@ END
     ins t
       
   let remove k t =
-    let kid = H.uid k in
+    let kid = Uid.to_int(H.uid k) in
     let rec rmv n = match HNode.node n with
       | Empty -> empty
       | Leaf j  -> if  k == j then empty else n
@@ -177,7 +177,7 @@ END
 
   let equal a b = HNode.equal a b 
 
-  let compare a b =  (HNode.uid a) - (HNode.uid b)
+  let compare a b =  (Uid.to_int (HNode.uid a)) - (Uid.to_int (HNode.uid b))
 
   let rec merge s t = 
     if (equal s t) (* This is cheap thanks to hash-consing *)
@@ -377,15 +377,25 @@ let from_list l = List.fold_left (fun acc e -> add e acc) empty l
 
 end
 
-module Int : S with type elt = int 
-  =
-  Make ( struct type t = int 
-               type data = t
-               external hash : t -> int = "%identity"
-               external uid : t -> int = "%identity"
-               let equal : t -> t -> bool = (==)
-               external make : t -> int = "%identity"
-               external node : t -> int = "%identity"
-                 
-        end
-       ) 
+module Int : sig
+  include S with type elt = int
+  val print : Format.formatter -> t -> unit
+end
+  = 
+struct
+  include Make ( struct type t = int 
+                       type data = t
+                       external hash : t -> int = "%identity"
+                       external uid : t -> Uid.t = "%identity"
+                       external equal : t -> t -> bool = "%eq"
+                       external make : t -> int = "%identity"
+                       external node : t -> int = "%identity"
+                         
+                end
+              ) 
+  let print ppf s = 
+    Format.pp_print_string ppf "{ ";
+    iter (fun i -> Format.fprintf ppf "%i " i) s;
+    Format.pp_print_string ppf "}";
+    Format.pp_print_flush ppf ()
+ end