ASL
|
This class implements a hash map, an unordered map of keys to values.
It is similar to class Map but elements will not keep a defined order. There must be a global function hash(const K&)
for the key type K
(there is a default hash function that may fit). Inserting and finding elements is usually faster than in a Map. The class has reference counting as all containers.
The contents can be iterated with range-based for in C++11:
Or with the foreach2
macro loop in older compilers:
#include <HashMap.h>
Public Member Functions | |
HashMap | clone () const |
Returns an independent copy of this map. | |
void | clear () |
Clears the map removing all elements. | |
const T & | operator[] (const K &key) const |
Returns a reference to the value associated to the given key, the key has to exist. | |
T & | operator[] (const K &key) |
Returns a reference to the value associated to the given key, creating one if the key does not exist. | |
T * | find (const K &key) |
Returns a pointer to the element with key key or a null pointer if it is not found. | |
const T & | get (const K &key, const T &def) const |
Returns the value for the given key or the value def if it is not found. | |
void | remove (const K &key) |
Removes the given key. | |
bool | has (const K &key) const |
Checks if the given key exists in the map. | |
int | length () const |
Returns the number of elements in the map. | |
bool | operator== (const HashMap &b) const |
Returns true if both maps are equal (equal keys and values) | |