Implement standard-library-compatible iterators for Dictionary

This commit is contained in:
Tim Wojtulewicz 2020-09-22 13:59:13 -07:00
parent 9e9998c6e5
commit 892124378c
16 changed files with 834 additions and 254 deletions

View file

@ -274,17 +274,16 @@ bool Manager::CreateStream(Stream* info, RecordVal* description)
{
// create config mapping in ReaderInfo. Has to be done before the construction of reader_obj.
zeek::detail::HashKey* k;
IterCookie* c = info->config->AsTable()->InitForIteration();
TableEntryVal* v;
while ( (v = info->config->AsTable()->NextEntry(k, c)) )
auto* info_config_table = info->config->AsTable();
for ( const auto& icte : *info_config_table )
{
auto k = icte.GetHashKey();
auto* v = icte.GetValue<TableEntryVal*>();
auto index = info->config->RecreateIndex(*k);
string key = index->Idx(0)->AsString()->CheckString();
string value = v->GetVal()->AsString()->CheckString();
rinfo.config.insert(std::make_pair(util::copy_string(key.c_str()), util::copy_string(value.c_str())));
delete k;
}
}
@ -1340,16 +1339,14 @@ void Manager::EndCurrentSend(ReaderFrontend* reader)
}
assert(i->stream_type == TABLE_STREAM);
TableStream* stream = (TableStream*) i;
auto* stream = static_cast<TableStream*>(i);
// lastdict contains all deleted entries and should be empty apart from that
IterCookie *c = stream->lastDict->InitForIteration();
stream->lastDict->MakeRobustCookie(c);
InputHash* ih;
zeek::detail::HashKey *lastDictIdxKey;
while ( ( ih = stream->lastDict->NextEntry(lastDictIdxKey, c) ) )
for ( auto it = stream->lastDict->begin_robust(); it != stream->lastDict->end_robust(); ++it )
{
auto lastDictIdxKey = it->GetHashKey();
InputHash* ih = it->GetValue<InputHash*>();
ValPtr val;
ValPtr predidx;
EnumValPtr ev;
@ -1376,8 +1373,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader)
{
// Keep it. Hence - we quit and simply go to the next entry of lastDict
// ah well - and we have to add the entry to currDict...
stream->currDict->Insert(lastDictIdxKey, stream->lastDict->RemoveEntry(lastDictIdxKey));
delete lastDictIdxKey;
stream->currDict->Insert(lastDictIdxKey.get(), stream->lastDict->RemoveEntry(lastDictIdxKey.get()));
continue;
}
}
@ -1393,13 +1389,12 @@ void Manager::EndCurrentSend(ReaderFrontend* reader)
}
stream->tab->Remove(*ih->idxkey);
stream->lastDict->Remove(lastDictIdxKey); // delete in next line
delete lastDictIdxKey;
delete(ih);
stream->lastDict->Remove(lastDictIdxKey.get()); // delete in next line
delete ih;
}
stream->lastDict->Clear(); // should be empt. buti- well... who knows...
delete(stream->lastDict);
stream->lastDict->Clear(); // should be empty. but well... who knows...
delete stream->lastDict;
stream->lastDict = stream->currDict;
stream->currDict = new PDict<InputHash>;