ATLAS Offline Software
|
Hash map from strings to arbitrary objects allowing concurrent, lockless reads. More...
#include <ConcurrentStrToValMap.h>
Classes | |
class | const_iterator |
Const iterator class. More... | |
struct | Hasher |
Hash functional for keys. More... | |
class | iterator |
Iterator class. More... | |
struct | Matcher |
Matching functional for keys. More... | |
Public Types | |
using | key_type = std::string |
Standard STL types. More... | |
using | mapped_type = VALUE |
using | size_type = size_t |
using | Updater_t = typename Impl_t::Updater_t |
Updater object. More... | |
using | Context_t = typename Updater_t::Context_t |
Context type. More... | |
using | const_iterator_value = std::pair< const key_type &, const mapped_type & > |
Value structures for iterators. More... | |
using | iterator_value = std::pair< const key_type, mapped_type & > |
typedef boost::iterator_range< const_iterator > | const_iterator_range |
A range defined by two iterators. More... | |
typedef boost::iterator_range< iterator > | iterator_range |
Public Member Functions | |
ConcurrentStrToValMap (Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext()) | |
Constructor. More... | |
ConcurrentStrToValMap (const ConcurrentStrToValMap &other, Updater_t &&updater, size_t capacity=64, const Context_t &ctx=Updater_t::defaultContext()) | |
Constructor from another map. More... | |
template<class InputIterator > | |
ConcurrentStrToValMap (InputIterator f, InputIterator l, Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext()) | |
Constructor from a range. More... | |
ConcurrentStrToValMap (const ConcurrentStrToValMap &other)=delete | |
Copy / move / assign not supported. More... | |
ConcurrentStrToValMap (ConcurrentStrToValMap &&other)=delete | |
ConcurrentStrToValMap & | operator= (const ConcurrentStrToValMap &other)=delete |
ConcurrentStrToValMap & | operator= (ConcurrentStrToValMap &&other)=delete |
~ConcurrentStrToValMap () | |
Destructor. More... | |
size_type | size () const |
Return the number of items currently in the map. More... | |
bool | empty () const |
Test if the map is currently empty. More... | |
size_t | capacity () const |
Return the current size (capacity) of the hash table. More... | |
const_iterator_range | range () const |
Return an iterator range covering the entire map. More... | |
iterator_range | range () |
Return an iterator range covering the entire map. More... | |
const_iterator | begin () const |
Iterator at the start of the map. More... | |
const_iterator | end () const |
Iterator at the end of the map. More... | |
iterator | begin () |
Iterator at the start of the map. More... | |
iterator | end () |
Iterator at the end of the map. More... | |
const_iterator | cbegin () const |
Iterator at the start of the map. More... | |
const_iterator | cend () const |
Iterator at the end of the map. More... | |
bool | contains (const key_type &key) const |
Test if a key is in the container. More... | |
size_type | count (const key_type &key) const |
Return the number of times a given key is in the container. More... | |
const_iterator | find (const key_type &key) const |
Look up an element in the map. More... | |
iterator | find (const key_type &key) |
Look up an element in the map. More... | |
const mapped_type & | at (const key_type &key) const |
Look up an element in the map. More... | |
mapped_type & | at (const key_type &key) |
Look up an element in the map. More... | |
std::pair< const_iterator, const_iterator > | equal_range (const key_type &key) const |
Return a range of iterators with entries matching key . More... | |
std::pair< iterator, iterator > | equal_range (const key_type &key) |
Return a range of iterators with entries matching key . More... | |
std::pair< const_iterator, bool > | emplace (const key_type &key, const mapped_type &val, const Context_t &ctx=Updater_t::defaultContext()) |
Add an element to the map. More... | |
std::pair< const_iterator, bool > | emplace (key_type &&key, const mapped_type &val, const Context_t &ctx=Updater_t::defaultContext()) |
Add an element to the map. More... | |
std::pair< const_iterator, bool > | emplace (const key_type &key, mapped_type &&val, const Context_t &ctx=Updater_t::defaultContext()) |
Add an element to the map. More... | |
std::pair< const_iterator, bool > | emplace (key_type &&key, mapped_type &&val, const Context_t &ctx=Updater_t::defaultContext()) |
Add an element to the map. More... | |
std::pair< const_iterator, bool > | emplace (const key_type &key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext()) |
Add an element to the map. More... | |
std::pair< const_iterator, bool > | emplace (key_type &&key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext()) |
Add an element to the map. More... | |
template<class PAIR > | |
std::pair< const_iterator, bool > | insert (const PAIR &p, const Context_t &ctx=Updater_t::defaultContext()) |
Add an element to the map. More... | |
template<class PAIR > | |
std::pair< const_iterator, bool > | insert (PAIR &&p, const Context_t &ctx=Updater_t::defaultContext()) |
Add an element to the map. More... | |
template<class InputIterator > | |
void | insert (InputIterator first, InputIterator last, const Context_t &ctx=Updater_t::defaultContext()) |
Insert a range of elements to the map. More... | |
void | reserve (size_type capacity, const Context_t &ctx=Updater_t::defaultContext()) |
Increase the table capacity. More... | |
void | rehash (size_type capacity) |
Increase the table capacity. More... | |
void | quiescent (const Context_t &ctx) |
Called when this thread is no longer referencing anything from this container. More... | |
void | swap (ConcurrentStrToValMap &other) |
Swap this container with another. More... | |
Updater_t & | updater () |
Access the Updater instance. More... | |
Private Types | |
using | Impl_t = typename detail::ConcurrentHashmapImpl< UPDATER, Hasher, Matcher > |
using | val_t = CxxUtils::detail::ConcurrentHashmapVal_t |
Representation type in the underlying map. More... | |
Private Member Functions | |
Impl_t::const_iterator | get (const key_type &key) const |
Do a lookup in the table. More... | |
std::pair< const_iterator, bool > | put (std::unique_ptr< key_type > key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext()) |
Insert an entry in the table. More... | |
Static Private Member Functions | |
static const std::string * | keyAsString (val_t val) |
Convert an underlying key value to a string pointer. More... | |
static val_t | keyAsVal (const std::string *s) |
Convert a string pointer to an underlying key value. More... | |
static mapped_type * | mappedAsMapped (val_t val) |
Convert an underlying mapped value a pointer to this type's mapped value. More... | |
static val_t | mappedAsVal (mapped_type *val) |
Convert this type's mapped value to an underlying mapped value. More... | |
Private Attributes | |
Impl_t | m_impl |
The underlying hash table. More... | |
Hash map from strings to arbitrary objects allowing concurrent, lockless reads.
This class implements a hash map from strings. The mapped type is arbitrary. It allows for concurrent access from many threads. Reads can proceed without taking out a lock, while writes are serialized with each other. Thus, this is appropriate for maps which are read-mostly.
This class includes non-const references that can be used to obtain non-const references to the mapped objects. Howeer, the mapped objects must themselves the thread-safe in order to safely modify them in a multithreaded context.
This is based on ConcurrentHashmapImpl.
Besides the key and mapped value types, this class is templated on an UPDATER class, which is used to manage the underlying memory. See IsUpdater.h for details. (AthenaKernel/RCUUpdater is a concrete version that should work in the context of Athena.)
This mostly supports the interface of std::unordered_map, with a few differences / omissions:
The mapped value can be given as any of:
I.e., any of these should work:
Definition at line 86 of file ConcurrentStrToValMap.h.
typedef boost::iterator_range<const_iterator> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::const_iterator_range |
A range defined by two iterators.
Definition at line 363 of file ConcurrentStrToValMap.h.
using CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::const_iterator_value = std::pair<const key_type&, const mapped_type&> |
Value structures for iterators.
For a map from K to V, a STL-style iterator should dereference to a std::pair<const K, V>. However, we don't actually store an object like that anywhere. In order to be able to have STL-like iterators, we instead use a pair where the second element is a const reference to the mapped value. We will return this by value when we deference an iterator. (The compiler should be able to optimize out the redundant packing and unpacking of fields.)
Definition at line 200 of file ConcurrentStrToValMap.h.
using CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::Context_t = typename Updater_t::Context_t |
Context type.
Definition at line 105 of file ConcurrentStrToValMap.h.
|
private |
Definition at line 92 of file ConcurrentStrToValMap.h.
typedef boost::iterator_range<iterator> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::iterator_range |
Definition at line 364 of file ConcurrentStrToValMap.h.
using CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::iterator_value = std::pair<const key_type, mapped_type&> |
Definition at line 201 of file ConcurrentStrToValMap.h.
using CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::key_type = std::string |
Standard STL types.
Definition at line 99 of file ConcurrentStrToValMap.h.
using CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::mapped_type = VALUE |
Definition at line 100 of file ConcurrentStrToValMap.h.
using CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::size_type = size_t |
Definition at line 101 of file ConcurrentStrToValMap.h.
using CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::Updater_t = typename Impl_t::Updater_t |
Updater object.
Definition at line 103 of file ConcurrentStrToValMap.h.
|
private |
Representation type in the underlying map.
Definition at line 94 of file ConcurrentStrToValMap.h.
CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::ConcurrentStrToValMap | ( | Updater_t && | updater, |
size_type | capacity = 64 , |
||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Constructor.
updater | Object used to manage memory (see comments at the start of the class). |
capacity | The initial table capacity. (Will be rounded up to a power of two.) |
ctx | Execution context. |
CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::ConcurrentStrToValMap | ( | const ConcurrentStrToValMap< VALUE, UPDATER > & | other, |
Updater_t && | updater, | ||
size_t | capacity = 64 , |
||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Constructor from another map.
updater | Object used to manage memory (see comments at the start of the class). |
capacity | The initial table capacity of the new table. (Will be rounded up to a power of two.) |
ctx | Execution context. |
(Not really a copy constructor since we need to pass updater
.)
CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::ConcurrentStrToValMap | ( | InputIterator | f, |
InputIterator | l, | ||
Updater_t && | updater, | ||
size_type | capacity = 64 , |
||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Constructor from a range.
f | Start iterator for the range. |
l | End iterator for the range. |
updater | Object used to manage memory (see comments at the start of the class). |
capacity | The initial table capacity of the new table. (Will be rounded up to a power of two.) |
ctx | Execution context. |
Constructor from a range of pairs.
|
delete |
Copy / move / assign not supported.
|
delete |
CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::~ConcurrentStrToValMap | ( | ) |
Destructor.
mapped_type& CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::at | ( | const key_type & | key | ) |
Look up an element in the map.
key | The element to find. |
Returns the value associated with the key. Throws std::out_of_range
if the key does not exist in the map.
This returns a non-const reference to the mapped object. The mapped object must be thread-safe itself in order to safely make any changes to it.
const mapped_type& CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::at | ( | const key_type & | key | ) | const |
Look up an element in the map.
key | The element to find. |
Returns the value associated with the key. Throws std::out_of_range
if the key does not exist in the map.
iterator CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::begin | ( | ) |
Iterator at the start of the map.
The mapped objects must themselves be thread-safe in order to make any changes to them through the returned iterators.
const_iterator CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::begin | ( | ) | const |
Iterator at the start of the map.
size_t CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::capacity | ( | ) | const |
Return the current size (capacity) of the hash table.
const_iterator CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::cbegin | ( | ) | const |
Iterator at the start of the map.
const_iterator CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::cend | ( | ) | const |
Iterator at the end of the map.
bool CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::contains | ( | const key_type & | key | ) | const |
Test if a key is in the container.
key | The key to test. |
size_type CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::count | ( | const key_type & | key | ) | const |
Return the number of times a given key is in the container.
key | The key to test. |
Returns either 0 or 1, depending on whether or not the key is in the map.
std::pair<const_iterator, bool> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::emplace | ( | const key_type & | key, |
const mapped_type & | val, | ||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Add an element to the map.
key | The key of the new item to add. |
val | The value of the new item to add. |
ctx | Execution context. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
std::pair<const_iterator, bool> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::emplace | ( | const key_type & | key, |
mapped_type && | val, | ||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Add an element to the map.
key | The key of the new item to add. |
val | The value of the new item to add. |
ctx | Execution context. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
std::pair<const_iterator, bool> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::emplace | ( | const key_type & | key, |
std::unique_ptr< mapped_type > | val, | ||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Add an element to the map.
key | The key of the new item to add. |
val | The value of the new item to add. |
ctx | Execution context. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
std::pair<const_iterator, bool> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::emplace | ( | key_type && | key, |
const mapped_type & | val, | ||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Add an element to the map.
key | The key of the new item to add. |
val | The value of the new item to add. |
ctx | Execution context. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
std::pair<const_iterator, bool> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::emplace | ( | key_type && | key, |
mapped_type && | val, | ||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Add an element to the map.
key | The key of the new item to add. |
val | The value of the new item to add. |
ctx | Execution context. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
std::pair<const_iterator, bool> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::emplace | ( | key_type && | key, |
std::unique_ptr< mapped_type > | val, | ||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Add an element to the map.
key | The key of the new item to add. |
val | The value of the new item to add. |
ctx | Execution context. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
bool CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::empty | ( | ) | const |
Test if the map is currently empty.
iterator CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::end | ( | ) |
Iterator at the end of the map.
The mapped objects must themselves be thread-safe in order to make any changes to them through the returned iterators.
const_iterator CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::end | ( | ) | const |
Iterator at the end of the map.
std::pair<iterator, iterator> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::equal_range | ( | const key_type & | key | ) |
Return a range of iterators with entries matching key
.
key | The element to find. |
As keys are unique in this container, this is either a single-element range, or both iterators are equal to end().
The mapped objects must themselves be thread-safe in order to make any changes to them through the returned iterators.
std::pair<const_iterator, const_iterator> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::equal_range | ( | const key_type & | key | ) | const |
Return a range of iterators with entries matching key
.
key | The element to find. |
As keys are unique in this container, this is either a single-element range, or both iterators are equal to end().
iterator CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::find | ( | const key_type & | key | ) |
Look up an element in the map.
key | The element to find. |
Returns either an iterator referencing the found element or end().
The mapped object must itself be thread-safe in order to make any changes to it through the returned iterator.
const_iterator CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::find | ( | const key_type & | key | ) | const |
Look up an element in the map.
key | The element to find. |
Returns either an iterator referencing the found element or end().
|
private |
Do a lookup in the table.
key | The key to look up. |
Returns an iterator of the underlying map pointing at the found entry or end();
std::pair<const_iterator, bool> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::insert | ( | const PAIR & | p, |
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Add an element to the map.
p | The item to add. Should be a pair where first is the string key and second is the integer value. |
ctx | Execution context. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
void CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::insert | ( | InputIterator | first, |
InputIterator | last, | ||
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Insert a range of elements to the map.
first | Start of the range. |
last | End of the range. |
ctx | Execution context. |
The range should be a sequence of pairs where first is the string key and second is the integer value.
std::pair<const_iterator, bool> CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::insert | ( | PAIR && | p, |
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Add an element to the map.
p | The item to add. Should be a pair where first is the string key and second is the integer value. |
ctx | Execution context. |
This will not overwrite an existing entry. The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
|
staticprivate |
Convert an underlying key value to a string pointer.
val | The underlying key value. |
|
staticprivate |
Convert a string pointer to an underlying key value.
s | The string pointer. |
|
staticprivate |
Convert an underlying mapped value a pointer to this type's mapped value.
val | The underlying mapped value. |
|
staticprivate |
Convert this type's mapped value to an underlying mapped value.
val | The mapped value. |
|
delete |
|
delete |
|
private |
Insert an entry in the table.
key | The key of the new item to add. |
val | The new mapped value to add. |
ctx | Execution context. |
The first element in the returned pair is an iterator referencing the added item. The second is a flag that is true if a new element was added.
void CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::quiescent | ( | const Context_t & | ctx | ) |
Called when this thread is no longer referencing anything from this container.
ctx | Execution context. |
iterator_range CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::range | ( | ) |
Return an iterator range covering the entire map.
The mapped objects must themselves be thread-safe in order to make any changes to them through the returned iterators.
const_iterator_range CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::range | ( | ) | const |
Return an iterator range covering the entire map.
void CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::rehash | ( | size_type | capacity | ) |
Increase the table capacity.
capacity | The new table capacity. |
No action will be taken if capacity
is smaller than the current capacity.
void CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::reserve | ( | size_type | capacity, |
const Context_t & | ctx = Updater_t::defaultContext() |
||
) |
Increase the table capacity.
capacity | The new table capacity. |
ctx | Execution context. |
No action will be taken if capacity
is smaller than the current capacity.
size_type CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::size | ( | ) | const |
Return the number of items currently in the map.
void CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::swap | ( | ConcurrentStrToValMap< VALUE, UPDATER > & | other | ) |
Swap this container with another.
other | The container with which to swap. |
This will also call swap on the Updater object; hence, the Updater object must also support swap.
This operation is NOT thread-safe. No other threads may be accessing either container during this operation.
Updater_t& CxxUtils::ConcurrentStrToValMap< VALUE, UPDATER >::updater | ( | ) |
Access the Updater instance.
|
private |
The underlying hash table.
Definition at line 787 of file ConcurrentStrToValMap.h.