X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fmathql_interpreter%2Funion.ml;h=a02fbd0f5f417a054a9dbf07961f3ab3b828763f;hb=4ac188650f64fb947c5d87dcf3c932a4d013d842;hp=5573c192ed74d77d3dcaaec436c84f4d23e00090;hpb=9b23e4b3a2862c73d0b61c96cd68562dac3bf7f6;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/union.ml b/helm/ocaml/mathql_interpreter/union.ml index 5573c192e..a02fbd0f5 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,36 @@ let union_ex alist1 alist2 = ) (* match *) ) ;; +*) +(* Merges two attribute group lists preserves order and gets rid of duplicates*) +let rec merge l1 l2 = + match (l1,l2) with + [],l + | l,[] -> l + | g1::tl1,g2::_ when g1 < g2 -> g1::(merge tl1 l2) + | g1::_,g2::tl2 when g2 < g1 -> g2::(merge l1 tl2) + | g1::tl1,g2::tl2 -> g1::(merge tl1 tl2) +;; +(* preserves order and gets rid of duplicates *) +let rec union_ex rs1 rs2 = + match (rs1, rs2) with + [],l + | l,[] -> l + | (uri1,l1)::tl1,(uri2,_)::_ when uri1 < uri2 -> (uri1,l1)::(union_ex tl1 rs2) + | (uri1,_)::_,(uri2,l2)::tl2 when uri2 < uri1 -> (uri2,l2)::(union_ex rs1 tl2) + | (uri1,l1)::tl1,(uri2,l2)::tl2 -> if l1 = l2 then (uri1,l1)::(union_ex tl1 tl2) + else (uri1,merge l1 l2)::(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 + print_endline ("UNION(" ^ ll1 ^ "," ^ ll2 ^ "): " ^ diff ^ "s") ; + flush stdout ; + res +;;