aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
gum::HashTableList< Key, Val, Alloc > Class Template Reference

A chained list used by gum::HashTable. More...

#include <agrum/tools/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 229 of file hashTable_tpl.h.

229  {
230  if (i >= __nb_elements) {
231  GUM_ERROR(NotFound, "not enough elements in the chained list");
232  }
233 
234  Bucket* ptr;
235 
236  for (ptr = __deb_list; i; --i, ptr = ptr->next) {}
237 
238  return ptr->elt();
239  }
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 243 of file hashTable_tpl.h.

243  {
244  if (i >= __nb_elements) {
245  GUM_ERROR(NotFound, "not enough elements in the chained list");
246  }
247 
248  Bucket* ptr;
249 
250  for (ptr = __deb_list; i; --i, ptr = ptr->next) {}
251 
252  return ptr->elt();
253  }
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 287 of file hashTable_tpl.h.

287  {
288  return (__nb_elements == Size(0));
289  }
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 278 of file hashTable_tpl.h.

278  {
279  for (Bucket* ptr = __deb_list; ptr != nullptr; ptr = ptr->next) {
280  if (ptr->key() == key) { return true; }
281  }
282 
283  return false;
284  }
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 292 of file hashTable_tpl.h.

293  {
294  // place the bucket at the beginning of the list
295  new_elt->prev = nullptr;
296  new_elt->next = __deb_list;
297 
298  if (__deb_list != nullptr)
299  __deb_list->prev = new_elt;
300  else
301  __end_list = new_elt;
302 
303  __deb_list = new_elt;
304 
305  ++__nb_elements;
306  }
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 194 of file hashTable_tpl.h.

195  {
196  // avoid self assignment
197  if (this
198  != reinterpret_cast< const HashTableList< Key, Val, Alloc >* >(&from)) {
199  clear();
200  __copy(from);
201  }
202 
203  return *this;
204  }
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.

181  {
182  // avoid self assignment
183  if (this != &from) {
184  clear();
185  __copy(from);
186  }
187 
188  return *this;
189  }
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 208 of file hashTable_tpl.h.

209  {
210  // avoid self assignment
211  if (this != &from) {
212  __deb_list = from.__deb_list;
213  __end_list = from.__end_list;
214  __nb_elements = from.__nb_elements;
215  from.__deb_list = nullptr;
216  }
217 
218  return *this;
219  }
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 268 of file hashTable_tpl.h.

268  {
269  for (Bucket* ptr = __deb_list; ptr != nullptr; ptr = ptr->next)
270  if (ptr->key() == key) return ptr->val();
271 
272  GUM_ERROR(NotFound,
273  "hashtable's chained list contains no element with this key <"
274  << key << ">");
275  }
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 257 of file hashTable_tpl.h.

257  {
258  for (Bucket* ptr = __deb_list; ptr != nullptr; ptr = ptr->next)
259  if (ptr->key() == key) return ptr->val();
260 
261  GUM_ERROR(NotFound,
262  "hashtable's chained list contains no element with this key <"
263  << key << ">");
264  }
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 222 of file hashTable_tpl.h.

223  {
224  __alloc_bucket = &alloc;
225  }
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 1209 of file hashTable_tpl.h.

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

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

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

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

1246  {
1247  bool deja = false;
1248  stream << "{";
1249 
1250  for (Size i = Size(0); i < table.__size; ++i)
1251  for (auto ptr = table.__nodes[i].__deb_list; ptr; ptr = ptr->next) {
1252  if (deja) stream << " , ";
1253 
1254  stream << ptr->key() << "=>" << ptr->val();
1255 
1256  deja = true;
1257  }
1258 
1259  stream << "}";
1260 
1261  return stream;
1262  }
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 1265 of file hashTable_tpl.h.

1266  {
1267  bool deja = false;
1268  stream << "{";
1269 
1270  for (Size i = Size(0); i < table.__size; ++i)
1271  for (auto ptr = table.__nodes[i].__deb_list; ptr; ptr = ptr->next) {
1272  if (deja) stream << " , ";
1273 
1274  stream << ptr->key() << "=>" << ptr->val();
1275 
1276  deja = true;
1277  }
1278 
1279  stream << "}";
1280 
1281  return stream;
1282  }
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: