1 | #pragma once |
---|---|
2 | |
3 | #include <Common/HashTable/ClearableHashSet.h> |
4 | #include <Common/HashTable/FixedHashTable.h> |
5 | |
6 | |
7 | template <typename Key> |
8 | struct FixedClearableHashTableCell |
9 | { |
10 | using State = ClearableHashSetState; |
11 | |
12 | using value_type = Key; |
13 | using mapped_type = VoidMapped; |
14 | UInt32 version; |
15 | |
16 | FixedClearableHashTableCell() {} |
17 | FixedClearableHashTableCell(const Key &, const State & state) : version(state.version) {} |
18 | |
19 | const VoidKey getKey() const { return {}; } |
20 | VoidMapped getMapped() const { return {}; } |
21 | |
22 | bool isZero(const State & state) const { return version != state.version; } |
23 | void setZero() { version = 0; } |
24 | |
25 | struct CellExt |
26 | { |
27 | Key key; |
28 | const VoidKey getKey() const { return {}; } |
29 | VoidMapped getMapped() const { return {}; } |
30 | const value_type & getValue() const { return key; } |
31 | void update(Key && key_, FixedClearableHashTableCell *) { key = key_; } |
32 | }; |
33 | }; |
34 | |
35 | |
36 | template <typename Key, typename Allocator = HashTableAllocator> |
37 | class FixedClearableHashSet : public FixedHashTable<Key, FixedClearableHashTableCell<Key>, Allocator> |
38 | { |
39 | public: |
40 | using Base = FixedHashTable<Key, FixedClearableHashTableCell<Key>, Allocator>; |
41 | using LookupResult = typename Base::LookupResult; |
42 | |
43 | void clear() |
44 | { |
45 | ++this->version; |
46 | this->m_size = 0; |
47 | } |
48 | }; |
49 |