ORIGINAL
Loading...
Searching...
No Matches
original::hashSet< TYPE, HASH, ALLOC > Class Template Referencefinal

Hash table based implementation of the set interface. More...

#include <sets.h>

Inheritance diagram for original::hashSet< TYPE, HASH, ALLOC >:
Inheritance graph
Collaboration diagram for original::hashSet< TYPE, HASH, ALLOC >:
Collaboration graph

Classes

class  Iterator
 Forward iterator for hashSet. More...
 

Public Member Functions

 hashSet (HASH hash=HASH{}, ALLOC alloc=ALLOC{})
 Constructs empty hashSet.
 
 hashSet (const hashSet &other)
 Copy constructor.
 
hashSetoperator= (const hashSet &other)
 Copy assignment operator.
 
 hashSet (hashSet &&other) noexcept
 Move constructor.
 
hashSetoperator= (hashSet &&other) noexcept
 Move assignment operator.
 
u_integer size () const override
 Gets number of elements.
 
bool contains (const TYPE &e) const override
 Checks if element exists.
 
bool add (const TYPE &e) override
 Adds new element.
 
bool remove (const TYPE &e) override
 Removes element.
 
Iteratorbegins () const override
 Gets begin iterator.
 
Iteratorends () const override
 Gets end iterator.
 
std::string className () const override
 Gets class name.
 
std::string toString (bool enter) const override
 Converts to string representation.
 
- Public Member Functions inherited from original::iterable< const TYPE >
auto forEach (Callback operation) -> void
 
auto forEach (const Callback &operation) const -> void
 
iterAdaptor begin ()
 Returns an iterator adapter pointing to the beginning of the container.
 
iterAdaptor begin () const
 Returns a const iterator adapter pointing to the beginning of the container.
 
iterAdaptor end ()
 Returns an iterator adapter pointing to the end sentinel of the container.
 
iterAdaptor end () const
 Returns a const iterator adapter pointing to the end sentinel of the container.
 
iterAdaptor first ()
 Returns an iterator adapter pointing to the first element.
 
iterAdaptor first () const
 Returns a const iterator adapter pointing to the first element.
 
iterAdaptor last ()
 Returns an iterator adapter pointing to the last element.
 
iterAdaptor last () const
 Returns a const iterator adapter pointing to the last element.
 
void forEach (Callback operation=Callback{})
 Applies a given operation to each element in the iterable container.
 
void forEach (const Callback &operation=Callback{}) const
 Applies a given operation to each element in the iterable container (const version).
 
auto forEach (Callback operation) -> void
 
auto forEach (const Callback &operation) const -> void
 
- Public Member Functions inherited from original::printable
 operator std::string () const
 Explicit conversion to std::string.
 
 operator const char * () const
 Explicit conversion to C-style string.
 
const char * toCString (bool enter) const
 Direct C-string access with formatting control.
 
template<typename TYPE>
auto formatString (const TYPE &t) -> std::string
 
template<typename TYPE>
auto formatCString (const TYPE &t) -> const char *
 
template<typename TYPE>
auto formatEnum (const TYPE &t) -> std::string
 
template<typename TYPE>
auto formatString (TYPE *const &ptr) -> std::string
 

Additional Inherited Members

- Static Public Member Functions inherited from original::printable
template<typename TYPE>
static std::string formatString (const TYPE &t)
 Universal value-to-string conversion.
 
template<typename TYPE>
static std::string formatString (TYPE *const &ptr)
 Pointer-specific formatting.
 
template<typename TYPE>
static const char * formatCString (const TYPE &t)
 C-string cache for temporary usage.
 
template<typename TYPE>
static std::string formatEnum (const TYPE &t)
 Enum formatting utility.
 
template<>
auto formatString (const char &t) -> std::string
 
template<>
auto formatString (const bool &t) -> std::string
 
template<>
auto formatString (const char *const &ptr) -> std::string
 

Detailed Description

template<typename TYPE, typename HASH = hash<TYPE>, typename ALLOC = allocator<couple<const TYPE, const bool>>>
class original::hashSet< TYPE, HASH, ALLOC >

Hash table based implementation of the set interface.

Template Parameters
TYPEElement type (must be hashable)
HASHHash function type (default: hash<TYPE>)
ALLOCAllocator type (default: allocator<couple<const TYPE, const bool>>)

This class provides a concrete implementation of the set interface using a hash table with separate chaining. It combines the functionality of:

  • set (interface)
  • hashTable (storage with bool values)
  • iterable (iteration support)

Performance Characteristics:

  • Insertion: Average O(1), Worst O(n)
  • Lookup: Average O(1), Worst O(n)
  • Deletion: Average O(1), Worst O(n)

The implementation guarantees:

  • Unique elements (no duplicates)
  • Type safety
  • Exception safety (basic guarantee)
  • Iterator validity unless modified

Constructor & Destructor Documentation

◆ hashSet() [1/3]

template<typename TYPE, typename HASH, typename ALLOC>
original::hashSet< TYPE, HASH, ALLOC >::hashSet ( HASH hash = HASH{},
ALLOC alloc = ALLOC{} )
explicit

Constructs empty hashSet.

Parameters
hashHash function to use
allocAllocator to use

◆ hashSet() [2/3]

template<typename TYPE, typename HASH, typename ALLOC>
original::hashSet< TYPE, HASH, ALLOC >::hashSet ( const hashSet< TYPE, HASH, ALLOC > & other)

Copy constructor.

Parameters
otherhashSet to copy

Performs deep copy of all elements and buckets

Note
Allocator is copied if propagate_on_container_copy_assignment is true

◆ hashSet() [3/3]

template<typename TYPE, typename HASH, typename ALLOC>
original::hashSet< TYPE, HASH, ALLOC >::hashSet ( hashSet< TYPE, HASH, ALLOC > && other)
noexcept

Move constructor.

Parameters
otherhashSet to move from

Transfers ownership of resources from other

Note
Leaves other in valid but unspecified state

Member Function Documentation

◆ add()

template<typename TYPE, typename HASH, typename ALLOC>
bool original::hashSet< TYPE, HASH, ALLOC >::add ( const TYPE & e)
override

Adds new element.

Parameters
eElement to add
Returns
true if added, false if element existed

◆ begins()

template<typename TYPE, typename HASH, typename ALLOC>
original::hashSet< TYPE, HASH, ALLOC >::Iterator * original::hashSet< TYPE, HASH, ALLOC >::begins ( ) const
overridevirtual

Gets begin iterator.

Returns
New iterator at first element

Implements original::iterable< const TYPE >.

◆ className()

template<typename TYPE, typename HASH, typename ALLOC>
std::string original::hashSet< TYPE, HASH, ALLOC >::className ( ) const
nodiscardoverridevirtual

Gets class name.

Returns
"hashSet"

Reimplemented from original::printable.

◆ contains()

template<typename TYPE, typename HASH, typename ALLOC>
bool original::hashSet< TYPE, HASH, ALLOC >::contains ( const TYPE & e) const
override

Checks if element exists.

Parameters
eElement to check
Returns
true if element exists

◆ ends()

template<typename TYPE, typename HASH, typename ALLOC>
original::hashSet< TYPE, HASH, ALLOC >::Iterator * original::hashSet< TYPE, HASH, ALLOC >::ends ( ) const
overridevirtual

Gets end iterator.

Returns
New iterator at position past last element

Implements original::iterable< const TYPE >.

◆ operator=() [1/2]

template<typename TYPE, typename HASH, typename ALLOC>
original::hashSet< TYPE, HASH, ALLOC > & original::hashSet< TYPE, HASH, ALLOC >::operator= ( const hashSet< TYPE, HASH, ALLOC > & other)

Copy assignment operator.

Parameters
otherhashSet to copy
Returns
Reference to this hashSet

Performs deep copy of all elements and buckets

Note
Allocator is copied if propagate_on_container_copy_assignment is true

◆ operator=() [2/2]

template<typename TYPE, typename HASH, typename ALLOC>
original::hashSet< TYPE, HASH, ALLOC > & original::hashSet< TYPE, HASH, ALLOC >::operator= ( hashSet< TYPE, HASH, ALLOC > && other)
noexcept

Move assignment operator.

Parameters
otherhashSet to move from
Returns
Reference to this hashSet

Transfers ownership of resources from other

Note
Leaves other in valid but unspecified state
Allocator is moved if propagate_on_container_move_assignment is true

◆ remove()

template<typename TYPE, typename HASH, typename ALLOC>
bool original::hashSet< TYPE, HASH, ALLOC >::remove ( const TYPE & e)
override

Removes element.

Parameters
eElement to remove
Returns
true if removed, false if element didn't exist

◆ size()

template<typename TYPE, typename HASH, typename ALLOC>
original::u_integer original::hashSet< TYPE, HASH, ALLOC >::size ( ) const
nodiscardoverride

Gets number of elements.

Returns
Current size

◆ toString()

template<typename TYPE, typename HASH, typename ALLOC>
std::string original::hashSet< TYPE, HASH, ALLOC >::toString ( bool enter) const
nodiscardoverridevirtual

Converts to string representation.

Parameters
enterAdd newline if true
Returns
String representation

Reimplemented from original::printable.


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