template<class K, class T>
class asl::HashMap< K, T >
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.
HashMap<String, float> constants;
constants["pi"] = 3.1415927;
float a = constants[
"pi"] *
sqr(radius);
{...}
bool has(const K &key) const
Checks if the given key exists in the map.
Definition HashMap.h:402
T sqr(T x)
Returns x squared.
Definition defs.h:194
The contents can be iterated with range-based for in C++11:
for(auto& e : constants)
{
cout << "Contstant " << *e.key << " has value: " << e.value << endl;
}
Or with the foreach2 macro loop in older compilers:
{
cout << "Contstant " << *name << " has value: " << value << endl;
}
String represents a character string that behaves similarly to JavaScript strings in that it can be c...
Definition String.h:126
#define foreach2(key, variable, set)
A for loop for associative containers resembling C++17 range-based for with structured binding.
Definition foreach1.h:72
|
|
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).
|