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

Unsafe iterators for the Set class. More...

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

+ Collaboration diagram for gum::SetIterator< Key >:

Public Member Functions

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

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. More...
 
using value_type = Key
 Types for STL compliance. More...
 
using reference = value_type &
 Types for STL compliance. More...
 
using const_reference = const value_type &
 Types for STL compliance. More...
 
using pointer = value_type *
 Types for STL compliance. More...
 
using const_pointer = const value_type *
 Types for STL compliance. More...
 
using difference_type = std::ptrdiff_t
 Types for STL compliance. More...
 

Friends

template<typename K , typename A >
class Set
 For efficiency, Set should be able to modify the hash table iterator. More...
 
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
Set<int> set;
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";
Template Parameters
KeyThe elements type.

Definition at line 1034 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 1043 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 1041 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 1044 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 1038 of file set.h.

◆ pointer

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

Types for STL compliance.

Definition at line 1042 of file set.h.

◆ reference

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

Types for STL compliance.

Definition at line 1040 of file set.h.

◆ value_type

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

Types for STL compliance.

Definition at line 1039 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 1051 of file set.h.

1052  {
1053  BEGIN,
1054  END
1055  };

Constructor & Destructor Documentation

◆ SetIterator() [1/5]

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

Default constructor: the iterator points toward nothing.

Definition at line 169 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

169  {
170  GUM_CONSTRUCTOR(SetIterator);
171  }
SetIterator() noexcept
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:169
+ Here is the call graph for this function:

◆ SetIterator() [2/5]

template<typename Key >
template<typename Alloc >
gum::SetIterator< Key >::SetIterator ( const Set< Key, Alloc > &  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().

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

◆ SetIterator() [3/5]

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

Copy constructor.

Parameters
fromThe iterator to copy.

Definition at line 183 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

183  :
184  _ht_iter_{iter._ht_iter_} {
185  GUM_CONS_CPY(SetIterator);
186  }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
SetIterator() noexcept
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:169
+ Here is the call graph for this function:

◆ SetIterator() [4/5]

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

Move constructor.

Parameters
fromThe iterator to move.

Definition at line 190 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

190  :
191  _ht_iter_{std::move(from._ht_iter_)} {
192  GUM_CONS_MOV(SetIterator);
193  }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
SetIterator() noexcept
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:169
+ Here is the call graph for this function:

◆ ~SetIterator()

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

Class destructor.

Definition at line 197 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

197  {
198  GUM_DESTRUCTOR(SetIterator);
199  }
SetIterator() noexcept
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:169
+ Here is the call graph for this function:

◆ SetIterator() [5/5]

template<typename Key >
template<typename Alloc >
INLINE gum::SetIterator< Key >::SetIterator ( const Set< Key, Alloc > &  set,
Position  pos 
)

Definition at line 176 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

176  :
177  _ht_iter_{pos == SetIterator< Key >::END ? set._inside_.cend() : set._inside_.cbegin()} {
178  GUM_CONSTRUCTOR(SetIterator);
179  }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
SetIterator() noexcept
Default constructor: the iterator points toward nothing.
Definition: set_tpl.h:169
+ 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 271 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

271  {
272  _ht_iter_.clear();
273  }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
void clear() noexcept
Makes the iterator point toward nothing (in particular, it is not related anymore to its current hash...
+ Here is the call 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 241 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

241  {
242  return _ht_iter_ != from._ht_iter_;
243  }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
+ 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 254 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

254  {
255  // note that, if the hashtable's iterator points toward nothing, it will
256  // raise an UndefinedIteratorValue exception
257  return _ht_iter_.key();
258  }
const key_type & key() const
Returns the key corresponding to the element pointed to by the iterator.
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
+ Here is the call graph for this function:

◆ 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 235 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

235  {
236  return SetIterator< Key >{*this} += nb;
237  }
+ 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 218 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

218  {
219  // note that, if the hashtable's iterator points toward nothing, the
220  // hashtable's iterator incrementation will do nothing. In particular, it
221  // will not segfault.
222  ++_ht_iter_;
223  return *this;
224  }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
+ 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 228 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

228  {
229  _ht_iter_ += nb;
230  return *this;
231  }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
+ 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 262 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

262  {
263  // note that, if the hashtable's iterator points toward nothing, it will
264  // raise an UndefinedIteratorValue exception
265  return &(_ht_iter_.key());
266  }
const key_type & key() const
Returns the key corresponding to the element pointed to by the iterator.
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
+ Here is the call graph for this function:

◆ 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 204 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

204  {
205  _ht_iter_ = from._ht_iter_;
206  return *this;
207  }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
+ 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 211 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

211  {
212  _ht_iter_ = std::move(from._ht_iter_);
213  return *this;
214  }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
+ Here is the call 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 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 248 of file set_tpl.h.

References gum::Set< Key, Alloc >::emplace().

248  {
249  return _ht_iter_ == from._ht_iter_;
250  }
HashTableConstIterator< Key, bool > _ht_iter_
The underlying iterator for the set&#39;s hash table containing the data.
Definition: set.h:1196
+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ Set

template<typename Key >
template<typename K , typename A >
friend class Set
friend

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

Definition at line 1192 of file set.h.

◆ SetIteratorSafe< Key >

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

Definition at line 1193 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 1196 of file set.h.


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