template<class K, class T, std::uint32_t Capacity, class HashFunc = xxHash32Func<K>>
nCine::StaticHashMap class

Statically allocated hashmap with open addressing and leapfrog probing.

Stores up to Capacity key/value pairs in fixed-size buffers embedded in the object, so no heap allocation occurs. Collisions are resolved with open addressing using a leapfrog probing scheme based on per-bucket delta offsets.

Public types

using Iterator = StaticHashMapIterator<K, T, HashFunc, Capacity, false>
Iterator type.
using ConstIterator = StaticHashMapIterator<K, T, HashFunc, Capacity, true>
Constant iterator type.
using ReverseIterator = nCine::ReverseIterator<Iterator>
Reverse iterator type.
using ConstReverseIterator = nCine::ReverseIterator<ConstIterator>
Constant reverse iterator type.

Constructors, destructors, conversion operators

StaticHashMap()
~StaticHashMap()
StaticHashMap(const StaticHashMap& other)
StaticHashMap(StaticHashMap&& other)

Public functions

auto operator=(const StaticHashMap& other) -> StaticHashMap&
auto operator=(StaticHashMap&& other) -> StaticHashMap&
auto begin() -> Iterator
Returns an iterator to the first element.
auto rbegin() -> ReverseIterator
Returns a reverse iterator to the last element.
auto end() -> Iterator
Returns an iterator past the last element.
auto rend() -> ReverseIterator
Returns a reverse iterator before the first element.
auto begin() const -> ConstIterator
Returns a constant iterator to the first element.
auto rbegin() const -> ConstReverseIterator
Returns a constant reverse iterator to the last element.
auto end() const -> ConstIterator
Returns a constant iterator past the last element.
auto rend() const -> ConstReverseIterator
Returns a constant reverse iterator before the first element.
auto cbegin() const -> ConstIterator
Returns a constant iterator to the first element.
auto crbegin() const -> ConstReverseIterator
Returns a constant reverse iterator to the last element.
auto cend() const -> ConstIterator
Returns a constant iterator past the last element.
auto crend() const -> ConstReverseIterator
Returns a constant reverse iterator before the first element.
auto operator[](const K& key) -> T&
Returns a reference to the value of the given key, inserting a default-constructed one if absent.
auto insert(const K& key, const T& value) -> bool
Inserts a copy of the value if no element with the same key exists.
auto insert(const K& key, T&& value) -> bool
Inserts the value by move if no element with the same key exists.
template<typename... Args>
auto emplace(const K& key, Args && ... args) -> bool
Constructs the value in place if no element with the same key exists.
auto capacity() const -> std::uint32_t
Returns the maximum number of elements the hashmap can hold.
auto empty() const -> bool
Returns true if the hashmap contains no elements.
auto size() const -> std::uint32_t
Returns the number of elements in the hashmap.
auto loadFactor() const -> float
Returns the ratio between used and total buckets.
auto hash(const K& key) const -> hash_t
Returns the hash of the given key.
void clear()
Removes all elements from the hashmap.
auto contains(const K& key, T& returnedValue) const -> bool
Copies the value for the given key into returnedValue if present, returning whether it was found.
auto find(const K& key) -> T*
Returns a pointer to the value for the given key, or nullptr if not found.
auto find(const K& key) const -> const T*
Returns a read-only pointer to the value for the given key, or nullptr if not found.
auto remove(const K& key) -> bool
Removes the element with the given key if it exists.

Function documentation

template<class K, class T, std::uint32_t Capacity, class HashFunc>
bool nCine::StaticHashMap<K, T, Capacity, HashFunc>::insert(const K& key, const T& value)

Inserts a copy of the value if no element with the same key exists.

Returns true if the element has been inserted

template<class K, class T, std::uint32_t Capacity, class HashFunc>
bool nCine::StaticHashMap<K, T, Capacity, HashFunc>::insert(const K& key, T&& value)

Inserts the value by move if no element with the same key exists.

Returns true if the element has been inserted

template<class K, class T, std::uint32_t Capacity, class HashFunc> template<typename... Args>
bool nCine::StaticHashMap<K, T, Capacity, HashFunc>::emplace(const K& key, Args && ... args)

Constructs the value in place if no element with the same key exists.

Returns true if the element has been emplaced

template<class K, class T, std::uint32_t Capacity, class HashFunc>
T* nCine::StaticHashMap<K, T, Capacity, HashFunc>::find(const K& key)

Returns a pointer to the value for the given key, or nullptr if not found.

template<class K, class T, std::uint32_t Capacity, class HashFunc>
const T* nCine::StaticHashMap<K, T, Capacity, HashFunc>::find(const K& key) const

Returns a read-only pointer to the value for the given key, or nullptr if not found.

template<class K, class T, std::uint32_t Capacity, class HashFunc>
bool nCine::StaticHashMap<K, T, Capacity, HashFunc>::remove(const K& key)

Removes the element with the given key if it exists.

Returns true if the element has been found and removed