1 #ifndef ZSERIO_HASH_CODE_UTIL_H_INC
2 #define ZSERIO_HASH_CODE_UTIL_H_INC
21 static const uint32_t HASH_PRIME_NUMBER = 37;
23 static const uint32_t HASH_SEED = 23;
34 return HASH_PRIME_NUMBER * seedValue;
46 inline typename std::enable_if<std::is_integral<T>::value && (
sizeof(T) <= 4), uint32_t>::type
calcHashCode(
47 uint32_t seedValue, T value)
61 inline typename std::enable_if<std::is_integral<T>::value && (
sizeof(T) > 4), uint32_t>::type
calcHashCode(
62 uint32_t seedValue, T value)
64 const auto unsignedValue =
static_cast<typename std::make_unsigned<T>::type
>(value);
65 return calcHashCodeFirstTerm(seedValue) +
static_cast<uint32_t
>(unsignedValue ^ (unsignedValue >> 32U));
104 return calcHashCode(seedValue,
static_cast<Bool::ValueType
>(value));
115 template <BitSize BIT_SIZE,
bool IS_SIGNED>
116 inline uint32_t
calcHashCode(uint32_t seedValue, detail::FixedIntWrapper<BIT_SIZE, IS_SIGNED> value)
118 using ValueType =
typename detail::FixedIntWrapper<BIT_SIZE, IS_SIGNED>::ValueType;
119 return calcHashCode(seedValue,
static_cast<ValueType
>(value));
130 template <
typename VALUE_TYPE>
131 inline uint32_t
calcHashCode(uint32_t seedValue, detail::DynIntWrapper<VALUE_TYPE> value)
133 return calcHashCode(seedValue,
static_cast<VALUE_TYPE
>(value));
144 template <
typename VALUE_TYPE, detail::VarIntType VAR_TYPE>
145 inline uint32_t
calcHashCode(uint32_t seedValue, detail::VarIntWrapper<VALUE_TYPE, VAR_TYPE> value)
147 return calcHashCode(seedValue,
static_cast<VALUE_TYPE
>(value));
158 template <
typename VALUE_TYPE, detail::FloatType FLOAT_TYPE>
159 inline uint32_t
calcHashCode(uint32_t seedValue, detail::FloatWrapper<VALUE_TYPE, FLOAT_TYPE> value)
161 return calcHashCode(seedValue,
static_cast<VALUE_TYPE
>(value));
174 template <
typename ALLOC>
177 uint32_t result = seedValue;
178 for (
auto element : stringValue)
194 inline uint32_t
calcHashCode(uint32_t seedValue, std::string_view stringValue)
196 uint32_t result = seedValue;
197 for (
auto element : stringValue)
213 template <
typename T>
214 inline std::enable_if_t<std::is_enum_v<T> || is_bitmask_v<T>, uint32_t>
calcHashCode(
215 uint32_t seedValue, T value)
228 template <
typename OBJECT>
229 inline std::enable_if_t<!std::is_enum_v<OBJECT> && !is_bitmask_v<OBJECT> && !std::is_integral_v<OBJECT>,
233 return calcHashCode(seedValue, std::hash<OBJECT>()(
object));
247 uint32_t result = seedValue;
248 for (
auto byte : bytes)
264 template <
typename ARRAY_ELEMENT,
typename ALLOC>
267 uint32_t result = seedValue;
268 for (
const ARRAY_ELEMENT& element : array)
uint64_t convertDoubleToUInt64(double float64)
std::basic_string< char, std::char_traits< char >, ALLOC > BasicString
std::vector< T, ALLOC > Vector
uint32_t convertFloatToUInt32(float float32)
uint32_t calcHashCodeFirstTerm(uint32_t seedValue)
uint32_t calcHashCode(uint32_t seedValue, const ArrayView< T, ARRAY_TRAITS > &array)