28 #ifndef GUM_HASH_FUNC_H 29 #define GUM_HASH_FUNC_H 34 #include <type_traits> 37 #include <agrum/agrum.h> 38 #include <agrum/tools/core/refPtr.h> 76 =
sizeof(
Size) == 4 ?
Size(2654435769UL) :
Size(11400714819323198486UL);
78 =
sizeof(
Size) == 4 ?
Size(3373259426UL) :
Size(14488038916154245684UL);
80 =
sizeof(
Size) == 4 ?
Size(4294967295UL) :
Size(18446744073709551615UL);
147 template <
typename Key >
165 void resize(
const Size new_size);
240 template <
typename Key >
272 template <
typename Key >
312 template <
typename Key >
344 template <
typename Key >
380 template <
typename Key >
403 template <
typename Key >
407 template <
typename... >
408 struct HashFuncConditionalType;
411 template <
typename Key >
412 struct HashFuncConditionalType< Key > {
417 template <
typename KEY_TYPE,
typename TYPE >
418 struct HashFuncConditionalType< KEY_TYPE, TYPE > {
419 using type =
typename std::conditional< std::is_same< KEY_TYPE, TYPE >::value,
445 template <
typename KEY_TYPE,
typename FIRST_TYPE,
typename... OTHER_TYPES >
446 struct HashFuncConditionalType< KEY_TYPE, FIRST_TYPE, OTHER_TYPES... > {
447 using type =
typename std::conditional<
448 std::is_same< KEY_TYPE, FIRST_TYPE >::value,
450 typename HashFuncConditionalType< KEY_TYPE, OTHER_TYPES... >::type >::type;
469 template <
typename key >
480 template <
typename Key1,
typename Key2 >
579 template <
typename Type >
663 template <
typename Type >
685 #ifndef GUM_NO_INLINE 686 # include <agrum/tools/core/hashFunc_inl.h> 690 #include <agrum/tools/core/hashFunc_tpl.h>
HashFuncSmallCastKey()
Class constructor.
static constexpr Size offset
HashFuncMediumCastKey()
Class constructor.
Generic hash functions for keys castable as Size and whose size is precisely twice that of Size...
static constexpr Size gold
static constexpr Size small_key_mask_
An additional mask to ensure that keys with fewer bits than Size are cast correctly.
Size hash_size_
The size of the hash table.
INLINE void emplace(Args &&... args)
HashFuncSmallKey()
Class constructor.
static constexpr Size mask
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.
friend class HashFunc
A friend for hashing quickly ref pointers.
static Size castToSize(const Key &key)
Returns the value of a key as a Size.
Generic hash functions for keys castable as Size whose size is either smaller than Size...
unsigned int right_shift_
performing y = x >> right_shift_ guarantees that y is a slot index of the hash table ...
Generic hash functions for keys castable as Size and whose size is precisely that of Size...
Size hash_mask_
performing y = x & hash_mask_ guarantees that y is a slot index of the hash table ...
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.
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...
HashFuncLargeCastKey()
Class constructor.
Useful constants for hash functions.
Generic hash functions for numeric keys smaller than or equal to Size.
virtual Size operator()(const Key &key) const override final
Computes the hashed value of a key.
virtual Size operator()(const std::pair< Key1, Key2 > &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.
static Size castToSize(const std::pair< Key1, Key2 > &key)
Returns the value of a key as a Size.
All hash functions should inherit from this class.
void resize(const Size new_size)
Update the hash function to take into account a resize of the hash table.
unsigned int hash_log2_size_
Log of the number of slots of the hash table in base 2.
Generic hash functions for keys castable as Size and whose size is strictly smaller than that of Size...
virtual Size operator()(const Key &key) const =0
Computes the hashed value of a key.
virtual Size operator()(const Key &key) const override final
Computes the hashed value of a key.
static Size castToSize(const Key &key)
Returns the value of a key as a Size.