31 #ifndef DOXYGEN_SHOULD_SKIP_THIS 36 template <
typename Key >
41 "the size of the hashtable must be at least 2 but a size of " 42 << new_size <<
" was provided to the resize function.");
46 _hash_size =
Size(1) << _hash_log2_size;
47 _hash_mask = _hash_size - 1;
52 template <
typename Key >
60 template <
typename Key >
62 static_assert(std::is_integral< Key >::value &&
sizeof(Key) <=
sizeof(
Size),
63 "Error: you used HashFuncSmallKey for a key which cannot be " 64 "converted (without narrowing) into a gum::Size");
68 template <
typename Key >
74 template <
typename Key >
82 template <
typename Key >
84 static_assert(
sizeof(Key) <
sizeof(
Size),
85 "Error: you used HashFuncSmallCastKey for a key whose size " 86 "is longer than or equal to that of gum::Size");
90 template <
typename Key >
96 template <
typename Key >
104 template <
typename Key >
106 static_assert(
sizeof(Key) ==
sizeof(
Size),
107 "Error: using HashFuncMediumCastKey for a key whose size " 108 "is different from that of a gum::Size");
112 template <
typename Key >
114 return *((
Size*)(&key));
118 template <
typename Key >
126 template <
typename Key >
128 static_assert(
sizeof(Key) == 2 *
sizeof(
Size),
129 "Error: you used HashFuncLargeCastKey for a key whose size " 130 "is different from twice that of a gum::Size");
134 template <
typename Key >
136 const Size* ptr =
reinterpret_cast< const Size*
>(&key);
137 return ptr[0] ^ ptr[1];
141 template <
typename Key >
149 template <
typename Key1,
typename Key2 >
150 INLINE
Size HashFunc< std::pair< Key1, Key2 > >::castToSize(
151 const std::pair< Key1, Key2 >& key) {
153 + HashFunc< Key2 >::castToSize(key.second);
157 template <
typename Key1,
typename Key2 >
158 INLINE
Size HashFunc< std::pair< Key1, Key2 > >::
159 operator()(
const std::pair< Key1, Key2 >& key)
const {
166 template <
typename Type >
167 INLINE
Size HashFunc< RefPtr< Type > >::castToSize(
const RefPtr< Type >& key) {
168 return HashFunc< Type* >::castToSize(key.__refCountPtr());
172 template <
typename Type >
173 INLINE
Size HashFunc< RefPtr< Type > >::
174 operator()(
const RefPtr< Type >& key)
const {
HashFuncSmallCastKey()
Class constructor.
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...
static constexpr Size offset
HashFuncMediumCastKey()
Class constructor.
static constexpr Size gold
HashFuncSmallKey()
Class constructor.
static constexpr Size _small_key_mask
An additional mask to ensure that keys with fewer bits than Size are cast correctly.
Classes providing basic hash functions for hash tables.
Size size() const
Returns the hash table size as known by the hash function.
virtual Size operator()(const Key &key) const override final
Computes the hashed value of a key.
gum is the global namespace for all aGrUM entities
static Size castToSize(const Key &key)
Returns the value of a key as a Size.
static Size castToSize(const Key &key)
Returns the value of a key as a Size.
static Size castToSize(const Key &key)
Cast key to the expected type.
HashFuncLargeCastKey()
Class constructor.
virtual Size operator()(const Key &key) const override final
Computes the hashed value of a key.
virtual Size operator()(const Key &key) const override final
Computes the hashed value of a key.
void resize(const Size new_size)
Update the hash function to take into account a resize of the hash table.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
virtual Size operator()(const Key &key) const override final
Computes the hashed value of a key.
#define GUM_ERROR(type, msg)
static Size castToSize(const Key &key)
Returns the value of a key as a Size.