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

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

#include <StaticHashSet.h>

Public Types

using Iterator = StaticHashSetIterator< K, HashFunc, Capacity >
 Iterator type.
 
using ConstIterator = StaticHashSetIterator< K, HashFunc, Capacity >
 Constant iterator type.
 
using ReverseIterator = nctl::ReverseIterator< Iterator >
 Reverse iterator type.
 
using ConstReverseIterator = nctl::ReverseIterator< ConstIterator >
 Reverse constant iterator type.
 

Public Member Functions

 StaticHashSet (const StaticHashSet &other)
 Copy constructor.
 
 StaticHashSet (StaticHashSet &&other)
 Move constructor.
 
StaticHashSetoperator= (const StaticHashSet &other)
 Aassignment operator.
 
StaticHashSetoperator= (StaticHashSet &&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.
 
bool insert (const K &key)
 Inserts an element if not already in.
 
bool insert (K &&key)
 Moves an element if not already in.
 
unsigned int capacity () const
 Returns the capacity of the hashset.
 
bool isEmpty () const
 Returns true if the hashset is empty.
 
unsigned int size () const
 Returns the number of elements in the hashset.
 
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 hashset.
 
bool contains (const K &key) const
 Checks whether an element is in the hashset or not.
 
K * find (const K &key)
 Checks whether an element is in the hashset or not.
 
const K * find (const K &key) const
 Checks whether an element is in the hashset or not (read-only)
 
bool remove (const K &key)
 Removes a key from the hashset, if it exists.
 

Friends

class StaticHashSetIterator< K, HashFunc, Capacity >
 
struct StaticHashSetHelperTraits< K, HashFunc, Capacity >
 

Detailed Description

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

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

Member Function Documentation

◆ find() [1/2]

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

Checks whether an element is in the hashset 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 , unsigned int Capacity, class HashFunc >
const K * nctl::StaticHashSet< K, Capacity, HashFunc >::find ( const K &  key) const

Checks whether an element is in the hashset 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 , unsigned int Capacity, class HashFunc >
bool nctl::StaticHashSet< K, Capacity, HashFunc >::insert ( const K &  key)

Inserts an element if not already in.

Returns
True if the element has been inserted

◆ insert() [2/2]

template<class K , unsigned int Capacity, class HashFunc >
bool nctl::StaticHashSet< K, Capacity, HashFunc >::insert ( K &&  key)

Moves an element if not already in.

Returns
True if the element has been inserted

◆ remove()

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

Removes a key from the hashset, if it exists.

Returns
True if the element has been found and removed

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