3#ifndef DUNE_COMMON_HASH_HH
4#define DUNE_COMMON_HASH_HH
98#define DUNE_DEFINE_HASH(template_args,type)
107#define DUNE_HASH_TEMPLATE_ARGS(...)
115#define DUNE_HASH_TYPE(...)
135#define DUNE_DEFINE_STD_HASH(template_args,type) \
138 template<template_args> \
142 typedef type argument_type; \
143 typedef std::size_t result_type; \
145 std::size_t operator()(const type& arg) const \
147 return hash_value(arg); \
163#define DUNE_HASH_TEMPLATE_ARGS(...) (__VA_ARGS__)
167#define DUNE_HASH_TYPE(...) (__VA_ARGS__)
171#define DUNE_HASH_EXPAND_VA_ARGS(...) __VA_ARGS__
174#define DUNE_DEFINE_HASH(template_args,type) \
175 DUNE_DEFINE_STD_HASH(DUNE_HASH_EXPAND_VA_ARGS template_args, DUNE_HASH_EXPAND_VA_ARGS type) \
210 template<
int sizeof_
size_t>
211 struct hash_combiner;
216 struct hash_combiner<8>
219 template<
typename typeof_
size_t,
typename T>
220 void operator()(typeof_size_t& seed,
const T& arg)
const
222 static_assert(
sizeof(typeof_size_t)==8,
"hash_combiner::operator() instantiated with nonmatching type and size");
238 const typeof_size_t kMul = 0x9ddfea08eb382d69ULL;
239 typeof_size_t h = hasher(arg);
240 typeof_size_t a = (seed ^ h) * kMul;
242 typeof_size_t b = (h ^ a) * kMul;
253 struct hash_combiner<4>
256 template<
typename typeof_
size_t,
typename T>
257 void operator()(typeof_size_t& seed,
const T& arg)
const
259 static_assert(
sizeof(typeof_size_t)==4,
"hash_combiner::operator() instantiated with nonmatching type and size");
269 const typeof_size_t c1 = 0xcc9e2d51;
270 const typeof_size_t c2 = 0x1b873593;
271 const typeof_size_t c3 = 0xe6546b64;
272 typeof_size_t h = hasher(arg);
273 typeof_size_t a = seed * c1;
274 a = (a >> 17) | (a << (32 - 17));
277 h = (h >> 19) | (h << (32 - 19));
295 hash_combiner<sizeof(std::size_t)>()(seed,arg);
308 template<
typename It>
311 std::size_t seed = 0;
312 for (; first != last; ++first)
328 template<
typename It>
331 for (; first != last; ++first)
Dune namespace.
Definition: alignment.hh:10
std::size_t hash_range(It first, It last)
Hashes all elements in the range [first,last) and returns the combined hash.
Definition: hash.hh:309
void hash_combine(std::size_t &seed, const T &arg)
Calculates the hash value of arg and combines it in-place with seed.
Definition: hash.hh:293
Functor for hashing objects of type T.
Definition: hash.hh:38
std::size_t operator()(const T &t) const
Calculates the hash of t.
Definition: hash.hh:41
Traits for type conversions and type information.