CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
Set< T, O > Class Template Reference

Set data container More...

#include <cc/Set>

Public Types

using Item = T
 Item type.
 
using Order = O
 Search order.
 

Standard Iterators

using value_type = Item
 Item value type.
 
using size_type = long
 Type of the container capacity.
 
using const_iterator = Iterator<const BucketVector<Item>>
 Readonly value iterator.
 
using const_reverse_iterator = ReverseIterator<const BucketVector<Item>>
 Readonly reverse value iterator.
 
const_iterator begin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator cbegin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator end () const
 Return readonly iterator pointing behind the last item
 
const_iterator cend () const
 Return readonly iterator pointing behind the last item
 
const_reverse_iterator rbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator crbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator rend () const
 Return reverse iterator pointing before the first item
 
const_reverse_iterator crend () const
 Return reverse iterator pointing before the first item
 

Construction and Assignment

 Set ()=default
 Construct an empty set.
 
 Set (const Set &other)=default
 Construct a copy of other.
 
 Set (std::initializer_list< Item > items)
 Construct with initial items.
 
 Set (Set &&other)
 Take over the right-side set other.
 
Setoperator= (const Set &other)=default
 Assign set other.
 
Setoperator= (Set &&other)
 Take over the right-side set other.
 
List< ItemtoList () const
 Get corresponding list representation.
 

Item Access

Locator head () const
 Get a locator pointing to the first item.
 
Locator tail () const
 Get a locator pointing to the last item.
 
Locator from (long index) const
 Get a locator pointing to the item at index.
 
long count () const
 Get the number of items stored in the set.
 
long size () const
 Get the number of items stored in the set.
 
 operator bool () const
 Check if this set is non-empty.
 
long operator+ () const
 Get the number of items stored in the set.
 
bool has (long index) const
 Check if index is valid.
 
const Itemat (Locator pos) const
 Get constant reference to the item at position pos.
 
const Itemat (long index) const
 Get constant references to the item at index.
 
Itemat (Locator pos)
 Get to the item at position pos.
 
Itemat (long index)
 Get references to the item at index.
 
const Itemoperator[] (long index) const
 Get constant references to the item at index.
 
const Itemfirst () const
 Get constant reference to first item.
 
const Itemlast () const
 Get constant reference to last item.
 
bool firstIs (const Item &item) const
 Tell if item is the first item.
 
bool lastIs (const Item &item) const
 Tell if item is the last item.
 
const Itemmin () const
 Get constant reference to the first item.
 
const Itemmax () const
 Get constant reference to the last item.
 

Set Operations

template<class Pattern = Item>
bool find (const Pattern &pattern, Out< Locator > pos=None{}) const
 Search for a matching key in the set.
 
template<class Pattern = Item>
bool lookup (const Pattern &pattern, Out< Item > item) const
 Search for key and return item.
 
template<class Pattern = Item>
bool contains (const Pattern &pattern) const
 Convenience function to check if the set contains key.
 
template<class Pattern >
Locator lowerBound (const Pattern &pattern) const
 Convenience function to find the start of a search range.
 
template<class Pattern >
Locator upperBound (const Pattern &pattern) const
 Convenience function to find the end of a search range.
 
bool insert (const Item &item, Out< Locator > pos=None{})
 Insert a new item to the set.
 
void establish (const Item &item)
 Insert an item to the set replacing any pre-existing same value item.
 
template<class Key = Item>
bool remove (const Key &key)
 Remove an item from the set.
 
Setoperator<< (const Item &item)
 Insert item to the set.
 
Setoperator>> (Item &item)
 Get and remove the smallest item.
 

Positional Operations

void removeAt (Locator &pos)
 Remove item at position pos (and advance pos to the next item)
 
void removeAt (long index)
 Remove item at index.
 

Global Operations

template<class F >
void forEach (F f) const
 Call function f for each item.
 
template<class F >
void forEachInRange (const Item &lower, const Item &upper, F f) const
 Call function f for each item in range [lower, upper].
 
void deplete ()
 Remove all items.
 

Comparism Operators

template<class Other >
bool operator== (const Other &other) const
 Equality operator.
 

Detailed Description

template<class T, class O = DefaultOrder>
class cc::Set< T, O >

Set data container

Template Parameters
TItem type
OSearch order

Member Typedef Documentation

◆ Item

template<class T , class O = DefaultOrder>
using Item = T

Item type.

◆ Order

template<class T , class O = DefaultOrder>
using Order = O

Search order.

◆ value_type

template<class T , class O = DefaultOrder>
using value_type = Item

Item value type.

◆ size_type

template<class T , class O = DefaultOrder>
using size_type = long

Type of the container capacity.

◆ const_iterator

template<class T , class O = DefaultOrder>
using const_iterator = Iterator<const BucketVector<Item>>

Readonly value iterator.

◆ const_reverse_iterator

template<class T , class O = DefaultOrder>
using const_reverse_iterator = ReverseIterator<const BucketVector<Item>>

Readonly reverse value iterator.

Constructor & Destructor Documentation

◆ Set() [1/4]

template<class T , class O = DefaultOrder>
Set ( )
default

Construct an empty set.

◆ Set() [2/4]

template<class T , class O = DefaultOrder>
Set ( const Set< T, O > & other)
default

Construct a copy of other.

◆ Set() [3/4]

template<class T , class O = DefaultOrder>
Set ( std::initializer_list< Item > items)

Construct with initial items.

◆ Set() [4/4]

template<class T , class O = DefaultOrder>
Set ( Set< T, O > && other)

Take over the right-side set other.

Member Function Documentation

◆ operator=() [1/2]

template<class T , class O = DefaultOrder>
Set & operator= ( const Set< T, O > & other)
default

Assign set other.

◆ operator=() [2/2]

template<class T , class O = DefaultOrder>
Set & operator= ( Set< T, O > && other)

Take over the right-side set other.

◆ toList()

template<class T , class O = DefaultOrder>
List< Item > toList ( ) const

Get corresponding list representation.

◆ head()

template<class T , class O = DefaultOrder>
Locator head ( ) const

Get a locator pointing to the first item.

◆ tail()

template<class T , class O = DefaultOrder>
Locator tail ( ) const

Get a locator pointing to the last item.

◆ from()

template<class T , class O = DefaultOrder>
Locator from ( long index) const

Get a locator pointing to the item at index.

◆ count()

template<class T , class O = DefaultOrder>
long count ( ) const

Get the number of items stored in the set.

◆ size()

template<class T , class O = DefaultOrder>
long size ( ) const

Get the number of items stored in the set.

◆ operator bool()

template<class T , class O = DefaultOrder>
operator bool ( ) const
explicit

Check if this set is non-empty.

◆ operator+()

template<class T , class O = DefaultOrder>
long operator+ ( ) const

Get the number of items stored in the set.

◆ has()

template<class T , class O = DefaultOrder>
bool has ( long index) const

Check if index is valid.

◆ at() [1/4]

template<class T , class O = DefaultOrder>
const Item & at ( Locator pos) const

Get constant reference to the item at position pos.

◆ at() [2/4]

template<class T , class O = DefaultOrder>
const Item & at ( long index) const

Get constant references to the item at index.

◆ at() [3/4]

template<class T , class O = DefaultOrder>
Item & at ( Locator pos)

Get to the item at position pos.

◆ at() [4/4]

template<class T , class O = DefaultOrder>
Item & at ( long index)

Get references to the item at index.

◆ operator[]()

template<class T , class O = DefaultOrder>
const Item & operator[] ( long index) const

Get constant references to the item at index.

◆ first()

template<class T , class O = DefaultOrder>
const Item & first ( ) const

Get constant reference to first item.

◆ last()

template<class T , class O = DefaultOrder>
const Item & last ( ) const

Get constant reference to last item.

◆ firstIs()

template<class T , class O = DefaultOrder>
bool firstIs ( const Item & item) const

Tell if item is the first item.

◆ lastIs()

template<class T , class O = DefaultOrder>
bool lastIs ( const Item & item) const

Tell if item is the last item.

◆ min()

template<class T , class O = DefaultOrder>
const Item & min ( ) const

Get constant reference to the first item.

◆ max()

template<class T , class O = DefaultOrder>
const Item & max ( ) const

Get constant reference to the last item.

◆ find()

template<class T , class O = DefaultOrder>
template<class Pattern = Item>
bool find ( const Pattern & pattern,
Out< Locator > pos = None{} ) const

Search for a matching key in the set.

Template Parameters
PatternPattern type (must be comparable with Key)
Parameters
patternPattern to search for
posReturns the position of the item that was found
Returns
True if a matching item was found

◆ lookup()

template<class T , class O = DefaultOrder>
template<class Pattern = Item>
bool lookup ( const Pattern & pattern,
Out< Item > item ) const

Search for key and return item.

Template Parameters
PatternPattern type (must be comparable with Key)
Parameters
patternPattern to search for
itemReturns the item found (if any)
Returns
True if key was found

◆ contains()

template<class T , class O = DefaultOrder>
template<class Pattern = Item>
bool contains ( const Pattern & pattern) const

Convenience function to check if the set contains key.

Template Parameters
PatternPattern type (must be comparable with Key)
Parameters
patternPattern to search for
Returns
True if key was found

◆ lowerBound()

template<class T , class O = DefaultOrder>
template<class Pattern >
Locator lowerBound ( const Pattern & pattern) const

Convenience function to find the start of a search range.

Template Parameters
PatternPattern type (must be comparable with Key)
Parameters
patternPattern to search for
Returns
Locator position
Note
pattern is included in the search range
See also
forEachInRange()

◆ upperBound()

template<class T , class O = DefaultOrder>
template<class Pattern >
Locator upperBound ( const Pattern & pattern) const

Convenience function to find the end of a search range.

Template Parameters
PatternPattern type (must be comparable with Key)
Parameters
patternPattern to search for
Returns
Locator position
Note
pattern is included in the search range
See also
forEachInRange()

◆ insert()

template<class T , class O = DefaultOrder>
bool insert ( const Item & item,
Out< Locator > pos = None{} )

Insert a new item to the set.

Parameters
itemItem to add
posReturns a locator pointing to the existing or newly inserted item
Returns
True if item was not yet a member of the set

◆ establish()

template<class T , class O = DefaultOrder>
void establish ( const Item & item)

Insert an item to the set replacing any pre-existing same value item.

Parameters
itemItem to add

◆ remove()

template<class T , class O = DefaultOrder>
template<class Key = Item>
bool remove ( const Key & key)

Remove an item from the set.

Template Parameters
KeySearch pattern type
Parameters
keyKey to search for
Returns
true If item was found and removed

◆ operator<<()

template<class T , class O = DefaultOrder>
Set & operator<< ( const Item & item)

Insert item to the set.

◆ operator>>()

template<class T , class O = DefaultOrder>
Set & operator>> ( Item & item)

Get and remove the smallest item.

◆ removeAt() [1/2]

template<class T , class O = DefaultOrder>
void removeAt ( Locator & pos)

Remove item at position pos (and advance pos to the next item)

◆ removeAt() [2/2]

template<class T , class O = DefaultOrder>
void removeAt ( long index)

Remove item at index.

◆ forEach()

template<class T , class O = DefaultOrder>
template<class F >
void forEach ( F f) const

Call function f for each item.

Template Parameters
FFunction type (lambda or functor)
Parameters
fUnary function which gets called for each item

◆ forEachInRange()

template<class T , class O = DefaultOrder>
template<class F >
void forEachInRange ( const Item & lower,
const Item & upper,
F f ) const

Call function f for each item in range [lower, upper].

Template Parameters
FFunction type (lambda or functor)
Parameters
lowerLower boundary
upperUpper boundary
fUnary function which gets called for each item
Note
lower and upper are included in the iteration range.

◆ deplete()

template<class T , class O = DefaultOrder>
void deplete ( )

Remove all items.

◆ begin()

template<class T , class O = DefaultOrder>
const_iterator begin ( ) const

Return readonly iterator pointing to the first item (if any)

◆ cbegin()

template<class T , class O = DefaultOrder>
const_iterator cbegin ( ) const

Return readonly iterator pointing to the first item (if any)

◆ end()

template<class T , class O = DefaultOrder>
const_iterator end ( ) const

Return readonly iterator pointing behind the last item

◆ cend()

template<class T , class O = DefaultOrder>
const_iterator cend ( ) const

Return readonly iterator pointing behind the last item

◆ rbegin()

template<class T , class O = DefaultOrder>
const_reverse_iterator rbegin ( ) const

Return readonly reverse iterator pointing to the last item (if any)

◆ crbegin()

template<class T , class O = DefaultOrder>
const_reverse_iterator crbegin ( ) const

Return readonly reverse iterator pointing to the last item (if any)

◆ rend()

template<class T , class O = DefaultOrder>
const_reverse_iterator rend ( ) const

Return reverse iterator pointing before the first item

◆ crend()

template<class T , class O = DefaultOrder>
const_reverse_iterator crend ( ) const

Return reverse iterator pointing before the first item

◆ operator==()

template<class T , class O = DefaultOrder>
template<class Other >
bool operator== ( const Other & other) const

Equality operator.