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::HashSet< K, HashFunc > Class Template Reference

A template based hashset implementation with open addressing and leapfrog probing. More...

#include <HashSet.h>

Public Types

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

Public Member Functions

 HashSet (unsigned int capacity)
 
 HashSet (const HashSet &other)
 Copy constructor.
 
 HashSet (HashSet &&other)
 Move constructor.
 
HashSetoperator= (const HashSet &other)
 Assignment operator.
 
HashSetoperator= (HashSet &&other)
 Move assignment operator.
 
void swap (HashSet &first, HashSet &second)
 Swaps two hashsets without copying their data.
 
ConstIterator begin ()
 Returns a constant iterator to the first element.
 
ConstReverseIterator rBegin ()
 Returns a reverse constant iterator to the last element.
 
ConstIterator end ()
 Returns a constant iterator to past the last element.
 
ConstReverseIterator rEnd ()
 Returns a reverse constant 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.
 
void rehash (unsigned int count)
 Sets the number of buckets to the new specified size and rehashes the container.
 

Friends

class HashSetIterator< K, HashFunc >
 
struct HashSetHelperTraits< K, HashFunc >
 

Detailed Description

template<class K, class HashFunc = FNV1aHashFunc<K>>
class nctl::HashSet< K, HashFunc >

A template based hashset implementation with open addressing and leapfrog probing.

Member Typedef Documentation

◆ Iterator

template<class K , class HashFunc = FNV1aHashFunc<K>>
using nctl::HashSet< K, HashFunc >::Iterator = HashSetIterator<K, HashFunc>

Iterator type.

Elements in the hashset can never be changed

Member Function Documentation

◆ find() [1/2]

template<class K , class HashFunc >
K * nctl::HashSet< K, HashFunc >::find ( const K &  key)

Checks whether an element is in the hashset or not.

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

◆ find() [2/2]

template<class K , class HashFunc >
const K * nctl::HashSet< K, HashFunc >::find ( const K &  key) const

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

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

◆ insert() [1/2]

template<class K , class HashFunc >
bool nctl::HashSet< K, 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 , class HashFunc >
bool nctl::HashSet< K, HashFunc >::insert ( K &&  key)

Moves an element if not already in.

Returns
True if the element has been inserted

◆ remove()

template<class K , class HashFunc >
bool nctl::HashSet< K, 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: