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
|
|
|
|
<
|
2017-04-01 07:20:54 +00:00
|
|
|
typename Key,
|
|
|
|
typename Cell,
|
|
|
|
typename Hash = DefaultHash<Key>,
|
|
|
|
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>;
|
|
|
|
using LookupResult = typename Impl::LookupResult;
|
|
|
|
|
2018-12-03 13:00:01 +00:00
|
|
|
using TwoLevelHashTable<Key, Cell, Hash, Grower, Allocator, ImplTable<Key, Cell, Hash, Grower, Allocator>>::TwoLevelHashTable;
|
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)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2019-10-29 15:16:51 +00:00
|
|
|
LookupResult it;
|
2017-04-01 07:20:54 +00:00
|
|
|
bool inserted;
|
|
|
|
this->emplace(x, it, inserted);
|
2014-12-24 19:00:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +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();
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2014-12-24 19:00:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
<
|
2017-04-01 07:20:54 +00:00
|
|
|
typename Key,
|
|
|
|
typename Mapped,
|
|
|
|
typename Hash = DefaultHash<Key>,
|
|
|
|
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
|
|
|
|
<
|
2017-04-01 07:20:54 +00:00
|
|
|
typename Key,
|
|
|
|
typename Mapped,
|
|
|
|
typename Hash = DefaultHash<Key>,
|
|
|
|
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>;
|