proxygen
folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > Class Template Reference

#include <AtomicHashArray.h>

Inheritance diagram for folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >:

Classes

struct  aha_iterator
 
struct  Config
 
struct  Deleter
 
struct  SimpleRetT
 

Public Types

typedef KeyT key_type
 
typedef ValueT mapped_type
 
typedef HashFcn hasher
 
typedef EqualFcn key_equal
 
typedef KeyConvertFcn key_convert
 
typedef std::pair< const KeyT, ValueTvalue_type
 
typedef std::size_t size_type
 
typedef std::ptrdiff_t difference_type
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 
typedef aha_iterator< const AtomicHashArray, const value_typeconst_iterator
 
typedef aha_iterator< AtomicHashArray, value_typeiterator
 
typedef std::unique_ptr< AtomicHashArray, DeleterSmartPtr
 

Public Member Functions

template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal>
iterator find (LookupKeyT k)
 
template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal>
const_iterator find (LookupKeyT k) const
 
std::pair< iterator, bool > insert (const value_type &r)
 
std::pair< iterator, bool > insert (value_type &&r)
 
template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal, typename LookupKeyToKeyFcn = key_convert, typename... ArgTs>
std::pair< iterator, bool > emplace (LookupKeyT key_in, ArgTs &&...vCtorArgs)
 
size_t erase (KeyT k)
 
void clear ()
 
size_t size () const
 
bool empty () const
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
iterator findAt (uint32_t idx)
 
const_iterator findAt (uint32_t idx) const
 
iterator makeIter (size_t idx)
 
const_iterator makeIter (size_t idx) const
 
double maxLoadFactor () const
 
void setEntryCountThreadCacheSize (uint32_t newSize)
 
uint32_t getEntryCountThreadCacheSize () const
 

Static Public Member Functions

static void destroy (AtomicHashArray *)
 
static SmartPtr create (size_t maxSize, const Config &c=Config())
 

Public Attributes

const size_t capacity_
 
const size_t maxEntries_
 
const KeyT kEmptyKey_
 
const KeyT kLockedKey_
 
const KeyT kErasedKey_
 

Private Member Functions

template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal, typename LookupKeyToKeyFcn = Identity, typename... ArgTs>
SimpleRetT insertInternal (LookupKeyT key, ArgTs &&...vCtorArgs)
 
template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal>
SimpleRetT findInternal (const LookupKeyT key)
 
template<typename MaybeKeyT >
void checkLegalKeyIfKey (MaybeKeyT key)
 
 AtomicHashArray (size_t capacity, KeyT emptyKey, KeyT lockedKey, KeyT erasedKey, double maxLoadFactor, uint32_t cacheSize)
 
 ~AtomicHashArray ()=default
 
void unlockCell (value_type *const cell, KeyT newKey)
 
bool tryLockCell (value_type *const cell)
 
template<class LookupKeyT = key_type, class LookupHashFcn = hasher>
size_t keyToAnchorIdx (const LookupKeyT k) const
 

Static Private Member Functions

static std::atomic< KeyT > * cellKeyPtr (const value_type &r)
 
static KeyT relaxedLoadKey (const value_type &r)
 
static KeyT acquireLoadKey (const value_type &r)
 

Private Attributes

const size_t kAnchorMask_
 
ThreadCachedInt< uint64_tnumEntries_
 
ThreadCachedInt< uint64_tnumPendingEntries_
 
std::atomic< int64_tisFull_
 
std::atomic< int64_tnumErases_
 
value_type cells_ [0]
 

Friends

class AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn >
 

Detailed Description

template<class KeyT, class ValueT, class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
class folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >

Definition at line 105 of file AtomicHashArray.h.

Member Typedef Documentation

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef aha_iterator<const AtomicHashArray, const value_type> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::const_iterator

Definition at line 135 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef const value_type* folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::const_pointer

Definition at line 126 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef const value_type& folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::const_reference

Definition at line 124 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef std::ptrdiff_t folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::difference_type

Definition at line 122 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef HashFcn folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::hasher

Definition at line 117 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef aha_iterator<AtomicHashArray, value_type> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::iterator

Definition at line 138 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef KeyConvertFcn folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::key_convert

Definition at line 119 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef EqualFcn folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::key_equal

Definition at line 118 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef KeyT folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::key_type

Definition at line 112 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef ValueT folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::mapped_type

Definition at line 116 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef value_type* folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::pointer

Definition at line 125 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef value_type& folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::reference

Definition at line 123 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef std::size_t folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::size_type

Definition at line 121 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef std::unique_ptr<AtomicHashArray, Deleter> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SmartPtr

Definition at line 156 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
typedef std::pair<const KeyT, ValueT> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::value_type

Definition at line 120 of file AtomicHashArray.h.

Constructor & Destructor Documentation

template<class KeyT , class ValueT , class HashFcn , class EqualFcn , class Allocator , class ProbeFcn , class KeyConvertFcn >
folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::AtomicHashArray ( size_t  capacity,
KeyT  emptyKey,
KeyT  lockedKey,
KeyT  erasedKey,
double  maxLoadFactor,
uint32_t  cacheSize 
)
private

Definition at line 45 of file AtomicHashArray-inl.h.

Referenced by folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::create(), and folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::destroy().

52  : capacity_(capacity),
53  maxEntries_(size_t(_maxLoadFactor * capacity_ + 0.5)),
54  kEmptyKey_(emptyKey),
55  kLockedKey_(lockedKey),
56  kErasedKey_(erasedKey),
58  numEntries_(0, cacheSize),
59  numPendingEntries_(0, cacheSize),
60  isFull_(0),
61  numErases_(0) {}
std::atomic< int64_t > isFull_
constexpr T nextPowTwo(T const v)
Definition: Bits.h:149
ThreadCachedInt< uint64_t > numEntries_
ThreadCachedInt< uint64_t > numPendingEntries_
std::atomic< int64_t > numErases_
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::~AtomicHashArray ( )
privatedefault

Member Function Documentation

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
static KeyT folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::acquireLoadKey ( const value_type r)
inlinestaticprivate
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
iterator folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::begin ( )
inline
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
const_iterator folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::begin ( ) const
inline

Definition at line 301 of file AtomicHashArray.h.

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::aha_iterator< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::advancePastEmpty().

301  {
302  const_iterator it(this, 0);
303  it.advancePastEmpty();
304  return it;
305  }
aha_iterator< const AtomicHashArray, const value_type > const_iterator
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
static std::atomic<KeyT>* folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::cellKeyPtr ( const value_type r)
inlinestaticprivate

Definition at line 383 of file AtomicHashArray.h.

References upload::const.

Referenced by folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::create(), and folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::erase().

383  {
384  // We need some illegal casting here in order to actually store
385  // our value_type as a std::pair<const,>. But a little bit of
386  // undefined behavior never hurt anyone ...
387  static_assert(
388  sizeof(std::atomic<KeyT>) == sizeof(KeyT),
389  "std::atomic is implemented in an unexpected way for AHM");
390  return const_cast<std::atomic<KeyT>*>(
391  reinterpret_cast<std::atomic<KeyT> const*>(&r.first));
392  }
int32_t KeyT
const
Definition: upload.py:398
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
template<typename MaybeKeyT >
void folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::checkLegalKeyIfKey ( MaybeKeyT  key)
inlineprivate
template<class KeyT , class ValueT , class HashFcn , class EqualFcn , class Allocator , class ProbeFcn , class KeyConvertFcn >
void folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::clear ( )

Definition at line 450 of file AtomicHashArray-inl.h.

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::capacity_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::cells_, folly::gen::first, FOR_EACH_RANGE, i, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::isFull_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kEmptyKey_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numEntries_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numErases_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numPendingEntries_, and folly::ThreadCachedInt< IntT, Tag >::set().

Referenced by TEST().

450  {
451  FOR_EACH_RANGE (i, 0, capacity_) {
452  if (cells_[i].first != kEmptyKey_) {
453  cells_[i].~value_type();
454  *const_cast<KeyT*>(&cells_[i].first) = kEmptyKey_;
455  }
456  CHECK(cells_[i].first == kEmptyKey_);
457  }
458  numEntries_.set(0);
460  isFull_.store(0, std::memory_order_relaxed);
461  numErases_.store(0, std::memory_order_relaxed);
462 }
std::atomic< int64_t > isFull_
int32_t KeyT
ThreadCachedInt< uint64_t > numEntries_
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
ThreadCachedInt< uint64_t > numPendingEntries_
std::atomic< int64_t > numErases_
void set(IntT newVal)
constexpr detail::First first
Definition: Base-inl.h:2553
template<class KeyT , class ValueT , class HashFcn , class EqualFcn , class Allocator , class ProbeFcn , class KeyConvertFcn >
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SmartPtr folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::create ( size_t  maxSize,
const Config c = Config() 
)
static

Definition at line 362 of file AtomicHashArray-inl.h.

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::AtomicHashArray(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::cellKeyPtr(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::Config::emptyKey, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::Config::entryCountThreadCacheSize, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::Config::erasedKey, FOR_EACH_RANGE, i, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::Config::lockedKey, map(), and folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::Config::maxLoadFactor.

Referenced by folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::AtomicHashMap(), folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insertInternal(), and TEST().

362  {
363  CHECK_LE(c.maxLoadFactor, 1.0);
364  CHECK_GT(c.maxLoadFactor, 0.0);
365  CHECK_NE(c.emptyKey, c.lockedKey);
366  size_t capacity = size_t(maxSize / c.maxLoadFactor);
367  size_t sz = sizeof(AtomicHashArray) + sizeof(value_type) * capacity;
368 
369  auto const mem = Allocator().allocate(sz);
370  try {
371  new (mem) AtomicHashArray(
372  capacity,
373  c.emptyKey,
374  c.lockedKey,
375  c.erasedKey,
376  c.maxLoadFactor,
377  c.entryCountThreadCacheSize);
378  } catch (...) {
379  Allocator().deallocate(mem, sz);
380  throw;
381  }
382 
383  SmartPtr map(static_cast<AtomicHashArray*>((void*)mem));
384 
385  /*
386  * Mark all cells as empty.
387  *
388  * Note: we're bending the rules a little here accessing the key
389  * element in our cells even though the cell object has not been
390  * constructed, and casting them to atomic objects (see cellKeyPtr).
391  * (Also, in fact we never actually invoke the value_type
392  * constructor.) This is in order to avoid needing to default
393  * construct a bunch of value_type when we first start up: if you
394  * have an expensive default constructor for the value type this can
395  * noticeably speed construction time for an AHA.
396  */
397  FOR_EACH_RANGE (i, 0, map->capacity_) {
398  cellKeyPtr(map->cells_[i])
399  ->store(map->kEmptyKey_, std::memory_order_relaxed);
400  }
401  return map;
402 }
std::unique_ptr< AtomicHashArray, Deleter > SmartPtr
std::pair< const KeyT, ValueT > value_type
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static Map map(mapCap)
Definition: Traits.h:594
AtomicHashArray(size_t capacity, KeyT emptyKey, KeyT lockedKey, KeyT erasedKey, double maxLoadFactor, uint32_t cacheSize)
static std::atomic< KeyT > * cellKeyPtr(const value_type &r)
char c
template<class KeyT , class ValueT , class HashFcn , class EqualFcn , class Allocator , class ProbeFcn , class KeyConvertFcn >
void folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::destroy ( AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > *  p)
static

Definition at line 419 of file AtomicHashArray-inl.h.

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::AtomicHashArray(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::capacity_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::cells_, FOR_EACH_RANGE, i, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kEmptyKey_, and folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::~AtomicHashArray().

Referenced by folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::clear(), and folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::Deleter::operator()().

419  {
420  assert(p);
421 
422  size_t sz = sizeof(AtomicHashArray) + sizeof(value_type) * p->capacity_;
423 
424  FOR_EACH_RANGE (i, 0, p->capacity_) {
425  if (p->cells_[i].first != p->kEmptyKey_) {
426  p->cells_[i].~value_type();
427  }
428  }
429  p->~AtomicHashArray();
430 
431  Allocator().deallocate((char*)p, sz);
432 }
std::pair< const KeyT, ValueT > value_type
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
AtomicHashArray(size_t capacity, KeyT emptyKey, KeyT lockedKey, KeyT erasedKey, double maxLoadFactor, uint32_t cacheSize)
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal, typename LookupKeyToKeyFcn = key_convert, typename... ArgTs>
std::pair<iterator, bool> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::emplace ( LookupKeyT  key_in,
ArgTs &&...  vCtorArgs 
)
inline

Definition at line 270 of file AtomicHashArray.h.

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::idx, k, and folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::success.

270  {
271  SimpleRetT ret = insertInternal<
272  LookupKeyT,
273  LookupHashFcn,
274  LookupEqualFcn,
275  LookupKeyToKeyFcn>(key_in, std::forward<ArgTs>(vCtorArgs)...);
276  return std::make_pair(iterator(this, ret.idx), ret.success);
277  }
SimpleRetT insertInternal(LookupKeyT key, ArgTs &&...vCtorArgs)
aha_iterator< AtomicHashArray, value_type > iterator
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
bool folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::empty ( ) const
inline

Definition at line 292 of file AtomicHashArray.h.

References folly::size().

292  {
293  return size() == 0;
294  }
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
iterator folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::end ( )
inline
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
const_iterator folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::end ( ) const
inline

Definition at line 310 of file AtomicHashArray.h.

310  {
311  return const_iterator(this, capacity_);
312  }
aha_iterator< const AtomicHashArray, const value_type > const_iterator
template<class KeyT , class ValueT , class HashFcn , class EqualFcn , class Allocator , class ProbeFcn , class KeyConvertFcn >
size_t folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::erase ( KeyT  k)

Definition at line 295 of file AtomicHashArray-inl.h.

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::acquireLoadKey(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::capacity_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::cellKeyPtr(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::cells_, folly::symbolizer::test::expect(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kEmptyKey_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kErasedKey_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::keyToAnchorIdx(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kLockedKey_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numErases_, and UNLIKELY.

295  {
296  CHECK_NE(key_in, kEmptyKey_);
297  CHECK_NE(key_in, kLockedKey_);
298  CHECK_NE(key_in, kErasedKey_);
299 
300  for (size_t idx = keyToAnchorIdx(key_in), numProbes = 0;;
301  idx = ProbeFcn()(idx, numProbes, capacity_)) {
302  DCHECK_LT(idx, capacity_);
303  value_type* cell = &cells_[idx];
304  KeyT currentKey = acquireLoadKey(*cell);
305  if (currentKey == kEmptyKey_ || currentKey == kLockedKey_) {
306  // If we hit an empty (or locked) element, this key does not exist. This
307  // is similar to how it's handled in find().
308  return 0;
309  }
310  if (EqualFcn()(currentKey, key_in)) {
311  // Found an existing entry for our key, attempt to mark it erased.
312  // Some other thread may have erased our key, but this is ok.
313  KeyT expect = currentKey;
314  if (cellKeyPtr(*cell)->compare_exchange_strong(expect, kErasedKey_)) {
315  numErases_.fetch_add(1, std::memory_order_relaxed);
316 
317  // Even if there's a value in the cell, we won't delete (or even
318  // default construct) it because some other thread may be accessing it.
319  // Locking it meanwhile won't work either since another thread may be
320  // holding a pointer to it.
321 
322  // We found the key and successfully erased it.
323  return 1;
324  }
325  // If another thread succeeds in erasing our key, we'll stop our search.
326  return 0;
327  }
328 
329  // NOTE: the way we count numProbes must be same in find(), insert(),
330  // and erase(). Otherwise it may break probing.
331  ++numProbes;
332  if (UNLIKELY(numProbes >= capacity_)) {
333  // probed every cell...fail
334  return 0;
335  }
336  }
337 }
int32_t KeyT
std::pair< const KeyT, ValueT > value_type
size_t keyToAnchorIdx(const LookupKeyT k) const
void expect(LineReader &lr, const char *expected)
static KeyT acquireLoadKey(const value_type &r)
static std::atomic< KeyT > * cellKeyPtr(const value_type &r)
#define UNLIKELY(x)
Definition: Likely.h:48
std::atomic< int64_t > numErases_
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal>
iterator folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::find ( LookupKeyT  k)
inline

Definition at line 221 of file AtomicHashArray.h.

221  {
222  return iterator(
223  this, findInternal<LookupKeyT, LookupHashFcn, LookupEqualFcn>(k).idx);
224  }
aha_iterator< AtomicHashArray, value_type > iterator
KeyT k
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal>
const_iterator folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::find ( LookupKeyT  k) const
inline

Definition at line 230 of file AtomicHashArray.h.

230  {
231  return const_cast<AtomicHashArray*>(this)
232  ->find<LookupKeyT, LookupHashFcn, LookupEqualFcn>(k);
233  }
AtomicHashArray(size_t capacity, KeyT emptyKey, KeyT lockedKey, KeyT erasedKey, double maxLoadFactor, uint32_t cacheSize)
KeyT k
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
iterator folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::findAt ( uint32_t  idx)
inline

Definition at line 317 of file AtomicHashArray.h.

317  {
318  DCHECK_LT(idx, capacity_);
319  return iterator(this, idx);
320  }
aha_iterator< AtomicHashArray, value_type > iterator
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
const_iterator folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::findAt ( uint32_t  idx) const
inline

Definition at line 321 of file AtomicHashArray.h.

321  {
322  return const_cast<AtomicHashArray*>(this)->findAt(idx);
323  }
iterator findAt(uint32_t idx)
AtomicHashArray(size_t capacity, KeyT emptyKey, KeyT lockedKey, KeyT erasedKey, double maxLoadFactor, uint32_t cacheSize)
template<class KeyT , class ValueT , class HashFcn , class EqualFcn , class Allocator , class ProbeFcn , class KeyConvertFcn >
template<class LookupKeyT , class LookupHashFcn , class LookupEqualFcn >
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::findInternal ( const LookupKeyT  key)
private

Definition at line 94 of file AtomicHashArray-inl.h.

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::acquireLoadKey(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::capacity_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::cells_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kEmptyKey_, LIKELY, and UNLIKELY.

94  {
95  checkLegalKeyIfKey<LookupKeyT>(key_in);
96 
97  for (size_t idx = keyToAnchorIdx<LookupKeyT, LookupHashFcn>(key_in),
98  numProbes = 0;
99  ;
100  idx = ProbeFcn()(idx, numProbes, capacity_)) {
101  const KeyT key = acquireLoadKey(cells_[idx]);
102  if (LIKELY(LookupEqualFcn()(key, key_in))) {
103  return SimpleRetT(idx, true);
104  }
105  if (UNLIKELY(key == kEmptyKey_)) {
106  // if we hit an empty element, this key does not exist
107  return SimpleRetT(capacity_, false);
108  }
109  // NOTE: the way we count numProbes must be same in find(), insert(),
110  // and erase(). Otherwise it may break probing.
111  ++numProbes;
112  if (UNLIKELY(numProbes >= capacity_)) {
113  // probed every cell...fail
114  return SimpleRetT(capacity_, false);
115  }
116  }
117 }
int32_t KeyT
#define LIKELY(x)
Definition: Likely.h:47
static KeyT acquireLoadKey(const value_type &r)
#define UNLIKELY(x)
Definition: Likely.h:48
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
uint32_t folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::getEntryCountThreadCacheSize ( ) const
inline
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
std::pair<iterator, bool> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insert ( const value_type r)
inline

Definition at line 246 of file AtomicHashArray.h.

Referenced by atomicHashArrayInsertRaceThread().

246  {
247  return emplace(r.first, r.second);
248  }
std::pair< iterator, bool > emplace(LookupKeyT key_in, ArgTs &&...vCtorArgs)
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
std::pair<iterator, bool> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insert ( value_type &&  r)
inline

Definition at line 249 of file AtomicHashArray.h.

References folly::gen::move.

249  {
250  return emplace(r.first, std::move(r.second));
251  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::pair< iterator, bool > emplace(LookupKeyT key_in, ArgTs &&...vCtorArgs)
template<class KeyT , class ValueT , class HashFcn , class EqualFcn , class Allocator , class ProbeFcn , class KeyConvertFcn >
template<typename LookupKeyT , typename LookupHashFcn , typename LookupEqualFcn , typename LookupKeyToKeyFcn , typename... ArgTs>
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insertInternal ( LookupKeyT  key,
ArgTs &&...  vCtorArgs 
)
private

Definition at line 158 of file AtomicHashArray-inl.h.

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::acquireLoadKey(), folly::detail::atomic_hash_spin_wait(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::capacity_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::cells_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::checkLegalKeyIfKey(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::isFull_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kEmptyKey_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kErasedKey_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kLockedKey_, folly::gen::mapped(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::maxEntries_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numEntries_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numPendingEntries_, folly::ThreadCachedInt< IntT, Tag >::readFast(), folly::ThreadCachedInt< IntT, Tag >::readFull(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::relaxedLoadKey(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::tryLockCell(), type, UNLIKELY, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::unlockCell(), and value.

158  {
159  const short NO_NEW_INSERTS = 1;
160  const short NO_PENDING_INSERTS = 2;
161  checkLegalKeyIfKey<LookupKeyT>(key_in);
162 
163  size_t idx = keyToAnchorIdx<LookupKeyT, LookupHashFcn>(key_in);
164  size_t numProbes = 0;
165  for (;;) {
166  DCHECK_LT(idx, capacity_);
167  value_type* cell = &cells_[idx];
168  if (relaxedLoadKey(*cell) == kEmptyKey_) {
169  // NOTE: isFull_ is set based on numEntries_.readFast(), so it's
170  // possible to insert more than maxEntries_ entries. However, it's not
171  // possible to insert past capacity_.
173  if (isFull_.load(std::memory_order_acquire)) {
175 
176  // Before deciding whether this insert succeeded, this thread needs to
177  // wait until no other thread can add a new entry.
178 
179  // Correctness assumes isFull_ is true at this point. If
180  // another thread now does ++numPendingEntries_, we expect it
181  // to pass the isFull_.load() test above. (It shouldn't insert
182  // a new entry.)
184  return (isFull_.load(std::memory_order_acquire) !=
185  NO_PENDING_INSERTS) &&
186  (numPendingEntries_.readFull() != 0);
187  });
188  isFull_.store(NO_PENDING_INSERTS, std::memory_order_release);
189 
190  if (relaxedLoadKey(*cell) == kEmptyKey_) {
191  // Don't insert past max load factor
192  return SimpleRetT(capacity_, false);
193  }
194  } else {
195  // An unallocated cell. Try once to lock it. If we succeed, insert here.
196  // If we fail, fall through to comparison below; maybe the insert that
197  // just beat us was for this very key....
198  if (tryLockCell(cell)) {
199  KeyT key_new;
200  // Write the value - done before unlocking
201  try {
202  key_new = LookupKeyToKeyFcn()(key_in);
203  typedef
204  typename std::remove_const<LookupKeyT>::type LookupKeyTNoConst;
205  constexpr bool kAlreadyChecked =
207  if (!kAlreadyChecked) {
208  checkLegalKeyIfKey(key_new);
209  }
210  DCHECK(relaxedLoadKey(*cell) == kLockedKey_);
211  // A const mapped_type is only constant once constructed, so cast
212  // away any const for the placement new here.
214  new (const_cast<mapped*>(&cell->second))
215  ValueT(std::forward<ArgTs>(vCtorArgs)...);
216  unlockCell(cell, key_new); // Sets the new key
217  } catch (...) {
218  // Transition back to empty key---requires handling
219  // locked->empty below.
220  unlockCell(cell, kEmptyKey_);
222  throw;
223  }
224  // An erase() can race here and delete right after our insertion
225  // Direct comparison rather than EqualFcn ok here
226  // (we just inserted it)
227  DCHECK(
228  relaxedLoadKey(*cell) == key_new ||
229  relaxedLoadKey(*cell) == kErasedKey_);
231  ++numEntries_; // This is a thread cached atomic increment :)
232  if (numEntries_.readFast() >= maxEntries_) {
233  isFull_.store(NO_NEW_INSERTS, std::memory_order_relaxed);
234  }
235  return SimpleRetT(idx, true);
236  }
238  }
239  }
240  DCHECK(relaxedLoadKey(*cell) != kEmptyKey_);
241  if (kLockedKey_ == acquireLoadKey(*cell)) {
243  [&] { return kLockedKey_ == acquireLoadKey(*cell); });
244  }
245 
246  const KeyT thisKey = acquireLoadKey(*cell);
247  if (LookupEqualFcn()(thisKey, key_in)) {
248  // Found an existing entry for our key, but we don't overwrite the
249  // previous value.
250  return SimpleRetT(idx, false);
251  } else if (thisKey == kEmptyKey_ || thisKey == kLockedKey_) {
252  // We need to try again (i.e., don't increment numProbes or
253  // advance idx): this case can happen if the constructor for
254  // ValueT threw for this very cell (the rethrow block above).
255  continue;
256  }
257 
258  // NOTE: the way we count numProbes must be same in find(),
259  // insert(), and erase(). Otherwise it may break probing.
260  ++numProbes;
261  if (UNLIKELY(numProbes >= capacity_)) {
262  // probed every cell...fail
263  return SimpleRetT(capacity_, false);
264  }
265 
266  idx = ProbeFcn()(idx, numProbes, capacity_);
267  }
268 }
std::atomic< int64_t > isFull_
int32_t KeyT
PskType type
void atomic_hash_spin_wait(Cond condition)
std::pair< const KeyT, ValueT > value_type
void checkLegalKeyIfKey(MaybeKeyT key)
ThreadCachedInt< uint64_t > numEntries_
int32_t ValueT
bool tryLockCell(value_type *const cell)
void unlockCell(value_type *const cell, KeyT newKey)
ThreadCachedInt< uint64_t > numPendingEntries_
static KeyT relaxedLoadKey(const value_type &r)
static const char *const value
Definition: Conv.cpp:50
static KeyT acquireLoadKey(const value_type &r)
Map mapped(Predicate pred=Predicate())
Definition: Base.h:540
#define UNLIKELY(x)
Definition: Likely.h:48
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
template<class LookupKeyT = key_type, class LookupHashFcn = hasher>
size_t folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::keyToAnchorIdx ( const LookupKeyT  k) const
inlineprivate

Definition at line 438 of file AtomicHashArray.h.

References k, and LIKELY.

Referenced by folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::erase().

438  {
439  const size_t hashVal = LookupHashFcn()(k);
440  const size_t probe = hashVal & kAnchorMask_;
441  return LIKELY(probe < capacity_) ? probe : hashVal % capacity_;
442  }
#define LIKELY(x)
Definition: Likely.h:47
KeyT k
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
iterator folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::makeIter ( size_t  idx)
inline
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
const_iterator folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::makeIter ( size_t  idx) const
inline

Definition at line 328 of file AtomicHashArray.h.

328  {
329  return const_iterator(this, idx);
330  }
aha_iterator< const AtomicHashArray, const value_type > const_iterator
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
double folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::maxLoadFactor ( ) const
inline
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
static KeyT folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::relaxedLoadKey ( const value_type r)
inlinestaticprivate

Definition at line 394 of file AtomicHashArray.h.

Referenced by folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insertInternal().

394  {
395  return cellKeyPtr(r)->load(std::memory_order_relaxed);
396  }
static std::atomic< KeyT > * cellKeyPtr(const value_type &r)
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
void folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::setEntryCountThreadCacheSize ( uint32_t  newSize)
inline

Definition at line 337 of file AtomicHashArray.h.

Referenced by folly::AtomicHashMap< int64_t, int64_t >::setEntryCountThreadCacheSize().

337  {
338  numEntries_.setCacheSize(newSize);
340  }
void setCacheSize(uint32_t newSize)
ThreadCachedInt< uint64_t > numEntries_
ThreadCachedInt< uint64_t > numPendingEntries_
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
size_t folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::size ( ) const
inline

Definition at line 288 of file AtomicHashArray.h.

Referenced by TEST().

288  {
289  return numEntries_.readFull() - numErases_.load(std::memory_order_relaxed);
290  }
ThreadCachedInt< uint64_t > numEntries_
std::atomic< int64_t > numErases_
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
bool folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::tryLockCell ( value_type *const  cell)
inlineprivate

Definition at line 431 of file AtomicHashArray.h.

References folly::symbolizer::test::expect().

Referenced by folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insertInternal().

431  {
433  return cellKeyPtr(*cell)->compare_exchange_strong(
434  expect, kLockedKey_, std::memory_order_acq_rel);
435  }
int32_t KeyT
void expect(LineReader &lr, const char *expected)
static std::atomic< KeyT > * cellKeyPtr(const value_type &r)
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
void folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::unlockCell ( value_type *const  cell,
KeyT  newKey 
)
inlineprivate

Definition at line 427 of file AtomicHashArray.h.

Referenced by folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insertInternal().

427  {
428  cellKeyPtr(*cell)->store(newKey, std::memory_order_release);
429  }
static std::atomic< KeyT > * cellKeyPtr(const value_type &r)

Friends And Related Function Documentation

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
friend class AtomicHashMap< KeyT,ValueT,HashFcn,EqualFcn,Allocator,ProbeFcn >
friend

Definition at line 355 of file AtomicHashArray.h.

Member Data Documentation

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
std::atomic<int64_t> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::isFull_
private
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
const size_t folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kAnchorMask_
private

Definition at line 147 of file AtomicHashArray.h.

template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
const KeyT folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kErasedKey_
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
const KeyT folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kLockedKey_
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
const size_t folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::maxEntries_
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
ThreadCachedInt<uint64_t> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numEntries_
private
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
std::atomic<int64_t> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numErases_
private
template<class KeyT , class ValueT , class HashFcn = std::hash<KeyT>, class EqualFcn = std::equal_to<KeyT>, class Allocator = std::allocator<char>, class ProbeFcn = AtomicHashArrayLinearProbeFcn, class KeyConvertFcn = Identity>
ThreadCachedInt<uint64_t> folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numPendingEntries_
private

The documentation for this class was generated from the following files: