Luna::HashMap

An container that contains key-value pairs with unique keys using open-addressing hashing algorithm.

template <typename _Kty, typename _Ty, typename _Hash, typename _KeyEqual, typename _Alloc>
class Luna::HashMap

Remark

LunaSDK provides two kinds of hashing-based containers: open-addressing containers and closed-addressing containers. The following containers are open-addressing containers, implemented using Robinhood hashing:

  1. HashMap

  2. HashSet

  3. SelfIndexedHashmap The following containers are closed-addressing containers, implemented using buckets and per-bucket linked-lists:

  4. UnorderedMap

  5. UnorderedSet

  6. UnorderedMultiMap

  7. UnorderedMultiSet

  8. SelfIndexedUnorderedMap

  9. SelfIndexedUnorderedMultiMap

Open addressing (also known as closed hashing) algorithms store elements directly in hash table arrays, while closed addressing (also known as open hashing) algorithms allocate dedicated memory for every element, and stores pointers to such elements in hash table arrays. In open-addressing containers, one hash table slot can only store on element, the second element with the same hash value must be relocated to another empty slot; in closed-addressing containers, all elements with the same hash value can be stored in the same hash table slot, usually stored as linked lists. See Open vs Closed Addressing for a detailed comparison of open addressing and closed addressing.

Prefer HashMap and HashSet instead of UnorderedMap and UnorderedSet, since it performs better in memory fragmentation, memory locality and cache performance. Use UnorderedMap and UnorderedSet if you have the following requirements:

  1. You want to insert multiple elements with the same key to the map, which is only supported by closed-addressing maps. Use UnorderedMultiMap, SelfIndexedUnorderedMultiMap and UnorderedMultiSet in such case.

  2. You element type has very big size, usually larger than 256, causing allocating element memory in data table become unacceptable because it will waste a lot of memory when the load factor is low. Closed-addressing maps only allocate memory for alive elements, making it consuming much less memory than open-addressing maps when the element size is big. Closed-addressing maps also support extracting element nodes from one map and insert them to another maps without the need of allocating memory for elements, making it efficient to transfer elements between maps.

Member functions