48#ifndef GUM_HASH_FUNC_H
49#define GUM_HASH_FUNC_H
101 =
sizeof(
Size) == 4 ?
Size(2654435769UL) :
Size(11400714819323198486UL);
103 =
sizeof(
Size) == 4 ?
Size(3373259426UL) :
Size(14488038916154245684UL);
105 =
sizeof(
Size) == 4 ?
Size(3719550786UL) :
Size(15975348984942515101UL);
107 =
sizeof(
Size) == 4 ?
Size(4294967295UL) :
Size(18446744073709551615UL);
173 template <
typename Key >
265 template <
typename Key >
301 template <
typename Key >
339 template <
typename Key >
370 template <
typename Key >
405 template <
typename Key >
408 using type =
typename std::conditional<
409 sizeof(Key) <=
sizeof(
Size) && std::is_integral< Key >::value,
411 typename std::conditional<
412 sizeof(Key) <
sizeof(
Size),
414 typename std::conditional<
sizeof(Key) ==
sizeof(
Size),
416 typename std::conditional<
sizeof(Key) == 2 *
sizeof(
Size),
427 template <
typename Key >
431 template <
typename... >
435 template <
typename Key >
441 template <
typename KEY_TYPE,
typename TYPE >
468 template <
typename KEY_TYPE,
typename FIRST_TYPE,
typename... OTHER_TYPES >
470 using type =
typename std::conditional<
471 std::is_same< KEY_TYPE, FIRST_TYPE >::value,
491 template <
typename key >
502 template <
typename Key1,
typename Key2 >
595 template <
typename Type >
672 template <
typename OTHER_KEY >
682 template <
typename Type >
All hash functions should inherit from this class.
virtual Size operator()(const Key &key) const =0
Computes the hashed value of a key.
unsigned int right_shift_
performing y = x >> right_shift_ guarantees that y is a slot index of the hash table
Size size() const
Returns the hash table size as known by the hash function.
Size hash_size_
The size of the hash table.
Size hash_mask_
performing y = x & hash_mask_ guarantees that y is a slot index of the hash table
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 precisely twice that of Size.
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.
Generic hash functions for keys castable as Size and whose size is precisely that of Size.
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.
Generic hash functions for keys castable as Size and whose size is strictly smaller than that of Size...
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.
Generic hash functions for numeric keys smaller than or equal to Size.
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.
Size operator()(const Debug &key) const final
Computes the hashed value of a key.
static Size castToSize(const Debug &key)
Returns the value of a key as a Size.
Size operator()(const std::pair< Key1, Key2 > &key) const 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.
Size operator()(const std::shared_ptr< Type > &key) const final
Computes the hashed value of a key.
static Size castToSize(const std::shared_ptr< Type > &key)
Returns the value of a key as a Size.
static Size castToSize(const std::string &key)
Returns the value of a key as a Size.
Size operator()(const std::string &key) const final
Computes the hashed value of a key.
Size operator()(std::string_view key) const
Non-virtual overload for heterogeneous lookup with string_view.
static Size castToSize(std::string_view key)
Returns the value of a string_view key as a Size (heterogeneous lookup).
Size operator()(const std::vector< Idx > &key) const final
Computes the hashed value of a key.
static Size castToSize(const std::vector< Idx > &key)
Returns the value of a key as a Size.
This class should be useless as only its specializations should be used.
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.
Inlined implementation of the basic hash functions.
Template implementation of the basic hash functions.
gum is the global namespace for all aGrUM entities
Generic hash functions for keys castable as Size whose size is either smaller than Size,...
typename std::conditional< sizeof(Key)<=sizeof(Size) &&std::is_integral< Key >::value, HashFuncSmallKey< Key >, typename std::conditional< sizeof(Key)< sizeof(Size), HashFuncSmallCastKey< Key >, typename std::conditional< sizeof(Key)==sizeof(Size), HashFuncMediumCastKey< Key >, typename std::conditional< sizeof(Key)==2 *sizeof(Size), HashFuncLargeCastKey< Key >, void >::type >::type >::type >:: type type
The type used by this class.
typename std::conditional< std::is_same< KEY_TYPE, FIRST_TYPE >::value, dummyHash< KEY_TYPE >, typename HashFuncConditionalType< KEY_TYPE, OTHER_TYPES... >::type >::type type
typename std:: conditional< std::is_same< KEY_TYPE, TYPE >::value, dummyHash< KEY_TYPE >, KEY_TYPE >::type type
This class enables to safely define hash functions for types that may or may not already has defined ...
Useful constants for hash functions.
static constexpr Size mask
static constexpr Size sqrt3
static constexpr Size offset
static constexpr Size gold