]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/union.ml
* New operators (Subset, SetEqual and RVarOccurrence) added to MathQL
[helm.git] / helm / ocaml / mathql_interpreter / union.ml
index 5573c192ed74d77d3dcaaec436c84f4d23e00090..65f73503be9ce5c3b9b5743e9e785c2c12ce9f23 100644 (file)
@@ -27,6 +27,7 @@
  * implementazione del comando UNION
  *)
 
+(*
 (*
  * 
  *)
@@ -104,4 +105,32 @@ let union_ex alist1 alist2 =
         ) (* match *)
        )
 ;;
+*)
 
+(* preserves order and gets rid of duplicates *)
+let rec union_ex l1 l2 =
+ let module S = Mathql_semantics in
+  match (l1, l2) with
+     [],l
+   | l,[] -> l
+   | ({S.uri = uri1} as entry1)::tl1,
+     ({S.uri = uri2} as entry2)::_ when uri1 < uri2 || entry1 < entry2 ->
+       entry1::(union_ex tl1 l2)
+   | ({S.uri = uri1} as entry1)::_,
+     ({S.uri = uri2} as entry2)::tl2 when uri2 < uri1 || entry2 < entry1 ->
+       entry2::(union_ex l1 tl2)
+   | entry1::tl1,entry2::tl2 -> (* same entry *)
+     entry1::(union_ex tl1 tl2)
+;;
+
+let union_ex l1 l2 =
+ let before = Unix.time () in
+ let res = union_ex l1 l2 in
+ let after = Unix.time () in
+  let ll1 = string_of_int (List.length l1) in
+  let ll2 = string_of_int (List.length l2) in
+  let diff = string_of_float (after -. before) in
+  prerr_endline ("UNION(" ^ ll1 ^ "," ^ ll2 ^ "): " ^ diff ^ "s") ;
+  flush stderr ;
+  res
+;;