![]() |
ATLAS Offline Software
|
Hash map from pointers/integers to arbitrary objects allowing concurrent, lockless reads. More...
#include <ConcurrentToValMap.h>
Classes | |
| class | const_iterator |
| Const iterator class. More... | |
| struct | Hasher |
| class | iterator |
| Iterator class. More... | |
| struct | Matcher |
Public Types | |
| using | key_type = KEY |
| Standard STL types. | |
| using | mapped_type = VALUE |
| using | size_type = size_t |
| using | Updater_t = typename Impl_t::Updater_t |
| Updater object. | |
| using | Context_t = typename Updater_t::Context_t |
| Context type. | |
| using | const_iterator_value = std::pair<const key_type, const mapped_type&> |
| Value structures for iterators. | |
| using | iterator_value = std::pair<const key_type, mapped_type&> |
| using | const_iterator_range = CxxUtils::iterator_range<const_iterator> |
| A range defined by two iterators. | |
| using | iterator_range = CxxUtils::iterator_range<iterator> |
Public Member Functions | |
| ConcurrentToValMap (Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext()) | |
| Constructor. | |
| ConcurrentToValMap (const ConcurrentToValMap &other, Updater_t &&updater, size_t capacity=64, const Context_t &ctx=Updater_t::defaultContext()) | |
| Constructor from another map. | |
| template<class InputIterator> | |
| ConcurrentToValMap (InputIterator f, InputIterator l, Updater_t &&updater, size_type capacity=64, const Context_t &ctx=Updater_t::defaultContext()) | |
| Constructor from a range. | |
| ConcurrentToValMap (const ConcurrentToValMap &other)=delete | |
| Copy / move / assign not supported. | |
| ConcurrentToValMap (ConcurrentToValMap &&other)=delete | |
| ConcurrentToValMap & | operator= (const ConcurrentToValMap &other)=delete |
| ConcurrentToValMap & | operator= (ConcurrentToValMap &&other)=delete |
| ~ConcurrentToValMap () | |
| Destructor. | |
| size_type | size () const |
| Return the number of items currently in the map. | |
| bool | empty () const |
| Test if the map is currently empty. | |
| size_t | capacity () const |
| Return the current size (capacity) of the hash table. | |
| const_iterator_range | range () const |
| Return an iterator range covering the entire map. | |
| iterator_range | range () |
| Return an iterator range covering the entire map. | |
| const_iterator | begin () const |
| Iterator at the start of the map. | |
| const_iterator | end () const |
| Iterator at the end of the map. | |
| iterator | begin () |
| Iterator at the start of the map. | |
| iterator | end () |
| Iterator at the end of the map. | |
| const_iterator | cbegin () const |
| Iterator at the start of the map. | |
| const_iterator | cend () const |
| Iterator at the end of the map. | |
| bool | contains (const key_type key) const |
| Test if a key is in the container. | |
| size_type | count (const key_type key) const |
| Return the number of times a given key is in the container. | |
| const_iterator | find (const key_type key) const |
| Look up an element in the map. | |
| iterator | find (const key_type key) |
| Look up an element in the map. | |
| const mapped_type & | at (const key_type key) const |
| Look up an element in the map. | |
| mapped_type & | at (const key_type key) |
| Look up an element in the map. | |
| std::pair< const_iterator, const_iterator > | equal_range (const key_type key) const |
Return a range of iterators with entries matching key. | |
| std::pair< iterator, iterator > | equal_range (const key_type key) |
Return a range of iterators with entries matching key. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| template<class PAIR> | |
| std::pair< const_iterator, bool > | insert (PAIR &&p, const Context_t &ctx=Updater_t::defaultContext()) |
| Add an element to the map. | |
| template<class InputIterator> | |
| void | insert (InputIterator first, InputIterator last, const Context_t &ctx=Updater_t::defaultContext()) |
| Insert a range of elements to the map. | |
| void | reserve (size_type capacity, const Context_t &ctx=Updater_t::defaultContext()) |
| Increase the table capacity. | |
| void | rehash (size_type capacity) |
| Increase the table capacity. | |
| void | quiescent (const Context_t &ctx) |
| Called when this thread is no longer referencing anything from this container. | |
| void | swap (ConcurrentToValMap &other) |
| Swap this container with another. | |
| Updater_t & | updater () |
| Access the Updater instance. | |
Private Types | |
| using | val_t = CxxUtils::detail::ConcurrentHashmapVal_t |
| Representation type in the underlying map. | |
| using | Impl_t |
| The underlying uint->uint hash table. | |
Private Member Functions | |
| Impl_t::const_iterator | get (const key_type key) const |
| Do a lookup in the table. | |
| std::pair< const_iterator, bool > | put (const key_type key, std::unique_ptr< mapped_type > val, const Context_t &ctx=Updater_t::defaultContext()) |
| Insert an entry in the table. | |
Static Private Member Functions | |
| static key_type | keyAsKey (val_t val) |
| Convert an underlying key value to this type's key value. | |
| static val_t | keyAsVal (key_type k) |
| Convert this type's key value to an underlying key value. | |
| static mapped_type * | mappedAsMapped (val_t val) |
| Convert an underlying mapped value a pointer to this type's mapped value. | |
| static val_t | mappedAsVal (mapped_type *val) |
| Convert this type's mapped value to an underlying mapped value. | |
Private Attributes | |
| Impl_t | m_impl |
| The underlying hash table. | |
Hash map from pointers/integers to arbitrary objects allowing concurrent, lockless reads.
This class implements a hash map, using keys that may be pointers or any integer type that can fit in an uintptr_t. 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.)
The operations used for calculating the hash of the keys and comparing keys can be customized with the HASHER and MATCHER template arguments (though the defaults should usually be fine).
One value of the key must be reserved as a null value, which no real keys may take. By default this is ‘0’, but it may be customized with the NULLVAL template argument. Note that the type of the NULLPTR template argument is a uintptr_t, not KEY.
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 102 of file ConcurrentToValMap.h.
| using CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::const_iterator_range = CxxUtils::iterator_range<const_iterator> |
A range defined by two iterators.
Definition at line 399 of file ConcurrentToValMap.h.
| using CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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 236 of file ConcurrentToValMap.h.
| using CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::Context_t = typename Updater_t::Context_t |
Context type.
Definition at line 141 of file ConcurrentToValMap.h.
|
private |
The underlying uint->uint hash table.
Definition at line 127 of file ConcurrentToValMap.h.
| using CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::iterator_range = CxxUtils::iterator_range<iterator> |
Definition at line 400 of file ConcurrentToValMap.h.
| using CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::iterator_value = std::pair<const key_type, mapped_type&> |
Definition at line 237 of file ConcurrentToValMap.h.
| using CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::key_type = KEY |
Standard STL types.
Definition at line 135 of file ConcurrentToValMap.h.
| using CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::mapped_type = VALUE |
Definition at line 136 of file ConcurrentToValMap.h.
| using CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::size_type = size_t |
Definition at line 137 of file ConcurrentToValMap.h.
| using CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::Updater_t = typename Impl_t::Updater_t |
Updater object.
Definition at line 139 of file ConcurrentToValMap.h.
|
private |
Representation type in the underlying map.
Definition at line 106 of file ConcurrentToValMap.h.
| CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::ConcurrentToValMap | ( | 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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::ConcurrentToValMap | ( | const ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL > & | 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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::ConcurrentToValMap | ( | 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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::~ConcurrentToValMap | ( | ) |
Destructor.
| mapped_type & CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::begin | ( | ) | const |
Iterator at the start of the map.
| size_t CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::capacity | ( | ) | const |
Return the current size (capacity) of the hash table.
| const_iterator CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::cbegin | ( | ) | const |
Iterator at the start of the map.
| const_iterator CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::cend | ( | ) | const |
Iterator at the end of the map.
| bool CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::contains | ( | const key_type | key | ) | const |
Test if a key is in the container.
| key | The key to test. |
| size_type CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::empty | ( | ) | const |
Test if the map is currently empty.
| iterator CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::end | ( | ) | const |
Iterator at the end of the map.
| std::pair< iterator, iterator > CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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 this type's key value.
| val | The underlying key value. |
|
staticprivate |
Convert this type's key value to an underlying key value.
| k | The key. |
|
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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::quiescent | ( | const Context_t & | ctx | ) |
Called when this thread is no longer referencing anything from this container.
| ctx | Execution context. |
| iterator_range CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::range | ( | ) | const |
Return an iterator range covering the entire map.
| void CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::size | ( | ) | const |
Return the number of items currently in the map.
| void CxxUtils::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::swap | ( | ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL > & | 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::ConcurrentToValMap< KEY, VALUE, UPDATER, HASHER, MATCHER, NULLVAL >::updater | ( | ) |
Access the Updater instance.
|
private |
The underlying hash table.
Definition at line 748 of file ConcurrentToValMap.h.