#include <userver/rcu/rcu_map.hpp>
Map-like structure allowing RCU keyset updates.
Only keyset changes are thread-safe in scope of this class. Values are stored in shared_ptrs and are not copied during keyset change. The map itself is implemented as rcu::Variable, so every keyset change (e.g. insert or erase) triggers the whole map copying. 
Definition at line 107 of file rcu_map.hpp.
Classes | |
| struct | InsertReturnTypeImpl | 
Public Types | |
| using | Hash = typename RcuMapTraits::Hash | 
| using | KeyEqual = typename RcuMapTraits::KeyEqual | 
| using | MutexType = typename RcuMapTraits::MutexType | 
| using | ValuePtr = std::shared_ptr<Value> | 
| using | Iterator = RcuMapIterator<Key, Value, Value, RcuMapTraits> | 
| using | ConstValuePtr = std::shared_ptr<const Value> | 
| using | ConstIterator = RcuMapIterator<Key, Value, const Value, RcuMapTraits> | 
| using | RawMap = std::unordered_map<Key, ValuePtr, Hash, KeyEqual> | 
| using | Snapshot = std::unordered_map<Key, ConstValuePtr, Hash, KeyEqual> | 
| using | InsertReturnType = InsertReturnTypeImpl<ValuePtr> | 
Public Member Functions | |
| RcuMap (const RcuMap &)=delete | |
| RcuMap (RcuMap &&)=delete | |
| RcuMap & | operator= (const RcuMap &)=delete | 
| RcuMap & | operator= (RcuMap &&)=delete | 
| size_t | SizeApprox () const | 
| Returns an estimated size of the map at some point in time.   | |
| const ConstValuePtr | operator[] (const Key &) const | 
| Returns a readonly value pointer by its key if exists.   | |
| const ValuePtr | operator[] (const Key &) | 
| Returns a modifiable value pointer by key if exists or default-creates one.   | |
| InsertReturnType | Insert (const Key &key, ValuePtr value) | 
| Inserts a new element into the container if there is no element with the key in the container. Returns a pair consisting of a pointer to the inserted element, or the already-existing element if no insertion happened, and a bool denoting whether the insertion took place.   | |
| template<typename... Args> | |
| InsertReturnType | Emplace (const Key &key, Args &&... args) | 
| Inserts a new element into the container constructed in-place with the given args if there is no element with the key in the container. Returns a pair consisting of a pointer to the inserted element, or the already-existing element if no insertion happened, and a bool denoting whether the insertion took place.   | |
| template<typename... Args> | |
| InsertReturnType | TryEmplace (const Key &key, Args &&... args) | 
If a key equivalent to key already exists in the container, does nothing. Otherwise, behaves like Emplace except that the element is constructed as std::make_shared<Value>(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(std::forward<Args>(args)...)). Returns a pair consisting of a pointer to the inserted element, or the already-existing element if no insertion happened, and a bool denoting whether the insertion took place.  | |
| template<typename RawKey > | |
| void | InsertOrAssign (RawKey &&key, ValuePtr value) | 
If a key equivalent to key already exists in the container, replaces the associated value. Otherwise, inserts a new pair into the map.   | |
| const ConstValuePtr | Get (const Key &) const | 
| Returns a readonly value pointer by its key or an empty pointer.  | |
| const ValuePtr | Get (const Key &) | 
| Returns a modifiable value pointer by key or an empty pointer.  | |
| bool | Erase (const Key &) | 
| Removes a key from the map.   | |
| ValuePtr | Pop (const Key &) | 
| Removes a key from the map returning its value.   | |
| void | Clear () | 
| Resets the map to an empty state.   | |
| void | Assign (RawMap new_map) | 
Replace current data by data from new_map.   | |
| rcu::WritablePtr< RawMap, RcuTraits > | StartWrite () | 
| Starts a transaction, used to perform a series of arbitrary changes to the map.   | |
| Snapshot | GetSnapshot () const | 
| Returns a readonly copy of the map.   | |
| template<typename... Args> | |
| RcuMap< K, V, RcuMapTraits >::InsertReturnType | Emplace (const K &key, Args &&... args) | 
| template<typename... Args> | |
| RcuMap< K, V, RcuMapTraits >::InsertReturnType | TryEmplace (const K &key, Args &&... args) | 
Iteration support  | |
Keyset is fixed at the start of the iteration and is not affected by concurrent changes.  | |
| ConstIterator | begin () const | 
| ConstIterator | end () const | 
| Iterator | begin () | 
| Iterator | end () | 
| using rcu::RcuMap< Key, Value, RcuMapTraits >::ConstIterator = RcuMapIterator<Key, Value, const Value, RcuMapTraits> | 
Definition at line 124 of file rcu_map.hpp.
| using rcu::RcuMap< Key, Value, RcuMapTraits >::ConstValuePtr = std::shared_ptr<const Value> | 
Definition at line 123 of file rcu_map.hpp.
| using rcu::RcuMap< Key, Value, RcuMapTraits >::Hash = typename RcuMapTraits::Hash | 
Definition at line 118 of file rcu_map.hpp.
| using rcu::RcuMap< Key, Value, RcuMapTraits >::InsertReturnType = InsertReturnTypeImpl<ValuePtr> | 
Definition at line 127 of file rcu_map.hpp.
| using rcu::RcuMap< Key, Value, RcuMapTraits >::Iterator = RcuMapIterator<Key, Value, Value, RcuMapTraits> | 
Definition at line 122 of file rcu_map.hpp.
| using rcu::RcuMap< Key, Value, RcuMapTraits >::KeyEqual = typename RcuMapTraits::KeyEqual | 
Definition at line 119 of file rcu_map.hpp.
| using rcu::RcuMap< Key, Value, RcuMapTraits >::MutexType = typename RcuMapTraits::MutexType | 
Definition at line 120 of file rcu_map.hpp.
| using rcu::RcuMap< Key, Value, RcuMapTraits >::RawMap = std::unordered_map<Key, ValuePtr, Hash, KeyEqual> | 
Definition at line 125 of file rcu_map.hpp.
| using rcu::RcuMap< Key, Value, RcuMapTraits >::Snapshot = std::unordered_map<Key, ConstValuePtr, Hash, KeyEqual> | 
Definition at line 126 of file rcu_map.hpp.
| using rcu::RcuMap< Key, Value, RcuMapTraits >::ValuePtr = std::shared_ptr<Value> | 
Definition at line 121 of file rcu_map.hpp.
| void rcu::RcuMap< K, V, RcuMapTraits >::Assign | ( | RawMap | new_map | ) | 
Replace current data by data from new_map. 
Definition at line 412 of file rcu_map.hpp.
| RcuMap< K, V, RcuMapTraits >::Iterator rcu::RcuMap< K, V, RcuMapTraits >::begin | ( | ) | 
Definition at line 256 of file rcu_map.hpp.
| RcuMap< K, V, RcuMapTraits >::ConstIterator rcu::RcuMap< K, V, RcuMapTraits >::begin | ( | ) | const | 
Definition at line 239 of file rcu_map.hpp.
| void rcu::RcuMap< K, V, RcuMapTraits >::Clear | ( | ) | 
Resets the map to an empty state.
Definition at line 407 of file rcu_map.hpp.
| RcuMap< K, V, RcuMapTraits >::InsertReturnType rcu::RcuMap< Key, Value, RcuMapTraits >::Emplace | ( | const K & | key, | 
| Args &&... | args ) | 
Definition at line 324 of file rcu_map.hpp.
| InsertReturnType rcu::RcuMap< Key, Value, RcuMapTraits >::Emplace | ( | const Key & | key, | 
| Args &&... | args ) | 
Inserts a new element into the container constructed in-place with the given args if there is no element with the key in the container. Returns a pair consisting of a pointer to the inserted element, or the already-existing element if no insertion happened, and a bool denoting whether the insertion took place.
| RcuMap< K, V, RcuMapTraits >::Iterator rcu::RcuMap< K, V, RcuMapTraits >::end | ( | ) | 
Definition at line 264 of file rcu_map.hpp.
| RcuMap< K, V, RcuMapTraits >::ConstIterator rcu::RcuMap< K, V, RcuMapTraits >::end | ( | ) | const | 
Definition at line 248 of file rcu_map.hpp.
| bool rcu::RcuMap< K, V, RcuMapTraits >::Erase | ( | const Key & | ) | 
Removes a key from the map.
Definition at line 384 of file rcu_map.hpp.
| RcuMap< K, V, RcuMapTraits >::Snapshot rcu::RcuMap< K, V, RcuMapTraits >::GetSnapshot | ( | ) | const | 
Returns a readonly copy of the map.
{begin(), end()} construct, preferable for long-running operations. Definition at line 424 of file rcu_map.hpp.
| RcuMap< K, V, RcuMapTraits >::InsertReturnType rcu::RcuMap< K, V, RcuMapTraits >::Insert | ( | const Key & | key, | 
| ValuePtr | value ) | 
Inserts a new element into the container if there is no element with the key in the container. Returns a pair consisting of a pointer to the inserted element, or the already-existing element if no insertion happened, and a bool denoting whether the insertion took place.
Definition at line 313 of file rcu_map.hpp.
| void rcu::RcuMap< Key, Value, RcuMapTraits >::InsertOrAssign | ( | RawKey && | key, | 
| RcuMap< Key, Value, RcuMapTraits >::ValuePtr | value ) | 
If a key equivalent to key already exists in the container, replaces the associated value. Otherwise, inserts a new pair into the map. 
Definition at line 365 of file rcu_map.hpp.
| const ValuePtr rcu::RcuMap< Key, Value, RcuMapTraits >::operator[] | ( | const Key & | ) | 
Returns a modifiable value pointer by key if exists or default-creates one.
| const ConstValuePtr rcu::RcuMap< Key, Value, RcuMapTraits >::operator[] | ( | const Key & | ) | const | 
Returns a readonly value pointer by its key if exists.
| MissingKeyException | if the key is not present | 
| RcuMap< K, V, RcuMapTraits >::ValuePtr rcu::RcuMap< K, V, RcuMapTraits >::Pop | ( | const Key & | ) | 
Removes a key from the map returning its value.
Definition at line 396 of file rcu_map.hpp.
| size_t rcu::RcuMap< K, V, RcuMapTraits >::SizeApprox | ( | ) | const | 
Returns an estimated size of the map at some point in time.
Definition at line 271 of file rcu_map.hpp.
| auto rcu::RcuMap< K, V, RcuMapTraits >::StartWrite | ( | ) | 
Starts a transaction, used to perform a series of arbitrary changes to the map.
The map is copied. Don't forget to Commit to apply the changes. 
Definition at line 417 of file rcu_map.hpp.
| RcuMap< K, V, RcuMapTraits >::InsertReturnType rcu::RcuMap< Key, Value, RcuMapTraits >::TryEmplace | ( | const K & | key, | 
| Args &&... | args ) | 
Definition at line 346 of file rcu_map.hpp.