![]() |
aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
|
Safe Const Iterators for hashtables. More...
#include <agrum/tools/core/hashTable.h>
Public Member Functions | |
template<typename Alloc > | |
INLINE | HashTableConstIteratorSafe (const HashTable< Key, Val, Alloc > &tab) |
Constructors / Destructors | |
HashTableConstIteratorSafe () | |
Basic constructor: creates an iterator pointing to nothing. More... | |
template<typename Alloc > | |
HashTableConstIteratorSafe (const HashTable< Key, Val, Alloc > &tab) | |
Constructor for an iterator pointing to the first element of a hashtable. More... | |
template<typename Alloc > | |
HashTableConstIteratorSafe (const HashTable< Key, Val, Alloc > &tab, Size ind_elt) | |
Constructor for an iterator pointing to the nth element of a hashtable. More... | |
HashTableConstIteratorSafe (const HashTableConstIteratorSafe< Key, Val > &from) | |
Copy constructor. More... | |
HashTableConstIteratorSafe (const HashTableConstIterator< Key, Val > &from) | |
Copy constructor. More... | |
HashTableConstIteratorSafe (HashTableConstIteratorSafe< Key, Val > &&from) | |
Move constructor. More... | |
~HashTableConstIteratorSafe () noexcept | |
Destructor. 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 | |
HashTableConstIteratorSafe< Key, Val > & | operator= (const HashTableConstIteratorSafe< Key, Val > &from) |
Copy operator. More... | |
HashTableConstIteratorSafe< Key, Val > & | operator= (const HashTableConstIterator< Key, Val > &from) |
Copy operator. More... | |
HashTableConstIteratorSafe< Key, Val > & | operator= (HashTableConstIteratorSafe< Key, Val > &&from) noexcept |
Move operator. More... | |
HashTableConstIteratorSafe< Key, Val > & | operator++ () noexcept |
Makes the iterator point to the next element in the hash table. More... | |
HashTableConstIteratorSafe< Key, Val > & | operator+= (Size i) noexcept |
Makes the iterator point to i elements further in the hashtable. More... | |
HashTableConstIteratorSafe< Key, Val > | operator+ (Size i) const |
Returns a new iterator poiting to i elements further in the hashtable. More... | |
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... | |
const value_type & | operator* () const |
Returns the element pointed to by the iterator. 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... | |
Friends | |
template<typename K , typename V , typename A > | |
class | HashTable |
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. More... | |
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 1922 of file hashTable.h.
using gum::HashTableConstIteratorSafe< Key, Val >::const_pointer = const value_type* |
Types for STL compliance.
Definition at line 1933 of file hashTable.h.
using gum::HashTableConstIteratorSafe< Key, Val >::const_reference = const value_type& |
Types for STL compliance.
Definition at line 1931 of file hashTable.h.
using gum::HashTableConstIteratorSafe< Key, Val >::difference_type = std::ptrdiff_t |
Types for STL compliance.
Definition at line 1934 of file hashTable.h.
using gum::HashTableConstIteratorSafe< Key, Val >::iterator_category = std::forward_iterator_tag |
Types for STL compliance.
Definition at line 1926 of file hashTable.h.
using gum::HashTableConstIteratorSafe< Key, Val >::key_type = Key |
Types for STL compliance.
Definition at line 1927 of file hashTable.h.
using gum::HashTableConstIteratorSafe< Key, Val >::mapped_type = Val |
Types for STL compliance.
Definition at line 1928 of file hashTable.h.
using gum::HashTableConstIteratorSafe< Key, Val >::pointer = value_type* |
Types for STL compliance.
Definition at line 1932 of file hashTable.h.
using gum::HashTableConstIteratorSafe< Key, Val >::reference = value_type& |
Types for STL compliance.
Definition at line 1930 of file hashTable.h.
using gum::HashTableConstIteratorSafe< Key, Val >::value_type = std::pair< const Key, Val > |
Types for STL compliance.
Definition at line 1929 of file hashTable.h.
INLINE gum::HashTableConstIteratorSafe< Key, Val >::HashTableConstIteratorSafe | ( | ) |
Basic constructor: creates an iterator pointing to nothing.
Definition at line 1322 of file hashTable_tpl.h.
gum::HashTableConstIteratorSafe< Key, Val >::HashTableConstIteratorSafe | ( | const HashTable< Key, Val, Alloc > & | tab | ) |
Constructor for an iterator pointing to the first element of a hashtable.
Alloc | The gum::HashTable allocator. |
tab | A gum::HashTable to iterate over. |
gum::HashTableConstIteratorSafe< Key, Val >::HashTableConstIteratorSafe | ( | 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.
Alloc | The gum::HashTable allocator. |
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 1359 of file hashTable_tpl.h.
INLINE gum::HashTableConstIteratorSafe< Key, Val >::HashTableConstIteratorSafe | ( | const HashTableConstIteratorSafe< Key, Val > & | from | ) |
Copy constructor.
from | The gum::HashTableConstIteratorSafe to copy. |
Definition at line 1422 of file hashTable_tpl.h.
|
explicit |
Copy constructor.
from | The gum::HashTableConstIterator to copy. |
Definition at line 1435 of file hashTable_tpl.h.
INLINE gum::HashTableConstIteratorSafe< Key, Val >::HashTableConstIteratorSafe | ( | HashTableConstIteratorSafe< Key, Val > && | from | ) |
Move constructor.
from | The gum::HashTableConstIteratorSafe to move. |
Definition at line 1447 of file hashTable_tpl.h.
|
noexcept |
Destructor.
Definition at line 1473 of file hashTable_tpl.h.
INLINE gum::HashTableConstIteratorSafe< Key, Val >::HashTableConstIteratorSafe | ( | const HashTable< Key, Val, Alloc > & | tab | ) |
Definition at line 1329 of file hashTable_tpl.h.
|
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 1597 of file hashTable_tpl.h.
|
protectednoexcept |
Returns the current iterator's bucket.
Definition at line 1747 of file hashTable_tpl.h.
|
protectednoexcept |
Returns the index in the hashtable's node vector pointed to by the iterator.
Definition at line 1752 of file hashTable_tpl.h.
|
protected |
Insert the iterator into the hashtable's list of safe iterators.
Definition at line 1298 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 1578 of file hashTable_tpl.h.
|
noexcept |
Checks whether two iterators are not equal.
from | from The iterator to test for inequality. |
Definition at line 1724 of file hashTable_tpl.h.
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 1737 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 1719 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 1612 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 1673 of file hashTable_tpl.h.
HashTableConstIteratorSafe< Key, Val > & gum::HashTableConstIteratorSafe< Key, Val >::operator= | ( | const HashTableConstIteratorSafe< Key, Val > & | from | ) |
Copy operator.
from | The gum::HashTableConstIteratorSafe to copy. |
Definition at line 1483 of file hashTable_tpl.h.
HashTableConstIteratorSafe< Key, Val > & gum::HashTableConstIteratorSafe< Key, Val >::operator= | ( | const HashTableConstIterator< Key, Val > & | from | ) |
Copy operator.
from | The gum::HashTableConstIterator to copy. |
Definition at line 1511 of file hashTable_tpl.h.
|
noexcept |
Move operator.
from | The gum::HashTableConstIteratorSafe to move. |
Definition at line 1539 of file hashTable_tpl.h.
|
noexcept |
Checks whether two iterators are equal.
from | from The iterator to test for equality. |
Definition at line 1730 of file hashTable_tpl.h.
|
protected |
Removes the iterator from its hashtable' safe iterators list.
Definition at line 1305 of file hashTable_tpl.h.
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 1588 of file hashTable_tpl.h.
|
friend |
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 2127 of file hashTable.h.
|
protected |
The bucket in the chained list pointed to by the iterator.
Definition at line 2139 of file hashTable.h.
|
protected |
the index of the chained list pointed to by the iterator in the array nodes__ of the hash table.
Definition at line 2136 of file hashTable.h.
|
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 2149 of file hashTable.h.
|
protected |
The hash table the iterator is pointing to.
Definition at line 2130 of file hashTable.h.