13#ifndef BELFEM_CL_SET_HPP
14#define BELFEM_CL_SET_HPP
16#include <unordered_set>
31 template<
typename Key >
34 std::unordered_set< Key > mSet;
40 using iterator =
typename std::unordered_set< Key >::iterator;
53 Set( std::initializer_list< Key > aInit ) : mSet( aInit )
62 template<
typename InputIt >
63 Set( InputIt aFirst, InputIt aLast ) : mSet( aFirst, aLast )
141 std::pair< iterator, bool >
144 return mSet.insert( aKey );
152 std::pair< iterator, bool >
155 return mSet.insert( std::move( aKey ) );
163 template<
typename InputIt >
167 mSet.insert( aFirst, aLast );
175 template<
typename... Args >
176 std::pair< iterator, bool >
179 return mSet.emplace( std::forward< Args >( args )... );
190 return mSet.find( aKey ) != mSet.end();
212 return mSet.count( aKey );
223 return mSet.find( aKey );
234 return mSet.find( aKey );
246 return mSet.erase( aKey );
257 return mSet.erase( aPos );
268 return mSet.erase( aFirst, aLast );
331 std::unordered_set< Key > &
342 const std::unordered_set< Key > &
356 mSet.swap( aOther.mSet );
383 for (
const auto & tKey : mSet )
403 for (
const auto & tKey : mSet )
425 for (
const auto & tKey : mSet )
434 for (
const auto & tKey : aOther )
458 for (
const auto & tKey : mSet )
487 if ( this->
size() != aOther.
size() )
492 for (
const auto & tKey : mSet )
510 return !( *
this == aOther );
Hash set with set operations.
Definition cl_Set.hpp:33
void clear()
Clear the set.
Definition cl_Set.hpp:108
size_t erase(const Key &aKey)
Erase a key from the set.
Definition cl_Set.hpp:244
Set< Key > operator-(const Set< Key > &aOther) const
Set difference operation.
Definition cl_Set.hpp:400
Set< Key > operator|(const Set< Key > &aOther) const
Set union operation.
Definition cl_Set.hpp:366
bool operator!=(const Set< Key > &aOther) const
Inequality operator.
Definition cl_Set.hpp:508
size_t size() const
Returns the size of the set.
Definition cl_Set.hpp:119
const_iterator end() const
Get end iterator (const).
Definition cl_Set.hpp:321
void swap(Set< Key > &aOther)
Swap contents with another set.
Definition cl_Set.hpp:354
void reserve(size_t n)
Reserve space for at least n elements.
Definition cl_Set.hpp:277
bool empty() const
Check if set is empty.
Definition cl_Set.hpp:130
Set< Key > & operator=(const Set< Key > &aSet)=default
Copy assignment operator.
Set(InputIt aFirst, InputIt aLast)
Constructor from iterators.
Definition cl_Set.hpp:63
std::unordered_set< Key > & set_data()
Expose the underlying container.
Definition cl_Set.hpp:332
Set(std::initializer_list< Key > aInit)
Constructor with initializer list.
Definition cl_Set.hpp:53
Set< Key > operator^(const Set< Key > &aOther) const
Set symmetric difference operation.
Definition cl_Set.hpp:420
void insert(InputIt aFirst, InputIt aLast)
Insert a range of elements.
Definition cl_Set.hpp:165
size_t count(const Key &aKey) const
Count occurrences of key (0 or 1 for set).
Definition cl_Set.hpp:210
Set()=default
Empty constructor.
std::pair< iterator, bool > insert(const Key &aKey)
Insert a key into the set.
Definition cl_Set.hpp:142
Set< Key > & operator=(Set< Key > &&aSet) noexcept=default
Move assignment operator.
typename std::unordered_set< Key >::iterator iterator
Definition cl_Set.hpp:40
const_iterator find(const Key &aKey) const
Find an element (const version).
Definition cl_Set.hpp:232
const std::unordered_set< Key > & set_data() const
Expose the underlying container (const).
Definition cl_Set.hpp:343
bool is_superset_of(const Set< Key > &aOther) const
Check if this is a superset of another set.
Definition cl_Set.hpp:474
iterator erase(const_iterator aFirst, const_iterator aLast)
Erase a range of elements.
Definition cl_Set.hpp:266
const_iterator begin() const
Get begin iterator (const).
Definition cl_Set.hpp:299
bool contains(const Key &aKey) const
Alternative name for key_exists (more set-like).
Definition cl_Set.hpp:199
std::pair< iterator, bool > emplace(Args &&... args)
Emplace a key (construct in-place).
Definition cl_Set.hpp:177
iterator end()
Get end iterator.
Definition cl_Set.hpp:310
Set< Key > operator&(const Set< Key > &aOther) const
Set intersection operation.
Definition cl_Set.hpp:380
iterator find(const Key &aKey)
Find an element.
Definition cl_Set.hpp:221
bool is_subset_of(const Set< Key > &aOther) const
Check if this is a subset of another set.
Definition cl_Set.hpp:451
iterator begin()
Get begin iterator.
Definition cl_Set.hpp:288
bool operator==(const Set< Key > &aOther) const
Equality operator.
Definition cl_Set.hpp:485
Set(const Set< Key > &aSet)=default
Copy constructor.
bool key_exists(const Key &aKey) const
Check if a key exists in the set.
Definition cl_Set.hpp:188
~Set()=default
Destructor.
Set(Set< Key > &&aSet) noexcept=default
Move constructor.
iterator erase(const_iterator aPos)
Erase an element by iterator.
Definition cl_Set.hpp:255
typename std::unordered_set< Key >::const_iterator const_iterator
Definition cl_Set.hpp:41
std::pair< iterator, bool > insert(Key &&aKey)
Insert a key using move semantics.
Definition cl_Set.hpp:153
USER GUIDES:
Definition cl_Capacitor.cpp:16