aGrUM  0.14.2
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 302 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 314 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 315 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 319 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 312 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 310 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 306 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 307 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 311 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 309 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 313 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 308 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 138 of file hashTable_tpl.h.

139  :
140  __alloc_bucket{from.__alloc_bucket} {
141  __copy(from);
142  }
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:540
void __copy(const HashTableList< Key, Val, OtherAlloc > &from)
A function used to perform copies of HashTableLists.
Definition: hashTable_tpl.h:42

◆ 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 145 of file hashTable_tpl.h.

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

◆ ~HashTableList()

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

Class destructor.

Definition at line 154 of file hashTable_tpl.h.

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

◆ 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 132 of file hashTable_tpl.h.

134  :
135  __alloc_bucket{allocator} {}
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:540

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 42 of file hashTable_tpl.h.

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

◆ 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 223 of file hashTable_tpl.h.

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

◆ 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 237 of file hashTable_tpl.h.

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

◆ 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 98 of file hashTable_tpl.h.

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

◆ 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 163 of file hashTable_tpl.h.

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

◆ 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 281 of file hashTable_tpl.h.

281  {
282  return (__nb_elements == Size(0));
283  }
Size __nb_elements
The number of elements in the chained list.
Definition: hashTable.h:537
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45

◆ 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 107 of file hashTable_tpl.h.

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

◆ 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 272 of file hashTable_tpl.h.

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

◆ 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 286 of file hashTable_tpl.h.

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

◆ 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 190 of file hashTable_tpl.h.

190  {
191  // avoid self assignment
192  if (this
193  != reinterpret_cast< const HashTableList< Key, Val, Alloc >* >(&from)) {
194  clear();
195  __copy(from);
196  }
197 
198  return *this;
199  }
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:42

◆ 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 177 of file hashTable_tpl.h.

177  {
178  // avoid self assignment
179  if (this != &from) {
180  clear();
181  __copy(from);
182  }
183 
184  return *this;
185  }
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:42

◆ 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 203 of file hashTable_tpl.h.

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

◆ 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 262 of file hashTable_tpl.h.

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

◆ 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 251 of file hashTable_tpl.h.

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

◆ 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 216 of file hashTable_tpl.h.

217  {
218  __alloc_bucket = &alloc;
219  }
BucketAllocator * __alloc_bucket
The allocator of the containing hashTable.
Definition: hashTable.h:540

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 514 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 515 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 517 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 519 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 516 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 518 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 1203 of file hashTable_tpl.h.

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

◆ 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 1221 of file hashTable_tpl.h.

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

◆ 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 1239 of file hashTable_tpl.h.

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

◆ 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 1259 of file hashTable_tpl.h.

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

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 540 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 534 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 537 of file hashTable.h.

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


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