ATLAS Offline Software
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ > Class Template Reference

Hash table allowing concurrent, lockless reads. More...

#include <ConcurrentHashmapImpl.h>

Collaboration diagram for CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >:

Classes

class  const_iterator
 Bidirectional iterator over occupied table entries. More...
 
struct  entry_t
 One entry in the hash table. More...
 
class  Table
 Table of hash entries. More...
 

Public Types

using val_t = ConcurrentHashmapVal_t
 Type used for keys and values — an unsigned big enough to hold a pointer. More...
 
using Hasher_t = HASHER_
 Hash object. More...
 
using Matcher_t = MATCHER_
 Key match object. More...
 
using Lock_t = HashmapLock
 Lock class used for external locking. More...
 
using Updater_t = UPDATER_< Table >
 Updater object. More...
 
using Context_t = typename Updater_t::Context_t
 Context type for the updater. More...
 
using const_iterator_range = std::pair< const_iterator, const_iterator >
 Two iterators defining a range. More...
 

Public Member Functions

 ConcurrentHashmapImpl (Updater_t &&updater, size_t capacity_in, const Hasher_t &hasher, const Matcher_t &matcher, const typename Updater_t::Context_t &ctx)
 Constructor. More...
 
 ConcurrentHashmapImpl (const ConcurrentHashmapImpl &)=delete
 
ConcurrentHashmapImploperator= (const ConcurrentHashmapImpl &)=delete
 
size_t size () const
 Return the number of items currently stored. More...
 
size_t capacity () const
 Return the current table size. More...
 
size_t erased () const
 The number of erased elements in the current table. More...
 
const Hasher_thasher () const
 Return the hasher object. More...
 
const Matcher_tmatcher () const
 Return the matcher object. More...
 
Lock_t lock ()
 Take a lock on the container. More...
 
std::pair< const_iterator, bool > put (val_t key, size_t hash, val_t val, bool overwrite, const typename Updater_t::Context_t &ctx)
 Add an entry to the table. More...
 
std::pair< const_iterator, bool > put (const Lock_t &lock, val_t key, size_t hash, val_t val, bool overwrite, const typename Updater_t::Context_t &ctx)
 Add an entry to the table, with external locking. More...
 
const_iterator get (val_t key, size_t hash) const
 Look up an entry in the table. More...
 
bool erase (val_t key, size_t hash)
 Erase an entry from the table. More...
 
bool erase (const Lock_t &lock, val_t key, size_t hash)
 Erase an entry from the table, with external locking. More...
 
const_iterator_range range () const
 Return a range that can be used to iterate over the container. More...
 
const_iterator begin () const
 A begin iterator for the container. More...
 
const_iterator end () const
 An end iterator for the container. More...
 
const_iterator clear (size_t capacity, const typename Updater_t::Context_t &ctx)
 Erase the table and change the capacity. More...
 
const_iterator clear (const typename Updater_t::Context_t &ctx)
 Erase the table (don't change the capacity). More...
 
void forceClear ()
 Erase the table by filling it with nulls. More...
 
void reserve (size_t capacity, const typename Updater_t::Context_t &ctx)
 Increase the table capacity. More...
 
void quiescent (const typename Updater_t::Context_t &ctx)
 Called when this thread is no longer referencing anything from this container. More...
 
void swap (ConcurrentHashmapImpl &other)
 Swap this container with another. More...
 
Updater_tupdater ()
 Access the Updater instance. More...
 

Static Public Attributes

static constexpr uintptr_t nullval = NULLVAL_
 Null key value. More...
 
static constexpr uintptr_t tombstone = TOMBSTONE_
 Tombstone key value. Must be different from nullval to allow erasures. More...
 
static constexpr size_t INVALID = static_cast<size_t>(-1)
 Used to represent an invalid table index. More...
 

Private Member Functions

bool grow (const Lock_t &lock, const typename Updater_t::Context_t &ctx)
 Make the table larger. More...
 
bool grow (const Lock_t &lock, size_t new_capacity, const typename Updater_t::Context_t &ctx)
 Make the table larger. More...
 

Static Private Member Functions

static uint64_t round_up (uint64_t)
 

Private Attributes

Updater_t m_updater
 Updater object managing memory. See above. More...
 
const Hasher_t m_hasher
 The hash object. More...
 
const Matcher_t m_matcher
 The key match object. More...
 
Tablem_table
 The current table instance. Must be holding the mutex to access this. More...
 
std::atomic< size_t > m_size
 Number of entries in the map. More...
 
std::atomic< size_t > m_erased
 Number of entries that have been erased. More...
 
std::mutex m_mutex
 Mutex to serialize changes to the map. More...
 

Static Private Attributes

static constexpr size_t CACHELINE = 64
 Assumed length in bytes of one cache line. More...
 
static constexpr size_t ENTRIES_PER_CACHELINE = CACHELINE / sizeof(entry_t)
 Number of entries in one cache line. More...
 
static constexpr size_t ENTRIES_PER_CACHELINE_MASK = (ENTRIES_PER_CACHELINE-1)
 Mask for the cache line part of an index. More...
 

Friends

class ::ConcurrentHashmapImplTest
 For unit testing. More...
 

Detailed Description

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
class CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >

Hash table allowing concurrent, lockless reads.

This class implements a simple hash map from uintptr_t to uintptr_t. This class isn't meant to be used directly; rather, a more user-friendly interface can be built on top of this. Although here we deal only with uintptr_t values, the hash and comparison operations are templated. This allows for handling more complex types, where the values stored in the map are pointers to the actual objects. We support inserting new items and modifying existing ones, and, with caveats, deletion. One value of the key must be reserved to indicate null; no keys with that value may be inserted. For deletion, a second distinct (tombstone) value of the key must be reserved to mark deleted entries.

Further caveats for deletion:

There can be only one writer at a time; this is enforced with internal locks. However, there can be any number of concurrent readers at any time. The reads are lockless. So this is appropriate when reads are much more frequent than writes.

Template arguments: UPDATER_ - Object used for memory management; see below. This has the same requirements as for ConcurrentRangeMap; see there for further details. HASHER_ - Functional to compute a hash value from a key. Defaults to std::hash. MATCHER_ - Functional to compare two keys for equality. Defaults to std::equal_to. NULLVAL_ - Value of the key to be considered null. A key with this value may not be inserted. TOMBSTONE_ - Value of the key used to mark a deleted entry. If identical to NULLVAL_, then deletions are not allowed.

Implementation notes: We use open addressing (see, eg, knuth AOCP 6.4), in which the payloads are kept in the hash table itself. We try to be cache friendly by probing all entries within a cache line before trying anything in a different cache line. If the table gets full, we make a new, larger, instance copying the data from the old one. The old table instances are then given to the Updater object to handle.

The implementation here is inspired by the hash maps from ConcurrencyKit (http://concurrencykit.org), though the code is all new.

nb. Can't use plain ‘MATCHER’ as a template argument because it collides with gtest.

Definition at line 207 of file ConcurrentHashmapImpl.h.

Member Typedef Documentation

◆ const_iterator_range

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
using CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::const_iterator_range = std::pair<const_iterator, const_iterator>

Two iterators defining a range.

Definition at line 592 of file ConcurrentHashmapImpl.h.

◆ Context_t

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
using CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::Context_t = typename Updater_t::Context_t

Context type for the updater.

Definition at line 362 of file ConcurrentHashmapImpl.h.

◆ Hasher_t

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
using CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::Hasher_t = HASHER_

Hash object.

Definition at line 213 of file ConcurrentHashmapImpl.h.

◆ Lock_t

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
using CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::Lock_t = HashmapLock

Lock class used for external locking.

Definition at line 224 of file ConcurrentHashmapImpl.h.

◆ Matcher_t

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
using CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::Matcher_t = MATCHER_

Key match object.

Definition at line 215 of file ConcurrentHashmapImpl.h.

◆ Updater_t

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
using CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::Updater_t = UPDATER_<Table>

Updater object.

Definition at line 360 of file ConcurrentHashmapImpl.h.

◆ val_t

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
using CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::val_t = ConcurrentHashmapVal_t

Type used for keys and values — an unsigned big enough to hold a pointer.

Definition at line 211 of file ConcurrentHashmapImpl.h.

Constructor & Destructor Documentation

◆ ConcurrentHashmapImpl() [1/2]

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::ConcurrentHashmapImpl ( Updater_t &&  updater,
size_t  capacity_in,
const Hasher_t hasher,
const Matcher_t matcher,
const typename Updater_t::Context_t &  ctx 
)

Constructor.

Parameters
updaterObject used to manage memory (see comments at the start of the class).
capacityMinimum initial table size.
hasherHash object to use.
matcherKey match object to use.
ctxExecution context.

◆ ConcurrentHashmapImpl() [2/2]

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::ConcurrentHashmapImpl ( const ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ > &  )
delete

Member Function Documentation

◆ begin()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
const_iterator CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::begin ( ) const

A begin iterator for the container.

◆ capacity()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
size_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::capacity ( ) const

Return the current table size.

◆ clear() [1/2]

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
const_iterator CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::clear ( const typename Updater_t::Context_t &  ctx)

Erase the table (don't change the capacity).

Parameters
ctxExecution context.

Returns an iterator pointing at the start of the old table.

◆ clear() [2/2]

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
const_iterator CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::clear ( size_t  capacity,
const typename Updater_t::Context_t &  ctx 
)

Erase the table and change the capacity.

Parameters
capacityThe new table capacity.
ctxExecution context.

Returns an iterator pointing at the start of the old table.

◆ end()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
const_iterator CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::end ( ) const

An end iterator for the container.

◆ erase() [1/2]

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
bool CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::erase ( const Lock_t lock,
val_t  key,
size_t  hash 
)

Erase an entry from the table, with external locking.

Parameters
lockThe lock object returned from lock().
keyThe key to erase.
hashThe hash of the key.

Mark the corresponding entry as deleted. Return true on success, false on failure (key not found).

The tombstone value must be different from the null value.

Take care if the key or value types require memory allocation.

This may cause the key type returned by an iterator to change asynchronously to the tombstone value.

◆ erase() [2/2]

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
bool CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::erase ( val_t  key,
size_t  hash 
)

Erase an entry from the table.

Parameters
keyThe key to erase.
hashThe hash of the key.

Mark the corresponding entry as deleted. Return true on success, false on failure (key not found).

The tombstone value must be different from the null value.

Take care if the key or value types require memory allocation.

This may cause the key type returned by an iterator to change asynchronously to the tombstone value.

◆ erased()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
size_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::erased ( ) const

The number of erased elements in the current table.

◆ forceClear()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
void CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::forceClear ( )

Erase the table by filling it with nulls.

This method is not safe to use concurrently — no other threads may be accessing the container at the same time, either for read or write.

◆ get()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
const_iterator CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::get ( val_t  key,
size_t  hash 
) const

Look up an entry in the table.

Parameters
keyThe key to find.
hashThe hash of the key.

Returns an iterator pointing at the found entry, or end().

◆ grow() [1/2]

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
bool CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::grow ( const Lock_t lock,
const typename Updater_t::Context_t &  ctx 
)
private

Make the table larger.

Parameters
ctxExecution context.

Must be holding a lock on the mutex to call this.

◆ grow() [2/2]

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
bool CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::grow ( const Lock_t lock,
size_t  new_capacity,
const typename Updater_t::Context_t &  ctx 
)
private

Make the table larger.

Parameters
new_capacityThe new table capacity (must be a power of 2).
ctxExecution context.

Must be holding a lock on the mutex to call this.

◆ hasher()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
const Hasher_t& CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::hasher ( ) const

Return the hasher object.

◆ lock()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
Lock_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::lock ( )

Take a lock on the container.

Take a lock on the container. The lock can then be passed to put(), allowing to factor out the locking when put() gets used in a loop. The lock will be released when the lock object is destroyed.

◆ matcher()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
const Matcher_t& CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::matcher ( ) const

Return the matcher object.

◆ operator=()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
ConcurrentHashmapImpl& CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::operator= ( const ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ > &  )
delete

◆ put() [1/2]

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
std::pair<const_iterator, bool> CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::put ( const Lock_t lock,
val_t  key,
size_t  hash,
val_t  val,
bool  overwrite,
const typename Updater_t::Context_t &  ctx 
)

Add an entry to the table, with external locking.

Parameters
lockThe lock object returned from lock().
keyThe key to insert.
hashThe hash of the key.
valThe value to insert.
overwriteIf true, then overwrite an existing entry. If false, an existing entry will not be changed.
ctxExecution context.

If the key already exists, then its value will be updated. Returns an iterator pointing at the entry and a flag which is true if a new element was added.

◆ put() [2/2]

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
std::pair<const_iterator, bool> CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::put ( val_t  key,
size_t  hash,
val_t  val,
bool  overwrite,
const typename Updater_t::Context_t &  ctx 
)

Add an entry to the table.

Parameters
keyThe key to insert.
hashThe hash of the key.
valThe value to insert.
overwriteIf true, then overwrite an existing entry. If false, an existing entry will not be changed.
ctxExecution context.

If the key already exists, then its value will be updated. Returns an iterator pointing at the entry and a flag which is true if a new element was added.

◆ quiescent()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
void CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::quiescent ( const typename Updater_t::Context_t &  ctx)

Called when this thread is no longer referencing anything from this container.

Parameters
ctxExecution context.

◆ range()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
const_iterator_range CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::range ( ) const

Return a range that can be used to iterate over the container.

◆ reserve()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
void CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::reserve ( size_t  capacity,
const typename Updater_t::Context_t &  ctx 
)

Increase the table capacity.

Parameters
capacityThe new table capacity.
ctxExecution context.

No action will be taken if capacity is smaller than the current capacity.

◆ round_up()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
static uint64_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::round_up ( uint64_t  )
staticprivate

◆ size()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
size_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::size ( ) const

Return the number of items currently stored.

(not necessarily synced)

◆ swap()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
void CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::swap ( ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ > &  other)

Swap this container with another.

Parameters
otherThe container with which to swap.

This will also call swap on the Updater object; hence, the Updater object must also support swap. The Hasher and Matcher instances are NOT swapped.

This operation is NOT thread-safe. No other threads may be accessing either container during this operation.

◆ updater()

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
Updater_t& CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::updater ( )

Access the Updater instance.

Friends And Related Function Documentation

◆ ::ConcurrentHashmapImplTest

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
friend class ::ConcurrentHashmapImplTest
friend

For unit testing.

Definition at line 249 of file ConcurrentHashmapImpl.h.

Member Data Documentation

◆ CACHELINE

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
constexpr size_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::CACHELINE = 64
staticconstexprprivate

Assumed length in bytes of one cache line.

Definition at line 235 of file ConcurrentHashmapImpl.h.

◆ ENTRIES_PER_CACHELINE

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
constexpr size_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::ENTRIES_PER_CACHELINE = CACHELINE / sizeof(entry_t)
staticconstexprprivate

Number of entries in one cache line.

Definition at line 244 of file ConcurrentHashmapImpl.h.

◆ ENTRIES_PER_CACHELINE_MASK

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
constexpr size_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::ENTRIES_PER_CACHELINE_MASK = (ENTRIES_PER_CACHELINE-1)
staticconstexprprivate

Mask for the cache line part of an index.

Definition at line 246 of file ConcurrentHashmapImpl.h.

◆ INVALID

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
constexpr size_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::INVALID = static_cast<size_t>(-1)
staticconstexpr

Used to represent an invalid table index.

Definition at line 221 of file ConcurrentHashmapImpl.h.

◆ m_erased

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
std::atomic<size_t> CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::m_erased
private

Number of entries that have been erased.

Definition at line 717 of file ConcurrentHashmapImpl.h.

◆ m_hasher

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
const Hasher_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::m_hasher
private

The hash object.

Definition at line 709 of file ConcurrentHashmapImpl.h.

◆ m_matcher

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
const Matcher_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::m_matcher
private

The key match object.

Definition at line 711 of file ConcurrentHashmapImpl.h.

◆ m_mutex

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
std::mutex CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::m_mutex
private

Mutex to serialize changes to the map.

Definition at line 719 of file ConcurrentHashmapImpl.h.

◆ m_size

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
std::atomic<size_t> CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::m_size
private

Number of entries in the map.

Definition at line 715 of file ConcurrentHashmapImpl.h.

◆ m_table

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
Table* CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::m_table
private

The current table instance. Must be holding the mutex to access this.

Definition at line 713 of file ConcurrentHashmapImpl.h.

◆ m_updater

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
Updater_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::m_updater
private

Updater object managing memory. See above.

Definition at line 707 of file ConcurrentHashmapImpl.h.

◆ nullval

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
constexpr uintptr_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::nullval = NULLVAL_
staticconstexpr

Null key value.

Definition at line 217 of file ConcurrentHashmapImpl.h.

◆ tombstone

template<template< class > class UPDATER_, typename HASHER_ = std::hash<uintptr_t>, typename MATCHER_ = std::equal_to<uintptr_t>, uintptr_t NULLVAL_ = 0, uintptr_t TOMBSTONE_ = NULLVAL_>
constexpr uintptr_t CxxUtils::detail::ConcurrentHashmapImpl< UPDATER_, HASHER_, MATCHER_, NULLVAL_, TOMBSTONE_ >::tombstone = TOMBSTONE_
staticconstexpr

Tombstone key value. Must be different from nullval to allow erasures.

Definition at line 219 of file ConcurrentHashmapImpl.h.


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