|
RPNX::DataStructures
Header-only C++ data structures and supporting utilities.
|
#include <sharded_unordered_map.hpp>
Public Types | |
| using | iterator = basic_iterator< false > |
| using | const_iterator = basic_iterator< true > |
Public Member Functions | |
| range< iterator > | range_exclusive () |
| range< const_iterator > | range_exclusive () const |
| std::size_t | estimate_size () const |
| std::size_t | size_exclusive () const |
| conc_sharded_unordered_map (std::size_t shard_count=std::thread::hardware_concurrency() *2, Alloc const &alloc=Alloc()) | |
| conc_sharded_unordered_map (conc_sharded_unordered_map const &)=delete | |
| conc_sharded_unordered_map & | operator= (conc_sharded_unordered_map const &)=delete |
| conc_sharded_unordered_map (conc_sharded_unordered_map &&)=delete | |
| conc_sharded_unordered_map & | operator= (conc_sharded_unordered_map &&)=delete |
| ~conc_sharded_unordered_map ()=default | |
| void | put (Key const &key, Value value) |
| template<typename Func> | |
| void | put_exec (Key const &key, Func func) |
| template<typename Func> | |
| bool | try_put_exec (Key const &key, Func func) |
| template<typename Func> | |
| Value & | get_or_create (Key const &key, Func func) |
| template<typename Func> | |
| Value & | get_or_init (Key const &key, Func func) |
| template<typename Func> | |
| Value & | get_or_init_iter (Key const &key, Func func) |
| bool | try_put (Key const &key, Value value) |
| Value | get (Key const &key) |
| void | erase (Key const &key) |
A sharded unordered map that serializes operations per shard.
| Key | The key type used to index values. |
| Value | The mapped value type. |
| Hash | The hash functor used to choose shards and hash keys inside each shard. |
| KeyEqual | The key equality predicate used inside each shard. |
| Alloc | The allocator used by the shard maps and rebound for shard storage. |
Operations that access the container structure lock the affected shard. Methods that return a reference release that lock before returning; the caller is responsible for ensuring the referenced element is not erased, replaced, or otherwise concurrently modified while the reference is being used.
References to existing elements are not invalidated by inserting other elements into the map, including insertions that rehash the underlying std::unordered_map. They are invalidated by erasing the referenced element and by destroying the map.
| using rpnx::conc_sharded_unordered_map< Key, Value, Hash, KeyEqual, Alloc >::const_iterator = basic_iterator< true > |
Const forward iterator type for exclusive whole-map iteration.
| using rpnx::conc_sharded_unordered_map< Key, Value, Hash, KeyEqual, Alloc >::iterator = basic_iterator< false > |
Mutable forward iterator type for exclusive whole-map iteration.
|
inlineexplicit |
Constructs a sharded map.
| shard_count | Requested number of shards. If zero or not a power of two, it is rounded up to the next power of two so shard selection can use a mask. |
| alloc | Allocator used for the underlying unordered maps and rebound for shard storage. |
|
delete |
Copy construction is disabled because shards contain mutexes and define synchronization ownership.
|
delete |
Move construction is disabled so references and shard synchronization state cannot be relocated.
|
default |
Destroys the map and all stored elements.
|
inline |
Erases a key from the map.
| key | Key to erase if present. |
|
inlinenodiscard |
Estimates the number of elements in the map while locking each shard independently.
|
inline |
Returns a copy of the value for a key.
| key | Key to look up. |
| std::out_of_range | if the key is absent. |
|
inline |
Returns the value for a key, creating it if missing.
| Func | Nullary callable type used to create the value when the key is absent. |
| key | Key to look up or insert. |
| func | Callable invoked while the target shard is locked if the key is absent. |
|
inline |
Returns the value for a key, default-constructing and initializing it if missing.
| Func | Callable type invoked as func(Value&) when the key is absent. |
| key | Key to look up or insert. |
| func | Callable invoked while the target shard is locked to initialize a new value. |
|
inline |
Returns the value for a key, default-constructing and initializing it with key/value access if missing.
| Func | Callable type invoked as func(Key const&, Value&) when the key is absent. |
| key | Key to look up or insert. |
| func | Callable invoked while the target shard is locked to initialize a new value. |
|
delete |
Move assignment is disabled so references and shard synchronization state cannot be relocated.
|
delete |
Copy assignment is disabled because shards contain mutexes and define synchronization ownership.
|
inline |
Inserts or replaces the value for a key.
| key | Key to update. |
| value | Value to store. |
|
inline |
Computes and stores a value for a key, replacing any existing value.
| Func | Nullary callable type used to create the value. |
| key | Key to update. |
| func | Callable invoked while the target shard is locked. |
|
inlinenodiscard |
Returns a mutable range over all shards without locking.
|
inlinenodiscard |
Returns a const range over all shards without locking.
|
inlinenodiscard |
Returns the number of elements in the map without locking.
|
inline |
Inserts a value only if the key is absent.
| key | Key to insert. |
| value | Value to store if the key is absent. |
|
inline |
Computes and stores a value only if the key is absent.
| Func | Nullary callable type used to create the value. |
| key | Key to insert. |
| func | Callable invoked while the target shard is locked if the key is absent. |