libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
HashSet< T > Class Template Reference

Unordered unique-element container wrapping std::unordered_set. More...

#include <hashset.h>

Public Types

using Ptr = SharedPtr< HashSet >
 Shared pointer type for HashSet.
 
using Data = std::unordered_set< T >
 Underlying std::unordered_set storage type.
 
using Value = T
 Value type.
 
using Iterator = typename Data::iterator
 Mutable forward iterator.
 
using ConstIterator = typename Data::const_iterator
 Const forward iterator.
 

Public Member Functions

 HashSet ()=default
 Default constructor. Creates an empty hash set.
 
 HashSet (const HashSet &other)
 Copy constructor.
 
 HashSet (HashSet &&other) noexcept
 Move constructor.
 
 HashSet (std::initializer_list< T > initList)
 Constructs a hash set from an initializer list.
 
 ~HashSet ()=default
 Destructor.
 
HashSetoperator= (const HashSet &other)
 Copy assignment operator.
 
HashSetoperator= (HashSet &&other) noexcept
 Move assignment operator.
 
Iterator begin () noexcept
 Returns a mutable iterator to the first element.
 
ConstIterator begin () const noexcept
 Returns a const iterator to the first element.
 
ConstIterator cbegin () const noexcept
 Returns a const iterator to the first element.
 
ConstIterator constBegin () const noexcept
 Returns a const iterator to the first element.
 
Iterator end () noexcept
 Returns a mutable iterator to one past the last element.
 
ConstIterator end () const noexcept
 Returns a const iterator to one past the last element.
 
ConstIterator cend () const noexcept
 Returns a const iterator to one past the last element.
 
ConstIterator constEnd () const noexcept
 Returns a const iterator to one past the last element.
 
bool isEmpty () const noexcept
 Returns true if the hash set has no elements.
 
size_t size () const noexcept
 Returns the number of elements.
 
bool contains (const T &value) const
 Returns true if value exists in the hash set.
 
bool insert (const T &value)
 Inserts a value into the hash set.
 
bool insert (T &&value)
 Inserts a value into the hash set (move overload).
 
bool remove (const T &value)
 Removes value from the hash set.
 
Iterator remove (Iterator pos)
 Removes the element at pos.
 
void clear () noexcept
 Removes all elements.
 
void swap (HashSet &other) noexcept
 Swaps contents with another hash set.
 
HashSet unite (const HashSet &other) const
 Returns the union of this set and other.
 
HashSet intersect (const HashSet &other) const
 Returns the intersection of this set and other.
 
HashSet subtract (const HashSet &other) const
 Returns this set minus other.
 
List< TtoList () const
 Converts the hash set to a List.
 
template<typename Func >
void forEach (Func &&func) const
 Calls func for every element.
 

Friends

bool operator== (const HashSet &lhs, const HashSet &rhs)
 Returns true if both hash sets have identical contents.
 
bool operator!= (const HashSet &lhs, const HashSet &rhs)
 Returns true if the hash sets differ.
 

Detailed Description

template<typename T>
class HashSet< T >

Unordered unique-element container wrapping std::unordered_set.

Provides a Qt-inspired API over std::unordered_set with consistent naming conventions matching the rest of libpromeki.

Template Parameters
TElement type (must be hashable).

Constructor & Destructor Documentation

◆ HashSet()

template<typename T >
HashSet< T >::HashSet ( std::initializer_list< T initList)
inline

Constructs a hash set from an initializer list.

Parameters
initListBrace-enclosed list of values.

Member Function Documentation

◆ constBegin()

template<typename T >
ConstIterator HashSet< T >::constBegin ( ) const
inlinenoexcept

Returns a const iterator to the first element.

◆ constEnd()

template<typename T >
ConstIterator HashSet< T >::constEnd ( ) const
inlinenoexcept

Returns a const iterator to one past the last element.

◆ forEach()

template<typename T >
template<typename Func >
void HashSet< T >::forEach ( Func &&  func) const
inline

Calls func for every element.

Template Parameters
FuncCallable with signature void(const T &).
Parameters
funcThe function to invoke.

◆ insert() [1/2]

template<typename T >
bool HashSet< T >::insert ( const T value)
inline

Inserts a value into the hash set.

Parameters
valueThe value to insert.
Returns
True if the value was inserted, false if it already existed.

◆ insert() [2/2]

template<typename T >
bool HashSet< T >::insert ( T &&  value)
inline

Inserts a value into the hash set (move overload).

Parameters
valueThe value to insert (moved).
Returns
True if the value was inserted, false if it already existed.

◆ intersect()

template<typename T >
HashSet HashSet< T >::intersect ( const HashSet< T > &  other) const
inline

Returns the intersection of this set and other.

Parameters
otherThe set to intersect with.
Returns
A new HashSet containing only elements present in both sets.

◆ remove() [1/2]

template<typename T >
bool HashSet< T >::remove ( const T value)
inline

Removes value from the hash set.

Parameters
valueThe value to remove.
Returns
True if the element was removed, false if not found.

◆ remove() [2/2]

template<typename T >
Iterator HashSet< T >::remove ( Iterator  pos)
inline

Removes the element at pos.

Parameters
posIterator to the element to remove.
Returns
Iterator to the next element.

◆ subtract()

template<typename T >
HashSet HashSet< T >::subtract ( const HashSet< T > &  other) const
inline

Returns this set minus other.

Parameters
otherThe set to subtract.
Returns
A new HashSet containing elements in this set but not in other.

◆ swap()

template<typename T >
void HashSet< T >::swap ( HashSet< T > &  other)
inlinenoexcept

Swaps contents with another hash set.

Parameters
otherThe hash set to swap with.

◆ toList()

template<typename T >
List< T > HashSet< T >::toList ( ) const
inline

Converts the hash set to a List.

Returns
A List containing all elements (order is unspecified).

◆ unite()

template<typename T >
HashSet HashSet< T >::unite ( const HashSet< T > &  other) const
inline

Returns the union of this set and other.

Parameters
otherThe set to unite with.
Returns
A new HashSet containing all elements from both sets.

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