aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::HashFunc< Instantiation > Class Template Reference

Hash function for gum::Instantiation. More...

#include <instantiation.h>

+ Inheritance diagram for gum::HashFunc< Instantiation >:
+ Collaboration diagram for gum::HashFunc< Instantiation >:

Public Member Functions

virtual Size operator() (const Instantiation &key) const override final
 Computes the hashed value of a key. More...
 
void resize (const Size new_size)
 Update the hash function to take into account a resize of the hash table. More...
 
Size size () const
 Returns the hash table size as known by the hash function. More...
 

Static Public Member Functions

static Size castToSize (const Instantiation &key)
 Returns the value of a key as a Size. More...
 

Protected Attributes

Size hash_size_
 The size of the hash table. More...
 
unsigned int hash_log2_size_
 Log of the number of slots of the hash table in base 2. More...
 
Size hash_mask_
 performing y = x & hash_mask_ guarantees that y is a slot index of the hash table More...
 
unsigned int right_shift_
 performing y = x >> right_shift_ guarantees that y is a slot index of the hash table More...
 

Detailed Description

template<>
class gum::HashFunc< Instantiation >

Hash function for gum::Instantiation.

Definition at line 1248 of file instantiation.h.

Member Function Documentation

◆ castToSize()

INLINE Size gum::HashFunc< Instantiation >::castToSize ( const Instantiation key)
static

Returns the value of a key as a Size.

returns a hashed key for hash tables the keys of which are represented by vectors of Idx

Parameters
keyThe value to return as a Size.
Returns
Returns the value of a key as a Size.

Definition at line 786 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

786  {
787  Size h = Size(0);
788  for (const DiscreteVariable* k:
789  key.variablesSequence()) // k are unique only by address (not by name)
790  h += HashFunc< const DiscreteVariable* >::castToSize(k) * Size(key.val(*k));
791 
792  return h;
793  }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ operator()()

INLINE Size gum::HashFunc< Instantiation >::operator() ( const Instantiation key) const
finaloverridevirtual

Computes the hashed value of a key.

returns a hashed key for hash tables the keys of which are represented by vectors of Idx

Parameters
keyThe key to compute the hashed value.
Returns
Returns the hashed value of a key.

Implements gum::HashFuncBase< Instantiation >.

Definition at line 797 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

797  {
798  return castToSize(key) & this->hash_mask_;
799  }
Size hash_mask_
performing y = x & hash_mask_ guarantees that y is a slot index of the hash table ...
Definition: hashFunc.h:214
static Size castToSize(const Instantiation &key)
Returns the value of a key as a Size.
+ Here is the call graph for this function:

◆ resize()

void gum::HashFuncBase< Instantiation >::resize ( const Size  new_size)
inherited

Update the hash function to take into account a resize of the hash table.

When the user wishes to resize the gum::HashTable so that the array is of size s, the gum::HashTable resizes itself to the smallest power of 2 greater than or equal to s. This new size is computed by function gum::HashFuncBase::resize(gum::Size). Hence, s should be the size of the array of lists, not the number of elements stored into the gum::HashTable.

Parameters
new_sizeThe hashtable's size wished by the user. Actually, a hashtable of size n is an array of n lists.
Exceptions
SizeErrorRaised if s is too small.

◆ size()

Size gum::HashFuncBase< Instantiation >::size ( ) const
inherited

Returns the hash table size as known by the hash function.

Returns
Returns the size of the hash table, i.e., the number of slots (lists) it contains.

Member Data Documentation

◆ hash_log2_size_

unsigned int gum::HashFuncBase< Instantiation >::hash_log2_size_
protectedinherited

Log of the number of slots of the hash table in base 2.

Definition at line 203 of file hashFunc.h.

◆ hash_mask_

Size gum::HashFuncBase< Instantiation >::hash_mask_
protectedinherited

performing y = x & hash_mask_ guarantees that y is a slot index of the hash table

To transform a Size x into a slot index of the hash table, you can either use x & hash_mask_ or x >> right_shift_ depending on whether you want to exploit the least significant bits of x (&) or the most significant one (>>).

Definition at line 214 of file hashFunc.h.

◆ hash_size_

Size gum::HashFuncBase< Instantiation >::hash_size_
protectedinherited

The size of the hash table.

Definition at line 200 of file hashFunc.h.

◆ right_shift_

unsigned int gum::HashFuncBase< Instantiation >::right_shift_
protectedinherited

performing y = x >> right_shift_ guarantees that y is a slot index of the hash table

To transform a Size x into a slot index of the hash table, you can either use x & hash_mask_ or x >> right_shift_ depending on whether you want to exploit the least significant bits of x (&) or the most significant one (>>).

Definition at line 225 of file hashFunc.h.


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