-(* intersect_attributes is successful iff there is no attribute with *)
-(* two different values in the two lists. The returned list is the *)
-(* union of the two lists. *)
-let rec intersect_attributes (attr1, attr2) =
- match attr1, attr2 with
- [],_ -> attr2
- | _,[] -> attr1
- | (key1,value1)::tl1, (key2,_)::_ when key1 < key2 ->
- (key1,value1)::(intersect_attributes (tl1,attr2))
- | (key1,_)::_, (key2,value2)::tl2 when key2 < key1 ->
- (key2,value2)::(intersect_attributes (attr1,tl2))
- | entry1::tl1, entry2::tl2 when entry1 = entry2 ->
- entry1::(intersect_attributes (tl1,tl2))
- | _, _ -> raise NotCompatible (* same keys, different values *)
+(* Catenates two lists preserving order and getting rid of duplicates *)
+let rec append (l1,l2) =
+ match l1,l2 with
+ [],_ -> l2
+ | _,[] -> l1
+ | s1::tl1, s2::_ when s1 < s2 -> s1::append (tl1,l2)
+ | s1::_, s2::tl2 when s2 < s1 -> s2::append (l1,tl2)
+ | s1::tl1, s2::tl2 -> s1::append (tl1,tl2)
+
+;;
+
+
+(* Sums two attribute groups preserving order *)
+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))
+
+;;
+
+(* Product between an attribute set and a group of attributes *)
+let rec sub_prod (aset, gr) = (*prende un aset e un gr, fa la somma tra tutti i gruppi di aset e gr*)
+ match aset with
+ [] -> []
+ | gr1::tl1 -> sum_groups (gr1, gr)::(sub_prod(tl1, gr))