]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/intersect.ml
Intersect patched..
[helm.git] / helm / ocaml / mathql_interpreter / intersect.ml
index 6503a39423579eab467ab080e2a45eef1d4dbfc4..84eb186a674296cf67d5324cc2e8a8912c6a74e9 100644 (file)
@@ -41,6 +41,7 @@ let rec sum_groups(gr1, gr2) =
   match gr1, gr2 with
      [],_ -> gr2
    | _,[] -> gr1
+   | gr1, gr2 when gr1 = gr2 -> gr1
    | (key1,l1)::tl1, (key2,l2)::_ when key1 < key2 -> (key1,l1)::(sum_groups (tl1,gr2))
    | (key1,l1)::_, (key2,l2)::tl2 when key2 < key1 -> (key2,l2)::(sum_groups (gr1,tl2))
    | (key1,l1)::tl1, (key2,l2)::tl2 -> (key1,(append (l1,l2)))::(sum_groups (tl1,tl2))
@@ -58,9 +59,9 @@ let rec sub_prod (aset, gr) =           (*prende un aset e un gr e fa la somma t
 (* Cartesian product between two attribute sets*)
 let rec prod (as1, as2) =
   match as1, as2 with
-    [],_ -> as2
-  | _,[] -> as1
-  | gr1::tl1, _ -> (sub_prod (as2, gr1))@(prod (tl1, as2))  (* chiamo la sub_prod con un el. as1 e as2 *)
+    [],_ -> []   
+  | _,[] -> []   
+  | gr1::tl1, _ -> append((sub_prod (as2, gr1)), (prod (tl1, as2)))  (* chiamo la sub_prod con un el. as1 e as2 *)
 ;;
 
 (* Intersection between two resource sets, preserves order and gets rid of duplicates *)