aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::SetIterator< Key > Class Template Reference

Unsafe iterators for the Set class. More...

#include <agrum/base/core/set.h>

Collaboration diagram for gum::SetIterator< Key >:

Public Types

enum  Position { BEGIN , END }
 An enumeration to position the iterator at the beginning or the end of the set. More...
using iterator_category = std::forward_iterator_tag
 Types for STL compliance.
using value_type = Key
 Types for STL compliance.
using reference = value_type&
 Types for STL compliance.
using const_reference = const value_type&
 Types for STL compliance.
using pointer = value_type*
 Types for STL compliance.
using const_pointer = const value_type*
 Types for STL compliance.
using difference_type = std::ptrdiff_t
 Types for STL compliance.

Public Member Functions

Constructors / Destructors
 SetIterator () noexcept
 Default constructor: the iterator points toward nothing.
 SetIterator (const Set< Key > &from, Position pos=BEGIN)
 Creates an iterator for a given set.
 SetIterator (const SetIterator< Key > &from) noexcept
 Copy constructor.
 SetIterator (SetIterator< Key > &&from) noexcept
 Move constructor.
 ~SetIterator () noexcept
 Class destructor.
Operators
SetIterator< Key > & operator= (const SetIterator< Key > &from) noexcept
 Assignment operator.
SetIterator< Key > & operator= (SetIterator< Key > &&from) noexcept
 Assignment operator.
SetIterator< Key > & operator++ () noexcept
 Increments the iterator.
SetIterator< Key > & operator+= (Size i) noexcept
 Makes the iterator point to i elements further in the set.
SetIterator< Key > operator+ (Size i) const noexcept
 Returns a new iterator.
bool operator!= (const SetIterator< Key > &from) const noexcept
 Indicates whether two iterators point to different elements or sets.
bool operator== (const SetIterator< Key > &from) const noexcept
 Indicates whether two iterators point toward the same element of a same set.
const Key & operator* () const
 Returns the element pointed to by the iterator.
const Key * operator-> () const
 Returns a pointer to the element pointed to by the iterator.
Accessors / Modifiers
void clear () noexcept
 makes the iterator point toward nothing (in particular, it is not related anymore to its current set).

Private Attributes

HashTableConstIterator< Key, bool_ht_iter_
 The underlying iterator for the set's hash table containing the data.

Friends

class Set< Key >
 For efficiency, Set should be able to modify the hash table iterator.
class SetIteratorSafe< Key >

Detailed Description

template<typename Key>
class gum::SetIterator< Key >

Unsafe iterators for the Set class.

Developers may consider using Set<x>::iterator instead of SetIterator<x>.

Warning
Use SetIterator only if you are sure that the iterator will never point to a deleted element. Pointing to a deleted element will most probably result in a segfault. If you are unsure, prefer using the safe iterators Set<>::iterator_safe.
Usage example:
// creation of a set with 10 elements
for (int i = 0; i< 10; ++i)
set<<i;
// parse the set
for (const auto iter = table.begin (); iter != table.end (); *++iter) {
// display the values
cerr << *iter << endl;
}
// check whether two iterators point toward the same element
Set<int>::iterator iter1 = table1.begin();
Set<int>::iterator iter2 = table1.end();
if (iter1 != iter)
cerr << "iter1 and iter2 point toward different elements";
Representation of a set.
Definition set.h:131
SetIterator< Key > iterator
Types for STL compliance.
Definition set.h:142
Template Parameters
KeyThe elements type.

Definition at line 819 of file set.h.

Member Typedef Documentation

◆ const_pointer

template<typename Key>
using gum::SetIterator< Key >::const_pointer = const value_type*

Types for STL compliance.

Definition at line 828 of file set.h.

◆ const_reference

template<typename Key>
using gum::SetIterator< Key >::const_reference = const value_type&

Types for STL compliance.

Definition at line 826 of file set.h.

◆ difference_type

template<typename Key>
using gum::SetIterator< Key >::difference_type = std::ptrdiff_t

Types for STL compliance.

Definition at line 829 of file set.h.

◆ iterator_category

template<typename Key>
using gum::SetIterator< Key >::iterator_category = std::forward_iterator_tag

Types for STL compliance.

Definition at line 823 of file set.h.

◆ pointer

template<typename Key>
using gum::SetIterator< Key >::pointer = value_type*

Types for STL compliance.

Definition at line 827 of file set.h.

◆ reference

template<typename Key>
using gum::SetIterator< Key >::reference = value_type&

Types for STL compliance.

Definition at line 825 of file set.h.

◆ value_type

template<typename Key>
using gum::SetIterator< Key >::value_type = Key

Types for STL compliance.

Definition at line 824 of file set.h.

Member Enumeration Documentation

◆ Position

template<typename Key>
enum gum::SetIterator::Position

An enumeration to position the iterator at the beginning or the end of the set.

Enumerator
BEGIN 
END 

Definition at line 837 of file set.h.

837{ BEGIN, END };

Constructor & Destructor Documentation

◆ SetIterator() [1/4]

template<typename Key>
INLINE gum::SetIterator< Key >::SetIterator ( )
explicitnoexcept

Default constructor: the iterator points toward nothing.

Definition at line 189 of file set_tpl.h.

189 {
191 }
Unsafe iterators for the Set class.
Definition set.h:819
SetIterator() noexcept
Default constructor: the iterator points toward nothing.
Definition set_tpl.h:189

References SetIterator().

Referenced by SetIterator(), SetIterator(), SetIterator(), SetIterator(), ~SetIterator(), operator!=(), operator+(), operator++(), operator+=(), operator=(), and operator==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetIterator() [2/4]

template<typename Key>
INLINE gum::SetIterator< Key >::SetIterator ( const Set< Key > & from,
Position pos = BEGIN )

Creates an iterator for a given set.

By default, the iterator points to the beginning of the set, but, using optional argument pos, you can make it point to end().

Parameters
fromThe gum::Set to iterator over.
posWhere to start iterating.

Definition at line 195 of file set_tpl.h.

195 :
196 _ht_iter_{pos == SetIterator< Key >::END ? set._inside_.cend() : set._inside_.cbegin()} {
198 }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set's hash table containing the data.
Definition set.h:981

References SetIterator(), _ht_iter_, END, and Set< Key >.

Here is the call graph for this function:

◆ SetIterator() [3/4]

template<typename Key>
INLINE gum::SetIterator< Key >::SetIterator ( const SetIterator< Key > & from)
noexcept

Copy constructor.

Parameters
fromThe iterator to copy.

Definition at line 202 of file set_tpl.h.

202 :
205 }

References SetIterator(), and _ht_iter_.

Here is the call graph for this function:

◆ SetIterator() [4/4]

template<typename Key>
INLINE gum::SetIterator< Key >::SetIterator ( SetIterator< Key > && from)
noexcept

Move constructor.

Parameters
fromThe iterator to move.

Definition at line 209 of file set_tpl.h.

References SetIterator(), and _ht_iter_.

Here is the call graph for this function:

◆ ~SetIterator()

template<typename Key>
INLINE gum::SetIterator< Key >::~SetIterator ( )
noexcept

Class destructor.

Definition at line 216 of file set_tpl.h.

216 {
218 }

References SetIterator().

Here is the call graph for this function:

Member Function Documentation

◆ clear()

template<typename Key>
INLINE void gum::SetIterator< Key >::clear ( )
noexcept

makes the iterator point toward nothing (in particular, it is not related anymore to its current set).

Definition at line 290 of file set_tpl.h.

290 {
291 _ht_iter_.clear();
292 }

References _ht_iter_.

Referenced by Set< Key >.

Here is the caller graph for this function:

◆ operator!=()

template<typename Key>
INLINE bool gum::SetIterator< Key >::operator!= ( const SetIterator< Key > & from) const
noexcept

Indicates whether two iterators point to different elements or sets.

Parameters
fromThe iterator to test for inequality.
Returns
Returns true if both iterator are not equal.

Definition at line 260 of file set_tpl.h.

260 {
261 return _ht_iter_ != from._ht_iter_;
262 }

References SetIterator(), and _ht_iter_.

Here is the call graph for this function:

◆ operator*()

template<typename Key>
INLINE const Key & gum::SetIterator< Key >::operator* ( ) const

Returns the element pointed to by the iterator.

Exceptions
UndefinedIteratorValueRaised if the iterator does not point to an element of the set (for instance if the set or the element previously pointed to by the iterator have been deleted).
Returns
Returns the element pointed to by the iterator.

Definition at line 273 of file set_tpl.h.

273 {
274 // note that, if the hashtable's iterator points toward nothing, it will
275 // raise an UndefinedIteratorValue exception
276 return _ht_iter_.key();
277 }

References _ht_iter_.

◆ operator+()

template<typename Key>
INLINE SetIterator< Key > gum::SetIterator< Key >::operator+ ( Size i) const
noexcept

Returns a new iterator.

Parameters
iThe number of increments.
Returns
Returns a new iterator.

Definition at line 254 of file set_tpl.h.

254 {
255 return SetIterator< Key >{*this} += nb;
256 }

References SetIterator().

Here is the call graph for this function:

◆ operator++()

template<typename Key>
INLINE SetIterator< Key > & gum::SetIterator< Key >::operator++ ( )
noexcept

Increments the iterator.

Returns
This iterator.

Definition at line 237 of file set_tpl.h.

237 {
238 // note that, if the hashtable's iterator points toward nothing, the
239 // hashtable's iterator incrementation will do nothing. In particular, it
240 // will not segfault.
241 ++_ht_iter_;
242 return *this;
243 }

References SetIterator().

Here is the call graph for this function:

◆ operator+=()

template<typename Key>
INLINE SetIterator< Key > & gum::SetIterator< Key >::operator+= ( Size i)
noexcept

Makes the iterator point to i elements further in the set.

Parameters
iThe number of increments.
Returns
Returns this iterator.

Definition at line 247 of file set_tpl.h.

247 {
248 _ht_iter_ += nb;
249 return *this;
250 }

References SetIterator(), and _ht_iter_.

Here is the call graph for this function:

◆ operator->()

template<typename Key>
INLINE const Key * gum::SetIterator< Key >::operator-> ( ) const

Returns a pointer to the element pointed to by the iterator.

Exceptions
UndefinedIteratorValueRaised if the iterator does not point to an element of the set (for instance if the set or the element previously pointed to by the iterator have been deleted).
Returns
Returns a pointer to the element pointed to by the iterator.

Definition at line 281 of file set_tpl.h.

281 {
282 // note that, if the hashtable's iterator points toward nothing, it will
283 // raise an UndefinedIteratorValue exception
284 return &(_ht_iter_.key());
285 }

◆ operator=() [1/2]

template<typename Key>
INLINE SetIterator< Key > & gum::SetIterator< Key >::operator= ( const SetIterator< Key > & from)
noexcept

Assignment operator.

Parameters
fromThe iterator to copy.
Returns
Returns this iterator.

Definition at line 223 of file set_tpl.h.

223 {
225 return *this;
226 }

References SetIterator(), and _ht_iter_.

Here is the call graph for this function:

◆ operator=() [2/2]

template<typename Key>
INLINE SetIterator< Key > & gum::SetIterator< Key >::operator= ( SetIterator< Key > && from)
noexcept

Assignment operator.

Parameters
fromThe iterator to copy.
Returns
Returns this iterator.

Definition at line 230 of file set_tpl.h.

230 {
232 return *this;
233 }

◆ operator==()

template<typename Key>
INLINE bool gum::SetIterator< Key >::operator== ( const SetIterator< Key > & from) const
noexcept

Indicates whether two iterators point toward the same element of a same set.

Parameters
fromThe iterator to test for equality.
Returns
Returns true if both iterator are equal.

Definition at line 267 of file set_tpl.h.

267 {
268 return _ht_iter_ == from._ht_iter_;
269 }

References SetIterator(), and _ht_iter_.

Here is the call graph for this function:

◆ Set< Key >

template<typename Key>
friend class Set< Key >
friend

For efficiency, Set should be able to modify the hash table iterator.

Definition at line 971 of file set.h.

References clear().

Referenced by SetIterator().

◆ SetIteratorSafe< Key >

template<typename Key>
friend class SetIteratorSafe< Key >
friend

Definition at line 971 of file set.h.

Member Data Documentation

◆ _ht_iter_

template<typename Key>
HashTableConstIterator< Key, bool > gum::SetIterator< Key >::_ht_iter_
private

The underlying iterator for the set's hash table containing the data.

Definition at line 981 of file set.h.

Referenced by SetIterator(), SetIterator(), SetIterator(), clear(), operator!=(), operator*(), operator+=(), operator=(), gum::SetIteratorSafe< Key >::operator=(), and operator==().


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