1 | #pragma once |
2 | |
3 | #include <Common/HashTable/StringHashMap.h> |
4 | #include <Common/HashTable/TwoLevelStringHashTable.h> |
5 | |
6 | template <typename TMapped, typename Allocator = HashTableAllocator, template <typename...> typename ImplTable = StringHashMap> |
7 | class TwoLevelStringHashMap : public TwoLevelStringHashTable<StringHashMapSubMaps<TMapped, Allocator>, ImplTable<TMapped, Allocator>> |
8 | { |
9 | public: |
10 | using Key = StringRef; |
11 | using Self = TwoLevelStringHashMap; |
12 | using Base = TwoLevelStringHashTable<StringHashMapSubMaps<TMapped, Allocator>, StringHashMap<TMapped, Allocator>>; |
13 | using LookupResult = typename Base::LookupResult; |
14 | |
15 | using Base::Base; |
16 | |
17 | template <typename Func> |
18 | void ALWAYS_INLINE forEachMapped(Func && func) |
19 | { |
20 | for (auto i = 0u; i < this->NUM_BUCKETS; ++i) |
21 | return this->impls[i].forEachMapped(func); |
22 | } |
23 | |
24 | TMapped & ALWAYS_INLINE operator[](const Key & x) |
25 | { |
26 | bool inserted; |
27 | LookupResult it; |
28 | this->emplace(x, it, inserted); |
29 | if (inserted) |
30 | new (&it->getMapped()) TMapped(); |
31 | return it->getMapped(); |
32 | } |
33 | }; |
34 | |