![]() |
aGrUM
0.16.0
|
Unsafe Iterators for hashtablesHashTableIterator provides a fast but unsafe way to parse 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 | HashTableIterator (const HashTable< Key, Val, Alloc > &tab) noexcept |
template<typename Alloc > | |
INLINE | HashTableIterator (const HashTable< Key, Val, Alloc > &tab, Size ind_elt) |
Constructors / Destructors | |
HashTableIterator () noexcept | |
Basic constructor: creates an iterator pointing to nothing. More... | |
template<typename Alloc > | |
HashTableIterator (const HashTable< Key, Val, Alloc > &tab) noexcept | |
Constructor for an iterator pointing to the first element of a hashtable. More... | |
template<typename Alloc > | |
HashTableIterator (const HashTable< Key, Val, Alloc > &tab, Size ind_elt) | |
Constructor for an iterator pointing to the nth element of a hashtable. More... | |
HashTableIterator (const HashTableIterator< Key, Val > &from) noexcept | |
Copy constructor. More... | |
HashTableIterator (HashTableIterator< Key, Val > &&from) noexcept | |
Move constructor. More... | |
~HashTableIterator () noexcept | |
Class destructor. More... | |
Operators | |
HashTableIterator< Key, Val > & | operator= (const HashTableIterator< Key, Val > &from) noexcept |
Copy operator. More... | |
HashTableIterator< Key, Val > & | operator= (HashTableIterator< Key, Val > &&from) noexcept |
Move operator. More... | |
HashTableIterator< Key, Val > & | operator++ () noexcept |
Makes the iterator point to the next element in the hash table. More... | |
HashTableIterator< Key, Val > & | operator+= (Size i) noexcept |
Makes the iterator point to i elements further in the hashtable. More... | |
HashTableIterator< Key, Val > | operator+ (Size i) const noexcept |
Returns a new iterator. More... | |
bool | operator!= (const HashTableIterator< Key, Val > &from) const noexcept |
Checks whether two iterators are pointing toward different elements. More... | |
bool | operator== (const HashTableIterator< 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 corresponding to the element 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 HashTableConstIterator< Key, Val > &from) const noexcept |
Checks whether two iterators are pointing toward different elements. More... | |
bool | operator== (const HashTableConstIterator< Key, Val > &from) const noexcept |
Checks whether two iterators are pointing toward equal elements. 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 by the iterator in the array of nodes of the hash table. More... | |
HashTable< Key, Val >::Bucket * | __bucket {nullptr} |
The bucket in the chained list pointed to by the iterator. More... | |
Protected Member Functions | |
HashTable< Key, Val >::Bucket * | __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... | |
Unsafe Iterators for hashtables
HashTableIterator provides a fast but unsafe way to parse HashTables.
They should only be used when parsing hashtables in which no element is removed from the hashtable. Removing an element where the iterator points to will mess the iterator as it will most certainly point to an unallocated memory. So, this kind of iterator should only be used when parsing "(key) constant" hash tables, e.g., when we wish to display the content of a hash table or when we wish to update the mapped values of some elements of the hash table without ever modifying their keys.
Developers may consider using HashTable<x,y>::iterator instead of HashTableIterator<x,y>.
Key | The gum::HashTable key. |
Val | The gum::HashTable Value. |
Definition at line 2750 of file hashTable.h.
using gum::HashTableIterator< Key, Val >::const_pointer = const value_type* |
types for STL compliance
Definition at line 2761 of file hashTable.h.
using gum::HashTableIterator< Key, Val >::const_reference = const value_type& |
types for STL compliance
Definition at line 2759 of file hashTable.h.
using gum::HashTableIterator< Key, Val >::difference_type = std::ptrdiff_t |
types for STL compliance
Definition at line 2762 of file hashTable.h.
using gum::HashTableIterator< Key, Val >::iterator_category = std::forward_iterator_tag |
types for STL compliance
Definition at line 2754 of file hashTable.h.
using gum::HashTableIterator< Key, Val >::key_type = Key |
types for STL compliance
Definition at line 2755 of file hashTable.h.
using gum::HashTableIterator< Key, Val >::mapped_type = Val |
types for STL compliance
Definition at line 2756 of file hashTable.h.
using gum::HashTableIterator< Key, Val >::pointer = value_type* |
types for STL compliance
Definition at line 2760 of file hashTable.h.
using gum::HashTableIterator< Key, Val >::reference = value_type& |
types for STL compliance
Definition at line 2758 of file hashTable.h.
using gum::HashTableIterator< Key, Val >::value_type = std::pair< const Key, Val > |
types for STL compliance
Definition at line 2757 of file hashTable.h.
|
noexcept |
Basic constructor: creates an iterator pointing to nothing.
Definition at line 2168 of file hashTable_tpl.h.
|
noexcept |
Constructor for an iterator pointing to the first element of a hashtable.
Alloc | The gum::HashTable allocator. |
tab | The gum::HashTable to iterate over. |
gum::HashTableIterator< Key, Val >::HashTableIterator | ( | 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. |
|
noexcept |
Copy constructor.
from | The gum::HashTableIterator to copy. |
Definition at line 2190 of file hashTable_tpl.h.
|
noexcept |
Move constructor.
from | The gum::HashTableIterator to move. |
Definition at line 2197 of file hashTable_tpl.h.
|
noexcept |
Class destructor.
Definition at line 2204 of file hashTable_tpl.h.
|
noexcept |
Definition at line 2175 of file hashTable_tpl.h.
INLINE gum::HashTableIterator< Key, Val >::HashTableIterator | ( | const HashTable< Key, Val, Alloc > & | tab, |
Size | ind_elt | ||
) |
Definition at line 2183 of file hashTable_tpl.h.
|
protectednoexceptinherited |
Returns the current iterator's bucket.
Definition at line 2154 of file hashTable_tpl.h.
|
protectednoexceptinherited |
Returns the index in the hashtable's node vector pointed to by the iterator.
Definition at line 2159 of file hashTable_tpl.h.
|
noexceptinherited |
Makes the iterator point toward nothing (in particular, it is not related anymore to its current hash table).
Definition at line 2036 of file hashTable_tpl.h.
Referenced by gum::SetIterator< Key >::clear().
|
inherited |
Returns the key corresponding to the element pointed to by the iterator.
Definition at line 2017 of file hashTable_tpl.h.
Referenced by gum::SetIterator< Key >::operator*(), and gum::SetIterator< Key >::operator->().
|
noexceptinherited |
Checks whether two iterators are pointing toward different elements.
from | The gum::HashTableConstIterator to test for inequality. |
Definition at line 2132 of file hashTable_tpl.h.
|
noexcept |
Checks whether two iterators are pointing toward different elements.
from | The gum::HashTableIterator to test for inequality. |
Definition at line 2256 of file hashTable_tpl.h.
INLINE HashTableIterator< Key, Val >::value_type & gum::HashTableIterator< Key, Val >::operator* | ( | ) |
Returns the value pointed to by the iterator.
Definition at line 2268 of file hashTable_tpl.h.
INLINE const HashTableIterator< Key, Val >::value_type & gum::HashTableIterator< Key, Val >::operator* | ( | ) | const |
Returns the value pointed to by the iterator.
Definition at line 2275 of file hashTable_tpl.h.
|
noexcept |
Returns a new iterator.
i | The number of increments. |
Definition at line 2248 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.
Definition at line 2234 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 2241 of file hashTable_tpl.h.
|
noexcept |
Copy operator.
from | The gum::HashTableIterator to copy. |
Definition at line 2220 of file hashTable_tpl.h.
|
noexcept |
Move operator.
from | The gum::HashTableIterator to move. |
Definition at line 2227 of file hashTable_tpl.h.
|
noexceptinherited |
Checks whether two iterators are pointing toward equal elements.
from | The gum::HashTableConstIterator to test for equality. |
Definition at line 2138 of file hashTable_tpl.h.
|
noexcept |
Checks whether two iterators are pointing toward equal elements.
from | The gum::HashTableIterator to test for equality. |
Definition at line 2262 of file hashTable_tpl.h.
|
inherited |
Returns the mapped value pointed to by the iterator.
Definition at line 2027 of file hashTable_tpl.h.
Referenced by gum::HashTableConstIterator< Key, bool >::val().
INLINE HashTableIterator< Key, Val >::mapped_type & gum::HashTableIterator< Key, Val >::val | ( | ) |
Returns the mapped value pointed to by the iterator.
Definition at line 2210 of file hashTable_tpl.h.
Referenced by gum::HashTableIterator< int, int >::val().
|
protectedinherited |
The bucket in the chained list pointed to by the iterator.
Definition at line 2681 of file hashTable.h.
Referenced by gum::HashTableConstIteratorSafe< const gum::DiscreteVariable *, Idx >::operator=().
|
protectedinherited |
The index of the chained list pointed by the iterator in the array of nodes of the hash table.
Definition at line 2678 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 2672 of file hashTable.h.
Referenced by gum::HashTableConstIterator< Key, bool >::HashTableConstIterator(), gum::HashTableConstIteratorSafe< const gum::DiscreteVariable *, Idx >::HashTableConstIteratorSafe(), gum::HashTableConstIteratorSafe< const gum::DiscreteVariable *, Idx >::operator=(), and gum::HashTableConstIterator< Key, bool >::operator=().