mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 08:38:20 +00:00
Merge remote-tracking branch 'origin/topic/vern/set-ops2'
* origin/topic/vern/set-ops2: documentation, test suite update implemented set relationals bug fix for set intersection set intersection implemented mirroring previous topic/vern/set-ops to get branch up to date, since I'm a n00b Fixed a couple memory leaks and added a leak test
This commit is contained in:
commit
06c6e1188a
11 changed files with 528 additions and 26 deletions
93
src/Val.cc
93
src/Val.cc
|
@ -1706,9 +1706,11 @@ int TableVal::RemoveFrom(Val* val) const
|
|||
HashKey* k;
|
||||
while ( tbl->NextEntry(k, c) )
|
||||
{
|
||||
Val* index = RecoverIndex(k);
|
||||
|
||||
Unref(index);
|
||||
// Not sure that this is 100% sound, since the HashKey
|
||||
// comes from one table but is being used in another.
|
||||
// OTOH, they are both the same type, so as long as
|
||||
// we don't have hash keys that are keyed per dictionary,
|
||||
// it should work ...
|
||||
Unref(t->Delete(k));
|
||||
delete k;
|
||||
}
|
||||
|
@ -1716,6 +1718,91 @@ int TableVal::RemoveFrom(Val* val) const
|
|||
return 1;
|
||||
}
|
||||
|
||||
TableVal* TableVal::Intersect(const TableVal* tv) const
|
||||
{
|
||||
TableVal* result = new TableVal(table_type);
|
||||
|
||||
const PDict(TableEntryVal)* t0 = AsTable();
|
||||
const PDict(TableEntryVal)* t1 = tv->AsTable();
|
||||
PDict(TableEntryVal)* t2 = result->AsNonConstTable();
|
||||
|
||||
// Figure out which is smaller; assign it to t1.
|
||||
if ( t1->Length() > t0->Length() )
|
||||
{ // Swap.
|
||||
const PDict(TableEntryVal)* tmp = t1;
|
||||
t1 = t0;
|
||||
t0 = tmp;
|
||||
}
|
||||
|
||||
IterCookie* c = t1->InitForIteration();
|
||||
HashKey* k;
|
||||
while ( t1->NextEntry(k, c) )
|
||||
{
|
||||
// Here we leverage the same assumption about consistent
|
||||
// hashes as in TableVal::RemoveFrom above.
|
||||
if ( t0->Lookup(k) )
|
||||
t2->Insert(k, new TableEntryVal(0));
|
||||
|
||||
delete k;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TableVal::EqualTo(const TableVal* tv) const
|
||||
{
|
||||
const PDict(TableEntryVal)* t0 = AsTable();
|
||||
const PDict(TableEntryVal)* t1 = tv->AsTable();
|
||||
|
||||
if ( t0->Length() != t1->Length() )
|
||||
return false;
|
||||
|
||||
IterCookie* c = t0->InitForIteration();
|
||||
HashKey* k;
|
||||
while ( t0->NextEntry(k, c) )
|
||||
{
|
||||
// Here we leverage the same assumption about consistent
|
||||
// hashes as in TableVal::RemoveFrom above.
|
||||
if ( ! t1->Lookup(k) )
|
||||
{
|
||||
delete k;
|
||||
t0->StopIteration(c);
|
||||
return false;
|
||||
}
|
||||
|
||||
delete k;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TableVal::IsSubsetOf(const TableVal* tv) const
|
||||
{
|
||||
const PDict(TableEntryVal)* t0 = AsTable();
|
||||
const PDict(TableEntryVal)* t1 = tv->AsTable();
|
||||
|
||||
if ( t0->Length() > t1->Length() )
|
||||
return false;
|
||||
|
||||
IterCookie* c = t0->InitForIteration();
|
||||
HashKey* k;
|
||||
while ( t0->NextEntry(k, c) )
|
||||
{
|
||||
// Here we leverage the same assumption about consistent
|
||||
// hashes as in TableVal::RemoveFrom above.
|
||||
if ( ! t1->Lookup(k) )
|
||||
{
|
||||
delete k;
|
||||
t0->StopIteration(c);
|
||||
return false;
|
||||
}
|
||||
|
||||
delete k;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int TableVal::ExpandAndInit(Val* index, Val* new_val)
|
||||
{
|
||||
BroType* index_type = index->Type();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue