33 #ifndef DOXYGEN_SHOULD_SKIP_THIS 38 template <
typename Key >
43 "the size of the hashtable must be at least 2 but a size of " 44 << new_size <<
" was provided to the resize function.");
48 _hash_size =
Size(1) << _hash_log2_size;
49 _hash_mask = _hash_size - 1;
54 template <
typename Key >
62 template <
typename Key >
64 static_assert(std::is_integral< Key >::value &&
sizeof(Key) <=
sizeof(
Size),
65 "Error: you used HashFuncSmallKey for a key which cannot be " 66 "converted (without narrowing) into a gum::Size");
70 template <
typename Key >
76 template <
typename Key >
84 template <
typename Key >
86 static_assert(
sizeof(Key) <
sizeof(
Size),
87 "Error: you used HashFuncSmallCastKey for a key whose size " 88 "is longer than or equal to that of gum::Size");
92 template <
typename Key >
98 template <
typename Key >
106 template <
typename Key >
108 static_assert(
sizeof(Key) ==
sizeof(
Size),
109 "Error: using HashFuncMediumCastKey for a key whose size " 110 "is different from that of a gum::Size");
114 template <
typename Key >
116 return *((
Size*)(&key));
120 template <
typename Key >
128 template <
typename Key >
130 static_assert(
sizeof(Key) == 2 *
sizeof(
Size),
131 "Error: you used HashFuncLargeCastKey for a key whose size " 132 "is different from twice that of a gum::Size");
136 template <
typename Key >
138 const Size* ptr =
reinterpret_cast< const Size*
>(&key);
139 return ptr[0] ^ ptr[1];
143 template <
typename Key >
151 template <
typename Key1,
typename Key2 >
152 INLINE
Size HashFunc< std::pair< Key1, Key2 > >::castToSize(
153 const std::pair< Key1, Key2 >& key) {
155 + HashFunc< Key2 >::castToSize(key.second);
159 template <
typename Key1,
typename Key2 >
160 INLINE
Size HashFunc< std::pair< Key1, Key2 > >::
161 operator()(
const std::pair< Key1, Key2 >& key)
const {
168 template <
typename Type >
169 INLINE
Size HashFunc< RefPtr< Type > >::castToSize(
const RefPtr< Type >& key) {
170 return HashFunc< Type* >::castToSize(key.__refCountPtr());
174 template <
typename Type >
175 INLINE
Size HashFunc< RefPtr< Type > >::
176 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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.