![]() |
aGrUM
0.16.0
|
Safe Iterators for hashtables. More...
#include <agrum/core/hashTable.h>
Public Member Functions | |
mapped_type & | val () |
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_type & | operator* () |
Returns the value pointed to by the iterator. More... | |
const value_type & | operator* () const |
Returns the value pointed to by the iterator. More... | |
Accessors / Modifiers | |
const key_type & | key () const |
Returns the key pointed to by the iterator. More... | |
const mapped_type & | val () 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... | |
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>.
Key | The gum::HashTable key. |
Val | The gum::HashTable Value. |
Definition at line 2220 of file hashTable.h.
using gum::HashTableIteratorSafe< Key, Val >::const_pointer = const value_type* |
Types for STL compliance.
Definition at line 2231 of file hashTable.h.
using gum::HashTableIteratorSafe< Key, Val >::const_reference = const value_type& |
Types for STL compliance.
Definition at line 2229 of file hashTable.h.
using gum::HashTableIteratorSafe< Key, Val >::difference_type = std::ptrdiff_t |
Types for STL compliance.
Definition at line 2232 of file hashTable.h.
using gum::HashTableIteratorSafe< Key, Val >::iterator_category = std::forward_iterator_tag |
Types for STL compliance.
Definition at line 2224 of file hashTable.h.
using gum::HashTableIteratorSafe< Key, Val >::key_type = Key |
Types for STL compliance.
Definition at line 2225 of file hashTable.h.
using gum::HashTableIteratorSafe< Key, Val >::mapped_type = Val |
Types for STL compliance.
Definition at line 2226 of file hashTable.h.
using gum::HashTableIteratorSafe< Key, Val >::pointer = value_type* |
Types for STL compliance.
Definition at line 2230 of file hashTable.h.
using gum::HashTableIteratorSafe< Key, Val >::reference = value_type& |
Types for STL compliance.
Definition at line 2228 of file hashTable.h.
using gum::HashTableIteratorSafe< Key, Val >::value_type = std::pair< const Key, Val > |
Types for STL compliance.
Definition at line 2227 of file hashTable.h.
INLINE gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe | ( | ) |
Basic constructor: creates an iterator pointing to nothing.
Definition at line 1749 of file hashTable_tpl.h.
gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe | ( | const HashTable< Key, Val, Alloc > & | tab | ) |
Constructor for an iterator pointing to the first element of a hashtable.
Alloc | The gum::HashTable allocator. |
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.
tab | the hash table to which the so-called element belongs |
ind_elt | the position of the element in the hash table (0 means the first element). |
Alloc | The gum::HashTable allocator. |
UndefinedIteratorValue | Raised if the element cannot be found |
INLINE gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe | ( | const HashTableIteratorSafe< Key, Val > & | from | ) |
Copy constructor.
from | the gum::HashTableIteratorSafe to copy. |
Definition at line 1771 of file hashTable_tpl.h.
|
explicit |
Copy constructor.
from | the gum::HashTableIterator to copy. |
Definition at line 1778 of file hashTable_tpl.h.
|
noexcept |
Move constructor.
from | The gum::HashTableIteratorSafe to move. |
Definition at line 1785 of file hashTable_tpl.h.
|
noexcept |
Class destructor.
Definition at line 1792 of file hashTable_tpl.h.
INLINE gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe | ( | const HashTable< Key, Val, Alloc > & | tab | ) |
Definition at line 1756 of file hashTable_tpl.h.
INLINE gum::HashTableIteratorSafe< Key, Val >::HashTableIteratorSafe | ( | const HashTable< Key, Val, Alloc > & | tab, |
Size | ind_elt | ||
) |
Definition at line 1764 of file hashTable_tpl.h.
|
protectednoexceptinherited |
Returns the current iterator's bucket.
Definition at line 1735 of file hashTable_tpl.h.
Referenced by gum::HashTable< Val, Size, IndexAllocator >::erase().
|
protectednoexceptinherited |
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().
|
protectedinherited |
Insert the iterator into the hashtable's list of safe iterators.
Definition at line 1287 of file hashTable_tpl.h.
|
protectedinherited |
Removes the iterator from its hashtable' safe iterators list.
Definition at line 1294 of file hashTable_tpl.h.
|
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.
|
inherited |
Returns the key pointed to by the iterator.
UndefinedIteratorValue | Raised 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().
|
noexceptinherited |
Checks whether two iterators are not equal.
from | from The iterator to test for inequality. |
Definition at line 1711 of file hashTable_tpl.h.
|
noexcept |
Checks whether two iterators are pointing toward different elements.
from | The gum::HashTableIteratorSafe to test for inequality. |
Definition at line 1849 of file hashTable_tpl.h.
INLINE HashTableIteratorSafe< Key, Val >::value_type & gum::HashTableIteratorSafe< Key, Val >::operator* | ( | ) |
Returns the value pointed to by the iterator.
UndefinedIteratorValue | Raised when the iterator does not point to a valid hash table element |
Definition at line 1861 of file hashTable_tpl.h.
INLINE const HashTableIteratorSafe< Key, Val >::value_type & gum::HashTableIteratorSafe< Key, Val >::operator* | ( | ) | const |
Returns the value pointed to by the iterator.
UndefinedIteratorValue | Raised when the iterator does not point to a valid hash table element. |
Definition at line 1867 of file hashTable_tpl.h.
INLINE HashTableIteratorSafe< Key, Val > gum::HashTableIteratorSafe< Key, Val >::operator+ | ( | Size | i | ) | const |
Returns a new iterator pointing to i elements further in the hashtable.
i | The number of increments. |
Definition at line 1841 of file hashTable_tpl.h.
|
noexcept |
Makes the iterator point to the next element in the hash table.
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.
Definition at line 1827 of file hashTable_tpl.h.
|
noexcept |
Makes the iterator point to i elements further in the hashtable.
i | The number of increments. |
Definition at line 1834 of file hashTable_tpl.h.
INLINE HashTableIteratorSafe< Key, Val > & gum::HashTableIteratorSafe< Key, Val >::operator= | ( | const HashTableIteratorSafe< Key, Val > & | from | ) |
Copy operator.
from | The gum::HashTableIteratorSafe to copy. |
Definition at line 1804 of file hashTable_tpl.h.
INLINE HashTableIteratorSafe< Key, Val > & gum::HashTableIteratorSafe< Key, Val >::operator= | ( | const HashTableIterator< Key, Val > & | from | ) |
Copy operator.
from | The gum::HashTableIterator to copy. |
Definition at line 1812 of file hashTable_tpl.h.
|
noexcept |
Move operator.
from | The gum::HashTableIteratorSafe to move. |
Definition at line 1820 of file hashTable_tpl.h.
|
noexceptinherited |
Checks whether two iterators are equal.
from | from The iterator to test for equality. |
Definition at line 1718 of file hashTable_tpl.h.
|
noexcept |
Checks whether two iterators are pointing toward equal elements.
from | The gum::HashTableIteratorSafe to test for equality. |
Definition at line 1855 of file hashTable_tpl.h.
|
inherited |
Returns the mapped value pointed to by the iterator.
UndefinedIteratorValue | Raised 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().
INLINE HashTableIteratorSafe< Key, Val >::mapped_type & gum::HashTableIteratorSafe< Key, Val >::val | ( | ) |
Returns the mapped value pointed to by the iterator.
UndefinedIteratorValue | Raised when the iterator does not point to a valid hash table element. |
Definition at line 1798 of file hashTable_tpl.h.
|
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=().
|
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=().
|
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=().
|
protectedinherited |
The hash table the iterator is pointing to.
Definition at line 2126 of file hashTable.h.
Referenced by gum::HashTableConstIteratorSafe< const gum::DiscreteVariable *, Idx >::HashTableConstIteratorSafe(), and gum::HashTableConstIteratorSafe< const gum::DiscreteVariable *, Idx >::operator=().