![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
Safe Iterators for hashtables. More...
#include <agrum/base/core/hashTable.h>
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. / template < typename Key, typename Val > class HashTableIteratorSafe: public HashTableConstIteratorSafe< Key, Val > { public: /// Types for STL compliance. /// @{ using iterator_category = std::forward_iterator_tag; using key_type = Key; using mapped_type = Val; using value_type = std::pair< const Key, Val >; using reference = value_type&; using const_reference = const value_type&; using pointer = value_type*; using const_pointer = const value_type*; using difference_type = std::ptrdiff_t; /// @} |
// ============================================================================ /// @name Constructors / Destructors // ============================================================================ /// @{
/**
// DOXYGEN_SHOULD_SKIP_THIS
/**
/**
| tab | the hash table to which the so-called element belongs |
| ind_elt | the position of the element in the hash table (0 means |
| UndefinedIteratorValue | Raised if the element cannot be found */ HashTableIteratorSafe(const HashTable< Key, Val >& tab, Size ind_elt); |
| from | the gum::HashTableIteratorSafe to copy. |
| from | the gum::HashTableIterator to copy. |
| from | The gum::HashTableIteratorSafe to move. |
/// @} // ============================================================================ /// @name Accessors / Modifiers // ============================================================================ /// @{
/// Usefull Alias /// @{ using HashTableConstIteratorSafe< Key, Val >::key; using HashTableConstIteratorSafe< Key, Val >::val; using HashTableConstIteratorSafe< Key, Val >::clear; /// @}
/**
| UndefinedIteratorValue | Raised when the iterator does not point |
/// @} // ============================================================================ /// @name Operators // ============================================================================ /// @{
/**
| from | The gum::HashTableIteratorSafe to copy. |
| from | The gum::HashTableIterator to copy. |
| from | The gum::HashTableIteratorSafe to move. |
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.