2019-08-20 17:38:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Common/HashTable/StringHashMap.h>
|
|
|
|
#include <Common/HashTable/TwoLevelStringHashTable.h>
|
|
|
|
|
|
|
|
template <typename TMapped, typename Allocator = HashTableAllocator, template <typename...> typename ImplTable = StringHashMap>
|
|
|
|
class TwoLevelStringHashMap : public TwoLevelStringHashTable<StringHashMapSubMaps<TMapped, Allocator>, ImplTable<TMapped, Allocator>>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using Key = StringRef;
|
|
|
|
using Self = TwoLevelStringHashMap;
|
|
|
|
using Base = TwoLevelStringHashTable<StringHashMapSubMaps<TMapped, Allocator>, StringHashMap<TMapped, Allocator>>;
|
|
|
|
using LookupResult = typename Base::LookupResult;
|
|
|
|
|
2019-10-29 15:16:51 +00:00
|
|
|
using Base::Base;
|
|
|
|
|
2019-08-20 17:38:56 +00:00
|
|
|
template <typename Func>
|
|
|
|
void ALWAYS_INLINE forEachMapped(Func && func)
|
|
|
|
{
|
|
|
|
for (auto i = 0u; i < this->NUM_BUCKETS; ++i)
|
|
|
|
return this->impls[i].forEachMapped(func);
|
|
|
|
}
|
|
|
|
|
2019-10-29 15:16:51 +00:00
|
|
|
TMapped & ALWAYS_INLINE operator[](const Key & x)
|
2019-08-20 17:38:56 +00:00
|
|
|
{
|
|
|
|
bool inserted;
|
|
|
|
LookupResult it;
|
2019-10-29 15:16:51 +00:00
|
|
|
this->emplace(x, it, inserted);
|
2019-08-20 17:38:56 +00:00
|
|
|
if (inserted)
|
2019-10-29 15:16:51 +00:00
|
|
|
new (&it->getMapped()) TMapped();
|
|
|
|
return it->getMapped();
|
2019-08-20 17:38:56 +00:00
|
|
|
}
|
|
|
|
};
|