ClickHouse/dbms/Common/HashTable/TwoLevelStringHashMap.h

34 lines
1.1 KiB
C++
Raw Normal View History

#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;
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)
{
bool inserted;
LookupResult it;
2019-10-29 15:16:51 +00:00
this->emplace(x, it, inserted);
if (inserted)
2019-10-29 15:16:51 +00:00
new (&it->getMapped()) TMapped();
return it->getMapped();
}
};