X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fmathql_interpreter%2Fintersect.ml;h=bf0d05c2c71454dd5aaad0e0be72472741009bc2;hb=69ecdb3f3ec94440f1736b5e0247f2ced2e5b2c6;hp=6bd620a108596575477b8c44cdf12cb426ed10d0;hpb=7f510b2df638258669d6539861a3f06ed5fab773;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/intersect.ml b/helm/ocaml/mathql_interpreter/intersect.ml index 6bd620a10..bf0d05c2c 100644 --- a/helm/ocaml/mathql_interpreter/intersect.ml +++ b/helm/ocaml/mathql_interpreter/intersect.ml @@ -55,22 +55,73 @@ let rec intersect_ex l1 l2 = {S.uri = uri2 ; S.attributes = attributes2}::tl2 -> try let attributes' = intersect_attributes (attributes1,attributes2) in - {S.uri = uri1 ; S.attributes = attributes'}::(intersect_ex tl1 tl2) + {S.uri = uri1 ; S.attributes = attributes' ; S.extra = ""}::(intersect_ex tl1 tl2) with NotCompatible -> intersect_ex tl1 tl2 ;; let intersect_ex l1 l2 = + (* PRE-CLAUDIO + (*let _ = print_string ("INTERSECT ") + and t = Unix.time () in*) + let result = + match (l1, l2) with + ((head1::tail1), (head2::tail2)) -> + (match (head1, head2) with + ([], _) -> assert false (* gli header non devono mai essere vuoti *) + | (_, []) -> assert false (* devono contenere almeno [retVal] *) + | (_, _) -> + (match (tail1, tail2) with + ([], _) -> [["retVal"]] (* se una delle due code e' vuota... *) + | (_, []) -> [["retVal"]] (* ... l'intersezione e' vuota *) + | (_, _) -> + [head2 @ + (List.find_all + (function t -> not (List.mem t head2)) + head1 + ) + ] (* header del risultato finale *) + @ + intersect_tails (List.tl head1) tail1 (List.tl head2) tail2 + (* + List.fold_left + (fun par1 elem1 -> par1 @ + List.map + (fun elem2 -> + [(List.hd elem1)] @ + (xres_join_context (List.tl head1) (List.tl elem1) + (List.tl head2) (List.tl elem2) + ) + ) + (List.find_all (* *) + (fun elem2 -> (* trova tutti gli elementi della lista tail2 *) + ((List.hd elem1) = (List.hd elem2)) && (* che stanno in tail1 *) + not ((xres_join_context (List.tl head1) (List.tl elem1) + (List.tl head2) (List.tl elem2)) = []) + (* e per i quali la xres_join_context non sia vuota *) + ) + tail2 (* List.find_all *) + ) + ) + [] + tail1 (* per ogni elemento di tail1 applica la List.fold_left *) + *) + ) (* match *) + ) + | _ -> [] + in + (*let _ = print_endline (string_of_float (Unix.time () -. t)); flush stdout in*) + result*) let before = Unix.time () in let res = intersect_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 + print_endline ("INTERSECT(" ^ ll1 ^ "," ^ ll2 ^ ") = " ^ string_of_int (List.length res) ^ ": " ^ diff ^ "s") ; - flush stderr ; + flush stdout ; res ;;