aGrUM  0.20.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 140 of file hashTable_tpl.h.

141  :
142  alloc_bucket__{from.alloc_bucket__} {
143  copy__(from);
144  }
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:44

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

148  :
149  deb_list__{from.deb_list__},
150  end_list__{from.end_list__}, nb_elements__{from.nb_elements__},
151  alloc_bucket__{from.alloc_bucket__} {
152  from.deb_list__ = nullptr;
153  }
BucketAllocator * alloc_bucket__
The allocator of the containing hashTable.
Definition: hashTable.h:543
HashTableBucket< Key, Val > * end_list__
A pointer on the last element of 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:534
Size nb_elements__
The number of elements in the chained list.
Definition: hashTable.h:540

◆ ~HashTableList()

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

Class destructor.

Definition at line 156 of file hashTable_tpl.h.

156  {
157  for (Bucket *next_ptr, *ptr = deb_list__; ptr != nullptr; ptr = next_ptr) {
158  next_ptr = ptr->next;
159  alloc_bucket__->destroy(ptr);
160  alloc_bucket__->deallocate(ptr, 1);
161  }
162  }
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 134 of file hashTable_tpl.h.

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

Member Function Documentation

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

228  {
229  if (i >= nb_elements__) {
230  GUM_ERROR(NotFound, "not enough elements in the chained list");
231  }
232 
233  Bucket* ptr;
234 
235  for (ptr = deb_list__; i; --i, ptr = ptr->next) {}
236 
237  return ptr->elt();
238  }
HashTableBucket< Key, Val > * deb_list__
A pointer on the first element of the chained list.
Definition: hashTable.h:534
Size nb_elements__
The number of elements in the chained list.
Definition: hashTable.h:540
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
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 242 of file hashTable_tpl.h.

242  {
243  if (i >= nb_elements__) {
244  GUM_ERROR(NotFound, "not enough elements in the chained list");
245  }
246 
247  Bucket* ptr;
248 
249  for (ptr = deb_list__; i; --i, ptr = ptr->next) {}
250 
251  return ptr->elt();
252  }
HashTableBucket< Key, Val > * deb_list__
A pointer on the first element of the chained list.
Definition: hashTable.h:534
Size nb_elements__
The number of elements in the chained list.
Definition: hashTable.h:540
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
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 100 of file hashTable_tpl.h.

100  {
101  for (Bucket* ptr = deb_list__; ptr != nullptr; ptr = ptr->next)
102  if (ptr->key() == key) return ptr;
103 
104  return nullptr;
105  }
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 165 of file hashTable_tpl.h.

165  {
166  for (Bucket *next_ptr, *ptr = deb_list__; ptr != nullptr; ptr = next_ptr) {
167  next_ptr = ptr->next;
168  alloc_bucket__->destroy(ptr);
169  alloc_bucket__->deallocate(ptr, 1);
170  }
171 
172  nb_elements__ = Size(0);
173  deb_list__ = nullptr;
174  end_list__ = nullptr;
175  }
BucketAllocator * alloc_bucket__
The allocator of the containing hashTable.
Definition: hashTable.h:543
HashTableBucket< Key, Val > * end_list__
A pointer on the last element of 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:534
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
Size nb_elements__
The number of elements in the chained list.
Definition: hashTable.h:540
HashTableBucket< Key, Val > Bucket
types for STL compliance
Definition: hashTable.h:318

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

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

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

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

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

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

273  {
274  for (Bucket* ptr = deb_list__; ptr != nullptr; ptr = ptr->next) {
275  if (ptr->key() == key) { return true; }
276  }
277 
278  return false;
279  }
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 287 of file hashTable_tpl.h.

288  {
289  // place the bucket at the beginning of the list
290  new_elt->prev = nullptr;
291  new_elt->next = deb_list__;
292 
293  if (deb_list__ != nullptr)
294  deb_list__->prev = new_elt;
295  else
296  end_list__ = new_elt;
297 
298  deb_list__ = new_elt;
299 
300  ++nb_elements__;
301  }
HashTableBucket< Key, Val > * end_list__
A pointer on the last element of 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:534
Size nb_elements__
The number of elements in the chained list.
Definition: hashTable.h:540

◆ 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.

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

◆ 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 179 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:44

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

208  {
209  // avoid self assignment
210  if (this != &from) {
211  deb_list__ = from.deb_list__;
212  end_list__ = from.end_list__;
213  nb_elements__ = from.nb_elements__;
214  from.deb_list__ = nullptr;
215  }
216 
217  return *this;
218  }
HashTableBucket< Key, Val > * end_list__
A pointer on the last element of 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:534
Size nb_elements__
The number of elements in the chained list.
Definition: hashTable.h:540

◆ 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, "No element with the key <" << key << ">");
270  }
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:54
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 256 of file hashTable_tpl.h.

256  {
257  for (Bucket* ptr = deb_list__; ptr != nullptr; ptr = ptr->next)
258  if (ptr->key() == key) return ptr->val();
259 
260  GUM_ERROR(NotFound, "No element with the key <" << 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:54
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 221 of file hashTable_tpl.h.

222  {
223  alloc_bucket__ = &alloc;
224  }
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 1217 of file hashTable_tpl.h.

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

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

1236  {
1237  bool deja = false;
1238  stream << "[";
1239 
1240  for (HashTableBucket< Key, Val >* ptr = list.deb_list__; ptr;
1241  ptr = ptr->list.next, deja = true) {
1242  if (deja) stream << " , ";
1243 
1244  stream << ptr->key() << "=>" << ptr->val();
1245  }
1246 
1247  stream << "]";
1248 
1249  return stream;
1250  }

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

1254  {
1255  bool deja = false;
1256  stream << "{";
1257 
1258  for (Size i = Size(0); i < table.size__; ++i)
1259  for (auto ptr = table.nodes__[i].deb_list__; ptr; ptr = ptr->next) {
1260  if (deja) stream << " , ";
1261 
1262  stream << ptr->key() << "=>" << ptr->val();
1263 
1264  deja = true;
1265  }
1266 
1267  stream << "}";
1268 
1269  return stream;
1270  }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

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

1274  {
1275  bool deja = false;
1276  stream << "{";
1277 
1278  for (Size i = Size(0); i < table.size__; ++i)
1279  for (auto ptr = table.nodes__[i].deb_list__; ptr; ptr = ptr->next) {
1280  if (deja) stream << " , ";
1281 
1282  stream << ptr->key() << "=>" << ptr->val();
1283 
1284  deja = true;
1285  }
1286 
1287  stream << "}";
1288 
1289  return stream;
1290  }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47

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.

◆ deb_list__

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

A pointer on the first element of the chained list.

Definition at line 534 of file hashTable.h.

◆ 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.


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