X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Fptset.ml;h=9d415f81ca0396b37ca05d2a4f2380f24fd5c13a;hp=774b9fc5fa6846d298adb282baff3197c3c5e717;hb=9a127b83fbb1171ebd36e6f42780093412a5e91a;hpb=a5677f6cf1ad13dcb9a0c8a8879eeec8e9162363 diff --git a/src/ptset.ml b/src/ptset.ml index 774b9fc..9d415f8 100644 --- a/src/ptset.ml +++ b/src/ptset.ml @@ -22,10 +22,10 @@ INCLUDE "utils.ml" -include Sigs.PTSET +include Ptset_sig module type HConsBuilder = - functor (H : Sigs.AUX.HashedType) -> Hcons.S with type data = H.t + functor (H : Common_sig.HashedType) -> Hcons.S with type data = H.t module Builder (HCB : HConsBuilder) (H : Hcons.Abstract) : S with type elt = H.t = @@ -38,7 +38,7 @@ struct | Branch of int * int * 'a * 'a module rec Node : Hcons.S with type data = Data.t = HCB(Data) - and Data : Sigs.AUX.HashedType with type t = Node.t set = + and Data : Common_sig.HashedType with type t = Node.t set = struct type t = Node.t set let equal x y = @@ -48,7 +48,7 @@ struct | Branch(b1,i1,l1,r1), Branch(b2,i2,l2,r2) -> b1 == b2 && i1 == i2 && (Node.equal l1 l2) && (Node.equal r1 r2) - | _ -> false + | (Empty|Leaf _|Branch _), _ -> false let hash = function | Empty -> 0 @@ -80,8 +80,9 @@ struct let singleton k = leaf k let is_singleton n = - match Node.node n with Leaf _ -> true - | _ -> false + match Node.node n with + | Leaf _ -> true + | Branch _ | Empty -> false let mem (k:elt) n = let kid = Uid.to_int (H.uid k) in @@ -119,10 +120,10 @@ struct loop 7 let hbit = Array.init 256 naive_highest_bit - (* - external clz : int -> int = "caml_clz" "noalloc" - external leading_bit : int -> int = "caml_leading_bit" "noalloc" - *) + (* + external clz : int -> int = "caml_clz" "noalloc" + external leading_bit : int -> int = "caml_leading_bit" "noalloc" + *) let highest_bit x = try let n = (x) lsr 24 in @@ -182,14 +183,14 @@ struct in rmv t - (* should run in O(1) thanks to Hash consing *) + (* should run in O(1) thanks to hash consing *) let equal a b = Node.equal a b let compare a b = (Uid.to_int (Node.uid a)) - (Uid.to_int (Node.uid b)) let rec merge s t = - if (equal s t) (* This is cheap thanks to hash-consing *) + if equal s t (* This is cheap thanks to hash-consing *) then s else match Node.node s, Node.node t with @@ -348,9 +349,9 @@ struct | Branch (p1,m1,l1,r1), Branch (p2,m2,l2,r2) -> if m1 == m2 && p1 == p2 then intersect l1 l2 || intersect r1 r2 - else if m1 < m2 && match_prefix p2 p1 m1 then + else if m1 > m2 && match_prefix p2 p1 m1 then intersect (if zero_bit p2 m1 then l1 else r1) s2 - else if m1 > m2 && match_prefix p1 p2 m2 then + else if m1 < m2 && match_prefix p1 p2 m2 then intersect s1 (if zero_bit p1 m2 then l2 else r2) else false