![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
Safe Const Iterators for hashtables. More...
#include <agrum/base/core/hashTable.h>
Public Types | |
| using | iterator_category = std::forward_iterator_tag |
| Types for STL compliance. | |
| using | key_type = Key |
| Types for STL compliance. | |
| using | mapped_type = Val |
| Types for STL compliance. | |
| using | value_type = std::pair< const Key, Val > |
| 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 | |
| HashTableConstIteratorSafe () | |
| Basic constructor: creates an iterator pointing to nothing. | |
| HashTableConstIteratorSafe (const HashTable< Key, Val > &tab) | |
| Constructor for an iterator pointing to the first element of a hashtable. | |
| HashTableConstIteratorSafe (const HashTable< Key, Val > &tab, Size ind_elt) | |
| Constructor for an iterator pointing to the nth element of a hashtable. | |
| HashTableConstIteratorSafe (const HashTableConstIteratorSafe< Key, Val > &from) | |
| Copy constructor. | |
| HashTableConstIteratorSafe (const HashTableConstIterator< Key, Val > &from) | |
| Copy constructor. | |
| HashTableConstIteratorSafe (HashTableConstIteratorSafe< Key, Val > &&from) | |
| Move constructor. | |
| ~HashTableConstIteratorSafe () noexcept | |
| Destructor. | |
Accessors / Modifiers | |
| const key_type & | key () const |
| Returns the key pointed to by the iterator. | |
| const mapped_type & | val () const |
| Returns the mapped value pointed to by the iterator. | |
| void | clear () noexcept |
| Makes the iterator point toward nothing (in particular, it is not related anymore to its current hash table). | |
Operators | |
| HashTableConstIteratorSafe< Key, Val > & | operator= (const HashTableConstIteratorSafe< Key, Val > &from) |
| Copy operator. | |
| HashTableConstIteratorSafe< Key, Val > & | operator= (const HashTableConstIterator< Key, Val > &from) |
| Copy operator. | |
| HashTableConstIteratorSafe< Key, Val > & | operator= (HashTableConstIteratorSafe< Key, Val > &&from) noexcept |
| Move operator. | |
| HashTableConstIteratorSafe< Key, Val > & | operator++ () noexcept |
| Makes the iterator point to the next element in the hash table. | |
| HashTableConstIteratorSafe< Key, Val > & | operator+= (Size i) noexcept |
| Makes the iterator point to i elements further in the hashtable. | |
| HashTableConstIteratorSafe< Key, Val > | operator+ (Size i) const |
| Returns a new iterator poiting to i elements further in the hashtable. | |
| bool | operator!= (const HashTableConstIteratorSafe< Key, Val > &from) const noexcept |
| Checks whether two iterators are not equal. | |
| bool | operator== (const HashTableConstIteratorSafe< Key, Val > &from) const noexcept |
| Checks whether two iterators are equal. | |
| const value_type & | operator* () const |
| Returns the element pointed to by the iterator. | |
Protected Member Functions | |
| HashTableBucket< Key, Val > * | _getBucket_ () const noexcept |
| Returns the current iterator's bucket. | |
| Size | _getIndex_ () const noexcept |
| Returns the index in the hashtable's node vector pointed to by the iterator. | |
| void | _removeFromSafeList_ () const |
| Removes the iterator from its hashtable' safe iterators list. | |
| void | _insertIntoSafeList_ () const |
| Insert the iterator into the hashtable's list of safe iterators. | |
Protected Attributes | |
| const HashTable< Key, Val > * | _table_ {nullptr} |
| The hash table the iterator is pointing to. | |
| Size | _index_ {Size(0)} |
| the index of the chained list pointed to by the iterator in the array nodes of the hash table. | |
| HashTableBucket< Key, Val > * | _bucket_ {nullptr} |
| The bucket in the chained list pointed to by the iterator. | |
| HashTableBucket< Key, Val > * | _next_bucket_ {nullptr} |
| the bucket we should start from when we decide to do a ++. | |
Friends | |
| class | HashTable< Key, Val > |
| Class HashTable must be a friend because it stores iterator end and this can be properly initialized only when the hashtable has been fully allocated. | |
Safe Const Iterators for hashtables.
HashTableConstIteratorSafe 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 HashTableConstIteratorSafe, using the latter to access this element will never crash the application. Instead it will properly throw a UndefinedIteratorValue exception.
Developers may consider using HashTable<x,y>::const_iterator_safe instead of HashTableConstIteratorSafe<x,y>.
Definition at line 1602 of file hashTable.h.
| using gum::HashTableConstIteratorSafe< Key, Val >::const_pointer = const value_type* |
Types for STL compliance.
Definition at line 1613 of file hashTable.h.
| using gum::HashTableConstIteratorSafe< Key, Val >::const_reference = const value_type& |
Types for STL compliance.
Definition at line 1611 of file hashTable.h.
| using gum::HashTableConstIteratorSafe< Key, Val >::difference_type = std::ptrdiff_t |
Types for STL compliance.
Definition at line 1614 of file hashTable.h.
| using gum::HashTableConstIteratorSafe< Key, Val >::iterator_category = std::forward_iterator_tag |
Types for STL compliance.
Definition at line 1606 of file hashTable.h.
| using gum::HashTableConstIteratorSafe< Key, Val >::key_type = Key |
Types for STL compliance.
Definition at line 1607 of file hashTable.h.
| using gum::HashTableConstIteratorSafe< Key, Val >::mapped_type = Val |
Types for STL compliance.
Definition at line 1608 of file hashTable.h.
| using gum::HashTableConstIteratorSafe< Key, Val >::pointer = value_type* |
Types for STL compliance.
Definition at line 1612 of file hashTable.h.
| using gum::HashTableConstIteratorSafe< Key, Val >::reference = value_type& |
Types for STL compliance.
Definition at line 1610 of file hashTable.h.
| using gum::HashTableConstIteratorSafe< Key, Val >::value_type = std::pair< const Key, Val > |
Types for STL compliance.
Definition at line 1609 of file hashTable.h.
|
explicit |
Basic constructor: creates an iterator pointing to nothing.
Definition at line 1035 of file hashTable_tpl.h.
Referenced by HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), ~HashTableConstIteratorSafe(), operator!=(), operator+(), operator=(), operator=(), operator=(), and operator==().
| INLINE gum::HashTableConstIteratorSafe< Key, Val >::HashTableConstIteratorSafe | ( | const HashTable< Key, Val > & | tab | ) |
Constructor for an iterator pointing to the first element of a hashtable.
| tab | A gum::HashTable to iterate over. |
Definition at line 1041 of file hashTable_tpl.h.
References HashTableConstIteratorSafe(), _insertIntoSafeList_(), _table_, and HashTable< Key, Val >.
| gum::HashTableConstIteratorSafe< Key, Val >::HashTableConstIteratorSafe | ( | const HashTable< Key, Val > & | 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). |
| UndefinedIteratorValue | Raised if the element cannot be found. |
Definition at line 1070 of file hashTable_tpl.h.
References _table_, and HashTable< Key, Val >.
| INLINE gum::HashTableConstIteratorSafe< Key, Val >::HashTableConstIteratorSafe | ( | const HashTableConstIteratorSafe< Key, Val > & | from | ) |
Copy constructor.
| from | The gum::HashTableConstIteratorSafe to copy. |
Definition at line 1130 of file hashTable_tpl.h.
References HashTableConstIteratorSafe(), _bucket_, _index_, _insertIntoSafeList_(), _next_bucket_, and _table_.
|
explicit |
Copy constructor.
| from | The gum::HashTableConstIterator to copy. |
Definition at line 1142 of file hashTable_tpl.h.
References HashTableConstIteratorSafe(), _bucket_, _index_, _insertIntoSafeList_(), and _table_.
| INLINE gum::HashTableConstIteratorSafe< Key, Val >::HashTableConstIteratorSafe | ( | HashTableConstIteratorSafe< Key, Val > && | from | ) |
Move constructor.
| from | The gum::HashTableConstIteratorSafe to move. |
Definition at line 1153 of file hashTable_tpl.h.
References HashTableConstIteratorSafe(), _bucket_, _index_, _next_bucket_, and _table_.
|
noexcept |
Destructor.
Definition at line 1175 of file hashTable_tpl.h.
References HashTableConstIteratorSafe(), and _removeFromSafeList_().
|
protectednoexcept |
Returns the current iterator's bucket.
Definition at line 1433 of file hashTable_tpl.h.
References _bucket_.
Referenced by gum::HashTable< Key, Val >::erase().
|
protectednoexcept |
Returns the index in the hashtable's node vector pointed to by the iterator.
Definition at line 1438 of file hashTable_tpl.h.
References _index_.
Referenced by gum::HashTable< Key, Val >::erase().
|
protected |
Insert the iterator into the hashtable's list of safe iterators.
Definition at line 1013 of file hashTable_tpl.h.
Referenced by HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), and operator=().
|
protected |
Removes the iterator from its hashtable' safe iterators list.
Definition at line 1019 of file hashTable_tpl.h.
References _table_.
Referenced by ~HashTableConstIteratorSafe(), operator=(), and operator=().
|
noexcept |
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 1290 of file hashTable_tpl.h.
| INLINE const HashTableConstIteratorSafe< Key, Val >::key_type & gum::HashTableConstIteratorSafe< Key, Val >::key | ( | ) | const |
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 1277 of file hashTable_tpl.h.
References _bucket_.
|
noexcept |
Checks whether two iterators are not equal.
| from | from The iterator to test for inequality. |
Definition at line 1413 of file hashTable_tpl.h.
References HashTableConstIteratorSafe(), _bucket_, HashTableConstIterator< Key, Val >::_bucket_, _index_, and HashTableConstIterator< Key, Val >::_index_.
| INLINE const HashTableConstIteratorSafe< Key, Val >::value_type & gum::HashTableConstIteratorSafe< Key, Val >::operator* | ( | ) | const |
Returns the element pointed to by the iterator.
| UndefinedIteratorValue | Raised when the iterator does not point to a valid hash table element. |
Definition at line 1426 of file hashTable_tpl.h.
| INLINE HashTableConstIteratorSafe< Key, Val > gum::HashTableConstIteratorSafe< Key, Val >::operator+ | ( | Size | i | ) | const |
Returns a new iterator poiting to i elements further in the hashtable.
| i | The number of steps to increment the gum::HashTableConstIteratorSafe. |
Definition at line 1408 of file hashTable_tpl.h.
References HashTableConstIteratorSafe().
|
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 1305 of file hashTable_tpl.h.
|
noexcept |
Makes the iterator point to i elements further in the hashtable.
| i | The number of steps to increment the gum::HashTableConstIteratorSafe. |
Definition at line 1364 of file hashTable_tpl.h.
References _bucket_, _index_, _next_bucket_, and _table_.
Referenced by gum::HashTable< const gum::DiscreteVariable *, Idx >::_create_().
| HashTableConstIteratorSafe< Key, Val > & gum::HashTableConstIteratorSafe< Key, Val >::operator= | ( | const HashTableConstIterator< Key, Val > & | from | ) |
Copy operator.
| from | The gum::HashTableConstIterator to copy. |
Definition at line 1211 of file hashTable_tpl.h.
References HashTableConstIteratorSafe(), _table_, and HashTableConstIterator< Key, Val >::_table_.
| HashTableConstIteratorSafe< Key, Val > & gum::HashTableConstIteratorSafe< Key, Val >::operator= | ( | const HashTableConstIteratorSafe< Key, Val > & | from | ) |
Copy operator.
| from | The gum::HashTableConstIteratorSafe to copy. |
Definition at line 1184 of file hashTable_tpl.h.
References HashTableConstIteratorSafe(), _bucket_, _index_, _insertIntoSafeList_(), _next_bucket_, _removeFromSafeList_(), and _table_.
Referenced by gum::HashTable< const gum::DiscreteVariable *, Idx >::_erase_().
|
noexcept |
Move operator.
| from | The gum::HashTableConstIteratorSafe to move. |
Definition at line 1238 of file hashTable_tpl.h.
References HashTableConstIteratorSafe(), _bucket_, HashTableConstIterator< Key, Val >::_bucket_, _index_, HashTableConstIterator< Key, Val >::_index_, _next_bucket_, _removeFromSafeList_(), _table_, and HashTableConstIterator< Key, Val >::_table_.
|
noexcept |
Checks whether two iterators are equal.
| from | from The iterator to test for equality. |
Definition at line 1419 of file hashTable_tpl.h.
References HashTableConstIteratorSafe(), _bucket_, HashTableConstIterator< Key, Val >::_bucket_, _index_, and HashTableConstIterator< Key, Val >::_index_.
| INLINE const HashTableConstIteratorSafe< Key, Val >::mapped_type & gum::HashTableConstIteratorSafe< Key, Val >::val | ( | ) | const |
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 1284 of file hashTable_tpl.h.
Class HashTable must be a friend because it stores iterator end and this can be properly initialized only when the hashtable has been fully allocated.
Thus, proper initialization can only take place within the constructor's code of the hashtable.
Definition at line 1793 of file hashTable.h.
Referenced by HashTableConstIteratorSafe(), and HashTableConstIteratorSafe().
|
protected |
The bucket in the chained list pointed to by the iterator.
Definition at line 1816 of file hashTable.h.
Referenced by HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), _getBucket_(), key(), operator!=(), operator*(), operator+=(), operator=(), operator=(), operator==(), and val().
|
protected |
the index of the chained list pointed to by the iterator in the array nodes of the hash table.
Definition at line 1813 of file hashTable.h.
Referenced by HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), _getIndex_(), operator!=(), operator+=(), operator=(), operator=(), and operator==().
|
protected |
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 1826 of file hashTable.h.
Referenced by HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), operator+=(), operator=(), and operator=().
|
protected |
The hash table the iterator is pointing to.
Definition at line 1807 of file hashTable.h.
Referenced by HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), HashTableConstIteratorSafe(), _removeFromSafeList_(), operator+=(), operator=(), operator=(), and operator=().