#include <wx/hashmap.h>
This is a simple, type-safe, and reasonably efficient hash map class, whose interface is a subset of the interface of STL containers.
In particular, the interface is modelled after std::map, and the various, non-standard, std::hash_map (http://www.cppreference.com/wiki/stl/map/start).
Example:
Declares a hash map class named CLASSNAME, with wxString keys and VALUE_T values.
Declares a hash map class named CLASSNAME, with void* keys and VALUE_T values.
The HASH_T and KEY_EQ_T are the types used for the hashing function and key comparison. wxWidgets provides three predefined hashing functions: wxIntegerHash
for integer types ( int, long, short, and their unsigned counterparts ), wxStringHash
for strings ( wxString, wxChar*, char* ), and wxPointerHash
for any kind of pointer. Similarly three equality predicates: wxIntegerEqual
, wxStringEqual
, wxPointerEqual
are provided. Using this you could declare a hash map mapping int values to wxString like this:
In the documentation below you should replace wxHashMap with the name you used in the class declaration.
An iterator is similar to a pointer, and so you can use the usual pointer operations: ++it ( and it++ ) to move to the next element, *it to access the element pointed to, it->first ( it->second ) to access the key ( value ) of the element pointed to.
Hash maps provide forward only iterators, this means that you can't use –it, it + 3, it1 - it2.
wxWidgets defines the following hashmap types:
<>< =''>:</>&;&;< =''>\ </></>
Public Member Functions | |
wxHashMap (size_type size=10) | |
The size parameter is just a hint, the table will resize automatically to preserve performance. | |
wxHashMap (const wxHashMap &map) | |
Copy constructor. | |
const_iterator | begin () const |
Returns an iterator pointing at the first element of the hash map. | |
iterator | begin () |
void | clear () |
Removes all elements from the hash map. | |
size_type | count (const key_type &key) const |
Counts the number of elements with the given key present in the map. | |
bool | empty () const |
Returns true if the hash map does not contain any elements, false otherwise. | |
const_iterator | end () const |
Returns an iterator pointing at the one-after-the-last element of the hash map. | |
iterator | end () |
size_type | erase (const key_type &key) |
Erases the element with the given key, and returns the number of elements erased (either 0 or 1). | |
void | erase (iterator it) |
Erases the element pointed to by the iterator. | |
void | erase (const_iterator it) |
iterator | find (const key_type &key) const |
If an element with the given key is present, the functions returns an iterator pointing at that element, otherwise an invalid iterator is returned. | |
const_iterator | find (const key_type &key) const |
Insert_Result | insert (const value_type &v) |
Inserts the given value in the hash map. | |
mapped_type | operator[] (const key_type &key) |
Use the key as an array subscript. | |
size_type | size () const |
Returns the number of elements in the map. | |
wxHashMap::wxHashMap | ( | size_type | size = 10 | ) |
The size parameter is just a hint, the table will resize automatically to preserve performance.
iterator wxHashMap::begin | ( | ) |
const_iterator wxHashMap::begin | ( | ) | const |
Returns an iterator pointing at the first element of the hash map.
Please remember that hash maps do not guarantee ordering.
void wxHashMap::clear | ( | ) |
Removes all elements from the hash map.
Counts the number of elements with the given key present in the map.
This function returns only 0 or 1.
bool wxHashMap::empty | ( | ) | const |
Returns true if the hash map does not contain any elements, false otherwise.
iterator wxHashMap::end | ( | ) |
const_iterator wxHashMap::end | ( | ) | const |
Returns an iterator pointing at the one-after-the-last element of the hash map.
Please remember that hash maps do not guarantee ordering.
Erases the element with the given key, and returns the number of elements erased (either 0 or 1).
void wxHashMap::erase | ( | const_iterator | it | ) |
void wxHashMap::erase | ( | iterator | it | ) |
Erases the element pointed to by the iterator.
After the deletion the iterator is no longer valid and must not be used.
If an element with the given key is present, the functions returns an iterator pointing at that element, otherwise an invalid iterator is returned.
Insert_Result wxHashMap::insert | ( | const value_type & | v | ) |
Inserts the given value in the hash map.
The return value is equivalent to a
The iterator points to the inserted element, the boolean value is true if v was actually inserted.
mapped_type wxHashMap::operator[] | ( | const key_type & | key | ) |
Use the key as an array subscript.
The only difference is that if the given key is not present in the hash map, an element with the default value_type()
is inserted in the table.
size_type wxHashMap::size | ( | ) | const |
Returns the number of elements in the map.