nCine 2022.04.r504-20bd01e
A cross-platform 2D game engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Friends | List of all members
nctl::StaticHashMap< K, T, Capacity, HashFunc > Class Template Reference

A template based hashmap implementation with open addressing and leapfrog probing (version with static allocation) More...

#include <StaticHashMap.h>

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 = nctl::ReverseIterator< Iterator >
 Reverse iterator type.
 
using ConstReverseIterator = nctl::ReverseIterator< ConstIterator >
 Reverse constant iterator type.
 

Public Member Functions

 StaticHashMap (const StaticHashMap &other)
 Copy constructor.
 
 StaticHashMap (StaticHashMap &&other)
 Move constructor.
 
StaticHashMapoperator= (const StaticHashMap &other)
 Aassignment operator.
 
StaticHashMapoperator= (StaticHashMap &&other)
 Move aassignment operator.
 
Iterator begin ()
 Returns an iterator to the first element.
 
ReverseIterator rBegin ()
 Returns a reverse iterator to the last element.
 
Iterator end ()
 Returns an iterator to past the last element.
 
ReverseIterator rEnd ()
 Returns a reverse iterator to prior the first element.
 
ConstIterator begin () const
 Returns a constant iterator to the first element.
 
ConstReverseIterator rBegin () const
 Returns a constant reverse iterator to the last element.
 
ConstIterator end () const
 Returns a constant iterator to past the last lement.
 
ConstReverseIterator rEnd () const
 Returns a constant reverse iterator to prior the first element.
 
ConstIterator cBegin () const
 Returns a constant iterator to the first element.
 
ConstReverseIterator crBegin () const
 Returns a constant reverse iterator to the last element.
 
ConstIterator cEnd () const
 Returns a constant iterator to past the last lement.
 
ConstReverseIterator crEnd () const
 Returns a constant reverse iterator to prior the first element.
 
T & operator[] (const K &key)
 Subscript operator.
 
bool insert (const K &key, const T &value)
 Inserts an element if no other has the same key.
 
bool insert (const K &key, T &&value)
 Moves an element if no other has the same key.
 
template<typename... Args>
bool emplace (const K &key, Args &&... args)
 Constructs an element if no other has the same key.
 
unsigned int capacity () const
 Returns the capacity of the hashmap.
 
bool isEmpty () const
 Returns true if the hashmap is empty.
 
unsigned int size () const
 Returns the number of elements in the hashmap.
 
float loadFactor () const
 Returns the ratio between used and total buckets.
 
hash_t hash (const K &key) const
 Returns the hash of a given key.
 
void clear ()
 Clears the hashmap.
 
bool contains (const K &key, T &returnedValue) const
 Checks whether an element is in the hashmap or not.
 
T * find (const K &key)
 Checks whether an element is in the hashmap or not.
 
const T * find (const K &key) const
 Checks whether an element is in the hashmap or not (read-only)
 
bool remove (const K &key)
 Removes a key from the hashmap, if it exists.
 

Friends

class StaticHashMapIterator< K, T, HashFunc, Capacity, false >
 
class StaticHashMapIterator< K, T, HashFunc, Capacity, true >
 
struct StaticHashMapHelperTraits< K, T, HashFunc, Capacity, false >
 
struct StaticHashMapHelperTraits< K, T, HashFunc, Capacity, true >
 

Detailed Description

template<class K, class T, unsigned int Capacity, class HashFunc = FNV1aHashFunc<K>>
class nctl::StaticHashMap< K, T, Capacity, HashFunc >

A template based hashmap implementation with open addressing and leapfrog probing (version with static allocation)

Member Function Documentation

◆ emplace()

template<class K , class T , unsigned int Capacity, class HashFunc >
template<typename... Args>
bool nctl::StaticHashMap< K, T, Capacity, HashFunc >::emplace ( const K &  key,
Args &&...  args 
)

Constructs an element if no other has the same key.

Returns
True if the element has been emplaced

◆ find() [1/2]

template<class K , class T , unsigned int Capacity, class HashFunc >
T * nctl::StaticHashMap< K, T, Capacity, HashFunc >::find ( const K &  key)

Checks whether an element is in the hashmap or not.

Note
Prefer this method if copying T is expensive, but always check the validity of returned pointer.

◆ find() [2/2]

template<class K , class T , unsigned int Capacity, class HashFunc >
const T * nctl::StaticHashMap< K, T, Capacity, HashFunc >::find ( const K &  key) const

Checks whether an element is in the hashmap or not (read-only)

Note
Prefer this method if copying T is expensive, but always check the validity of returned pointer.

◆ insert() [1/2]

template<class K , class T , unsigned int Capacity, class HashFunc >
bool nctl::StaticHashMap< K, T, Capacity, HashFunc >::insert ( const K &  key,
const T &  value 
)

Inserts an element if no other has the same key.

Returns
True if the element has been inserted

◆ insert() [2/2]

template<class K , class T , unsigned int Capacity, class HashFunc >
bool nctl::StaticHashMap< K, T, Capacity, HashFunc >::insert ( const K &  key,
T &&  value 
)

Moves an element if no other has the same key.

Returns
True if the element has been inserted

◆ remove()

template<class K , class T , unsigned int Capacity, class HashFunc >
bool nctl::StaticHashMap< K, T, Capacity, HashFunc >::remove ( const K &  key)

Removes a key from the hashmap, if it exists.

Returns
True if the element has been found and removed

The documentation for this class was generated from the following file: