Description
The current Intersect function is below: (please read my comments)
I would like Intersect to accept a relation with different output arity. The output tuples of the two relations need to be merged together. The merge will be based on the constraints and may not be straightforward.
Relation* Relation::Intersect(const Relation* rhs) const{
// 1. Check that the arities are compatible.
// This requirement is what I want to change. I would like it to require the input arities to be the same, but the output arities can vary.
if (rhs->mInArity != mInArity || rhs->mOutArity != mOutArity) {
throw assert_exception("Relation::Union: mismatched arities");
}
// we will still construct a new relation -- however, the output arity will be a bit more difficult to figure out.
// We need to figure out which output tuple variables overlap and should not be duplicated
Relation *result = new Relation(mInArity, mOutArity);
// Have to do cross product intersection between conjunctions in both sets.
// still need to do this!
for (std::list<Conjunction*>::const_iterator i=mConjunctions.begin();
i != mConjunctions.end(); i++) {
for (std::list<Conjunction*>::const_iterator
j=rhs->mConjunctions.begin();
j != rhs->mConjunctions.end(); j++) {
result->addConjunction((*i)->Intersect(*j));
}
}
//result->cleanUp(); FIXME: might want later when cleanup can merge
//constraints that have adjacent constraints
return result;
}