struct
type t = Atom.t array
let equal a1 a2 =
let n = Array.length a1 in
let n2 = Array.length a2 in
if n <> n2 then false
else
let res = ref true in
let i = ref 0 in
while !res && !i < n do
res := (Atom.compare a1.(!i) a2.(!i) = 0);
incr i
done;
!res
let hash = Hashtbl.hash_param 100 500
let subset a1 a2 =
TimerSubset.start ();
let n1 = Array.length a1 in
let n2 = Array.length a2 in
let s =
if n1 > n2 then false
else
let i1 = ref 0 in
let i2 = ref 0 in
while !i1 < n1 && !i2 < n2 do
let c = Atom.compare a1.(!i1) a2.(!i2) in
if c = 0 then (incr i1; incr i2)
else if c < 0 then i2 := n2
else incr i2
done;
!i1 = n1
in
TimerSubset.pause ();
s
let trivial_is_implied a1 a2 =
TimerSubset.start ();
let n1 = Array.length a1 in
let n2 = Array.length a2 in
let s =
if n1 > n2 then false
else
let i1 = ref 0 in
let i2 = ref 0 in
while !i1 < n1 && !i2 < n2 do
let c = Atom.trivial_is_implied a1.(!i1) a2.(!i2) in
if c = 0 then (incr i1; incr i2)
else if c < 0 then i2 := n2
else incr i2
done;
!i1 = n1
in
TimerSubset.pause ();
s
let subset = trivial_is_implied
let of_satom s =
Array.of_list (SAtom.elements s)
let to_satom =
Array.fold_left (fun s a -> SAtom.add a s) SAtom.empty
let union a b = Array.append a b
let apply_subst sigma a =
TimerApply.start ();
if Variable.is_subst_identity sigma then (TimerApply.pause (); a)
else
let a' = Array.init (Array.length a) (fun i -> Atom.subst sigma a.(i)) in
Array.fast_sort Atom.compare a';
TimerApply.pause ();
a'
let alpha atoms args =
let subst = Variable.build_subst args Variable.alphas in
List.map snd subst, apply_subst subst atoms
let nb_diff a1 a2 =
TimerSubset.start ();
let cpt = ref 0 in
let n1 = Array.length a1 in
let n2 = Array.length a2 in
let i1 = ref 0 in
let i2 = ref 0 in
while !i1 < n1 && !i2 < n2 do
let c = Atom.compare a1.(!i1) a2.(!i2) in
if c = 0 then (incr i1; incr i2)
else if c < 0 then (incr cpt; incr i1)
else incr i2
done;
TimerSubset.pause ();
!cpt + (n1 - !i1)
let compare_nb_diff a p1 p2 =
Pervasives.compare (nb_diff p1 a) (nb_diff p2 a)
let nb_common a1 a2 =
TimerSubset.start ();
let cpt = ref 0 in
let n1 = Array.length a1 in
let n2 = Array.length a2 in
let i1 = ref 0 in
let i2 = ref 0 in
while !i1 < n1 && !i2 < n2 do
let c = Atom.compare a1.(!i1) a2.(!i2) in
if c = 0 then (incr cpt; incr i1; incr i2)
else if c < 0 then incr i1
else incr i2
done;
TimerSubset.pause ();
(float_of_int !cpt) /. (float_of_int n1)
let compare_nb_common a p1 p2 =
Pervasives.compare (nb_common p2 a) (nb_common p1 a)
let diff a1 a2 =
let n1 = Array.length a1 in
let n2 = Array.length a2 in
let i1 = ref 0 in
let i2 = ref 0 in
let cpt = ref 0 in
let d = Array.copy a1 in
while !i1 < n1 && !i2 < n2 do
let ai1 = a1.(!i1) in
let c = Atom.compare ai1 a2.(!i2) in
if c = 0 then (incr i1; incr i2)
else if c < 0 then begin
d.(!cpt) <- ai1;
incr cpt;
incr i1
end
else incr i2
done;
while !i1 < n1 do
d.(!cpt) <- a1.(!i1);
incr cpt;
incr i1
done;
Array.sub d 0 !cpt
let print fmt a =
fprintf fmt "@[<hov>%a@]" (Atom.print_atoms false "&&") (Array.to_list a)
end