![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
A chained list used by gum::HashTable. More...
#include <agrum/base/core/hashTable.h>
Public Types | |
| 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 | size_type = Size |
| types for STL compliance | |
| using | Bucket = HashTableBucket< Key, Val > |
| types for STL compliance | |
Public Member Functions | |
Constructors / Destructors | |
| HashTableList () noexcept | |
| Basic constructor that creates an empty list. | |
| HashTableList (const HashTableList< Key, Val > &from) | |
| Copy constructor. | |
| HashTableList (HashTableList< Key, Val > &&from) noexcept | |
| Move constructor. | |
| ~HashTableList () | |
| Class destructor. | |
Operators | |
| HashTableList< Key, Val > & | operator= (const HashTableList< Key, Val > &from) |
| Assignment operator. | |
| HashTableList< Key, Val > & | operator= (HashTableList< Key, Val > &&from) noexcept |
| Move operator. | |
Accessors / Modifiers | |
| value_type & | at (Size i) |
| Function at returns the ith element in the current chained list. | |
| const value_type & | at (Size i) const |
| Function at returns the ith element in the current chained list. | |
| mapped_type & | operator[] (const key_type &key) |
| Returns the value corresponding to a given key. | |
| const mapped_type & | operator[] (const key_type &key) const |
| Returns the value corresponding to a given key. | |
| bool | exists (const key_type &key) const |
| Returns true if a value with the given key exists. | |
| void | insert (Bucket *new_elt) noexcept |
| Inserts a new element in the chained list. | |
| void | erase (Bucket *ptr) |
| Removes an element from this chained list. | |
| void | clear () |
| Removes all the elements of this chained list. | |
| bool | empty () const noexcept |
| Returns true if this chained list is empty. | |
| Bucket * | bucket (const Key &key) const |
| A method to get the bucket corresponding to a given key. | |
Private Member Functions | |
| void | _copy_ (const HashTableList< Key, Val > &from) |
| A function used to perform copies of HashTableLists. | |
Private Attributes | |
| HashTableBucket< Key, Val > * | _deb_list_ {nullptr} |
| A pointer on the first element of the chained list. | |
| HashTableBucket< Key, Val > * | _end_list_ {nullptr} |
| A pointer on the last element of the chained list. | |
| Size | _nb_elements_ {Size(0)} |
| The number of elements in the chained list. | |
Friends | |
| class | HashTable< Key, Val > |
| Friend for faster access. | |
| class | HashTableIterator< Key, Val > |
| Friend for faster access. | |
| class | HashTableConstIterator< Key, Val > |
| Friend for faster access. | |
| class | HashTableIteratorSafe< Key, Val > |
| Friend for faster access. | |
| class | HashTableConstIteratorSafe< Key, Val > |
| Friend for faster access. | |
| std::ostream & | operator<< (std::ostream &s, const HashTableList< Key, Val > &list) |
| Prints the content of a gum::HashTableList in the stream. | |
| std::ostream & | operator<< (std::ostream &s, const HashTableList< Key *, Val > &list) |
| Prints the content of a gum::HashTableList with pointers key in the stream. | |
| std::ostream & | operator<< (std::ostream &s, const HashTable< Key, Val > &table) |
| Prints the content of a gum::HashTable in the stream. | |
| std::ostream & | operator<< (std::ostream &s, const HashTable< Key *, Val > &table) |
| Prints the content of a gum::HashTable with pointers key in the stream. | |
A chained list used by gum::HashTable.
| Key | The type for keys in a gum::HashTable. |
| Val | The type for values in a gum::HashTable. |
Definition at line 317 of file hashTable.h.
| using gum::HashTableList< Key, Val >::Bucket = HashTableBucket< Key, Val > |
types for STL compliance
Definition at line 329 of file hashTable.h.
| using gum::HashTableList< Key, Val >::const_pointer = const value_type* |
types for STL compliance
Definition at line 327 of file hashTable.h.
| using gum::HashTableList< Key, Val >::const_reference = const value_type& |
types for STL compliance
Definition at line 325 of file hashTable.h.
| using gum::HashTableList< Key, Val >::key_type = Key |
types for STL compliance
Definition at line 321 of file hashTable.h.
| using gum::HashTableList< Key, Val >::mapped_type = Val |
types for STL compliance
Definition at line 322 of file hashTable.h.
| using gum::HashTableList< Key, Val >::pointer = value_type* |
types for STL compliance
Definition at line 326 of file hashTable.h.
| using gum::HashTableList< Key, Val >::reference = value_type& |
types for STL compliance
Definition at line 324 of file hashTable.h.
| using gum::HashTableList< Key, Val >::size_type = Size |
types for STL compliance
Definition at line 328 of file hashTable.h.
| using gum::HashTableList< Key, Val >::value_type = std::pair< const Key, Val > |
types for STL compliance
Definition at line 323 of file hashTable.h.
|
noexcept |
Basic constructor that creates an empty list.
This is what is used basically by gum::HashTable.
Definition at line 134 of file hashTable_tpl.h.
Referenced by HashTable< Key, Val >, and operator<<.
| INLINE gum::HashTableList< Key, Val >::HashTableList | ( | const HashTableList< Key, Val > & | from | ) |
Copy constructor.
The new list and that which is copied do not share elements: the new list contains new instances of the keys and values stored in the copied list. Of course, if these values are pointers, the new values point toward the same elements.
| from | The gum::HashTableList to copy. |
Definition at line 137 of file hashTable_tpl.h.
References _copy_().
|
noexcept |
Move constructor.
| from | The gum::HashTableList to move. |
Definition at line 142 of file hashTable_tpl.h.
References _deb_list_.
| INLINE gum::HashTableList< Key, Val >::~HashTableList | ( | ) |
Class destructor.
Definition at line 148 of file hashTable_tpl.h.
References _deb_list_, and gum::HashTableBucket< Key, Val >::next.
|
private |
A function used to perform copies of HashTableLists.
This code is shared by the copy constructor and the copy operator. If it cannot perform the necessary allocations, no memory leak occurs and the list is set to the empty list.
| from | The gum::HashTableList to copy. |
Definition at line 64 of file hashTable_tpl.h.
References _deb_list_, _end_list_, _nb_elements_, and gum::HashTableBucket< Key, Val >::next.
Referenced by HashTableList(), and operator=().
| INLINE HashTableList< Key, Val >::value_type & gum::HashTableList< Key, Val >::at | ( | Size | i | ) |
Function at returns the ith element in the current chained list.
The first element has index 0.
| i | The index to look up. |
| NotFound | Raised if the list has fewer than i elements. |
Definition at line 194 of file hashTable_tpl.h.
References _deb_list_, _nb_elements_, gum::HashTableBucket< Key, Val >::elt(), GUM_ERROR, and gum::HashTableBucket< Key, Val >::next.
| INLINE const HashTableList< Key, Val >::value_type & gum::HashTableList< Key, Val >::at | ( | Size | i | ) | const |
Function at returns the ith element in the current chained list.
The first element has index 0.
| i | The index to look up. |
| NotFound | Raised if the list has fewer than i elements. |
Definition at line 206 of file hashTable_tpl.h.
References _deb_list_, _nb_elements_, gum::HashTableBucket< Key, Val >::elt(), GUM_ERROR, and gum::HashTableBucket< Key, Val >::next.
| INLINE HashTableBucket< Key, Val > * gum::HashTableList< Key, Val >::bucket | ( | const Key & | key | ) | const |
A method to get the bucket corresponding to a given key.
This enables efficient removals of buckets.
| key | The key of the bucket to return. |
Definition at line 108 of file hashTable_tpl.h.
References _deb_list_.
Referenced by HashTable< Key, Val >.
| INLINE void gum::HashTableList< Key, Val >::clear | ( | ) |
Removes all the elements of this chained list.
Definition at line 156 of file hashTable_tpl.h.
References _deb_list_, _end_list_, _nb_elements_, and gum::HashTableBucket< Key, Val >::next.
Referenced by operator=().
|
noexcept |
Returns true if this chained list is empty.
Definition at line 244 of file hashTable_tpl.h.
References _nb_elements_.
| INLINE void gum::HashTableList< Key, Val >::erase | ( | Bucket * | ptr | ) |
Removes an element from this chained list.
| ptr | The element to remove. |
Definition at line 116 of file hashTable_tpl.h.
References _deb_list_, _end_list_, _nb_elements_, GUM_ERROR, gum::HashTableBucket< Key, Val >::next, and gum::HashTableBucket< Key, Val >::prev.
| INLINE bool gum::HashTableList< Key, Val >::exists | ( | const key_type & | key | ) | const |
Returns true if a value with the given key exists.
Checks whether there exists an element with a given key in the list.
| key | The key to test for existence. |
Definition at line 235 of file hashTable_tpl.h.
References _deb_list_.
|
noexcept |
Inserts a new element in the chained list.
The element is inserted at the beginning of the list.
| new_elt | The element to add in the gum::HashTableList. |
Definition at line 249 of file hashTable_tpl.h.
References _deb_list_, _end_list_, and _nb_elements_.
| INLINE HashTableList< Key, Val > & gum::HashTableList< Key, Val >::operator= | ( | const HashTableList< Key, Val > & | from | ) |
Assignment operator.
The new list and that which is copied do not share elements: the new list contains new instances of the keys and values stored in the copied list. Of course, if these values are pointers, the new values point toward the same elements.
If some allocation problem occurs or if copying the Val elements cannot be performed properly, exceptions may be raised. In this case, the function guarantees that no memory leak occurs and that the list is kept in a coherent state (that of an empty list).
| from | The gum::HashTableList to copy. |
Definition at line 169 of file hashTable_tpl.h.
References _copy_(), and clear().
|
noexcept |
Move operator.
| from | The gum::HashTableList to copy. |
Definition at line 181 of file hashTable_tpl.h.
References _deb_list_, _end_list_, and _nb_elements_.
| INLINE HashTableList< Key, Val >::mapped_type & gum::HashTableList< Key, Val >::operator[] | ( | const key_type & | key | ) |
Returns the value corresponding to a given key.
| key | The key for which a value is returned. |
| NotFound | is raised if the element cannot be found |
Definition at line 227 of file hashTable_tpl.h.
References _deb_list_, and GUM_ERROR.
| INLINE const HashTableList< Key, Val >::mapped_type & gum::HashTableList< Key, Val >::operator[] | ( | const key_type & | key | ) | const |
Returns the value corresponding to a given key.
| key | The key for which a value is returned. |
| NotFound | is raised if the element cannot be found |
Definition at line 218 of file hashTable_tpl.h.
References _deb_list_, and GUM_ERROR.
Friend for faster access.
Definition at line 481 of file hashTable.h.
References HashTableList(), and bucket().
Referenced by operator<<.
|
friend |
Friend for faster access.
Definition at line 481 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 481 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 481 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 481 of file hashTable.h.
|
friend |
Prints the content of a gum::HashTable with pointers key in the stream.
Definition at line 990 of file hashTable_tpl.h.
References gum::HashTable< Key, Val >::_nodes_, and gum::HashTable< Key, Val >::_size_.
|
friend |
Prints the content of a gum::HashTable in the stream.
Definition at line 971 of file hashTable_tpl.h.
References gum::HashTable< Key, Val >::_nodes_, gum::HashTable< Key, Val >::_size_, and HashTable< Key, Val >.
|
friend |
Prints the content of a gum::HashTableList with pointers key in the stream.
Definition at line 954 of file hashTable_tpl.h.
References HashTableList(), and _deb_list_.
|
friend |
Prints the content of a gum::HashTableList in the stream.
Definition at line 937 of file hashTable_tpl.h.
|
private |
A pointer on the first element of the chained list.
Definition at line 500 of file hashTable.h.
Referenced by HashTableList(), ~HashTableList(), _copy_(), at(), at(), bucket(), clear(), erase(), exists(), insert(), operator<<, operator=(), operator[](), and operator[]().
|
private |
A pointer on the last element of the chained list.
Definition at line 503 of file hashTable.h.
Referenced by _copy_(), clear(), erase(), insert(), and operator=().
|
private |