Unordered associative container wrapping std::unordered_map. More...
#include <hashmap.h>
Public Types | |
| using | Ptr = SharedPtr< HashMap > |
| Shared pointer type for HashMap. | |
| using | Data = std::unordered_map< K, V > |
| Underlying std::unordered_map storage type. | |
| using | Key = K |
| Key type. | |
| using | Value = V |
| Value type. | |
| using | Iterator = typename Data::iterator |
| Mutable forward iterator. | |
| using | ConstIterator = typename Data::const_iterator |
| Const forward iterator. | |
Public Member Functions | |
| HashMap ()=default | |
| Default constructor. Creates an empty hash map. | |
| HashMap (const HashMap &other) | |
| Copy constructor. | |
| HashMap (HashMap &&other) noexcept | |
| Move constructor. | |
| HashMap (std::initializer_list< std::pair< const K, V > > initList) | |
| Constructs a hash map from an initializer list of key-value pairs. | |
| ~HashMap ()=default | |
| Destructor. | |
| HashMap & | operator= (const HashMap &other) |
| Copy assignment operator. | |
| HashMap & | operator= (HashMap &&other) noexcept |
| Move assignment operator. | |
| Iterator | begin () noexcept |
| Returns a mutable iterator to the first entry. | |
| ConstIterator | begin () const noexcept |
| Returns a const iterator to the first entry. | |
| ConstIterator | cbegin () const noexcept |
| Returns a const iterator to the first entry. | |
| ConstIterator | constBegin () const noexcept |
| Returns a const iterator to the first entry. | |
| Iterator | end () noexcept |
| Returns a mutable iterator to one past the last entry. | |
| ConstIterator | end () const noexcept |
| Returns a const iterator to one past the last entry. | |
| ConstIterator | cend () const noexcept |
| Returns a const iterator to one past the last entry. | |
| ConstIterator | constEnd () const noexcept |
| Returns a const iterator to one past the last entry. | |
| bool | isEmpty () const noexcept |
| Returns true if the hash map has no entries. | |
| size_t | size () const noexcept |
| Returns the number of key-value pairs. | |
| V & | operator[] (const K &key) |
Returns a reference to the value for key, inserting a default-constructed value if it does not exist. | |
| const V & | operator[] (const K &key) const |
Returns a const reference to the value for key. | |
| V | value (const K &key, const V &defaultValue=V{}) const |
Returns the value for key, or defaultValue if the key is not present. | |
| bool | contains (const K &key) const |
Returns true if key exists in the hash map. | |
| Iterator | find (const K &key) |
Finds the entry for key. | |
| ConstIterator | find (const K &key) const |
| Const overload of find(). | |
| void | insert (const K &key, const V &val) |
| Inserts or assigns a key-value pair. | |
| void | insert (const K &key, V &&val) |
| Inserts or assigns a key-value pair (move overload). | |
| bool | remove (const K &key) |
Removes the entry for key. | |
| Iterator | remove (Iterator pos) |
Removes the entry at pos. | |
| void | clear () noexcept |
| Removes all entries. | |
| void | swap (HashMap &other) noexcept |
| Swaps contents with another hash map. | |
| List< K > | keys () const |
| Returns a list of all keys. | |
| List< V > | values () const |
| Returns a list of all values. | |
| template<typename Func > | |
| void | forEach (Func &&func) const |
Calls func for every key-value pair. | |
Friends | |
| bool | operator== (const HashMap &lhs, const HashMap &rhs) |
| Returns true if both hash maps have identical contents. | |
| bool | operator!= (const HashMap &lhs, const HashMap &rhs) |
| Returns true if the hash maps differ. | |
Unordered associative container wrapping std::unordered_map.
Provides a Qt-inspired API over std::unordered_map with consistent naming
| K | Key type (must be hashable). |
| V | Value type. |
Constructs a hash map from an initializer list of key-value pairs.
| initList | Brace-enclosed list of {key, value} pairs. |
|
inlinenoexcept |
Returns a const iterator to the first entry.
Returns a const iterator to one past the last entry.
Finds the entry for key.
| key | The key to search for. |
Calls func for every key-value pair.
| Func | Callable with signature void(const K &, const V &). |
| func | The function to invoke. |
Inserts or assigns a key-value pair.
| key | The key. |
| val | The value. |
Inserts or assigns a key-value pair (move overload).
| key | The key. |
| val | The value (moved). |
Returns a reference to the value for key, inserting a default-constructed value if it does not exist.
| key | The key to look up. |
Removes the entry for key.
| key | The key to remove. |
Removes the entry at pos.
| pos | Iterator to the entry to remove. |
Swaps contents with another hash map.
| other | The hash map to swap with. |
Returns the value for key, or defaultValue if the key is not present.
| key | The key to look up. |
| defaultValue | Fallback value. |