xenium
|
A generic lock-free hash-map. More...
#include <harris_michael_hash_map.hpp>
Classes | |
class | accessor |
An accessor to safely access the value of an element. More... | |
class | iterator |
A ForwardIterator to safely iterate the hash-map. More... | |
Public Member Functions | |
template<class... Args> | |
bool | emplace (Args &&... args) |
Inserts a new element into the container if the container doesn't already contain an element with an equivalent key. The element is constructed in-place with the given args . More... | |
template<class... Args> | |
std::pair< iterator, bool > | emplace_or_get (Args &&... args) |
Inserts a new element into the container if the container doesn't already contain an element with an equivalent key. The element is constructed in-place with the given args . More... | |
template<class... Args> | |
std::pair< iterator, bool > | get_or_emplace (Key key, Args &&... args) |
Inserts a new element into the container if the container doesn't already contain an element with an equivalent key. The element is constructed as value_type(std::piecewise_construct, std::forward_as_tuple(k), std::forward_as_tuple(std::forward<Args>(args)...)) . More... | |
template<class Factory > | |
std::pair< iterator, bool > | get_or_emplace_lazy (Key key, Factory factory) |
Inserts a new element into the container if the container doesn't already contain an element with an equivalent key. The value for the newly constructed element is created by calling value_factory . More... | |
bool | erase (const Key &key) |
Removes the element with the key equivalent to key (if one exists). More... | |
iterator | erase (iterator pos) |
Removes the specified element from the container. More... | |
iterator | find (const Key &key) |
Finds an element with key equivalent to key. More... | |
bool | contains (const Key &key) |
Checks if there is an element with key equivalent to key in the container. More... | |
accessor | operator[] (const Key &key) |
The accessor More... | |
iterator | begin () |
Returns an iterator to the first element of the container. More... | |
iterator | end () |
Returns an iterator to the element following the last element of the container. More... | |
A generic lock-free hash-map.
This hash-map consists of a fixed number of buckets were each bucket is essentially a harris_michael_list_based_set
instance. The number of buckets is fixed, so the hash-map does not support dynamic resizing.
This hash-map is less efficient than many other available concurrent hash-maps, but it is lock-free and fully generic, i.e., it supports arbitrary types for Key
and Value
.
This data structure is based on the solution proposed by Michael [Mic02] which builds upon the original proposal by Harris [Har01].
Supported policies:
xenium::policy::reclaimer
xenium::policy::hash
xenium::hash<Key>
)xenium::policy::map_to_bucket
xenium::utils::modulo<std::size_t>
)xenium::policy::backoff
xenium::no_backoff
)xenium::policy::buckets
xenium::policy::memoize_hash
Key
types; otherwise true)Key | |
Value | |
Policies | list of policies to customize the behaviour |
auto xenium::harris_michael_hash_map< Key, Value, Policies >::begin |
Returns an iterator to the first element of the container.
bool xenium::harris_michael_hash_map< Key, Value, Policies >::contains | ( | const Key & | key | ) |
Checks if there is an element with key equivalent to key in the container.
Progress guarantees: lock-free
key | key of the element to search for |
true
if there is such an element, otherwise false
bool xenium::harris_michael_hash_map< Key, Value, Policies >::emplace | ( | Args &&... | args | ) |
Inserts a new element into the container if the container doesn't already contain an element with an equivalent key. The element is constructed in-place with the given args
.
The element is always constructed. If there already is an element with the key in the container, the newly constructed element will be destroyed immediately.
No iterators or references are invalidated.
Progress guarantees: lock-free
args | arguments to forward to the constructor of the element |
true
if an element was inserted, otherwise false
std::pair<iterator, bool> xenium::harris_michael_hash_map< Key, Value, Policies >::emplace_or_get | ( | Args &&... | args | ) |
Inserts a new element into the container if the container doesn't already contain an element with an equivalent key. The element is constructed in-place with the given args
.
The element is always constructed. If there already is an element with the key in the container, the newly constructed element will be destroyed immediately.
No iterators or references are invalidated.
Progress guarantees: lock-free
args | arguments to forward to the constructor of the element |
true
if an element was inserted, otherwise false
auto xenium::harris_michael_hash_map< Key, Value, Policies >::end |
Returns an iterator to the element following the last element of the container.
This element acts as a placeholder; attempting to access it results in undefined behavior.
bool xenium::harris_michael_hash_map< Key, Value, Policies >::erase | ( | const Key & | key | ) |
Removes the element with the key equivalent to key (if one exists).
No iterators or references are invalidated.
Progress guarantees: lock-free
key | key of the element to remove |
true
if an element was removed, otherwise false
auto xenium::harris_michael_hash_map< Key, Value, Policies >::erase | ( | iterator | pos | ) |
Removes the specified element from the container.
No iterators or references are invalidated.
Progress guarantees: lock-free
pos | the iterator identifying the element to remove |
auto xenium::harris_michael_hash_map< Key, Value, Policies >::find | ( | const Key & | key | ) |
Finds an element with key equivalent to key.
Progress guarantees: lock-free
key | key of the element to search for |
std::pair<iterator, bool> xenium::harris_michael_hash_map< Key, Value, Policies >::get_or_emplace | ( | Key | key, |
Args &&... | args | ||
) |
Inserts a new element into the container if the container doesn't already contain an element with an equivalent key. The element is constructed as value_type(std::piecewise_construct, std::forward_as_tuple(k), std::forward_as_tuple(std::forward<Args>(args)...))
.
The element may be constructed even if there already is an element with the key in the container, in which case the newly constructed element will be destroyed immediately.
No iterators or references are invalidated. Progress guarantees: lock-free
key | the key of element to be inserted. |
args | arguments to forward to the constructor of the element |
true
if an element was inserted, otherwise false
std::pair<iterator, bool> xenium::harris_michael_hash_map< Key, Value, Policies >::get_or_emplace_lazy | ( | Key | key, |
Factory | factory | ||
) |
Inserts a new element into the container if the container doesn't already contain an element with an equivalent key. The value for the newly constructed element is created by calling value_factory
.
The element may be constructed even if there already is an element with the key in the container, in which case the newly constructed element will be destroyed immediately.
No iterators or references are invalidated. Progress guarantees: lock-free
Func |
key | the key of element to be inserted. |
factory | a functor that is used to create the Value instance when constructing the new element to be inserted. |
true
if an element was inserted, otherwise false
auto xenium::harris_michael_hash_map< Key, Value, Policies >::operator[] | ( | const Key & | key | ) |
The accessor
key |