mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Implement standard-library-compatible iterators for Dictionary
This commit is contained in:
parent
9e9998c6e5
commit
892124378c
16 changed files with 834 additions and 254 deletions
|
@ -210,11 +210,10 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
|
|||
kp1 = reinterpret_cast<char*>(kp+1);
|
||||
|
||||
auto tbl = tv->AsTable();
|
||||
auto it = tbl->InitForIteration();
|
||||
auto lv = make_intrusive<ListVal>(TYPE_ANY);
|
||||
|
||||
struct HashKeyComparer {
|
||||
bool operator()(const HashKey* a, const HashKey* b) const
|
||||
bool operator()(const std::unique_ptr<HashKey>& a, const std::unique_ptr<HashKey>& b) const
|
||||
{
|
||||
if ( a->Hash() != b->Hash() )
|
||||
return a->Hash() < b->Hash();
|
||||
|
@ -226,19 +225,16 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
|
|||
}
|
||||
};
|
||||
|
||||
std::map<HashKey*, int, HashKeyComparer> hashkeys;
|
||||
HashKey* k;
|
||||
std::map<std::unique_ptr<HashKey>, int, HashKeyComparer> hashkeys;
|
||||
auto idx = 0;
|
||||
|
||||
while ( tbl->NextEntry(k, it) )
|
||||
for ( const auto& entry : *tbl )
|
||||
{
|
||||
hashkeys[k] = idx++;
|
||||
auto k = entry.GetHashKey();
|
||||
lv->Append(tv->RecreateIndex(*k));
|
||||
hashkeys[std::move(k)] = idx++;
|
||||
}
|
||||
|
||||
for ( auto& kv : hashkeys )
|
||||
delete kv.first;
|
||||
|
||||
for ( auto& kv : hashkeys )
|
||||
{
|
||||
auto idx = kv.second;
|
||||
|
@ -253,11 +249,10 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
|
|||
auto val = tv->FindOrDefault(key);
|
||||
|
||||
if ( ! (kp1 = SingleValHash(type_check, kp1, val->GetType().get(),
|
||||
val.get(), false)) )
|
||||
val.get(), false)) )
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue