mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 00:58:19 +00:00
set intersection implemented
This commit is contained in:
parent
6449b0ab9e
commit
072a25df0f
2 changed files with 13 additions and 11 deletions
|
@ -860,6 +860,9 @@ Val* BinaryExpr::SetFold(Val* v1, Val* v2) const
|
||||||
if ( tag != EXPR_AND && tag != EXPR_OR && tag != EXPR_SUB )
|
if ( tag != EXPR_AND && tag != EXPR_OR && tag != EXPR_SUB )
|
||||||
BadTag("BinaryExpr::SetFold");
|
BadTag("BinaryExpr::SetFold");
|
||||||
|
|
||||||
|
if ( tag == EXPR_AND )
|
||||||
|
return tv1->Intersect(tv2);
|
||||||
|
|
||||||
// TableVal* result = new TableVal(v1->Type()->AsTableType());
|
// TableVal* result = new TableVal(v1->Type()->AsTableType());
|
||||||
TableVal* result = v1->Clone()->AsTableVal();
|
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");
|
reporter->InternalError("set difference failed to type check");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
BadTag("BinaryExpr::SetFold", expr_name(tag));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
src/Val.cc
18
src/Val.cc
|
@ -1729,7 +1729,7 @@ TableVal* TableVal::Intersect(const TableVal* tv) const
|
||||||
|
|
||||||
const PDict(TableEntryVal)* t1 = tv->AsTable();
|
const PDict(TableEntryVal)* t1 = tv->AsTable();
|
||||||
const PDict(TableEntryVal)* t2 = AsTable();
|
const PDict(TableEntryVal)* t2 = AsTable();
|
||||||
const PDict(TableEntryVal)* t3 = result->AsTable();
|
PDict(TableEntryVal)* t3 = result->AsNonConstTable();
|
||||||
|
|
||||||
// Figure out which is smaller.
|
// Figure out which is smaller.
|
||||||
if ( t1->Length() > t2->Length() )
|
if ( t1->Length() > t2->Length() )
|
||||||
|
@ -1743,16 +1743,12 @@ TableVal* TableVal::Intersect(const TableVal* tv) const
|
||||||
HashKey* k;
|
HashKey* k;
|
||||||
while ( t1->NextEntry(k, c) )
|
while ( t1->NextEntry(k, c) )
|
||||||
{
|
{
|
||||||
//### // Here we leverage the same assumption about consistent
|
// Here we leverage the same assumption about consistent
|
||||||
//### // hashes as in TableVal::RemoveFrom above.
|
// hashes as in TableVal::RemoveFrom above.
|
||||||
//### if ( t2->Lookup(k) )
|
if ( t2->Lookup(k) )
|
||||||
//### {
|
t3->Insert(k, new TableEntryVal(0));
|
||||||
//### Val* index = RecoverIndex();
|
|
||||||
//### result->
|
delete k;
|
||||||
//###
|
|
||||||
//### Unref(index);
|
|
||||||
//### Unref(t->Delete(k));
|
|
||||||
//### delete k;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue