1 #ifndef ZSERIO_HASH_CODE_UTIL_H_INC
2 #define ZSERIO_HASH_CODE_UTIL_H_INC
18 static const uint32_t HASH_PRIME_NUMBER = 37;
20 static const uint32_t HASH_SEED = 23;
31 return HASH_PRIME_NUMBER * seedValue;
43 inline typename std::enable_if<std::is_integral<T>::value && (
sizeof(T) <= 4), uint32_t>::type
calcHashCode(
44 uint32_t seedValue, T value)
58 inline typename std::enable_if<std::is_integral<T>::value && (
sizeof(T) > 4), uint32_t>::type
calcHashCode(
59 uint32_t seedValue, T value)
61 const auto unsignedValue =
static_cast<typename std::make_unsigned<T>::type
>(value);
62 return calcHashCodeFirstTerm(seedValue) +
static_cast<uint32_t
>(unsignedValue ^ (unsignedValue >> 32U));
99 template <
typename ALLOC>
101 uint32_t seedValue,
const std::basic_string<
char, std::char_traits<char>, ALLOC>& stringValue)
103 uint32_t result = seedValue;
104 for (
auto element : stringValue)
120 template <
typename ENUM_TYPE>
121 inline typename std::enable_if<std::is_enum<ENUM_TYPE>::value, uint32_t>::type
calcHashCode(
122 uint32_t seedValue, ENUM_TYPE enumValue)
135 template <
typename OBJECT>
136 inline typename std::enable_if<!std::is_enum<OBJECT>::value && !std::is_integral<OBJECT>::value, uint32_t>::type
150 template <
typename ARRAY_ELEMENT,
typename ALLOC>
151 inline uint32_t
calcHashCode(uint32_t seedValue,
const std::vector<ARRAY_ELEMENT, ALLOC>& array)
153 uint32_t result = seedValue;
154 for (
const ARRAY_ELEMENT& element : array)
172 template <
typename FIELD>
191 template <
typename FIELD,
typename ALLOC>
uint64_t convertDoubleToUInt64(double float64)
uint32_t convertFloatToUInt32(float float32)
uint32_t calcHashCodeFirstTerm(uint32_t seedValue)
std::enable_if< std::is_integral< T >::value &&(sizeof(T)<=4), uint32_t >::type calcHashCode(uint32_t seedValue, T value)
detail::heap_optional_holder< T, ALLOC > HeapOptionalHolder
uint32_t enumHashCode(T value)
detail::inplace_optional_holder< T > InplaceOptionalHolder