aGrUM  0.16.0
gum::HashTableIteratorSafe< Key, Val > Class Template Reference

Safe Iterators for hashtables. More...

#include <agrum/core/hashTable.h>

+ Inheritance diagram for gum::HashTableIteratorSafe< Key, Val >:
+ Collaboration diagram for gum::HashTableIteratorSafe< Key, Val >:

Public Member Functions

mapped_typeval ()
 Returns the mapped value pointed to by the iterator. More...
 
template<typename Alloc >
INLINE HashTableIteratorSafe (const HashTable< Key, Val, Alloc > &tab)
 
template<typename Alloc >
INLINE HashTableIteratorSafe (const HashTable< Key, Val, Alloc > &tab, Size ind_elt)
 
Constructors / Destructors
 HashTableIteratorSafe ()
 Basic constructor: creates an iterator pointing to nothing. More...
 
template<typename Alloc >
 HashTableIteratorSafe (const HashTable< Key, Val, Alloc > &tab)
 Constructor for an iterator pointing to the first element of a hashtable. More...
 
template<typename Alloc >
 HashTableIteratorSafe (const HashTable< Key, Val, Alloc > &tab, Size ind_elt)
 Constructor for an iterator pointing to the nth element of a hashtable. More...
 
 HashTableIteratorSafe (const HashTableIteratorSafe< Key, Val > &from)
 Copy constructor. More...
 
 HashTableIteratorSafe (const HashTableIterator< Key, Val > &from)
 Copy constructor. More...
 
 HashTableIteratorSafe (HashTableIteratorSafe< Key, Val > &&from) noexcept
 Move constructor. More...
 
 ~HashTableIteratorSafe () noexcept
 Class destructor. More...
 
Operators
HashTableIteratorSafe< Key, Val > & operator= (const HashTableIteratorSafe< Key, Val > &from)
 Copy operator. More...
 
HashTableIteratorSafe< Key, Val > & operator= (const HashTableIterator< Key, Val > &from)
 Copy operator. More...
 
HashTableIteratorSafe< Key, Val > & operator= (HashTableIteratorSafe< Key, Val > &&from) noexcept
 Move operator. More...
 
HashTableIteratorSafe< Key, Val > & operator++ () noexcept
 Makes the iterator point to the next element in the hash table. More...
 
HashTableIteratorSafe< Key, Val > & operator+= (Size i) noexcept
 Makes the iterator point to i elements further in the hashtable. More...
 
HashTableIteratorSafe< Key, Val > operator+ (Size i) const
 Returns a new iterator pointing to i elements further in the hashtable. More...
 
bool operator!= (const HashTableIteratorSafe< Key, Val > &from) const noexcept
 Checks whether two iterators are pointing toward different elements. More...
 
bool operator== (const HashTableIteratorSafe< Key, Val > &from) const noexcept
 Checks whether two iterators are pointing toward equal elements. More...
 
value_typeoperator* ()
 Returns the value pointed to by the iterator. More...
 
const value_typeoperator* () const
 Returns the value pointed to by the iterator. More...
 
Accessors / Modifiers
const key_typekey () const
 Returns the key pointed to by the iterator. More...
 
const mapped_typeval () const
 Returns the mapped value pointed to by the iterator. More...
 
void clear () noexcept
 Makes the iterator point toward nothing (in particular, it is not related anymore to its current hash table). More...
 
Operators
bool operator!= (const HashTableConstIteratorSafe< Key, Val > &from) const noexcept
 Checks whether two iterators are not equal. More...
 
bool operator== (const HashTableConstIteratorSafe< Key, Val > &from) const noexcept
 Checks whether two iterators are equal. More...
 

Public Types

using iterator_category = std::forward_iterator_tag
 Types for STL compliance. More...
 
using key_type = Key
 Types for STL compliance. More...
 
using mapped_type = Val
 Types for STL compliance. More...
 
using value_type = std::pair< const Key, Val >
 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...
 

Protected Attributes

const HashTable< Key, Val > * __table {nullptr}
 The hash table the iterator is pointing to. More...
 
Size __index {Size(0)}
 the index of the chained list pointed to by the iterator in the array __nodes of the hash table. More...
 
HashTableBucket< Key, Val > * __bucket {nullptr}
 The bucket in the chained list pointed to by the iterator. More...
 
HashTableBucket< Key, Val > * __next_bucket {nullptr}
 the bucket we should start from when we decide to do a ++. More...
 

Protected Member Functions

HashTableBucket< Key, Val > * __getBucket () const noexcept
 Returns the current iterator's bucket. More...
 
Size __getIndex () const noexcept
 Returns the index in the hashtable's node vector pointed to by the iterator. More...
 
void __removeFromSafeList () const
 Removes the iterator from its hashtable' safe iterators list. More...
 
void __insertIntoSafeList () const
 Insert the iterator into the hashtable's list of safe iterators. More...
 

Detailed Description

template<typename Key, typename Val>
class gum::HashTableIteratorSafe< Key, Val >

Safe Iterators for hashtables.

HashTableIteratorSafe provides a safe way to parse HashTables. They are safe because they are kept informed by the hashtable they belong to of the elements deleted by the user. Hence, even if the user removes an element pointed to by a HashTableIteratorSafe, using the latter to access this element will never crash the application. Instead it will properly throw an UndefinedIteratorValue exception.

Developers may consider using HashTable<x,y>::iterator_safe instead of HashTableIteratorSafe<x,y>.

Usage example:
// creation of a hash table with 10 elements
HashTable<int,string> table;
for (int i = 0; i< 10; ++i)
table.insert (i,"xxx" + string (i,'x'));
// parse the hash table
for (HashTable<int,string>::iterator_safe iter = table.beginSafe ();
iter != table.endSafe (); ++iter) {
// display the values
cerr << "at " << iter.key() << " value = " << iter.val () << endl;
std::pair<const int, string>& xelt = *iter;
}
// check whether two iterators point toward the same element
HashTable<int,string>::iterator_safe iter1 = table1.beginSafe ();
HashTable<int,string>::iterator_safe iter2 = table1.endSafe ();
if (iter1 != iter) {
cerr << "iter1 and iter2 point toward different elements";
}
// make iter1 point toward nothing
iter1.clear ();
Template Parameters
KeyThe gum::HashTable key.
ValThe gum::HashTable Value.

Definition at line 2220 of file hashTable.h.

Member Typedef Documentation

◆ const_pointer

template<typename Key, typename Val>
using gum::HashTableIteratorSafe< Key, Val >::const_pointer = const value_type*

Types for STL compliance.

Definition at line 2231 of file hashTable.h.

◆ const_reference

template<typename Key, typename Val>
using gum::HashTableIteratorSafe< Key, Val >::const_reference = const value_type&

Types for STL compliance.

Definition at line 2229 of file hashTable.h.

◆ difference_type

template<typename Key, typename Val>
using gum::HashTableIteratorSafe< Key, Val >::difference_type = std::ptrdiff_t

Types for STL compliance.

Definition at line 2232 of file hashTable.h.

◆ iterator_category

template<typename Key, typename Val>
using gum::HashTableIteratorSafe< Key, Val >::iterator_category = std::forward_iterator_tag

Types for STL compliance.

Definition at line 2224 of file hashTable.h.

◆ key_type

template<typename Key, typename Val>
using gum::HashTableIteratorSafe< Key, Val >::key_type = Key

Types for STL compliance.

Definition at line 2225 of file hashTable.h.

◆ mapped_type

template<typename Key, typename Val>
using gum::HashTableIteratorSafe< Key, Val >::mapped_type = Val

Types for STL compliance.

Definition at line 2226 of file hashTable.h.

◆ pointer

template<typename Key, typename Val>
using gum::HashTableIteratorSafe< Key, Val >::pointer = value_type*

Types for STL compliance.

Definition at line 2230 of file hashTable.h.

◆ reference

template<typename Key, typename Val>
using gum::HashTableIteratorSafe< Key, Val >::reference = value_type&

Types for STL compliance.

Definition at line 2228 of file hashTable.h.

◆ value_type

template<typename Key, typename Val>
using gum::HashTableIteratorSafe< Key, Val >::value_type = std::pair< const Key, Val >

Types for STL compliance.

Definition at line 2227 of file hashTable.h.

Constructor & Destructor Documentation

◆ HashTableIteratorSafe() [1/8]

template<typename Key , typename Val >
INLINE gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe ( )

Basic constructor: creates an iterator pointing to nothing.

Definition at line 1749 of file hashTable_tpl.h.

1749  :
1750  HashTableConstIteratorSafe< Key, Val >() {
1751  GUM_CONSTRUCTOR(HashTableIteratorSafe);
1752  }
HashTableIteratorSafe()
Basic constructor: creates an iterator pointing to nothing.

◆ HashTableIteratorSafe() [2/8]

template<typename Key, typename Val>
template<typename Alloc >
gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe ( const HashTable< Key, Val, Alloc > &  tab)

Constructor for an iterator pointing to the first element of a hashtable.

Template Parameters
AllocThe gum::HashTable allocator.

◆ HashTableIteratorSafe() [3/8]

template<typename Key, typename Val>
template<typename Alloc >
gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe ( const HashTable< Key, Val, Alloc > &  tab,
Size  ind_elt 
)

Constructor for an iterator pointing to the nth element of a hashtable.

The method runs in time linear to ind_elt.

Parameters
tabthe hash table to which the so-called element belongs
ind_eltthe position of the element in the hash table (0 means the first element).
Template Parameters
AllocThe gum::HashTable allocator.
Exceptions
UndefinedIteratorValueRaised if the element cannot be found

◆ HashTableIteratorSafe() [4/8]

template<typename Key, typename Val>
INLINE gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe ( const HashTableIteratorSafe< Key, Val > &  from)

Copy constructor.

Parameters
fromthe gum::HashTableIteratorSafe to copy.
Returns
This gum::HashTableIteratorSafe.

Definition at line 1771 of file hashTable_tpl.h.

1772  :
1773  HashTableConstIteratorSafe< Key, Val >(from) {
1774  GUM_CONS_CPY(HashTableIteratorSafe);
1775  }
HashTableIteratorSafe()
Basic constructor: creates an iterator pointing to nothing.

◆ HashTableIteratorSafe() [5/8]

template<typename Key, typename Val>
INLINE gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe ( const HashTableIterator< Key, Val > &  from)
explicit

Copy constructor.

Parameters
fromthe gum::HashTableIterator to copy.
Returns
This gum::HashTableIteratorSafe.

Definition at line 1778 of file hashTable_tpl.h.

1779  :
1780  HashTableConstIteratorSafe< Key, Val >(from) {
1781  GUM_CONS_CPY(HashTableIteratorSafe);
1782  }
HashTableIteratorSafe()
Basic constructor: creates an iterator pointing to nothing.

◆ HashTableIteratorSafe() [6/8]

template<typename Key, typename Val>
INLINE gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe ( HashTableIteratorSafe< Key, Val > &&  from)
noexcept

Move constructor.

Parameters
fromThe gum::HashTableIteratorSafe to move.
Returns
Returns this gum::HashTableIteratorSafe.

Definition at line 1785 of file hashTable_tpl.h.

1786  :
1787  HashTableConstIteratorSafe< Key, Val >(std::move(from)) {
1788  GUM_CONS_MOV(HashTableIteratorSafe);
1789  }
HashTableIteratorSafe()
Basic constructor: creates an iterator pointing to nothing.

◆ ~HashTableIteratorSafe()

template<typename Key , typename Val >
INLINE gum::HashTableIteratorSafe< Key, Val >::~HashTableIteratorSafe ( )
noexcept

Class destructor.

Definition at line 1792 of file hashTable_tpl.h.

1792  {
1793  GUM_DESTRUCTOR(HashTableIteratorSafe);
1794  }
HashTableIteratorSafe()
Basic constructor: creates an iterator pointing to nothing.

◆ HashTableIteratorSafe() [7/8]

template<typename Key, typename Val>
template<typename Alloc >
INLINE gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe ( const HashTable< Key, Val, Alloc > &  tab)

Definition at line 1756 of file hashTable_tpl.h.

1757  :
1758  HashTableConstIteratorSafe< Key, Val >(tab) {
1759  GUM_CONSTRUCTOR(HashTableIteratorSafe);
1760  }
HashTableIteratorSafe()
Basic constructor: creates an iterator pointing to nothing.

◆ HashTableIteratorSafe() [8/8]

template<typename Key, typename Val>
template<typename Alloc >
INLINE gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe ( const HashTable< Key, Val, Alloc > &  tab,
Size  ind_elt 
)

Definition at line 1764 of file hashTable_tpl.h.

1765  :
1766  HashTableConstIteratorSafe< Key, Val >(tab, ind_elt) {
1767  GUM_CONSTRUCTOR(HashTableIteratorSafe);
1768  }
HashTableIteratorSafe()
Basic constructor: creates an iterator pointing to nothing.

Member Function Documentation

◆ __getBucket()

template<typename Key , typename Val >
INLINE HashTableBucket< Key, Val > * gum::HashTableConstIteratorSafe< Key, Val >::__getBucket ( ) const
protectednoexceptinherited

Returns the current iterator's bucket.

Definition at line 1735 of file hashTable_tpl.h.

Referenced by gum::HashTable< Val, Size, IndexAllocator >::erase().

1735  {
1736  return __bucket;
1737  }
HashTableBucket< Key, Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: hashTable.h:2135
+ Here is the caller graph for this function:

◆ __getIndex()

template<typename Key , typename Val >
INLINE Size gum::HashTableConstIteratorSafe< Key, Val >::__getIndex ( ) const
protectednoexceptinherited

Returns the index in the hashtable's node vector pointed to by the iterator.

Returns
Returns the index in the hashtable's node vector pointed to by the iterator.

Definition at line 1740 of file hashTable_tpl.h.

Referenced by gum::HashTable< Val, Size, IndexAllocator >::erase().

1740  {
1741  return __index;
1742  }
Size __index
the index of the chained list pointed to by the iterator in the array __nodes of the hash table...
Definition: hashTable.h:2132
+ Here is the caller graph for this function:

◆ __insertIntoSafeList()

template<typename Key , typename Val >
INLINE void gum::HashTableConstIteratorSafe< Key, Val >::__insertIntoSafeList ( ) const
protectedinherited

Insert the iterator into the hashtable's list of safe iterators.

Definition at line 1287 of file hashTable_tpl.h.

1287  {
1288  __table->__safe_iterators.push_back(
1289  const_cast< HashTableConstIteratorSafe< Key, Val >* >(this));
1290  }
std::vector< HashTableConstIteratorSafe< Key, Val > *> __safe_iterators
The list of safe iterators pointing to the hash table.
Definition: hashTable.h:1753
const HashTable< Key, Val > * __table
The hash table the iterator is pointing to.
Definition: hashTable.h:2126

◆ __removeFromSafeList()

template<typename Key , typename Val >
INLINE void gum::HashTableConstIteratorSafe< Key, Val >::__removeFromSafeList ( ) const
protectedinherited

Removes the iterator from its hashtable' safe iterators list.

Definition at line 1294 of file hashTable_tpl.h.

1294  {
1295  if (__table == nullptr) return;
1296 
1297  // find where the iterator is
1298  std::vector< HashTableConstIteratorSafe< Key, Val >* >& iter_vect =
1300 
1301  auto len = iter_vect.size();
1302  for (Size i = Size(0); i < len; ++i) {
1303  if (iter_vect[i] == this) {
1304  iter_vect.erase(iter_vect.begin() + i);
1305  break;
1306  }
1307  }
1308  }
std::vector< HashTableConstIteratorSafe< Key, Val > *> __safe_iterators
The list of safe iterators pointing to the hash table.
Definition: hashTable.h:1753
const HashTable< Key, Val > * __table
The hash table the iterator is pointing to.
Definition: hashTable.h:2126
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48

◆ clear()

template<typename Key , typename Val >
INLINE void gum::HashTableConstIteratorSafe< Key, Val >::clear ( )
noexceptinherited

Makes the iterator point toward nothing (in particular, it is not related anymore to its current hash table).

It is mainly used by the hashtable when the latter is deleted while the iterator is still alive.

Definition at line 1583 of file hashTable_tpl.h.

1583  {
1584  // remove the iterator from the table's iterator list
1586 
1587  // set its table as well as the element it points to to 0
1588  __table = nullptr;
1589  __bucket = nullptr;
1590  __next_bucket = nullptr;
1591  __index = Size(0);
1592  }
Size __index
the index of the chained list pointed to by the iterator in the array __nodes of the hash table...
Definition: hashTable.h:2132
HashTableBucket< Key, Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: hashTable.h:2135
void __removeFromSafeList() const
Removes the iterator from its hashtable&#39; safe iterators list.
const HashTable< Key, Val > * __table
The hash table the iterator is pointing to.
Definition: hashTable.h:2126
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
HashTableBucket< Key, Val > * __next_bucket
the bucket we should start from when we decide to do a ++.
Definition: hashTable.h:2145

◆ key()

template<typename Key , typename Val >
INLINE const HashTableConstIteratorSafe< Key, Val >::key_type & gum::HashTableConstIteratorSafe< Key, Val >::key ( ) const
inherited

Returns the key pointed to by the iterator.

Returns
Returns the key pointed to by the iterator.
Exceptions
UndefinedIteratorValueRaised when the iterator does not point to a valid hash table element

Definition at line 1564 of file hashTable_tpl.h.

Referenced by gum::SetTerminalNodePolicy< GUM_SCALAR >::id(), and gum::HashTableConstIteratorSafe< const gum::DiscreteVariable *, Idx >::key().

1564  {
1565  if (__bucket != nullptr)
1566  return __bucket->key();
1567  else {
1568  GUM_ERROR(UndefinedIteratorValue, "Accessing a nullptr object");
1569  }
1570  }
HashTableBucket< Key, Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: hashTable.h:2135
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ operator!=() [1/2]

template<typename Key, typename Val>
INLINE bool gum::HashTableConstIteratorSafe< Key, Val >::operator!= ( const HashTableConstIteratorSafe< Key, Val > &  from) const
noexceptinherited

Checks whether two iterators are not equal.

Parameters
fromfrom The iterator to test for inequality.
Returns
Returns true if from and this iterator are inequal.

Definition at line 1711 of file hashTable_tpl.h.

1712  {
1713  return ((__bucket != from.__bucket) || (__index != from.__index));
1714  }
Size __index
the index of the chained list pointed to by the iterator in the array __nodes of the hash table...
Definition: hashTable.h:2132
HashTableBucket< Key, Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: hashTable.h:2135

◆ operator!=() [2/2]

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

Checks whether two iterators are pointing toward different elements.

Parameters
fromThe gum::HashTableIteratorSafe to test for inequality.
Returns
Returns true if this and from are not equal.

Definition at line 1849 of file hashTable_tpl.h.

1849  {
1851  }
bool operator!=(const HashTableConstIteratorSafe< Key, Val > &from) const noexcept
Checks whether two iterators are not equal.

◆ operator*() [1/2]

template<typename Key , typename Val >
INLINE HashTableIteratorSafe< Key, Val >::value_type & gum::HashTableIteratorSafe< Key, Val >::operator* ( )

Returns the value pointed to by the iterator.

Returns
Returns the value pointed to by the iterator.
Exceptions
UndefinedIteratorValueRaised when the iterator does not point to a valid hash table element

Definition at line 1861 of file hashTable_tpl.h.

1861  {
1862  return const_cast< Val& >(HashTableConstIteratorSafe< Key, Val >::operator*());
1863  }
const value_type & operator*() const
Returns the element pointed to by the iterator.

◆ operator*() [2/2]

template<typename Key , typename Val >
INLINE const HashTableIteratorSafe< Key, Val >::value_type & gum::HashTableIteratorSafe< Key, Val >::operator* ( ) const

Returns the value pointed to by the iterator.

Returns
Returns the value pointed to by the iterator.
Exceptions
UndefinedIteratorValueRaised when the iterator does not point to a valid hash table element.

Definition at line 1867 of file hashTable_tpl.h.

1867  {
1869  }
const value_type & operator*() const
Returns the element pointed to by the iterator.

◆ operator+()

template<typename Key , typename Val >
INLINE HashTableIteratorSafe< Key, Val > gum::HashTableIteratorSafe< Key, Val >::operator+ ( Size  i) const

Returns a new iterator pointing to i elements further in the hashtable.

Parameters
iThe number of increments.
Returns
Returns this gum::HashTableIteratorSafe.

Definition at line 1841 of file hashTable_tpl.h.

1841  {
1842  HashTableIteratorSafe< Key, Val > iter{*this};
1843  iter += nb;
1844  return iter;
1845  }

◆ operator++()

template<typename Key , typename Val >
INLINE HashTableIteratorSafe< Key, Val > & gum::HashTableIteratorSafe< Key, Val >::operator++ ( )
noexcept

Makes the iterator point to the next element in the hash table.

for (iter = hash.beginSafe (); iter != hash.endSafe (); ++iter) { }

The above loop is guaranteed to parse the whole hash table as long as no element is added to or deleted from the hash table while being in the loop. Deleting elements during the loop is guaranteed to never produce a segmentation fault.

Returns
This gum::HashTableIteratorSafe.

Definition at line 1827 of file hashTable_tpl.h.

1827  {
1829  return *this;
1830  }
HashTableConstIteratorSafe< Key, Val > & operator++() noexcept
Makes the iterator point to the next element in the hash table.

◆ operator+=()

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

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

Parameters
iThe number of increments.
Returns
Return this gum::HashTableIteratorSafe.

Definition at line 1834 of file hashTable_tpl.h.

1834  {
1836  return *this;
1837  }
HashTableConstIteratorSafe< Key, Val > & operator+=(Size i) noexcept
Makes the iterator point to i elements further in the hashtable.

◆ operator=() [1/3]

template<typename Key, typename Val>
INLINE HashTableIteratorSafe< Key, Val > & gum::HashTableIteratorSafe< Key, Val >::operator= ( const HashTableIteratorSafe< Key, Val > &  from)

Copy operator.

Parameters
fromThe gum::HashTableIteratorSafe to copy.
Returns
Returns this gum::HashTableIterator.

Definition at line 1804 of file hashTable_tpl.h.

1804  {
1805  GUM_OP_CPY(HashTableIteratorSafe);
1807  return *this;
1808  }
HashTableConstIteratorSafe< Key, Val > & operator=(const HashTableConstIteratorSafe< Key, Val > &from)
Copy operator.
HashTableIteratorSafe()
Basic constructor: creates an iterator pointing to nothing.

◆ operator=() [2/3]

template<typename Key, typename Val>
INLINE HashTableIteratorSafe< Key, Val > & gum::HashTableIteratorSafe< Key, Val >::operator= ( const HashTableIterator< Key, Val > &  from)

Copy operator.

Parameters
fromThe gum::HashTableIterator to copy.
Returns
Returns this gum::HashTableIterator.

Definition at line 1812 of file hashTable_tpl.h.

1812  {
1813  GUM_OP_CPY(HashTableIteratorSafe);
1815  return *this;
1816  }
HashTableConstIteratorSafe< Key, Val > & operator=(const HashTableConstIteratorSafe< Key, Val > &from)
Copy operator.
HashTableIteratorSafe()
Basic constructor: creates an iterator pointing to nothing.

◆ operator=() [3/3]

template<typename Key, typename Val>
INLINE HashTableIteratorSafe< Key, Val > & gum::HashTableIteratorSafe< Key, Val >::operator= ( HashTableIteratorSafe< Key, Val > &&  from)
noexcept

Move operator.

Parameters
fromThe gum::HashTableIteratorSafe to move.
Returns
Returns this gum::HashTableIterator.

Definition at line 1820 of file hashTable_tpl.h.

1820  {
1822  return *this;
1823  }
HashTableConstIteratorSafe< Key, Val > & operator=(const HashTableConstIteratorSafe< Key, Val > &from)
Copy operator.

◆ operator==() [1/2]

template<typename Key, typename Val>
INLINE bool gum::HashTableConstIteratorSafe< Key, Val >::operator== ( const HashTableConstIteratorSafe< Key, Val > &  from) const
noexceptinherited

Checks whether two iterators are equal.

Parameters
fromfrom The iterator to test for equality.
Returns
Returns true if from and this iterator are equal.

Definition at line 1718 of file hashTable_tpl.h.

1719  {
1720  return ((__bucket == from.__bucket) && (__index == from.__index));
1721  }
Size __index
the index of the chained list pointed to by the iterator in the array __nodes of the hash table...
Definition: hashTable.h:2132
HashTableBucket< Key, Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: hashTable.h:2135

◆ operator==() [2/2]

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

Checks whether two iterators are pointing toward equal elements.

Parameters
fromThe gum::HashTableIteratorSafe to test for equality.
Returns
Returns true if this and from are equal.

Definition at line 1855 of file hashTable_tpl.h.

1855  {
1857  }
bool operator==(const HashTableConstIteratorSafe< Key, Val > &from) const noexcept
Checks whether two iterators are equal.

◆ val() [1/2]

template<typename Key , typename Val >
INLINE const HashTableConstIteratorSafe< Key, Val >::mapped_type & gum::HashTableConstIteratorSafe< Key, Val >::val ( ) const
inherited

Returns the mapped value pointed to by the iterator.

Returns
Returns the mapped value pointed to by the iterator.
Exceptions
UndefinedIteratorValueRaised when the iterator does not point to a valid hash table element.

Definition at line 1574 of file hashTable_tpl.h.

Referenced by gum::HashTableConstIteratorSafe< const gum::DiscreteVariable *, Idx >::val(), and gum::SetTerminalNodePolicy< GUM_SCALAR >::value().

1574  {
1575  if (__bucket != nullptr)
1576  return __bucket->val();
1577  else {
1578  GUM_ERROR(UndefinedIteratorValue, "Accessing a nullptr object");
1579  }
1580  }
HashTableBucket< Key, Val > * __bucket
The bucket in the chained list pointed to by the iterator.
Definition: hashTable.h:2135
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ val() [2/2]

template<typename Key , typename Val >
INLINE HashTableIteratorSafe< Key, Val >::mapped_type & gum::HashTableIteratorSafe< Key, Val >::val ( )

Returns the mapped value pointed to by the iterator.

Returns
Returns the mapped value pointed to by the iterator.
Exceptions
UndefinedIteratorValueRaised when the iterator does not point to a valid hash table element.

Definition at line 1798 of file hashTable_tpl.h.

1798  {
1799  return const_cast< Val& >(HashTableConstIteratorSafe< Key, Val >::val());
1800  }
const mapped_type & val() const
Returns the mapped value pointed to by the iterator.

Member Data Documentation

◆ __bucket

template<typename Key, typename Val>
HashTableBucket< Key, Val >* gum::HashTableConstIteratorSafe< Key, Val >::__bucket {nullptr}
protectedinherited

The bucket in the chained list pointed to by the iterator.

Definition at line 2135 of file hashTable.h.

Referenced by gum::HashTableConstIteratorSafe< const gum::DiscreteVariable *, Idx >::operator=().

◆ __index

template<typename Key, typename Val>
Size gum::HashTableConstIteratorSafe< Key, Val >::__index {Size(0)}
protectedinherited

the index of the chained list pointed to by the iterator in the array __nodes of the hash table.

Definition at line 2132 of file hashTable.h.

Referenced by gum::HashTableConstIteratorSafe< const gum::DiscreteVariable *, Idx >::operator=().

◆ __next_bucket

template<typename Key, typename Val>
HashTableBucket< Key, Val >* gum::HashTableConstIteratorSafe< Key, Val >::__next_bucket {nullptr}
protectedinherited

the bucket we should start from when we decide to do a ++.

Usually it should be equal to nullptr. However, if the user has deleted the object pointed to by bucket, this will point to another bucket. When it is equal to nullptr, it means that the bucket reached after a ++ belongs to another slot of the hash table's '__node' vector.

Definition at line 2145 of file hashTable.h.

Referenced by gum::HashTableConstIteratorSafe< const gum::DiscreteVariable *, Idx >::operator=().

◆ __table

template<typename Key, typename Val>
const HashTable< Key, Val >* gum::HashTableConstIteratorSafe< Key, Val >::__table {nullptr}
protectedinherited

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