55#ifndef DOXYGEN_SHOULD_SKIP_THIS
60 template <
typename Key >
65 "the size of the hashtable must be at least 2 but a size of "
66 << new_size <<
" was provided to the resize function.");
70 hash_size_ =
Size(1) << hash_log2_size_;
71 hash_mask_ = hash_size_ - 1;
76 template <
typename Key >
84 template <
typename Key >
86 static_assert(std::is_integral< Key >::value &&
sizeof(Key) <=
sizeof(
Size),
87 "Error: you used HashFuncSmallKey for a key which cannot be "
88 "converted (without narrowing) into a gum::Size");
92 template <
typename Key >
98 template <
typename Key >
106 template <
typename Key >
108 static_assert(
sizeof(Key) <
sizeof(
Size),
109 "Error: you used HashFuncSmallCastKey for a key whose size "
110 "is longer than or equal to that of gum::Size");
114 template <
typename Key >
123 memcpy(&result, &key,
sizeof(Key));
129 template <
typename Key >
137 template <
typename Key >
139 static_assert(
sizeof(Key) ==
sizeof(
Size),
140 "Error: using HashFuncMediumCastKey for a key whose size "
141 "is different from that of a gum::Size");
145 template <
typename Key >
147 return *((
Size*)(&key));
151 template <
typename Key >
159 template <
typename Key >
161 static_assert(
sizeof(Key) == 2 *
sizeof(
Size),
162 "Error: you used HashFuncLargeCastKey for a key whose size "
163 "is different from twice that of a gum::Size");
167 template <
typename Key >
169 const Size* ptr =
reinterpret_cast< const Size*
>(&key);
170 return ptr[0] ^ ptr[1];
174 template <
typename Key >
182 template <
typename Key1,
typename Key2 >
189 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 override 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.
virtual Size operator()(const Key &key) const override 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.
virtual Size operator()(const Key &key) const override 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.
virtual Size operator()(const Key &key) const override 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