35 inline size_t operator()(
size_t idx,
size_t ,
size_t capacity)
const
40 return LIKELY(idx < capacity) ? idx : (idx - capacity);
45 inline size_t operator()(
size_t idx,
size_t numProbes,
size_t capacity)
const
50 return LIKELY(idx < capacity) ? idx : (idx - capacity);
56 class KeyHash = std::hash<KeyT>,
57 class KeyEqual = std::equal_to<KeyT>,
58 class ProbeFcn = AtomicHashSetLinearProbeFcn>
60 static_assert((std::is_convertible<KeyT, int32_t>::value ||
61 std::is_convertible<KeyT, int64_t>::value ||
62 std::is_convertible<KeyT, const void *>::value),
63 "You are trying to use AtomicHashSet with disallowed key "
64 "types. You must use atomically compare-and-swappable integer "
65 "keys, or a different container class.");
77 typedef typename std::conditional<isAtomic, std::atomic<KeyT>, KeyT>::type cell_type;
78 std::vector<cell_type> cells_;
97 KeyHash hasher = KeyHash(),
98 KeyEqual equalityChecker = KeyEqual(),
129 if (*cell == existingKey) {
140 return cell->compare_exchange_strong(existingKey, newKey, std::memory_order_acq_rel);
145 size_t idx = keyToAnchorIdx(key);
146 size_t numProbes = 0;
148 cell_type *cell = &cells_[idx];
153 return std::make_pair(key,
true);
159 return std::make_pair(existingKey,
false);
170 idx = ProbeFcn()(idx, numProbes,
capacity_);
175 inline size_t keyToAnchorIdx(
const KeyT k)
const
177 const size_t hashVal =
hasher_(k);
178 const size_t probe = hashVal & kAnchorMask_;
typedef double(DMatrix)[4][4]
AtomicHashSet & operator=(const AtomicHashSet &)=delete
AtomicHashSet(size_t maxSize, KeyHash hasher=KeyHash(), KeyEqual equalityChecker=KeyEqual(), const Config &c=Config())
bool tryUpdateCell(std::atomic< KeyT > *cell, KeyT &existingKey, KeyT newKey)
bool tryUpdateCell(KeyT *cell, KeyT &existingKey, KeyT newKey)
std::pair< KeyT, bool > emplace(KeyT key)
KeyEqual equalityChecker_
AtomicHashSet(const AtomicHashSet &)=delete
size_t operator()(size_t idx, size_t, size_t capacity) const
size_t operator()(size_t idx, size_t numProbes, size_t capacity) const