HashMap

A template class suitable for creating hash maps and hash sets. Internally, the hash map/set uses leapfrog probing. A hash map/set created using HashMap is not thread-safe, so if you manipulate it from multiple threads, you must enforce mutual exclusion yourself.

See HashMap Traits.

Member Functions

HashMap(u32 initialSize = 8) [code]

Constructs an empty HashMap.

HashMap(HashMap&& other) [code]

Move constructor. other is set to an invalid state. After this call, it's not legal to insert or find items in other unless it is set back to a valid state using move assignment.

void operator=(HashMap&& other) [code]

Move assignment operator. other is set to an invalid state. After this call, it's not legal to insert or find items in other unless it is set back to a valid state using move assignment.

void clear() [code]

Destructs all Items in the HashMap and sets it to an invalid state. After this call, it's not legal to insert or find items in the hash map unless it is set back to a valid state using move assignment.

bool isEmpty() const [code]

Returns true if the hash map is empty.

u32 numItems() const [code]

Returns the number of items in the hash map.

Cursor insertOrFind(const Key& key, const Context* context = nullptr) [code]

Find Key in the hash map. If no matching Item exists, a new item is inserted. Call Cursor::wasFound() on the return value to determine whether the item was found or inserted. Note that when a new item is inserted, it might be the caller's responsibility to ensure the hash table is left in a consistent state, depending on the behavior of the Traits class's construct function.

Cursor find(const Key& key, const Context* context = nullptr) [code]
ConstCursor find(const Key& key, const Context* context = nullptr) const [code]

Attempts to find Key in the hash map. Call Cursor::wasFound() on the return value to determine whether a matching Item was found. If the hash map is const, a ConstCursor is returned instead of a Cursor. The difference between Cursor and ConstCursor is that a non-const Cursor can be used to erase existing items from the map.

Iterator begin() [code]
ConstIterator begin() const [code]
Iterator end() [code]
ConstIterator end() const [code]

Required functions to support range-for syntax.