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

#include <AtomicHashArray.h>

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

Classes

struct  ahm_iterator
 
struct  SimpleRetT
 

Public Types

typedef KeyT key_type
 
typedef ValueT mapped_type
 
typedef std::pair< const KeyT, ValueTvalue_type
 
typedef HashFcn hasher
 
typedef EqualFcn key_equal
 
typedef KeyConvertFcn key_convert
 
typedef value_typepointer
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef std::ptrdiff_t difference_type
 
typedef std::size_t size_type
 
typedef SubMap::Config Config
 
typedef ahm_iterator< const AtomicHashMap, const value_type, typename SubMap::const_iteratorconst_iterator
 
typedef ahm_iterator< AtomicHashMap, value_type, typename SubMap::iteratoriterator
 

Public Member Functions

 AtomicHashMap (size_t finalSizeEst, const Config &c=Config())
 
 ~AtomicHashMap ()
 
key_equal key_eq () const
 
hasher hash_function () const
 
std::pair< iterator, bool > insert (const value_type &r)
 
std::pair< iterator, bool > insert (key_type k, const mapped_type &v)
 
std::pair< iterator, bool > insert (value_type &&r)
 
std::pair< iterator, bool > insert (key_type k, mapped_type &&v)
 
template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal, typename LookupKeyToKeyFcn = key_convert, typename... ArgTs>
std::pair< iterator, bool > emplace (LookupKeyT k, ArgTs &&...vCtorArg)
 
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
 
size_type erase (key_type k)
 
void clear ()
 
size_t size () const
 
bool empty () const
 
size_type count (key_type k) const
 
iterator findAt (uint32_t idx)
 
const_iterator findAt (uint32_t idx) const
 
size_t capacity () const
 
size_t spaceRemaining () const
 
void setEntryCountThreadCacheSize (int32_t newSize)
 
int numSubMaps () const
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
uint32_t recToIdx (const value_type &r, bool mayInsert=true)
 
uint32_t recToIdx (value_type &&r, bool mayInsert=true)
 
uint32_t recToIdx (key_type k, const mapped_type &v, bool mayInsert=true)
 
uint32_t recToIdx (key_type k, mapped_type &&v, bool mayInsert=true)
 
uint32_t keyToIdx (const KeyT k, bool mayInsert=false)
 
const value_typeidxToRec (uint32_t idx) const
 
template<typename LookupKeyT , typename LookupHashFcn , typename LookupEqualFcn , typename LookupKeyToKeyFcn , typename... ArgTs>
std::pair< typename AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::iterator, bool > emplace (LookupKeyT k, ArgTs &&...vCtorArgs)
 

Public Attributes

const float kGrowthFrac_
 

Private Types

typedef AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > SubMap
 

Private Member Functions

template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal, typename LookupKeyToKeyFcn = key_convert, typename... ArgTs>
SimpleRetT insertInternal (LookupKeyT key, ArgTs &&...value)
 
template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal>
SimpleRetT findInternal (const LookupKeyT k) const
 
SimpleRetT findAtInternal (uint32_t idx) const
 
bool tryLockMap (unsigned int idx)
 

Static Private Member Functions

static uint32_t encodeIndex (uint32_t subMap, uint32_t subMapIdx)
 

Private Attributes

std::atomic< SubMap * > subMaps_ [kNumSubMaps_]
 
std::atomic< uint32_tnumMapsAllocated_
 

Static Private Attributes

static const uint32_t kNumSubMapBits_ = 4
 
static const uint32_t kSecondaryMapBit_ = 1u << 31
 
static const uint32_t kSubMapIndexShift_ = 32 - kNumSubMapBits_ - 1
 
static const uint32_t kSubMapIndexMask_ = (1 << kSubMapIndexShift_) - 1
 
static const uint32_t kNumSubMaps_ = 1 << kNumSubMapBits_
 
static const uintptr_t kLockedPtr_ = 0x88ULL << 48
 

Detailed Description

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
class folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >

Definition at line 95 of file AtomicHashArray.h.

Member Typedef Documentation

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef SubMap::Config folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::Config

Definition at line 188 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef ahm_iterator< const AtomicHashMap, const value_type, typename SubMap::const_iterator> folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::const_iterator

Definition at line 191 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef const value_type& folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::const_reference

Definition at line 185 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef std::ptrdiff_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::difference_type

Definition at line 186 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef HashFcn folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::hasher

Definition at line 180 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef ahm_iterator<AtomicHashMap, value_type, typename SubMap::iterator> folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::iterator

Definition at line 199 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef KeyConvertFcn folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::key_convert

Definition at line 182 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef EqualFcn folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::key_equal

Definition at line 181 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef KeyT folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::key_type

Definition at line 177 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef ValueT folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::mapped_type

Definition at line 178 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef value_type* folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::pointer

Definition at line 183 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef value_type& folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::reference

Definition at line 184 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef std::size_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::size_type

Definition at line 187 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn> folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SubMap
private

Definition at line 174 of file AtomicHashMap.h.

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
typedef std::pair<const KeyT, ValueT> folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::value_type

Definition at line 179 of file AtomicHashMap.h.

Constructor & Destructor Documentation

template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::AtomicHashMap ( size_t  finalSizeEst,
const Config c = Config() 
)
explicit

Definition at line 42 of file AtomicHashMap-inl.h.

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::create(), FOR_EACH_RANGE, i, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kNumSubMaps_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::Config::maxLoadFactor, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numMapsAllocated_, and folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::subMaps_.

43  : kGrowthFrac_(
45  : config.growthFactor) {
46  CHECK(config.maxLoadFactor > 0.0f && config.maxLoadFactor < 1.0f);
47  subMaps_[0].store(
48  SubMap::create(finalSizeEst, config).release(),
49  std::memory_order_relaxed);
50  auto subMapCount = kNumSubMaps_;
51  FOR_EACH_RANGE (i, 1, subMapCount) {
52  subMaps_[i].store(nullptr, std::memory_order_relaxed);
53  }
54  numMapsAllocated_.store(1, std::memory_order_relaxed);
55 }
const float kGrowthFrac_
AHArrayT::Config config
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
std::atomic< uint32_t > numMapsAllocated_
static SmartPtr create(size_t maxSize, const Config &c=Config())
static const uint32_t kNumSubMaps_
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::~AtomicHashMap ( )
inline

Definition at line 209 of file AtomicHashMap.h.

209  {
210  const unsigned int numMaps =
211  numMapsAllocated_.load(std::memory_order_relaxed);
212  FOR_EACH_RANGE (i, 0, numMaps) {
213  SubMap* thisMap = subMaps_[i].load(std::memory_order_relaxed);
214  DCHECK(thisMap);
215  SubMap::destroy(thisMap);
216  }
217  }
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > SubMap
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static void destroy(AtomicHashArray *)
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
std::atomic< uint32_t > numMapsAllocated_

Member Function Documentation

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
iterator folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::begin ( )
inline

Definition at line 379 of file AtomicHashMap.h.

Referenced by TEST().

379  {
380  iterator it(this, 0, subMaps_[0].load(std::memory_order_relaxed)->begin());
381  it.checkAdvanceToNextSubmap();
382  return it;
383  }
def load()
Definition: deadlock.py:441
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
ahm_iterator< AtomicHashMap, value_type, typename SubMap::iterator > iterator
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const_iterator folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::begin ( ) const
inline

Definition at line 385 of file AtomicHashMap.h.

385  {
386  const_iterator it(
387  this, 0, subMaps_[0].load(std::memory_order_relaxed)->begin());
388  it.checkAdvanceToNextSubmap();
389  return it;
390  }
ahm_iterator< const AtomicHashMap, const value_type, typename SubMap::const_iterator > const_iterator
def load()
Definition: deadlock.py:441
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
size_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::capacity ( ) const

Definition at line 412 of file AtomicHashMap-inl.h.

References FOR_EACH_RANGE, i, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numMapsAllocated_, and folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::subMaps_.

Referenced by TEST().

412  {
413  size_t totalCap(0);
414  int const numMaps = numMapsAllocated_.load(std::memory_order_acquire);
415  FOR_EACH_RANGE (i, 0, numMaps) {
416  totalCap += subMaps_[i].load(std::memory_order_relaxed)->capacity_;
417  }
418  return totalCap;
419 }
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
std::atomic< uint32_t > numMapsAllocated_
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
void folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::clear ( )

Definition at line 466 of file AtomicHashMap-inl.h.

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::destroy(), FOR_EACH_RANGE, i, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numMapsAllocated_, and folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::subMaps_.

Referenced by TEST().

466  {
467  subMaps_[0].load(std::memory_order_relaxed)->clear();
468  int const numMaps = numMapsAllocated_.load(std::memory_order_relaxed);
469  FOR_EACH_RANGE (i, 1, numMaps) {
470  SubMap* thisMap = subMaps_[i].load(std::memory_order_relaxed);
471  DCHECK(thisMap);
472  SubMap::destroy(thisMap);
473  subMaps_[i].store(nullptr, std::memory_order_relaxed);
474  }
475  numMapsAllocated_.store(1, std::memory_order_relaxed);
476 }
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > SubMap
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
static void destroy(AtomicHashArray *)
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
std::atomic< uint32_t > numMapsAllocated_
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
size_type folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::count ( key_type  k) const
inline

Definition at line 334 of file AtomicHashMap.h.

Referenced by TEST().

334  {
335  return find(k) == end() ? 0 : 1;
336  }
iterator find(LookupKeyT k)
KeyT k
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>
std::pair< typename AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn>::iterator, bool> folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::emplace ( LookupKeyT  k,
ArgTs &&...  vCtorArgs 
)

Definition at line 89 of file AtomicHashMap-inl.h.

References folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::i, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insertInternal(), folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::j, k, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::makeIter(), folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::subMaps_, and folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::success.

89  {
90  SimpleRetT ret = insertInternal<
91  LookupKeyT,
92  LookupHashFcn,
93  LookupEqualFcn,
94  LookupKeyToKeyFcn>(k, std::forward<ArgTs>(vCtorArgs)...);
95  SubMap* subMap = subMaps_[ret.i].load(std::memory_order_relaxed);
96  return std::make_pair(
97  iterator(this, ret.i, subMap->makeIter(ret.j)), ret.success);
98 }
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > SubMap
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
SimpleRetT insertInternal(LookupKeyT key, ArgTs &&...value)
KeyT k
ahm_iterator< AtomicHashMap, value_type, typename SubMap::iterator > iterator
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
template<typename LookupKeyT = key_type, typename LookupHashFcn = hasher, typename LookupEqualFcn = key_equal, typename LookupKeyToKeyFcn = key_convert, typename... ArgTs>
std::pair<iterator, bool> folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::emplace ( LookupKeyT  k,
ArgTs &&...  vCtorArg 
)
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
bool folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::empty ( ) const
inline

Definition at line 330 of file AtomicHashMap.h.

Referenced by TEST().

330  {
331  return size() == 0;
332  }
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::encodeIndex ( uint32_t  subMap,
uint32_t  subMapIdx 
)
inlinestaticprivate

Definition at line 536 of file AtomicHashMap-inl.h.

References folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kNumSubMapBits_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kSecondaryMapBit_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kSubMapIndexMask_, and folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kSubMapIndexShift_.

536  {
537  DCHECK_EQ(offset & kSecondaryMapBit_, 0); // offset can't be too big
538  if (subMap == 0) {
539  return offset;
540  }
541  // Make sure subMap isn't too big
542  DCHECK_EQ(subMap >> kNumSubMapBits_, 0);
543  // Make sure subMap bits of offset are clear
544  DCHECK_EQ(offset & (~kSubMapIndexMask_ | kSecondaryMapBit_), 0);
545 
546  // Set high-order bits to encode which submap this index belongs to
547  return offset | (subMap << kSubMapIndexShift_) | kSecondaryMapBit_;
548 }
static const uint32_t kNumSubMapBits_
static const uint32_t kSubMapIndexMask_
static const uint32_t kSubMapIndexShift_
static const uint32_t kSecondaryMapBit_
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
iterator folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::end ( )
inline

Definition at line 392 of file AtomicHashMap.h.

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

392  {
393  return iterator();
394  }
ahm_iterator< AtomicHashMap, value_type, typename SubMap::iterator > iterator
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const_iterator folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::end ( ) const
inline

Definition at line 396 of file AtomicHashMap.h.

396  {
397  return const_iterator();
398  }
ahm_iterator< const AtomicHashMap, const value_type, typename SubMap::const_iterator > const_iterator
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::size_type folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::erase ( key_type  k)

Definition at line 384 of file AtomicHashMap-inl.h.

References FOR_EACH_RANGE, i, deadlock::load(), folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numMapsAllocated_, and folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::subMaps_.

Referenced by TEST().

384  {
385  int const numMaps = numMapsAllocated_.load(std::memory_order_acquire);
386  FOR_EACH_RANGE (i, 0, numMaps) {
387  // Check each map successively. If one succeeds, we're done!
388  if (subMaps_[i].load(std::memory_order_relaxed)->erase(k)) {
389  return 1;
390  }
391  }
392  // Didn't find our key...
393  return 0;
394 }
def load()
Definition: deadlock.py:441
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
std::atomic< uint32_t > numMapsAllocated_
size_type erase(key_type k)
KeyT k
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
template<class LookupKeyT , class LookupHashFcn , class LookupEqualFcn >
AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::iterator folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::find ( LookupKeyT  k)

Definition at line 232 of file AtomicHashMap-inl.h.

References folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::end(), folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::i, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::j, k, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::makeIter(), folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::subMaps_, and folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::success.

Referenced by BENCHMARK(), Counters::getValue(), and TEST().

232  {
233  SimpleRetT ret = findInternal<LookupKeyT, LookupHashFcn, LookupEqualFcn>(k);
234  if (!ret.success) {
235  return end();
236  }
237  SubMap* subMap = subMaps_[ret.i].load(std::memory_order_relaxed);
238  return iterator(this, ret.i, subMap->makeIter(ret.j));
239 }
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > SubMap
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
KeyT k
ahm_iterator< AtomicHashMap, value_type, typename SubMap::iterator > iterator
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
template<class LookupKeyT , class LookupHashFcn , class LookupEqualFcn >
AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::const_iterator folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::find ( LookupKeyT  k) const

Definition at line 265 of file AtomicHashMap-inl.h.

265  {
266  return const_cast<AtomicHashMap*>(this)
267  ->find<LookupKeyT, LookupHashFcn, LookupEqualFcn>(k);
268 }
AtomicHashMap(size_t finalSizeEst, const Config &c=Config())
KeyT k
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
iterator folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::findAt ( uint32_t  idx)
inline

Definition at line 347 of file AtomicHashMap.h.

Referenced by TEST().

347  {
348  SimpleRetT ret = findAtInternal(idx);
349  DCHECK_LT(ret.i, numSubMaps());
350  return iterator(
351  this,
352  ret.i,
353  subMaps_[ret.i].load(std::memory_order_relaxed)->makeIter(ret.j));
354  }
int numSubMaps() const
SimpleRetT findAtInternal(uint32_t idx) const
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
ahm_iterator< AtomicHashMap, value_type, typename SubMap::iterator > iterator
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const_iterator folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::findAt ( uint32_t  idx) const
inline

Definition at line 355 of file AtomicHashMap.h.

355  {
356  return const_cast<AtomicHashMap*>(this)->findAt(idx);
357  }
AtomicHashMap(size_t finalSizeEst, const Config &c=Config())
iterator findAt(uint32_t idx)
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::findAtInternal ( uint32_t  idx) const
private

Definition at line 344 of file AtomicHashMap-inl.h.

References folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kSecondaryMapBit_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kSubMapIndexMask_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kSubMapIndexShift_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numMapsAllocated_, and uint32_t.

344  {
345  uint32_t subMapIdx, subMapOffset;
346  if (idx & kSecondaryMapBit_) {
347  // idx falls in a secondary map
348  idx &= ~kSecondaryMapBit_; // unset secondary bit
349  subMapIdx = idx >> kSubMapIndexShift_;
350  DCHECK_LT(subMapIdx, numMapsAllocated_.load(std::memory_order_relaxed));
351  subMapOffset = idx & kSubMapIndexMask_;
352  } else {
353  // idx falls in primary map
354  subMapIdx = 0;
355  subMapOffset = idx;
356  }
357  return SimpleRetT(subMapIdx, subMapOffset, true);
358 }
std::atomic< uint32_t > numMapsAllocated_
static const uint32_t kSubMapIndexMask_
static const uint32_t kSubMapIndexShift_
static const uint32_t kSecondaryMapBit_
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
template<class LookupKeyT , class LookupHashFcn , class LookupEqualFcn >
AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::findInternal ( const LookupKeyT  k) const
private

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

References folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::capacity_, FOR_EACH_RANGE, i, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::idx, k, LIKELY, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numMapsAllocated_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::subMaps_, and folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::success.

295  {
296  SubMap* const primaryMap = subMaps_[0].load(std::memory_order_relaxed);
297  typename SubMap::SimpleRetT ret =
298  primaryMap
299  ->template findInternal<LookupKeyT, LookupHashFcn, LookupEqualFcn>(k);
300  if (LIKELY(ret.idx != primaryMap->capacity_)) {
301  return SimpleRetT(0, ret.idx, ret.success);
302  }
303  const unsigned int numMaps =
304  numMapsAllocated_.load(std::memory_order_acquire);
305  FOR_EACH_RANGE (i, 1, numMaps) {
306  // Check each map successively. If one succeeds, we're done!
307  SubMap* thisMap = subMaps_[i].load(std::memory_order_relaxed);
308  ret =
309  thisMap
310  ->template findInternal<LookupKeyT, LookupHashFcn, LookupEqualFcn>(
311  k);
312  if (LIKELY(ret.idx != thisMap->capacity_)) {
313  return SimpleRetT(i, ret.idx, ret.success);
314  }
315  }
316  // Didn't find our key...
317  return SimpleRetT(numMaps, 0, false);
318 }
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > SubMap
#define LIKELY(x)
Definition: Likely.h:47
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
std::atomic< uint32_t > numMapsAllocated_
KeyT k
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
hasher folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::hash_function ( ) const
inline

Definition at line 222 of file AtomicHashMap.h.

222  {
223  return hasher();
224  }
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const value_type& folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::idxToRec ( uint32_t  idx) const
inline

Definition at line 430 of file AtomicHashMap.h.

430  {
431  SimpleRetT ret = findAtInternal(idx);
432  return subMaps_[ret.i].load(std::memory_order_relaxed)->idxToRec(ret.j);
433  }
SimpleRetT findAtInternal(uint32_t idx) const
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
std::pair<iterator, bool> folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insert ( const value_type r)
inline

Definition at line 241 of file AtomicHashMap.h.

Referenced by BENCHMARK(), Counters::increment(), and TEST().

241  {
242  return emplace(r.first, r.second);
243  }
std::pair< iterator, bool > emplace(LookupKeyT k, ArgTs &&...vCtorArg)
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
std::pair<iterator, bool> folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insert ( key_type  k,
const mapped_type v 
)
inline

Definition at line 244 of file AtomicHashMap.h.

244  {
245  return emplace(k, v);
246  }
KeyT k
std::pair< iterator, bool > emplace(LookupKeyT k, ArgTs &&...vCtorArg)
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
std::pair<iterator, bool> folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insert ( value_type &&  r)
inline

Definition at line 247 of file AtomicHashMap.h.

247  {
248  return emplace(r.first, std::move(r.second));
249  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::pair< iterator, bool > emplace(LookupKeyT k, ArgTs &&...vCtorArg)
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
std::pair<iterator, bool> folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insert ( key_type  k,
mapped_type &&  v 
)
inline

Definition at line 250 of file AtomicHashMap.h.

250  {
251  return emplace(k, std::move(v));
252  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
KeyT k
std::pair< iterator, bool > emplace(LookupKeyT k, ArgTs &&...vCtorArg)
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
template<typename LookupKeyT , typename LookupHashFcn , typename LookupEqualFcn , typename LookupKeyToKeyFcn , typename... ArgTs>
AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::insertInternal ( LookupKeyT  key,
ArgTs &&...  value 
)
private

Definition at line 130 of file AtomicHashMap-inl.h.

References folly::detail::atomic_hash_spin_wait(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::capacity_, config, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::create(), 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, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::getEntryCountThreadCacheSize(), i, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::idx, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kEmptyKey_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kErasedKey_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kGrowthFrac_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kLockedKey_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kLockedPtr_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kNumSubMaps_, deadlock::load(), folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::Config::lockedKey, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::Config::maxLoadFactor, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::maxLoadFactor(), folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numMapsAllocated_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::subMaps_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::SimpleRetT::success, and folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::tryLockMap().

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

130  {
131 beginInsertInternal:
132  auto nextMapIdx = // this maintains our state
133  numMapsAllocated_.load(std::memory_order_acquire);
134  typename SubMap::SimpleRetT ret;
135  FOR_EACH_RANGE (i, 0, nextMapIdx) {
136  // insert in each map successively. If one succeeds, we're done!
137  SubMap* subMap = subMaps_[i].load(std::memory_order_relaxed);
138  ret = subMap->template insertInternal<
139  LookupKeyT,
140  LookupHashFcn,
141  LookupEqualFcn,
142  LookupKeyToKeyFcn>(key, std::forward<ArgTs>(vCtorArgs)...);
143  if (ret.idx == subMap->capacity_) {
144  continue; // map is full, so try the next one
145  }
146  // Either collision or success - insert in either case
147  return SimpleRetT(i, ret.idx, ret.success);
148  }
149 
150  // If we made it this far, all maps are full and we need to try to allocate
151  // the next one.
152 
153  SubMap* primarySubMap = subMaps_[0].load(std::memory_order_relaxed);
154  if (nextMapIdx >= kNumSubMaps_ ||
155  primarySubMap->capacity_ * kGrowthFrac_ < 1.0) {
156  // Can't allocate any more sub maps.
157  throw AtomicHashMapFullError();
158  }
159 
160  if (tryLockMap(nextMapIdx)) {
161  // Alloc a new map and shove it in. We can change whatever
162  // we want because other threads are waiting on us...
163  size_t numCellsAllocated = (size_t)(
164  primarySubMap->capacity_ *
165  std::pow(1.0 + kGrowthFrac_, nextMapIdx - 1));
166  size_t newSize = size_t(numCellsAllocated * kGrowthFrac_);
167  DCHECK(
168  subMaps_[nextMapIdx].load(std::memory_order_relaxed) ==
169  (SubMap*)kLockedPtr_);
170  // create a new map using the settings stored in the first map
171 
172  Config config;
173  config.emptyKey = primarySubMap->kEmptyKey_;
174  config.lockedKey = primarySubMap->kLockedKey_;
175  config.erasedKey = primarySubMap->kErasedKey_;
176  config.maxLoadFactor = primarySubMap->maxLoadFactor();
177  config.entryCountThreadCacheSize =
178  primarySubMap->getEntryCountThreadCacheSize();
179  subMaps_[nextMapIdx].store(
180  SubMap::create(newSize, config).release(), std::memory_order_relaxed);
181 
182  // Publish the map to other threads.
183  numMapsAllocated_.fetch_add(1, std::memory_order_release);
184  DCHECK_EQ(
185  nextMapIdx + 1, numMapsAllocated_.load(std::memory_order_relaxed));
186  } else {
187  // If we lost the race, we'll have to wait for the next map to get
188  // allocated before doing any insertion here.
190  return nextMapIdx >= numMapsAllocated_.load(std::memory_order_acquire);
191  });
192  }
193 
194  // Relaxed is ok here because either we just created this map, or we
195  // just did a spin wait with an acquire load on numMapsAllocated_.
196  SubMap* loadedMap = subMaps_[nextMapIdx].load(std::memory_order_relaxed);
197  DCHECK(loadedMap && loadedMap != (SubMap*)kLockedPtr_);
198  ret = loadedMap->insertInternal(key, std::forward<ArgTs>(vCtorArgs)...);
199  if (ret.idx != loadedMap->capacity_) {
200  return SimpleRetT(nextMapIdx, ret.idx, ret.success);
201  }
202  // We took way too long and the new map is already full...try again from
203  // the top (this should pretty much never happen).
204  goto beginInsertInternal;
205 }
bool tryLockMap(unsigned int idx)
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > SubMap
void atomic_hash_spin_wait(Cond condition)
def load()
Definition: deadlock.py:441
const float kGrowthFrac_
AHArrayT::Config config
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
std::atomic< uint32_t > numMapsAllocated_
SubMap::Config Config
SimpleRetT insertInternal(LookupKeyT key, ArgTs &&...value)
static SmartPtr create(size_t maxSize, const Config &c=Config())
static const uintptr_t kLockedPtr_
static const uint32_t kNumSubMaps_
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
key_equal folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::key_eq ( ) const
inline

Definition at line 219 of file AtomicHashMap.h.

219  {
220  return key_equal();
221  }
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::keyToIdx ( const KeyT  k,
bool  mayInsert = false 
)
inline

Definition at line 426 of file AtomicHashMap.h.

426  {
427  return recToIdx(value_type(k), mayInsert);
428  }
std::pair< const KeyT, ValueT > value_type
uint32_t recToIdx(const value_type &r, bool mayInsert=true)
KeyT k
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
int folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numSubMaps ( ) const
inline

Definition at line 375 of file AtomicHashMap.h.

Referenced by TEST().

375  {
376  return numMapsAllocated_.load(std::memory_order_acquire);
377  }
std::atomic< uint32_t > numMapsAllocated_
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::recToIdx ( const value_type r,
bool  mayInsert = true 
)
inline

Definition at line 402 of file AtomicHashMap.h.

402  {
403  SimpleRetT ret =
404  mayInsert ? insertInternal(r.first, r.second) : findInternal(r.first);
405  return encodeIndex(ret.i, ret.j);
406  }
SimpleRetT findInternal(const LookupKeyT k) const
SimpleRetT insertInternal(LookupKeyT key, ArgTs &&...value)
static uint32_t encodeIndex(uint32_t subMap, uint32_t subMapIdx)
constexpr detail::First first
Definition: Base-inl.h:2553
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::recToIdx ( value_type &&  r,
bool  mayInsert = true 
)
inline

Definition at line 408 of file AtomicHashMap.h.

408  {
409  SimpleRetT ret = mayInsert ? insertInternal(r.first, std::move(r.second))
410  : findInternal(r.first);
411  return encodeIndex(ret.i, ret.j);
412  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
SimpleRetT findInternal(const LookupKeyT k) const
SimpleRetT insertInternal(LookupKeyT key, ArgTs &&...value)
static uint32_t encodeIndex(uint32_t subMap, uint32_t subMapIdx)
constexpr detail::First first
Definition: Base-inl.h:2553
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::recToIdx ( key_type  k,
const mapped_type v,
bool  mayInsert = true 
)
inline

Definition at line 415 of file AtomicHashMap.h.

415  {
416  SimpleRetT ret = mayInsert ? insertInternal(k, v) : findInternal(k);
417  return encodeIndex(ret.i, ret.j);
418  }
SimpleRetT findInternal(const LookupKeyT k) const
SimpleRetT insertInternal(LookupKeyT key, ArgTs &&...value)
static uint32_t encodeIndex(uint32_t subMap, uint32_t subMapIdx)
KeyT k
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::recToIdx ( key_type  k,
mapped_type &&  v,
bool  mayInsert = true 
)
inline

Definition at line 420 of file AtomicHashMap.h.

420  {
421  SimpleRetT ret =
422  mayInsert ? insertInternal(k, std::move(v)) : findInternal(k);
423  return encodeIndex(ret.i, ret.j);
424  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
SimpleRetT findInternal(const LookupKeyT k) const
SimpleRetT insertInternal(LookupKeyT key, ArgTs &&...value)
static uint32_t encodeIndex(uint32_t subMap, uint32_t subMapIdx)
KeyT k
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
void folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::setEntryCountThreadCacheSize ( int32_t  newSize)
inline

Definition at line 365 of file AtomicHashMap.h.

365  {
366  const int numMaps = numMapsAllocated_.load(std::memory_order_acquire);
367  for (int i = 0; i < numMaps; ++i) {
368  SubMap* map = subMaps_[i].load(std::memory_order_relaxed);
369  map->setEntryCountThreadCacheSize(newSize);
370  }
371  }
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > SubMap
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
std::atomic< uint32_t > numMapsAllocated_
Definition: Traits.h:594
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
size_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::size ( ) const

Definition at line 494 of file AtomicHashMap-inl.h.

References FOR_EACH_RANGE, i, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numMapsAllocated_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::subMaps_, and uint32_t.

Referenced by TEST(), and Counters::toString().

494  {
495  size_t totalSize(0);
496  int const numMaps = numMapsAllocated_.load(std::memory_order_acquire);
497  FOR_EACH_RANGE (i, 0, numMaps) {
498  totalSize += subMaps_[i].load(std::memory_order_relaxed)->size();
499  }
500  return totalSize;
501 }
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
std::atomic< uint32_t > numMapsAllocated_
template<typename KeyT , typename ValueT , typename HashFcn , typename EqualFcn , typename Allocator , typename ProbeFcn , typename KeyConvertFcn >
size_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::spaceRemaining ( ) const

Definition at line 438 of file AtomicHashMap-inl.h.

References FOR_EACH_RANGE, i, max, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::maxEntries_, folly::AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numEntries_, folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::numMapsAllocated_, folly::ThreadCachedInt< IntT, Tag >::readFull(), and folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::subMaps_.

438  {
439  size_t spaceRem(0);
440  int const numMaps = numMapsAllocated_.load(std::memory_order_acquire);
441  FOR_EACH_RANGE (i, 0, numMaps) {
442  SubMap* thisMap = subMaps_[i].load(std::memory_order_relaxed);
443  spaceRem +=
444  std::max(0, thisMap->maxEntries_ - &thisMap->numEntries_.readFull());
445  }
446  return spaceRem;
447 }
LogLevel max
Definition: LogLevel.cpp:31
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > SubMap
#define FOR_EACH_RANGE(i, begin, end)
Definition: Foreach.h:313
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
std::atomic< uint32_t > numMapsAllocated_
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
bool folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::tryLockMap ( unsigned int  idx)
inlineprivate

Definition at line 475 of file AtomicHashMap.h.

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

475  {
476  SubMap* val = nullptr;
477  return subMaps_[idx].compare_exchange_strong(
478  val, (SubMap*)kLockedPtr_, std::memory_order_acquire);
479  }
AtomicHashArray< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn > SubMap
double val
Definition: String.cpp:273
std::atomic< SubMap * > subMaps_[kNumSubMaps_]
static const uintptr_t kLockedPtr_

Member Data Documentation

template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const float folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kGrowthFrac_
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const uintptr_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kLockedPtr_ = 0x88ULL << 48
staticprivate
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kNumSubMapBits_ = 4
staticprivate
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kNumSubMaps_ = 1 << kNumSubMapBits_
staticprivate
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kSecondaryMapBit_ = 1u << 31
staticprivate
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kSubMapIndexMask_ = (1 << kSubMapIndexShift_) - 1
staticprivate
template<class KeyT, class ValueT, class HashFcn, class EqualFcn, class Allocator, class ProbeFcn, class KeyConvertFcn>
const uint32_t folly::AtomicHashMap< KeyT, ValueT, HashFcn, EqualFcn, Allocator, ProbeFcn, KeyConvertFcn >::kSubMapIndexShift_ = 32 - kNumSubMapBits_ - 1
staticprivate

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