Get Involved

HashMap

A class template for hash maps and hash sets. Allows you to create various kinds of associative maps using hashed key lookups.

HashMap is a versatile class template. It provides the functionality of both std::unordered_map and std::unordered_set while supporting use cases that aren't possible with either of those class templates:

The find() and insertOrFind() functions return Cursor (or ConstCursor) objects. With a Cursor object, you can determine whether the given key was found, retrieve the item associated with that key, or erase the item from the map.

Internally, HashMap uses leapfrog probing.

HashMap is not thread-safe. If you manipulate a map object from multiple threads, you must enforce mutual exclusion yourself.

See HashMap Traits.

Header File

#include <ply-runtime/container/HashMap.h>

Also included from <ply-runtime/Base.h>.

Member Functions

  HashMap::HashMap(u32 initialSize = 8) [code]

Constructs an empty HashMap.

  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 HashMap::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 HashMap::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 HashMap::isEmpty() const [code]

Returns true if the hash map is empty.

 u32 HashMap::numItems() const [code]

Returns the number of items in the hash map.

 Cursor HashMap::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 HashMap::find(const Key& key, const Context* context = nullptr) [code]
 ConstCursor HashMap::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 HashMap::begin() [code]
 ConstIterator HashMap::begin() const [code]
 Iterator HashMap::end() [code]
 ConstIterator HashMap::end() const [code]

Required functions to support range-for syntax.