Ocean
Ocean::HashSet< T > Class Template Reference

This class implements a hash set. More...

Public Member Functions

 HashSet (const HashSet< T > &hashSet)
 Copy constructor. More...
 
 HashSet (HashSet< T > &&hashSet) noexcept
 Move constructor. More...
 
 HashSet (const size_t capacity, const ValueFunction &function=defaultHashFunction)
 Creates a new hash set object by a given capacity. More...
 
bool insert (const T &element, const bool oneOnly=true, const bool extendCapacity=true)
 Adds a new element to this hash set. More...
 
bool insert (T &&element, const bool oneOnly=true, const bool extendCapacity=true)
 Adds (moves) a new element to this hash set. More...
 
bool remove (const T &element)
 Removes an element from this hash set. More...
 
bool find (const T &element) const
 Returns whether this hash set holds a given element. More...
 
void clear ()
 Removes all elements from this has set. More...
 
size_t size () const
 Returns the number of elements this hash set currently holds. More...
 
size_t capacity () const
 Returns the capacity of this hash set. More...
 
bool isEmpty () const
 Returns whether this hash set is empty. More...
 
HashSet< T > & operator= (const HashSet< T > &hashSet)
 Assign operator. More...
 
HashSet< T > & operator= (HashSet< T > &&hashSet) noexcept
 Move operator. More...
 

Protected Types

typedef std::pair< std::pair< size_t, size_t >, T > Element
 Definition of a pair combining a counter states and an object. More...
 
typedef std::vector< ElementElements
 Definition of a vector holding the set objects. More...
 
typedef size_t(* ValueFunction) (const T &element)
 Definition of a function pointer returning a hash set value. More...
 

Protected Member Functions

 HashSet (size_t capacity, HashSet< T > &&hashSet)
 Creates a new hash set by a given hash set. More...
 
bool isConsistent () const
 Returns whether this hash set is still consistent. More...
 

Static Protected Member Functions

static size_t defaultHashFunction (const T &element)
 Default hash function for elements supporting an cast size_t cast. More...
 

Protected Attributes

Elements setElements
 Hash set elements. More...
 
size_t setSize
 Number of elements this has set holds. More...
 
ValueFunction setFunction
 Value function. More...
 

Detailed Description

template<typename T>
class Ocean::HashSet< T >

This class implements a hash set.

Template Parameters
TThe data type that is stored by the hash set

Member Typedef Documentation

◆ Element

template<typename T >
typedef std::pair<std::pair<size_t, size_t>, T> Ocean::HashSet< T >::Element
protected

Definition of a pair combining a counter states and an object.

◆ Elements

template<typename T >
typedef std::vector<Element> Ocean::HashSet< T >::Elements
protected

Definition of a vector holding the set objects.

◆ ValueFunction

template<typename T >
typedef size_t(* Ocean::HashSet< T >::ValueFunction) (const T &element)
protected

Definition of a function pointer returning a hash set value.

Constructor & Destructor Documentation

◆ HashSet() [1/4]

template<typename T >
Ocean::HashSet< T >::HashSet ( const HashSet< T > &  hashSet)
inline

Copy constructor.

Parameters
hashSetThe hash set to copy

◆ HashSet() [2/4]

template<typename T >
Ocean::HashSet< T >::HashSet ( HashSet< T > &&  hashSet)
inlinenoexcept

Move constructor.

Parameters
hashSetThe hash set to move

◆ HashSet() [3/4]

template<typename T >
Ocean::HashSet< T >::HashSet ( const size_t  capacity,
const ValueFunction function = defaultHashFunction 
)
explicit

Creates a new hash set object by a given capacity.

Parameters
capacityMaximal capacity the hash set will support
functionHash function to be used

◆ HashSet() [4/4]

template<typename T >
Ocean::HashSet< T >::HashSet ( size_t  capacity,
HashSet< T > &&  hashSet 
)
protected

Creates a new hash set by a given hash set.

Parameters
capacityThe capacity of the new has set, with range [hashSet.size(), infinity)
hashSetThe hash set which defines the initial values of this hash set, will be moved

Member Function Documentation

◆ capacity()

template<typename T >
size_t Ocean::HashSet< T >::capacity
inline

Returns the capacity of this hash set.

Returns
Maximal capacity this hash set supports

◆ clear()

template<typename T >
void Ocean::HashSet< T >::clear

Removes all elements from this has set.

◆ defaultHashFunction()

template<typename T >
size_t Ocean::HashSet< T >::defaultHashFunction ( const T &  element)
inlinestaticprotected

Default hash function for elements supporting an cast size_t cast.

Parameters
elementElement to return the hash value for
Returns
Resulting hash value

◆ find()

template<typename T >
bool Ocean::HashSet< T >::find ( const T &  element) const

Returns whether this hash set holds a given element.

Parameters
elementElement to be checked
Returns
True, if succeeded

◆ insert() [1/2]

template<typename T >
bool Ocean::HashSet< T >::insert ( const T &  element,
const bool  oneOnly = true,
const bool  extendCapacity = true 
)

Adds a new element to this hash set.

Parameters
elementElement to be added
oneOnlyAdds the element if it does not exist already
extendCapacityTrue, to extend the capacity if necessary
Returns
True, if the element has been added

◆ insert() [2/2]

template<typename T >
bool Ocean::HashSet< T >::insert ( T &&  element,
const bool  oneOnly = true,
const bool  extendCapacity = true 
)

Adds (moves) a new element to this hash set.

Parameters
elementElement to be moved
oneOnlyAdds the element if it does not exist already
extendCapacityTrue, to extend the capacity if necessary
Returns
True, if the element has been added

◆ isConsistent()

template<typename T >
bool Ocean::HashSet< T >::isConsistent
protected

Returns whether this hash set is still consistent.

Returns
True, if so

◆ isEmpty()

template<typename T >
bool Ocean::HashSet< T >::isEmpty
inline

Returns whether this hash set is empty.

Returns
True, if so

◆ operator=() [1/2]

template<typename T >
HashSet< T > & Ocean::HashSet< T >::operator= ( const HashSet< T > &  hashSet)
inline

Assign operator.

Parameters
hashSetThe hash set to assign
Returns
The reference to this object

◆ operator=() [2/2]

template<typename T >
HashSet< T > & Ocean::HashSet< T >::operator= ( HashSet< T > &&  hashSet)
inlinenoexcept

Move operator.

Parameters
hashSetThe hash set to move
Returns
The reference to this object

◆ remove()

template<typename T >
bool Ocean::HashSet< T >::remove ( const T &  element)

Removes an element from this hash set.

Parameters
elementElement to be removed
Returns
True, if succeeded

◆ size()

template<typename T >
size_t Ocean::HashSet< T >::size
inline

Returns the number of elements this hash set currently holds.

Returns
Number of elements

Field Documentation

◆ setElements

template<typename T >
Elements Ocean::HashSet< T >::setElements
protected

Hash set elements.

◆ setFunction

template<typename T >
ValueFunction Ocean::HashSet< T >::setFunction
protected

Value function.

◆ setSize

template<typename T >
size_t Ocean::HashSet< T >::setSize
protected

Number of elements this has set holds.


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