60 static_assert(std::is_copy_constructible_v<Value>);
65 template<
typename T>
size_t hash(
const T &value)
const
70 template<
typename T1,
typename T2>
bool equal(
const T1 &a,
const T2 &
b)
const
72 return IsEqual{}(a,
b);
76 using TBBMap = tbb::concurrent_hash_map<Key, Value, Hasher>;
92 return map_.find(accessor, key);
101 return map_.find(accessor, key);
110 return map_.insert(accessor, key);
115 return map_.insert(accessor, key);
124 return map_.erase(key);
134 std::pair<Key, Value> item;
136 SetKey(
Key key) : item(std::move(key), Value()) {}
140 return Hash{}(this->item.first);
148 friend bool operator==(
const SetKey &a,
const SetKey &
b)
150 return IsEqual{}(a.item.first,
b.item.first);
153 friend bool operator==(
const Key &a,
const SetKey &
b)
155 return IsEqual{}(a,
b.item.first);
158 friend bool operator==(
const SetKey &a,
const Key &
b)
160 return IsEqual{}(a.item.first,
b);
164 using UsedSet = Set<SetKey>;
167 std::unique_lock<std::mutex> mutex;
168 std::pair<Key, Value> *data =
nullptr;
170 std::pair<Key, Value> *operator->()
185 accessor.mutex = std::unique_lock(mutex_);
186 SetKey *stored_key =
const_cast<SetKey *
>(set_.lookup_key_ptr_as(key));
190 accessor.data = &stored_key->item;
194 bool add(Accessor &accessor,
const Key &key)
196 accessor.mutex = std::unique_lock(mutex_);
197 const bool newly_added = !set_.contains_as(key);
198 SetKey &stored_key =
const_cast<SetKey &
>(set_.lookup_key_or_add_as(key));
199 accessor.data = &stored_key.item;
205 std::unique_lock
lock(mutex_);
206 return set_.remove_as(key);