10# include <tbb/concurrent_unordered_set.h>
33template<
typename Key,
typename Hash = DefaultHash<Key>,
typename IsEqual = DefaultEquality<Key>>
41 struct TransparentIsEqual :
public IsEqual {
42 using is_transparent = void;
45 struct Hasher :
public Hash {
46 using transparent_key_equal = TransparentIsEqual;
49 using TBBSet = tbb::concurrent_unordered_set<Key, Hasher>;
57 template<
typename ForwardKey>
const Key *
lookup_ptr(
const ForwardKey &key)
const
59 typename TBBSet::const_iterator it = set_.find(key);
60 return (it == set_.end()) ?
nullptr : &*it;
80 return *set_.emplace(std::forward<ForwardKey>(key)).first;
92 set_.reserve(
typename TBBSet::size_type(n));
102 template<
typename ForwardKey>
struct Unwrap {
103 static const ForwardKey &get(
const ForwardKey &key)
108 template<
typename T>
struct Unwrap<std::unique_ptr<T>> {
109 static const T &get(
const std::unique_ptr<T> &key)
118 return Hash{}(Unwrap<ForwardKey>::get(key));
122 template<
typename ForwardKeyA,
typename ForwardKeyB>
123 bool operator()(
const ForwardKeyA &a,
const ForwardKeyB &
b)
const
125 return IsEqual{}(Unwrap<ForwardKeyA>::get(a), Unwrap<ForwardKeyB>::get(
b));
136 mutable std::unique_ptr<Mutex> mutex_ = std::make_unique<Mutex>();
142 : mutex_(std::exchange(other.mutex_, std::make_unique<Mutex>())), set_(std::move(other.set_))
147 std::destroy_at(
this);
156 template<
typename ForwardKey>
const Key *
lookup_ptr(
const ForwardKey &key)
const
158 std::lock_guard
lock{*mutex_};
159 const std::unique_ptr<Key> *stored = set_.lookup_key_ptr_as(key);
160 return stored ? stored->get() :
nullptr;
178 std::lock_guard
lock{*mutex_};
179 return *set_.lookup_key_or_add_as(std::make_unique<Key>(std::forward<ForwardKey>(key)));
185 std::lock_guard
lock{*mutex_};
192 std::lock_guard
lock{*mutex_};
void reserve(const int64_t n)
const Key & lookup_key_or_add_as(ForwardKey &&key)
const Key & lookup_key_or_add(const Key &key)
const Key * lookup_ptr(const ForwardKey &key) const
ConcurrentSet(ConcurrentSet &&other) noexcept
const Key & lookup_key_or_add(Key &&key)
ConcurrentSet & operator=(ConcurrentSet &&other) noexcept
NonCopyable(const NonCopyable &other)=delete
unsigned __int64 uint64_t
constexpr int64_t default_inline_buffer_capacity(size_t element_size)
PythonProbingStrategy<> DefaultProbingStrategy