2014-12-24 19:00:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/HashTable/TwoLevelHashTable.h>
|
|
|
|
#include <Common/HashTable/HashMap.h>
|
2014-12-24 19:00:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
<
|
|
|
|
typename Key,
|
|
|
|
typename Cell,
|
|
|
|
typename Hash = DefaultHash<Key>,
|
2014-12-26 03:00:51 +00:00
|
|
|
typename Grower = TwoLevelHashTableGrower<>,
|
2018-12-03 13:00:01 +00:00
|
|
|
typename Allocator = HashTableAllocator,
|
2018-12-04 12:12:52 +00:00
|
|
|
template <typename ...> typename ImplTable = HashMapTable
|
2014-12-24 19:00:14 +00:00
|
|
|
>
|
2018-12-03 13:00:01 +00:00
|
|
|
class TwoLevelHashMapTable : public TwoLevelHashTable<Key, Cell, Hash, Grower, Allocator, ImplTable<Key, Cell, Hash, Grower, Allocator>>
|
2014-12-24 19:00:14 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-08-20 09:58:44 +00:00
|
|
|
using Impl = ImplTable<Key, Cell, Hash, Grower, Allocator>;
|
2022-09-21 16:59:07 +00:00
|
|
|
using Base = TwoLevelHashTable<Key, Cell, Hash, Grower, Allocator, ImplTable<Key, Cell, Hash, Grower, Allocator>>;
|
2019-08-20 09:58:44 +00:00
|
|
|
using LookupResult = typename Impl::LookupResult;
|
|
|
|
|
2022-09-21 16:59:07 +00:00
|
|
|
using Base::Base;
|
|
|
|
using Base::prefetch;
|
2014-12-30 12:58:02 +00:00
|
|
|
|
2019-08-08 16:16:19 +00:00
|
|
|
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)
|
2014-12-24 19:00:14 +00:00
|
|
|
{
|
2019-10-29 15:16:51 +00:00
|
|
|
LookupResult it;
|
2014-12-24 19:00:14 +00:00
|
|
|
bool inserted;
|
|
|
|
this->emplace(x, it, inserted);
|
|
|
|
|
2015-03-07 01:03:14 +00:00
|
|
|
if (inserted)
|
2019-10-29 15:16:51 +00:00
|
|
|
new (&it->getMapped()) typename Cell::Mapped();
|
2014-12-24 19:00:14 +00:00
|
|
|
|
2019-10-29 15:16:51 +00:00
|
|
|
return it->getMapped();
|
2014-12-24 19:00:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
<
|
|
|
|
typename Key,
|
|
|
|
typename Mapped,
|
|
|
|
typename Hash = DefaultHash<Key>,
|
2014-12-26 03:00:51 +00:00
|
|
|
typename Grower = TwoLevelHashTableGrower<>,
|
2018-12-03 13:00:01 +00:00
|
|
|
typename Allocator = HashTableAllocator,
|
2018-12-04 12:12:52 +00:00
|
|
|
template <typename ...> typename ImplTable = HashMapTable
|
2014-12-24 19:00:14 +00:00
|
|
|
>
|
2018-12-03 13:00:01 +00:00
|
|
|
using TwoLevelHashMap = TwoLevelHashMapTable<Key, HashMapCell<Key, Mapped, Hash>, Hash, Grower, Allocator, ImplTable>;
|
2014-12-24 19:00:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
<
|
|
|
|
typename Key,
|
|
|
|
typename Mapped,
|
|
|
|
typename Hash = DefaultHash<Key>,
|
2014-12-26 03:00:51 +00:00
|
|
|
typename Grower = TwoLevelHashTableGrower<>,
|
2018-12-03 13:00:01 +00:00
|
|
|
typename Allocator = HashTableAllocator,
|
2018-12-04 12:12:52 +00:00
|
|
|
template <typename ...> typename ImplTable = HashMapTable
|
2014-12-24 19:00:14 +00:00
|
|
|
>
|
2018-12-03 13:00:01 +00:00
|
|
|
using TwoLevelHashMapWithSavedHash = TwoLevelHashMapTable<Key, HashMapCellWithSavedHash<Key, Mapped, Hash>, Hash, Grower, Allocator, ImplTable>;
|