56#ifndef DOXYGEN_SHOULD_SKIP_THIS
61 template <
typename Key >
66 "the size of the hashtable must be at least 2 but a size of "
67 << new_size <<
" was provided to the resize function.");
71 hash_size_ =
Size(1) << hash_log2_size_;
72 hash_mask_ = hash_size_ - 1;
77 template <
typename Key >
85 template <
typename Key >
87 static_assert(std::is_integral_v< Key > &&
sizeof(Key) <=
sizeof(
Size),
88 "Error: you used HashFuncSmallKey for a key which cannot be "
89 "converted (without narrowing) into a gum::Size");
93 template <
typename Key >
99 template <
typename Key >
107 template <
typename Key >
109 static_assert(
sizeof(Key) <
sizeof(
Size),
110 "Error: you used HashFuncSmallCastKey for a key whose size "
111 "is longer than or equal to that of gum::Size");
115 template <
typename Key >
124 memcpy(&result, &key,
sizeof(Key));
130 template <
typename Key >
138 template <
typename Key >
140 static_assert(
sizeof(Key) ==
sizeof(
Size),
141 "Error: using HashFuncMediumCastKey for a key whose size "
142 "is different from that of a gum::Size");
146 template <
typename Key >
148 return *((
Size*)(&key));
152 template <
typename Key >
160 template <
typename Key >
162 static_assert(
sizeof(Key) == 2 *
sizeof(
Size),
163 "Error: you used HashFuncLargeCastKey for a key whose size "
164 "is different from twice that of a gum::Size");
168 template <
typename Key >
170 const Size* ptr =
reinterpret_cast< const Size*
>(&key);
171 return ptr[0] ^ ptr[1];
175 template <
typename Key >
183 template <
typename Key1,
typename Key2 >
190 template <
typename Key1,
typename Key2 >
198 template <
typename Type >
204 template <
typename Type >
Size size() const
Returns the hash table size as known by the hash function.
void resize(const Size new_size)
Update the hash function to take into account a resize of the hash table.
virtual Size operator()(const Key &key) const final
Computes the hashed value of a key.
HashFuncLargeCastKey()
Class constructor.
static Size castToSize(const Key &key)
Cast key to the expected type.
static Size castToSize(const Key &key)
Returns the value of a key as a Size.
Size operator()(const Key &key) const final
Computes the hashed value of a key.
HashFuncMediumCastKey()
Class constructor.
HashFuncSmallCastKey()
Class constructor.
static Size castToSize(const Key &key)
Returns the value of a key as a Size.
Size operator()(const Key &key) const final
Computes the hashed value of a key.
static constexpr Size small_key_mask_
An additional mask to ensure that keys with fewer bits than Size are cast correctly.
static Size castToSize(const Key &key)
Returns the value of a key as a Size.
Size operator()(const Key &key) const final
Computes the hashed value of a key.
HashFuncSmallKey()
Class constructor.
This class should be useless as only its specializations should be used.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
unsigned int _hashTableLog2_(const Size nb)
Returns the size in bits - 1 necessary to store the smallest power of 2 greater than or equal to nb.
Classes providing basic hash functions for hash tables.
gum is the global namespace for all aGrUM entities
static constexpr Size offset
static constexpr Size gold