aGrUM  0.16.0
gum::HashTableList< Key, Val, Alloc > Class Template Reference

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_typeat (Size i)
 Function at returns the ith element in the current chained list. More...
 
const value_typeat (Size i) const
 Function at returns the ith element in the current chained list. More...
 
mapped_typeoperator[] (const key_type &key)
 Returns the value corresponding to a given key. More...
 
const mapped_typeoperator[] (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...
 
Bucketbucket (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...
 

Detailed Description

template<typename Key, typename Val, typename Alloc>
class gum::HashTableList< Key, Val, Alloc >

A chained list used by gum::HashTable.

Template Parameters
KeyThe type for keys in a gum::HashTable.
ValThe type for values in a gum::HashTable.
AllocThe gum::HashTable allocator.

Definition at line 305 of file hashTable.h.

Member Typedef Documentation

◆ allocator_type

template<typename Key, typename Val, typename Alloc>
using gum::HashTableList< Key, Val, Alloc >::allocator_type = Alloc

types for STL compliance

Definition at line 317 of file hashTable.h.

◆ Bucket

template<typename Key, typename Val, typename Alloc>
using gum::HashTableList< Key, Val, Alloc >::Bucket = HashTableBucket< Key, Val >

types for STL compliance

Definition at line 318 of file hashTable.h.

◆ BucketAllocator

template<typename Key, typename Val, typename Alloc>
using gum::HashTableList< Key, Val, Alloc >::BucketAllocator = typename Alloc::template rebind< Bucket >::other

The Bucket allocator.

Definition at line 322 of file hashTable.h.

◆ const_pointer

template<typename Key, typename Val, typename Alloc>
using gum::HashTableList< Key, Val, Alloc >::const_pointer = const value_type*

types for STL compliance

Definition at line 315 of file hashTable.h.

◆ const_reference

template<typename Key, typename Val, typename Alloc>
using gum::HashTableList< Key, Val, Alloc >::const_reference = const value_type&

types for STL compliance

Definition at line 313 of file hashTable.h.

◆ key_type

template<typename Key, typename Val, typename Alloc>
using gum::HashTableList< Key, Val, Alloc >::key_type = Key

types for STL compliance

Definition at line 309 of file hashTable.h.

◆ mapped_type

template<typename Key, typename Val, typename Alloc>
using gum::HashTableList< Key, Val, Alloc >::mapped_type = Val

types for STL compliance

Definition at line 310 of file hashTable.h.

◆ pointer

template<typename Key, typename Val, typename Alloc>
using gum::HashTableList< Key, Val, Alloc >::pointer = value_type*

types for STL compliance

Definition at line 314 of file hashTable.h.

◆ reference

template<typename Key, typename Val, typename Alloc>
using gum::HashTableList< Key, Val, Alloc >::reference = value_type&

types for STL compliance

Definition at line 312 of file hashTable.h.

◆ size_type

template<typename Key, typename Val, typename Alloc>
using gum::HashTableList< Key, Val, Alloc >::size_type = Size

types for STL compliance

Definition at line 316 of file hashTable.h.

◆ value_type

template<typename Key, typename Val, typename Alloc>
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.

Constructor & Destructor Documentation

◆ HashTableList() [1/4]

template<typename Key, typename Val, typename Alloc>
gum::HashTableList< Key, Val, Alloc >::HashTableList ( BucketAllocator allocator = nullptr)
noexcept

Basic constructor that creates an empty list.

This is what is used basically by gum::HashTable.

Warning
If the allocator is not passed in argument, do not forget to use method setAllocator after the creation.
Parameters
allocatorThe gum::HashTableBucket allocator.

◆ HashTableList() [2/4]

template<typename Key, typename Val, typename Alloc>
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.

Warning
Both from and this will share the same allocator.
Parameters
fromThe gum::HashTableList to copy.

Definition at line 141 of file hashTable_tpl.h.

142  :
143  __alloc_bucket{from.__alloc_bucket} {
144  __copy(from);
145  }
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:543
void __copy(const HashTableList< Key, Val, OtherAlloc > &from)
A function used to perform copies of HashTableLists.
Definition: hashTable_tpl.h:45

◆ HashTableList() [3/4]

template<typename Key, typename Val, typename Alloc>
INLINE gum::HashTableList< Key, Val, Alloc >::HashTableList ( HashTableList< Key, Val, Alloc > &&  from)
noexcept

Move constructor.

Parameters
fromThe gum::HashTableList to move.

Definition at line 148 of file hashTable_tpl.h.

149  :
150  __deb_list{from.__deb_list},
151  __end_list{from.__end_list}, __nb_elements{from.__nb_elements},
152  __alloc_bucket{from.__alloc_bucket} {
153  from.__deb_list = nullptr;
154  }
Size __nb_elements
The number of elements in the chained list.
Definition: hashTable.h:540
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:543
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
HashTableBucket< Key, Val > * __end_list
A pointer on the last element of the chained list.
Definition: hashTable.h:537

◆ ~HashTableList()

template<typename Key , typename Val , typename Alloc >
INLINE gum::HashTableList< Key, Val, Alloc >::~HashTableList ( )

Class destructor.

Definition at line 157 of file hashTable_tpl.h.

157  {
158  for (Bucket *next_ptr, *ptr = __deb_list; ptr != nullptr; ptr = next_ptr) {
159  next_ptr = ptr->next;
160  __alloc_bucket->destroy(ptr);
161  __alloc_bucket->deallocate(ptr, 1);
162  }
163  }
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:543
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
HashTableBucket< Key, Val > Bucket
types for STL compliance
Definition: hashTable.h:318

◆ HashTableList() [4/4]

template<typename Key, typename Val, typename Alloc>
template<typename Key, typename Val, typename Alloc>
INLINE gum::HashTableList< Key, Val, Alloc >::HashTableList ( typename HashTableList< Key, Val, Alloc >::BucketAllocator allocator)
noexcept

Definition at line 135 of file hashTable_tpl.h.

137  :
138  __alloc_bucket{allocator} {}
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:543

Member Function Documentation

◆ __copy()

template<typename Key, typename Val, typename Alloc >
template<typename OtherAlloc >
void gum::HashTableList< Key, Val, Alloc >::__copy ( const HashTableList< Key, Val, OtherAlloc > &  from)
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.

Parameters
fromThe gum::HashTableList to copy.
Template Parameters
OtherAllocThe other gum::HashTableList allocator.

Definition at line 45 of file hashTable_tpl.h.

46  {
47  Bucket *ptr, *old_ptr{nullptr}, *new_elt{nullptr};
48  // set the defaults
49  __deb_list = nullptr;
50 
51  // copy from's list
52  try {
53  for (ptr = from.__deb_list; ptr != nullptr; ptr = ptr->next) {
54  // copy the current from's bucket (may throw an exception either because
55  // new cannot allocate the bucket or because the copy constructor of Val
56  // throws an exception)
57  new_elt = __alloc_bucket->allocate(1);
58 
59  try {
60  __alloc_bucket->construct(new_elt, *ptr);
61  } catch (...) {
62  __alloc_bucket->deallocate(new_elt, 1);
63  throw;
64  }
65 
66  // rechain properly the new list
67  new_elt->prev = old_ptr;
68 
69  if (old_ptr != nullptr)
70  old_ptr->next = new_elt;
71  else
72  __deb_list = new_elt;
73 
74  old_ptr = new_elt;
75  }
76 
77  if (old_ptr != nullptr) old_ptr->next = nullptr;
78 
79  // update the number of elements stored into the list and the end of the
80  // list
81  __nb_elements = from.__nb_elements;
82  __end_list = new_elt;
83  } catch (...) {
84  // problem: we could not allocate an element in the list => we delete
85  // the elements created so far and we throw an exception
86  for (; __deb_list != nullptr; __deb_list = new_elt) {
87  new_elt = __deb_list->next;
88  __alloc_bucket->destroy(__deb_list);
89  __alloc_bucket->deallocate(__deb_list, 1);
90  }
91 
92  __nb_elements = 0;
93  __end_list = nullptr;
94 
95  throw;
96  }
97  }
Size __nb_elements
The number of elements in the chained list.
Definition: hashTable.h:540
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:543
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
HashTableBucket< Key, Val > * __end_list
A pointer on the last element of the chained list.
Definition: hashTable.h:537
HashTableBucket< Key, Val > Bucket
types for STL compliance
Definition: hashTable.h:318

◆ at() [1/2]

template<typename Key , typename Val , typename Alloc >
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.

Parameters
iThe index to look up.
Returns
Returns the value at index i.
Exceptions
NotFoundRaised if the list has fewer than i elements.

Definition at line 226 of file hashTable_tpl.h.

226  {
227  if (i >= __nb_elements) {
228  GUM_ERROR(NotFound, "not enough elements in the chained list");
229  }
230 
231  Bucket* ptr;
232 
233  for (ptr = __deb_list; i; --i, ptr = ptr->next) {}
234 
235  return ptr->elt();
236  }
Size __nb_elements
The number of elements in the chained list.
Definition: hashTable.h:540
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
HashTableBucket< Key, Val > Bucket
types for STL compliance
Definition: hashTable.h:318

◆ at() [2/2]

template<typename Key , typename Val , typename Alloc >
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.

Parameters
iThe index to look up.
Returns
Returns the value at index i.
Exceptions
NotFoundRaised if the list has fewer than i elements.

Definition at line 240 of file hashTable_tpl.h.

240  {
241  if (i >= __nb_elements) {
242  GUM_ERROR(NotFound, "not enough elements in the chained list");
243  }
244 
245  Bucket* ptr;
246 
247  for (ptr = __deb_list; i; --i, ptr = ptr->next) {}
248 
249  return ptr->elt();
250  }
Size __nb_elements
The number of elements in the chained list.
Definition: hashTable.h:540
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
HashTableBucket< Key, Val > Bucket
types for STL compliance
Definition: hashTable.h:318

◆ bucket()

template<typename Key, typename Val , typename Alloc >
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.

Parameters
keyThe key of the bucket to return.
Returns
Returns the buckket matching key.

Definition at line 101 of file hashTable_tpl.h.

101  {
102  for (Bucket* ptr = __deb_list; ptr != nullptr; ptr = ptr->next)
103  if (ptr->key() == key) return ptr;
104 
105  return nullptr;
106  }
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
HashTableBucket< Key, Val > Bucket
types for STL compliance
Definition: hashTable.h:318

◆ clear()

template<typename Key , typename Val , typename Alloc >
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.

166  {
167  for (Bucket *next_ptr, *ptr = __deb_list; ptr != nullptr; ptr = next_ptr) {
168  next_ptr = ptr->next;
169  __alloc_bucket->destroy(ptr);
170  __alloc_bucket->deallocate(ptr, 1);
171  }
172 
173  __nb_elements = Size(0);
174  __deb_list = nullptr;
175  __end_list = nullptr;
176  }
Size __nb_elements
The number of elements in the chained list.
Definition: hashTable.h:540
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:543
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
HashTableBucket< Key, Val > * __end_list
A pointer on the last element of the chained list.
Definition: hashTable.h:537
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
HashTableBucket< Key, Val > Bucket
types for STL compliance
Definition: hashTable.h:318

◆ empty()

template<typename Key , typename Val , typename Alloc >
INLINE bool gum::HashTableList< Key, Val, Alloc >::empty ( ) const
noexcept

Returns true if this chained list is empty.

Returns
Returns true if this chained list is empty.

Definition at line 284 of file hashTable_tpl.h.

284  {
285  return (__nb_elements == Size(0));
286  }
Size __nb_elements
The number of elements in the chained list.
Definition: hashTable.h:540
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48

◆ erase()

template<typename Key , typename Val , typename Alloc >
INLINE void gum::HashTableList< Key, Val, Alloc >::erase ( Bucket ptr)

Removes an element from this chained list.

Parameters
ptrThe element to remove.

Definition at line 110 of file hashTable_tpl.h.

110  {
111  // check that the pointer is not nullptr
112  if (ptr == nullptr) {
113  GUM_ERROR(NullElement, "trying to erase a nullptr bucket");
114  }
115 
116  // relink properly the doubly chained list
117  if (ptr->prev != nullptr)
118  ptr->prev->next = ptr->next;
119  else
120  __deb_list = ptr->next;
121 
122  if (ptr->next != nullptr)
123  ptr->next->prev = ptr->prev;
124  else
125  __end_list = ptr->prev;
126 
127  // remove the current element from the list
128  __alloc_bucket->destroy(ptr);
129  __alloc_bucket->deallocate(ptr, 1);
130 
131  --__nb_elements;
132  }
Size __nb_elements
The number of elements in the chained list.
Definition: hashTable.h:540
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:543
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
HashTableBucket< Key, Val > * __end_list
A pointer on the last element of the chained list.
Definition: hashTable.h:537
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ exists()

template<typename Key , typename Val , typename Alloc >
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.

Parameters
keyThe key to test for existence.
Returns
Returns true if a value with the given key exists.

Definition at line 275 of file hashTable_tpl.h.

275  {
276  for (Bucket* ptr = __deb_list; ptr != nullptr; ptr = ptr->next) {
277  if (ptr->key() == key) { return true; }
278  }
279 
280  return false;
281  }
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
HashTableBucket< Key, Val > Bucket
types for STL compliance
Definition: hashTable.h:318

◆ insert()

template<typename Key , typename Val , typename Alloc >
INLINE void gum::HashTableList< Key, Val, Alloc >::insert ( Bucket new_elt)
noexcept

Inserts a new element in the chained list.

The element is inserted at the beginning of the list.

Parameters
new_eltThe element to add in the gum::HashTableList.

Definition at line 289 of file hashTable_tpl.h.

290  {
291  // place the bucket at the beginning of the list
292  new_elt->prev = nullptr;
293  new_elt->next = __deb_list;
294 
295  if (__deb_list != nullptr)
296  __deb_list->prev = new_elt;
297  else
298  __end_list = new_elt;
299 
300  __deb_list = new_elt;
301 
302  ++__nb_elements;
303  }
Size __nb_elements
The number of elements in the chained list.
Definition: hashTable.h:540
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
HashTableBucket< Key, Val > * __end_list
A pointer on the last element of the chained list.
Definition: hashTable.h:537

◆ operator=() [1/4]

template<typename Key, typename Val, typename Alloc>
template<typename OtherAlloc >
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.

193  {
194  // avoid self assignment
195  if (this
196  != reinterpret_cast< const HashTableList< Key, Val, Alloc >* >(&from)) {
197  clear();
198  __copy(from);
199  }
200 
201  return *this;
202  }
void clear()
Removes all the elements of this chained list.
void __copy(const HashTableList< Key, Val, OtherAlloc > &from)
A function used to perform copies of HashTableLists.
Definition: hashTable_tpl.h:45

◆ operator=() [2/4]

template<typename Key, typename Val, typename Alloc>
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).

Warning
operator= does not change the current allocator of *this
Parameters
fromThe gum::HashTableList to copy.
Returns
Returns this gum::HashTableList.

Definition at line 180 of file hashTable_tpl.h.

180  {
181  // avoid self assignment
182  if (this != &from) {
183  clear();
184  __copy(from);
185  }
186 
187  return *this;
188  }
void clear()
Removes all the elements of this chained list.
void __copy(const HashTableList< Key, Val, OtherAlloc > &from)
A function used to perform copies of HashTableLists.
Definition: hashTable_tpl.h:45

◆ operator=() [3/4]

template<typename Key, typename Val, typename Alloc>
template<typename OtherAlloc >
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).

Warning
operator= does not change the current allocator of *this
Parameters
fromThe gum::HashTableList to copy.
Returns
Returns this gum::HashTableList.

◆ operator=() [4/4]

template<typename Key, typename Val, typename Alloc>
INLINE HashTableList< Key, Val, Alloc > & gum::HashTableList< Key, Val, Alloc >::operator= ( HashTableList< Key, Val, Alloc > &&  from)
noexcept

Move operator.

Warning
operator= does not change the current allocator of *this
Parameters
fromThe gum::HashTableList to copy.
Returns
Returns this gum::HashTableList.

Definition at line 206 of file hashTable_tpl.h.

206  {
207  // avoid self assignment
208  if (this != &from) {
209  __deb_list = from.__deb_list;
210  __end_list = from.__end_list;
211  __nb_elements = from.__nb_elements;
212  from.__deb_list = nullptr;
213  }
214 
215  return *this;
216  }
Size __nb_elements
The number of elements in the chained list.
Definition: hashTable.h:540
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
HashTableBucket< Key, Val > * __end_list
A pointer on the last element of the chained list.
Definition: hashTable.h:537

◆ operator[]() [1/2]

template<typename Key , typename Val , typename Alloc >
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.

Parameters
keyThe key for which a value is returned.
Returns
Returns the value corresponding to a given key.
Exceptions
NotFoundis raised if the element cannot be found

Definition at line 265 of file hashTable_tpl.h.

265  {
266  for (Bucket* ptr = __deb_list; ptr != nullptr; ptr = ptr->next)
267  if (ptr->key() == key) return ptr->val();
268 
269  GUM_ERROR(NotFound,
270  "hashtable's chained list contains no element with this key <"
271  << key << ">");
272  }
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
HashTableBucket< Key, Val > Bucket
types for STL compliance
Definition: hashTable.h:318

◆ operator[]() [2/2]

template<typename Key , typename Val , typename Alloc >
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.

Parameters
keyThe key for which a value is returned.
Returns
Returns the value corresponding to a given key.
Exceptions
NotFoundis raised if the element cannot be found

Definition at line 254 of file hashTable_tpl.h.

254  {
255  for (Bucket* ptr = __deb_list; ptr != nullptr; ptr = ptr->next)
256  if (ptr->key() == key) return ptr->val();
257 
258  GUM_ERROR(NotFound,
259  "hashtable's chained list contains no element with this key <"
260  << key << ">");
261  }
HashTableBucket< Key, Val > * __deb_list
A pointer on the first element of the chained list.
Definition: hashTable.h:534
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
HashTableBucket< Key, Val > Bucket
types for STL compliance
Definition: hashTable.h:318

◆ setAllocator()

template<typename Key, typename Val, typename Alloc>
INLINE void gum::HashTableList< Key, Val, Alloc >::setAllocator ( BucketAllocator alloc)

Sets a new allocator.

Parameters
allocThe new allocator.

Definition at line 219 of file hashTable_tpl.h.

220  {
221  __alloc_bucket = &alloc;
222  }
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:543

Friends And Related Function Documentation

◆ HashTableList

template<typename Key, typename Val, typename Alloc>
template<typename K , typename V , typename A >
friend class HashTableList
friend

Friend for faster access.

Definition at line 517 of file hashTable.h.

◆ HashTable< Key, Val, Alloc >

template<typename Key, typename Val, typename Alloc>
friend class HashTable< Key, Val, Alloc >
friend

Friend for faster access.

Definition at line 518 of file hashTable.h.

◆ HashTableConstIterator< Key, Val >

template<typename Key, typename Val, typename Alloc>
friend class HashTableConstIterator< Key, Val >
friend

Friend for faster access.

Definition at line 520 of file hashTable.h.

◆ HashTableConstIteratorSafe< Key, Val >

template<typename Key, typename Val, typename Alloc>
friend class HashTableConstIteratorSafe< Key, Val >
friend

Friend for faster access.

Definition at line 522 of file hashTable.h.

◆ HashTableIterator< Key, Val >

template<typename Key, typename Val, typename Alloc>
friend class HashTableIterator< Key, Val >
friend

Friend for faster access.

Definition at line 519 of file hashTable.h.

◆ HashTableIteratorSafe< Key, Val >

template<typename Key, typename Val, typename Alloc>
friend class HashTableIteratorSafe< Key, Val >
friend

Friend for faster access.

Definition at line 521 of file hashTable.h.

◆ operator<< [1/4]

template<typename Key, typename Val, typename Alloc>
std::ostream& operator<< ( std::ostream &  s,
const HashTableList< Key, Val, Alloc > &  list 
)
friend

Prints the content of a gum::HashTableList in the stream.

Definition at line 1206 of file hashTable_tpl.h.

1207  {
1208  bool deja = false;
1209  stream << "[";
1210 
1211  for (HashTableBucket< Key, Val >* ptr = list.__deb_list; ptr;
1212  ptr = ptr->list.next, deja = true) {
1213  if (deja) stream << " , ";
1214 
1215  stream << ptr->key() << "=>" << ptr->val();
1216  }
1217 
1218  stream << "]";
1219 
1220  return stream;
1221  }

◆ operator<< [2/4]

template<typename Key, typename Val, typename Alloc>
std::ostream& operator<< ( std::ostream &  s,
const HashTableList< Key *, Val, Alloc > &  list 
)
friend

Prints the content of a gum::HashTableList with pointers key in the stream.

Definition at line 1224 of file hashTable_tpl.h.

1225  {
1226  bool deja = false;
1227  stream << "[";
1228 
1229  for (HashTableBucket< Key, Val >* ptr = list.__deb_list; ptr;
1230  ptr = ptr->list.next, deja = true) {
1231  if (deja) stream << " , ";
1232 
1233  stream << ptr->key() << "=>" << ptr->val();
1234  }
1235 
1236  stream << "]";
1237 
1238  return stream;
1239  }

◆ operator<< [3/4]

template<typename Key, typename Val, typename Alloc>
std::ostream& operator<< ( std::ostream &  s,
const HashTable< Key, Val, Alloc > &  table 
)
friend

Prints the content of a gum::HashTable in the stream.

Definition at line 1242 of file hashTable_tpl.h.

1243  {
1244  bool deja = false;
1245  stream << "{";
1246 
1247  for (Size i = Size(0); i < table.__size; ++i)
1248  for (auto ptr = table.__nodes[i].__deb_list; ptr; ptr = ptr->next) {
1249  if (deja) stream << " , ";
1250 
1251  stream << ptr->key() << "=>" << ptr->val();
1252 
1253  deja = true;
1254  }
1255 
1256  stream << "}";
1257 
1258  return stream;
1259  }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48

◆ operator<< [4/4]

template<typename Key, typename Val, typename Alloc>
std::ostream& operator<< ( std::ostream &  s,
const HashTable< Key *, Val, Alloc > &  table 
)
friend

Prints the content of a gum::HashTable with pointers key in the stream.

Definition at line 1262 of file hashTable_tpl.h.

1263  {
1264  bool deja = false;
1265  stream << "{";
1266 
1267  for (Size i = Size(0); i < table.__size; ++i)
1268  for (auto ptr = table.__nodes[i].__deb_list; ptr; ptr = ptr->next) {
1269  if (deja) stream << " , ";
1270 
1271  stream << ptr->key() << "=>" << ptr->val();
1272 
1273  deja = true;
1274  }
1275 
1276  stream << "}";
1277 
1278  return stream;
1279  }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48

Member Data Documentation

◆ __alloc_bucket

template<typename Key, typename Val, typename Alloc>
BucketAllocator* gum::HashTableList< Key, Val, Alloc >::__alloc_bucket
mutableprivate

The allocator of the containing hashTable.

Definition at line 543 of file hashTable.h.

Referenced by gum::HashTableList< Val, Size, IndexAllocator >::HashTableList().

◆ __deb_list

template<typename Key, typename Val, typename Alloc>
HashTableBucket< Key, Val >* gum::HashTableList< Key, Val, Alloc >::__deb_list {nullptr}
private

◆ __end_list

template<typename Key, typename Val, typename Alloc>
HashTableBucket< Key, Val >* gum::HashTableList< Key, Val, Alloc >::__end_list {nullptr}
private

A pointer on the last element of the chained list.

Definition at line 537 of file hashTable.h.

◆ __nb_elements

template<typename Key, typename Val, typename Alloc>
Size gum::HashTableList< Key, Val, Alloc >::__nb_elements {Size(0)}
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().


The documentation for this class was generated from the following files: