X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fmathql_interpreter%2Funion.ml;fp=helm%2Focaml%2Fmathql_interpreter%2Funion.ml;h=65f73503be9ce5c3b9b5743e9e785c2c12ce9f23;hb=7f510b2df638258669d6539861a3f06ed5fab773;hp=5573c192ed74d77d3dcaaec436c84f4d23e00090;hpb=9f45f8febfade5e1dca7a022154f2635be2af9b2;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/union.ml b/helm/ocaml/mathql_interpreter/union.ml index 5573c192e..65f73503b 100644 --- a/helm/ocaml/mathql_interpreter/union.ml +++ b/helm/ocaml/mathql_interpreter/union.ml @@ -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 +;;