![]() |
aGrUM 3.1.1
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. | |
| Bucket * | bucket (std::string_view key) const |
| Heterogeneous lookup: find bucket by string_view without allocation. | |
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 316 of file hashTable.h.
| using gum::HashTableList< Key, Val >::Bucket = HashTableBucket< Key, Val > |
types for STL compliance
Definition at line 328 of file hashTable.h.
| using gum::HashTableList< Key, Val >::const_pointer = const value_type* |
types for STL compliance
Definition at line 326 of file hashTable.h.
| using gum::HashTableList< Key, Val >::const_reference = const value_type& |
types for STL compliance
Definition at line 324 of file hashTable.h.
| using gum::HashTableList< Key, Val >::key_type = Key |
types for STL compliance
Definition at line 320 of file hashTable.h.
| using gum::HashTableList< Key, Val >::mapped_type = Val |
types for STL compliance
Definition at line 321 of file hashTable.h.
| using gum::HashTableList< Key, Val >::pointer = value_type* |
types for STL compliance
Definition at line 325 of file hashTable.h.
| using gum::HashTableList< Key, Val >::reference = value_type& |
types for STL compliance
Definition at line 323 of file hashTable.h.
| using gum::HashTableList< Key, Val >::size_type = Size |
types for STL compliance
Definition at line 327 of file hashTable.h.
| using gum::HashTableList< Key, Val >::value_type = std::pair< const Key, Val > |
types for STL compliance
Definition at line 322 of file hashTable.h.
|
defaultnoexcept |
Basic constructor that creates an empty list.
This is what is used basically by gum::HashTable.
References HashTableList(), at(), bucket(), clear(), empty(), erase(), exists(), and insert().
Referenced by HashTableList(), HashTableList(), HashTable< Key, Val >, and operator<<.
| 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 147 of file hashTable_tpl.h.
References HashTableList(), and _copy_().
|
noexcept |
Move constructor.
| from | The gum::HashTableList to move. |
Definition at line 152 of file hashTable_tpl.h.
References _deb_list_.
| gum::HashTableList< Key, Val >::~HashTableList | ( | ) |
Class destructor.
Definition at line 160 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 63 of file hashTable_tpl.h.
References _deb_list_, _end_list_, _nb_elements_, and gum::HashTableBucket< Key, Val >::next.
Referenced by HashTableList(), and operator=().
| 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 206 of file hashTable_tpl.h.
References _deb_list_, _nb_elements_, gum::HashTableBucket< Key, Val >::elt(), GUM_ERROR, and gum::HashTableBucket< Key, Val >::next.
Referenced by HashTableList().
| 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 218 of file hashTable_tpl.h.
References _deb_list_, _nb_elements_, gum::HashTableBucket< Key, Val >::elt(), GUM_ERROR, and gum::HashTableBucket< Key, Val >::next.
| 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 HashTableList(), and HashTable< Key, Val >.
| HashTableBucket< Key, Val > * gum::HashTableList< Key, Val >::bucket | ( | std::string_view | key | ) | const |
Heterogeneous lookup: find bucket by string_view without allocation.
Definition at line 116 of file hashTable_tpl.h.
References _deb_list_.
| void gum::HashTableList< Key, Val >::clear | ( | ) |
Removes all the elements of this chained list.
Definition at line 168 of file hashTable_tpl.h.
References _deb_list_, _end_list_, _nb_elements_, and gum::HashTableBucket< Key, Val >::next.
Referenced by HashTableList(), and operator=().
|
noexcept |
Returns true if this chained list is empty.
Definition at line 256 of file hashTable_tpl.h.
References _nb_elements_.
Referenced by HashTableList().
| void gum::HashTableList< Key, Val >::erase | ( | Bucket * | ptr | ) |
Removes an element from this chained list.
| ptr | The element to remove. |
Definition at line 126 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.
Referenced by HashTableList().
| 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 247 of file hashTable_tpl.h.
References _deb_list_.
Referenced by HashTableList().
|
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 261 of file hashTable_tpl.h.
References _deb_list_, _end_list_, and _nb_elements_.
Referenced by HashTableList().
| 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 181 of file hashTable_tpl.h.
References _copy_(), and clear().
|
noexcept |
Move operator.
| from | The gum::HashTableList to copy. |
Definition at line 193 of file hashTable_tpl.h.
References _deb_list_, _end_list_, and _nb_elements_.
| 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 239 of file hashTable_tpl.h.
References _deb_list_, and GUM_ERROR.
| 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 230 of file hashTable_tpl.h.
References _deb_list_, and GUM_ERROR.
Friend for faster access.
Definition at line 483 of file hashTable.h.
References HashTableList(), and bucket().
Referenced by operator<<.
|
friend |
Friend for faster access.
Definition at line 483 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 483 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 483 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 483 of file hashTable.h.
|
friend |
Prints the content of a gum::HashTable with pointers key in the stream.
Definition at line 1091 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 1072 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 1055 of file hashTable_tpl.h.
References HashTableList(), and _deb_list_.
|
friend |
Prints the content of a gum::HashTableList in the stream.
Definition at line 1038 of file hashTable_tpl.h.
|
private |
A pointer on the first element of the chained list.
Definition at line 503 of file hashTable.h.
Referenced by HashTableList(), ~HashTableList(), _copy_(), at(), at(), bucket(), bucket(), clear(), erase(), exists(), insert(), operator<<, operator=(), operator[](), and operator[]().
|
private |
A pointer on the last element of the chained list.
Definition at line 506 of file hashTable.h.
Referenced by _copy_(), clear(), erase(), insert(), and operator=().
|
private |