set intersection implemented

This commit is contained in:
Vern Paxson 2018-06-24 10:43:58 -07:00
parent 6449b0ab9e
commit 072a25df0f
2 changed files with 13 additions and 11 deletions

View file

@ -860,6 +860,9 @@ Val* BinaryExpr::SetFold(Val* v1, Val* v2) const
if ( tag != EXPR_AND && tag != EXPR_OR && tag != EXPR_SUB )
BadTag("BinaryExpr::SetFold");
if ( tag == EXPR_AND )
return tv1->Intersect(tv2);
// TableVal* result = new TableVal(v1->Type()->AsTableType());
TableVal* result = v1->Clone()->AsTableVal();
@ -875,6 +878,9 @@ Val* BinaryExpr::SetFold(Val* v1, Val* v2) const
reporter->InternalError("set difference failed to type check");
}
else
BadTag("BinaryExpr::SetFold", expr_name(tag));
return result;
}

View file

@ -1729,7 +1729,7 @@ TableVal* TableVal::Intersect(const TableVal* tv) const
const PDict(TableEntryVal)* t1 = tv->AsTable();
const PDict(TableEntryVal)* t2 = AsTable();
const PDict(TableEntryVal)* t3 = result->AsTable();
PDict(TableEntryVal)* t3 = result->AsNonConstTable();
// Figure out which is smaller.
if ( t1->Length() > t2->Length() )
@ -1743,16 +1743,12 @@ TableVal* TableVal::Intersect(const TableVal* tv) const
HashKey* k;
while ( t1->NextEntry(k, c) )
{
//### // Here we leverage the same assumption about consistent
//### // hashes as in TableVal::RemoveFrom above.
//### if ( t2->Lookup(k) )
//### {
//### Val* index = RecoverIndex();
//### result->
//###
//### Unref(index);
//### Unref(t->Delete(k));
//### delete k;
// Here we leverage the same assumption about consistent
// hashes as in TableVal::RemoveFrom above.
if ( t2->Lookup(k) )
t3->Insert(k, new TableEntryVal(0));
delete k;
}
return result;