Template Class hash_t
Defined in File hash.hpp
Inheritance Relationships
Base Type
public std::unordered_map< key, value >
Class Documentation
-
template<typename key, typename value>
class hash_t : public std::unordered_map<key, value> Thread-safe hash table wrapper around
std::unordered_map.It supports concurrent reads and synchronized writes.
- Template Parameters:
key – Type of the hash-table key.
value – Type of the hash-table value.
Public Types
Shared pointer type.
Public Functions
-
inline hash_t()
Default constructor.
-
inline hash_t(const std::pair<const key, value> &data_)
Constructor from a single pair
- Parameters:
data_ – Initial key-value pair inserted at construction time.
-
inline hash_t(const hash_t<key, value> &other_)
Copy constructor
- Parameters:
other_ – Source hash table copied while holding a read lock.
-
inline size_t size_() const
Get the size of the hash table
- Returns:
Number of key-value entries currently stored.
-
inline bool contains_(const key &key_) const
Thread-safe check whether a key exists in the hash table.
- Parameters:
key_ – Key tested for existence in the hash table.
- Returns:
truewhenkey_exists,falseotherwise.
-
inline value at_(const key &key_) const
Thread-safe access to a value by key.
- Parameters:
key_ – Key whose associated value is retrieved.
- Returns:
Copy of the value stored for
key_.
-
inline void insert_(const std::pair<const key, value> &data_)
Thread-safe insertion of a key-value pair.
- Parameters:
data_ – Key-value pair inserted into the hash table.
-
inline void try_emplace_(const key &key_, const value &value_)
Thread-safe emplacement of a key-value pair.
- Parameters:
key_ – Key of the entry to insert or update in the hash table.
value_ – Value associated with
key_to insert or update.
-
inline void erase_(const key &key_)
Thread-safe erasure of a key-value pair by key.
- Parameters:
key_ – Key of the entry to erase from the hash table.
-
inline void conditional_erase_(const key &key_)
Thread-safe conditional erasure of a key-value pair by key.
- Parameters:
key_ – Key of the entry to conditionally erase from the hash table.
-
inline value *find_(const key &key_)
Find the value associated with a key in the hash table.
- Parameters:
key_ – Key whose associated value is searched for.
- Returns:
Pointer to the value if
key_exists,nullptrotherwise.
-
inline void lock_read() const
Lock the object for shared reading.
-
inline void unlock_read() const
Unlock the shared reading lock.
-
inline void lock() const
Lock the object for writing.
-
inline void unlock() const
Unlock the writing lock.
Public Static Functions
Make shared pointer function
- Returns:
Shared pointer owning a new empty thread-safe hash table.
Private Members
-
mutable std::shared_mutex _mutex
Mutex that is used to lock the dictionary for reading and writing.