ClickHouse/src/Common/HashTable/TwoLevelHashMap.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.0 KiB
C++
Raw Normal View History

#pragma once
#include <Common/HashTable/TwoLevelHashTable.h>
#include <Common/HashTable/HashMap.h>
template
<
typename Key,
typename Cell,
typename Hash = DefaultHash<Key>,
typename Grower = TwoLevelHashTableGrower<>,
typename Allocator = HashTableAllocator,
2018-12-04 12:12:52 +00:00
template <typename ...> typename ImplTable = HashMapTable
>
class TwoLevelHashMapTable : public TwoLevelHashTable<Key, Cell, Hash, Grower, Allocator, ImplTable<Key, Cell, Hash, Grower, Allocator>>
{
public:
using Impl = ImplTable<Key, Cell, Hash, Grower, Allocator>;
using Base = TwoLevelHashTable<Key, Cell, Hash, Grower, Allocator, ImplTable<Key, Cell, Hash, Grower, Allocator>>;
using LookupResult = typename Impl::LookupResult;
using Base::Base;
using Base::prefetch;
template <typename Func>
void ALWAYS_INLINE forEachMapped(Func && func)
{
for (auto i = 0u; i < this->NUM_BUCKETS; ++i)
this->impls[i].forEachMapped(func);
}
2019-10-29 15:16:51 +00:00
typename Cell::Mapped & ALWAYS_INLINE operator[](const Key & x)
{
2019-10-29 15:16:51 +00:00
LookupResult it;
bool inserted;
this->emplace(x, it, inserted);
if (inserted)
2019-10-29 15:16:51 +00:00
new (&it->getMapped()) typename Cell::Mapped();
2019-10-29 15:16:51 +00:00
return it->getMapped();
}
};
template
<
typename Key,
typename Mapped,
typename Hash = DefaultHash<Key>,
typename Grower = TwoLevelHashTableGrower<>,
typename Allocator = HashTableAllocator,
2018-12-04 12:12:52 +00:00
template <typename ...> typename ImplTable = HashMapTable
>
using TwoLevelHashMap = TwoLevelHashMapTable<Key, HashMapCell<Key, Mapped, Hash>, Hash, Grower, Allocator, ImplTable>;
template
<
typename Key,
typename Mapped,
typename Hash = DefaultHash<Key>,
typename Grower = TwoLevelHashTableGrower<>,
typename Allocator = HashTableAllocator,
2018-12-04 12:12:52 +00:00
template <typename ...> typename ImplTable = HashMapTable
>
using TwoLevelHashMapWithSavedHash = TwoLevelHashMapTable<Key, HashMapCellWithSavedHash<Key, Mapped, Hash>, Hash, Grower, Allocator, ImplTable>;