From 072a25df0f353009fb4655c39eb2efca7a000ab4 Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Sun, 24 Jun 2018 10:43:58 -0700 Subject: [PATCH] set intersection implemented --- src/Expr.cc | 6 ++++++ src/Val.cc | 18 +++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Expr.cc b/src/Expr.cc index 617a7637df..ed14eb6045 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -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; } diff --git a/src/Val.cc b/src/Val.cc index 540719ef14..d6bcdae4a6 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -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;