![]() |
aGrUM
0.16.0
|
A chained list used by gum::HashTable. More...
#include <agrum/core/hashTable.h>
Public Member Functions | |
template<typename Key, typename Val, typename Alloc> | |
INLINE | HashTableList (typename HashTableList< Key, Val, Alloc >::BucketAllocator *allocator) noexcept |
template<typename OtherAlloc > | |
INLINE HashTableList< Key, Val, Alloc > & | operator= (const HashTableList< Key, Val, OtherAlloc > &from) |
Constructors / Destructors | |
HashTableList (BucketAllocator *allocator=nullptr) noexcept | |
Basic constructor that creates an empty list. More... | |
HashTableList (const HashTableList< Key, Val, Alloc > &from) | |
Copy constructor. More... | |
HashTableList (HashTableList< Key, Val, Alloc > &&from) noexcept | |
Move constructor. More... | |
~HashTableList () | |
Class destructor. More... | |
Operators | |
HashTableList< Key, Val, Alloc > & | operator= (const HashTableList< Key, Val, Alloc > &from) |
Assignment operator. More... | |
template<typename OtherAlloc > | |
HashTableList< Key, Val, Alloc > & | operator= (const HashTableList< Key, Val, OtherAlloc > &from) |
Generalized assignment operator. More... | |
HashTableList< Key, Val, Alloc > & | operator= (HashTableList< Key, Val, Alloc > &&from) noexcept |
Move operator. More... | |
Accessors / Modifiers | |
value_type & | at (Size i) |
Function at returns the ith element in the current chained list. More... | |
const value_type & | at (Size i) const |
Function at returns the ith element in the current chained list. More... | |
mapped_type & | operator[] (const key_type &key) |
Returns the value corresponding to a given key. More... | |
const mapped_type & | operator[] (const key_type &key) const |
Returns the value corresponding to a given key. More... | |
bool | exists (const key_type &key) const |
Returns true if a value with the given key exists. More... | |
void | insert (Bucket *new_elt) noexcept |
Inserts a new element in the chained list. More... | |
void | erase (Bucket *ptr) |
Removes an element from this chained list. More... | |
void | clear () |
Removes all the elements of this chained list. More... | |
bool | empty () const noexcept |
Returns true if this chained list is empty. More... | |
Bucket * | bucket (const Key &key) const |
A method to get the bucket corresponding to a given key. More... | |
void | setAllocator (BucketAllocator &alloc) |
Sets a new allocator. More... | |
Public Types | |
using | BucketAllocator = typename Alloc::template rebind< Bucket >::other |
The Bucket allocator. 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 | size_type = Size |
types for STL compliance More... | |
using | allocator_type = Alloc |
types for STL compliance More... | |
using | Bucket = HashTableBucket< Key, Val > |
types for STL compliance More... | |
Friends | |
template<typename K , typename V , typename A > | |
class | HashTableList |
Friend for faster access. More... | |
class | HashTable< Key, Val, Alloc > |
Friend for faster access. More... | |
class | HashTableIterator< Key, Val > |
Friend for faster access. More... | |
class | HashTableConstIterator< Key, Val > |
Friend for faster access. More... | |
class | HashTableIteratorSafe< Key, Val > |
Friend for faster access. More... | |
class | HashTableConstIteratorSafe< Key, Val > |
Friend for faster access. More... | |
std::ostream & | operator<< (std::ostream &, const HashTableList< Key, Val, Alloc > &) |
Prints the content of a gum::HashTableList in the stream. More... | |
std::ostream & | operator<< (std::ostream &, const HashTableList< Key *, Val, Alloc > &) |
Prints the content of a gum::HashTableList with pointers key in the stream. More... | |
std::ostream & | operator<< (std::ostream &, const HashTable< Key, Val, Alloc > &) |
Prints the content of a gum::HashTable in the stream. More... | |
std::ostream & | operator<< (std::ostream &, const HashTable< Key *, Val, Alloc > &) |
Prints the content of a gum::HashTable with pointers key in the stream. More... | |
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. |
Alloc | The gum::HashTable allocator. |
Definition at line 305 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::allocator_type = Alloc |
types for STL compliance
Definition at line 317 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::Bucket = HashTableBucket< Key, Val > |
types for STL compliance
Definition at line 318 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::BucketAllocator = typename Alloc::template rebind< Bucket >::other |
The Bucket allocator.
Definition at line 322 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::const_pointer = const value_type* |
types for STL compliance
Definition at line 315 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::const_reference = const value_type& |
types for STL compliance
Definition at line 313 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::key_type = Key |
types for STL compliance
Definition at line 309 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::mapped_type = Val |
types for STL compliance
Definition at line 310 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::pointer = value_type* |
types for STL compliance
Definition at line 314 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::reference = value_type& |
types for STL compliance
Definition at line 312 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::size_type = Size |
types for STL compliance
Definition at line 316 of file hashTable.h.
using gum::HashTableList< Key, Val, Alloc >::value_type = std::pair< const Key, Val > |
types for STL compliance
Definition at line 311 of file hashTable.h.
|
noexcept |
Basic constructor that creates an empty list.
This is what is used basically by gum::HashTable.
allocator | The gum::HashTableBucket allocator. |
INLINE gum::HashTableList< Key, Val, Alloc >::HashTableList | ( | const HashTableList< Key, Val, Alloc > & | 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 141 of file hashTable_tpl.h.
|
noexcept |
Move constructor.
from | The gum::HashTableList to move. |
Definition at line 148 of file hashTable_tpl.h.
INLINE gum::HashTableList< Key, Val, Alloc >::~HashTableList | ( | ) |
Class destructor.
Definition at line 157 of file hashTable_tpl.h.
|
noexcept |
Definition at line 135 of file hashTable_tpl.h.
|
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. |
OtherAlloc | The other gum::HashTableList allocator. |
Definition at line 45 of file hashTable_tpl.h.
INLINE HashTableList< Key, Val, Alloc >::value_type & gum::HashTableList< Key, Val, Alloc >::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 226 of file hashTable_tpl.h.
INLINE const HashTableList< Key, Val, Alloc >::value_type & gum::HashTableList< Key, Val, Alloc >::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 240 of file hashTable_tpl.h.
INLINE HashTableBucket< Key, Val > * gum::HashTableList< Key, Val, Alloc >::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 101 of file hashTable_tpl.h.
INLINE void gum::HashTableList< Key, Val, Alloc >::clear | ( | ) |
Removes all the elements of this chained list.
Definition at line 166 of file hashTable_tpl.h.
|
noexcept |
Returns true if this chained list is empty.
Definition at line 284 of file hashTable_tpl.h.
INLINE void gum::HashTableList< Key, Val, Alloc >::erase | ( | Bucket * | ptr | ) |
Removes an element from this chained list.
ptr | The element to remove. |
Definition at line 110 of file hashTable_tpl.h.
INLINE bool gum::HashTableList< Key, Val, Alloc >::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 275 of file hashTable_tpl.h.
|
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 289 of file hashTable_tpl.h.
INLINE HashTableList< Key, Val, Alloc >& gum::HashTableList< Key, Val, Alloc >::operator= | ( | const HashTableList< Key, Val, OtherAlloc > & | from | ) |
Definition at line 193 of file hashTable_tpl.h.
INLINE HashTableList< Key, Val, Alloc > & gum::HashTableList< Key, Val, Alloc >::operator= | ( | const HashTableList< Key, Val, Alloc > & | 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 180 of file hashTable_tpl.h.
HashTableList< Key, Val, Alloc >& gum::HashTableList< Key, Val, Alloc >::operator= | ( | const HashTableList< Key, Val, OtherAlloc > & | from | ) |
Generalized 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. |
|
noexcept |
Move operator.
from | The gum::HashTableList to copy. |
Definition at line 206 of file hashTable_tpl.h.
INLINE HashTableList< Key, Val, Alloc >::mapped_type & gum::HashTableList< Key, Val, Alloc >::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 265 of file hashTable_tpl.h.
INLINE const HashTableList< Key, Val, Alloc >::mapped_type & gum::HashTableList< Key, Val, Alloc >::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 254 of file hashTable_tpl.h.
INLINE void gum::HashTableList< Key, Val, Alloc >::setAllocator | ( | BucketAllocator & | alloc | ) |
Sets a new allocator.
alloc | The new allocator. |
Definition at line 219 of file hashTable_tpl.h.
|
friend |
Friend for faster access.
Definition at line 517 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 518 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 520 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 522 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 519 of file hashTable.h.
|
friend |
Friend for faster access.
Definition at line 521 of file hashTable.h.
|
friend |
Prints the content of a gum::HashTableList in the stream.
Definition at line 1206 of file hashTable_tpl.h.
|
friend |
Prints the content of a gum::HashTableList with pointers key in the stream.
Definition at line 1224 of file hashTable_tpl.h.
|
friend |
Prints the content of a gum::HashTable in the stream.
Definition at line 1242 of file hashTable_tpl.h.
|
friend |
Prints the content of a gum::HashTable with pointers key in the stream.
Definition at line 1262 of file hashTable_tpl.h.
|
mutableprivate |
The allocator of the containing hashTable.
Definition at line 543 of file hashTable.h.
Referenced by gum::HashTableList< Val, Size, IndexAllocator >::HashTableList().
|
private |
A pointer on the first element of the chained list.
Definition at line 534 of file hashTable.h.
Referenced by gum::HashTableList< Val, Size, IndexAllocator >::__copy(), gum::HashTableList< Val, Size, IndexAllocator >::HashTableList(), gum::operator<<(), and gum::HashTableList< Val, Size, IndexAllocator >::operator=().
|
private |
A pointer on the last element of the chained list.
Definition at line 537 of file hashTable.h.
|
private |
The number of elements in the chained list.
Definition at line 540 of file hashTable.h.
Referenced by gum::HashTableList< Val, Size, IndexAllocator >::__copy().