HashMap Traits

Creating a HashMap requires you to define your own Traits class. Derive your Traits class from BaseHashMapTraits to reduce the amount of boilerplate code. Your Traits class must define the following members:

typename Key

(Required) The type used to locate existing items in the hash map.

typename Item

(Required) The type that gets stored in the hash map itself.

static u32 hash(const Key&)

(Optional) Compute a 32-bit hash value for the key. If you don't define a custom hash function here, the default implementation calls the key's appendTo member function with a Hasher object (an object that helps implement MurmurHash3).

static void construct(Item*, const Key&)

(Optional) Constructs an Item in-place. If you don't define construct, the default implementation tries to pass Key to Item's constructor (using SFINAE); if no such constructor exists, it calls Item's default constructor. In all cases, if Key is ignored when constructing the Item, it's the caller's responsibility to ensure that the hash table is left in a consistent state after inserting a new item.

static ComparandType comparand(const Item&)

(Optional) Converts an Item to another type, of your choosing, that will be passed as the first argument to equal. If you don't define comparand in your traits class, it will inherit a default implementation from BaseHashMapTraits that returns a const reference to the Item itself.

typename Context
static ComparandType comparand(const Item&, const Context&)

(Optional) A type to help implement comparand. If you don't define this type in your traits class, it will inherit an empty struct from BaseHashMapTraits.

static bool equal(const ComparandType&, const Key&)

(Optional) Returns true if the comparand type matches key. ComparandType can be any type of your choosing. By default, it's Item, but if you want to make it a different type, implement the comparand function in your Traits class.