CppCommon
1.0.4.1
C++ Common Library
|
Hash map container. More...
#include <hashmap.h>
Public Types | |
typedef TKey | key_type |
typedef TValue | mapped_type |
typedef std::pair< TKey, TValue > | value_type |
typedef value_type & | reference |
typedef const value_type & | const_reference |
typedef value_type * | pointer |
typedef const value_type * | const_pointer |
typedef ptrdiff_t | difference_type |
typedef size_t | size_type |
typedef HashMapIterator< HashMap< TKey, TValue, THash, TEqual, TAllocator >, TKey, TValue > | iterator |
typedef HashMapConstIterator< HashMap< TKey, TValue, THash, TEqual, TAllocator >, TKey, TValue > | const_iterator |
typedef HashMapReverseIterator< HashMap< TKey, TValue, THash, TEqual, TAllocator >, TKey, TValue > | reverse_iterator |
typedef HashMapConstReverseIterator< HashMap< TKey, TValue, THash, TEqual, TAllocator >, TKey, TValue > | const_reverse_iterator |
Public Member Functions | |
HashMap (size_t capacity=128, const TKey &blank=TKey(), const THash &hash=THash(), const TEqual &equal=TEqual(), const TAllocator &allocator=TAllocator()) | |
Initialize the hash map with a given capacity and blank key value. More... | |
template<class InputIterator > | |
HashMap (InputIterator first, InputIterator last, bool unused, size_t capacity=128, const TKey &blank=TKey(), const THash &hash=THash(), const TEqual &equal=TEqual(), const TAllocator &allocator=TAllocator()) | |
HashMap (const HashMap &hashmap) | |
HashMap (const HashMap &hashmap, size_t capacity) | |
HashMap (HashMap &&)=default | |
~HashMap ()=default | |
HashMap & | operator= (const HashMap &hashmap) |
HashMap & | operator= (HashMap &&)=default |
operator bool () const noexcept | |
Check if the hash map is not empty. More... | |
mapped_type & | operator[] (const TKey &key) |
Access to the item with the given key or insert a new one. More... | |
bool | empty () const noexcept |
Is the hash map empty? More... | |
size_t | size () const noexcept |
Get the hash map size. More... | |
size_t | max_size () const noexcept |
Get the hash map maximum size. More... | |
size_t | bucket_count () const noexcept |
Get the hash map bucket count. More... | |
size_t | max_bucket_count () const noexcept |
Get the hash map maximum bucket count. More... | |
size_t | key_hash (const TKey &key) const noexcept |
Calculate hash of the given key. More... | |
bool | key_equal (const TKey &key1, const TKey &key2) const noexcept |
Compare two keys: if the first key equals to the second one? More... | |
iterator | begin () noexcept |
Get the begin hash map iterator. More... | |
const_iterator | begin () const noexcept |
const_iterator | cbegin () const noexcept |
iterator | end () noexcept |
Get the end hash map iterator. More... | |
const_iterator | end () const noexcept |
const_iterator | cend () const noexcept |
reverse_iterator | rbegin () noexcept |
Get the reverse begin hash map iterator. More... | |
const_reverse_iterator | rbegin () const noexcept |
const_reverse_iterator | crbegin () const noexcept |
reverse_iterator | rend () noexcept |
Get the reverse end hash map iterator. More... | |
const_reverse_iterator | rend () const noexcept |
const_reverse_iterator | crend () const noexcept |
iterator | find (const TKey &key) noexcept |
Find the iterator which points to the first item with the given key in the hash map or return end iterator. More... | |
const_iterator | find (const TKey &key) const noexcept |
std::pair< iterator, iterator > | equal_range (const TKey &key) noexcept |
Find the bounds of a range that includes all the elements in the hash map with the given key. More... | |
std::pair< const_iterator, const_iterator > | equal_range (const TKey &key) const noexcept |
size_t | count (const TKey &key) const noexcept |
Find the count of items with the given key. More... | |
mapped_type & | at (const TKey &key) noexcept |
Access to the item with the given key or throw std::out_of_range exception. More... | |
const mapped_type & | at (const TKey &key) const noexcept |
Access to the constant item with the given key or throw std::out_of_range exception. More... | |
std::pair< iterator, bool > | insert (const value_type &item) |
Insert a new item into the hash map. More... | |
std::pair< iterator, bool > | insert (value_type &&item) |
Insert a new item into the hash map. More... | |
template<typename... Args> | |
std::pair< iterator, bool > | emplace (Args &&... args) |
Emplace a new item into the hash map. More... | |
size_t | erase (const TKey &key) |
Erase the item with the given key from the hash map. More... | |
void | erase (const const_iterator &position) |
Erase the item by its iterator from the hash map. More... | |
void | rehash (size_t capacity) |
Rehash the hash map to the given capacity or more. More... | |
void | reserve (size_t count) |
Reserve the hash map capacity to fit the given count of items. More... | |
void | clear () noexcept |
Clear the hash map. More... | |
void | swap (HashMap &hashmap) noexcept |
Swap two instances. More... | |
template<typename... Args> | |
std::pair< typename HashMap< TKey, TValue, THash, TEqual, TAllocator >::iterator, bool > | emplace (Args &&... args) |
template<typename... Args> | |
std::pair< typename HashMap< TKey, TValue, THash, TEqual, TAllocator >::iterator, bool > | emplace_internal (const TKey &key, Args &&... args) |
Friends | |
class | HashMapIterator< HashMap< TKey, TValue, THash, TEqual, TAllocator >, TKey, TValue > |
class | HashMapConstIterator< HashMap< TKey, TValue, THash, TEqual, TAllocator >, TKey, TValue > |
class | HashMapReverseIterator< HashMap< TKey, TValue, THash, TEqual, TAllocator >, TKey, TValue > |
class | HashMapConstReverseIterator< HashMap< TKey, TValue, THash, TEqual, TAllocator >, TKey, TValue > |
template<typename UKey , typename UValue , typename UHash , typename UEqual , typename UAllocator > | |
void | swap (HashMap< UKey, UValue, UHash, UEqual, UAllocator > &hashmap1, HashMap< UKey, UValue, UHash, UEqual, UAllocator > &hashmap2) noexcept |
Hash map container.
Hash map is an efficient structure for associative keys/value storing and accessing without keeping order. It uses hash function to convert string key into the integer and use the index to quick access value data.
Open address hash map resolves collisions of the same hash values by inserting new item into the next free place (probing with step 1).
Not thread-safe.
typedef HashMapConstIterator<HashMap<TKey, TValue, THash, TEqual, TAllocator>, TKey, TValue> CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::const_iterator |
typedef const value_type* CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::const_pointer |
typedef const value_type& CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::const_reference |
typedef HashMapConstReverseIterator<HashMap<TKey, TValue, THash, TEqual, TAllocator>, TKey, TValue> CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::const_reverse_iterator |
typedef ptrdiff_t CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::difference_type |
typedef HashMapIterator<HashMap<TKey, TValue, THash, TEqual, TAllocator>, TKey, TValue> CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::iterator |
typedef TKey CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::key_type |
typedef TValue CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::mapped_type |
typedef value_type* CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::pointer |
typedef value_type& CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::reference |
typedef HashMapReverseIterator<HashMap<TKey, TValue, THash, TEqual, TAllocator>, TKey, TValue> CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::reverse_iterator |
typedef size_t CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::size_type |
typedef std::pair<TKey, TValue> CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::value_type |
|
inlineexplicit |
Initialize the hash map with a given capacity and blank key value.
capacity | - Hash map capacity (default is 128) |
blank | - Blank key value (default is TKey()) |
hash | - Key hasher (default is THash()) |
equal | - Key comparator (default is THash()) |
allocator | - Allocator (default is TAllocator()) |
Definition at line 12 of file hashmap.inl.
|
inline |
Definition at line 23 of file hashmap.inl.
|
inline |
Definition at line 31 of file hashmap.inl.
|
inline |
Definition at line 39 of file hashmap.inl.
|
default |
|
default |
|
inlinenoexcept |
Access to the constant item with the given key or throw std::out_of_range exception.
key | - Key of the item |
Definition at line 179 of file hashmap.inl.
|
inlinenoexcept |
Access to the item with the given key or throw std::out_of_range exception.
key | - Key of the item |
Definition at line 169 of file hashmap.inl.
|
inlinenoexcept |
Definition at line 63 of file hashmap.inl.
|
inlinenoexcept |
Get the begin hash map iterator.
Definition at line 57 of file hashmap.inl.
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 69 of file hashmap.inl.
|
inlinenoexcept |
Definition at line 87 of file hashmap.inl.
|
inlinenoexcept |
Clear the hash map.
Definition at line 306 of file hashmap.inl.
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 105 of file hashmap.inl.
|
inlinenoexcept |
Definition at line 123 of file hashmap.inl.
std::pair<iterator, bool> CppCommon::HashMap< TKey, TValue, THash, TEqual, TAllocator >::emplace | ( | Args &&... | args | ) |
Emplace a new item into the hash map.
args | - Arguments to emplace |
|
inline |
Definition at line 202 of file hashmap.inl.
|
inline |
Definition at line 226 of file hashmap.inl.
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 81 of file hashmap.inl.
|
inlinenoexcept |
Get the end hash map iterator.
Definition at line 75 of file hashmap.inl.
|
inlinenoexcept |
Definition at line 163 of file hashmap.inl.
|
inlinenoexcept |
Find the bounds of a range that includes all the elements in the hash map with the given key.
Definition at line 157 of file hashmap.inl.
|
inline |
Erase the item by its iterator from the hash map.
position | - Iterator position to the erased item |
Definition at line 219 of file hashmap.inl.
|
inline |
Erase the item with the given key from the hash map.
key | - Key of the item to erase |
Definition at line 208 of file hashmap.inl.
|
inlinenoexcept |
Definition at line 143 of file hashmap.inl.
|
inlinenoexcept |
Find the iterator which points to the first item with the given key in the hash map or return end iterator.
Definition at line 129 of file hashmap.inl.
|
inline |
Insert a new item into the hash map.
item | - Item to insert as a key/value pair |
Definition at line 189 of file hashmap.inl.
|
inline |
Insert a new item into the hash map.
item | - Item to insert as a key/value pair |
Definition at line 195 of file hashmap.inl.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlineexplicitnoexcept |
|
inline |
Definition at line 47 of file hashmap.inl.
|
default |
|
inline |
|
inlinenoexcept |
Definition at line 99 of file hashmap.inl.
|
inlinenoexcept |
Get the reverse begin hash map iterator.
Definition at line 93 of file hashmap.inl.
|
inline |
Rehash the hash map to the given capacity or more.
capacity | - Hash map capacity |
Definition at line 291 of file hashmap.inl.
|
inlinenoexcept |
Definition at line 117 of file hashmap.inl.
|
inlinenoexcept |
Get the reverse end hash map iterator.
Definition at line 111 of file hashmap.inl.
|
inline |
Reserve the hash map capacity to fit the given count of items.
count | - Count of items to fit |
Definition at line 299 of file hashmap.inl.
|
inlinenoexcept |
|
inlinenoexcept |
Swap two instances.
Definition at line 314 of file hashmap.inl.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |