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); \
151 template<template_args> \
152 struct hash<const type> \
155 typedef type argument_type; \
156 typedef std::size_t result_type; \
158 std::size_t operator()(const type& arg) const \
160 return hash_value(arg); \
176#define DUNE_HASH_TEMPLATE_ARGS(...) (__VA_ARGS__)
180#define DUNE_HASH_TYPE(...) (__VA_ARGS__)
184#define DUNE_HASH_EXPAND_VA_ARGS(...) __VA_ARGS__
187#define DUNE_DEFINE_HASH(template_args,type) \
188 DUNE_DEFINE_STD_HASH(DUNE_HASH_EXPAND_VA_ARGS template_args, DUNE_HASH_EXPAND_VA_ARGS type) \
223 template<
int sizeof_
size_t>
224 struct hash_combiner;
229 struct hash_combiner<8>
232 template<
typename typeof_
size_t,
typename T>
233 void operator()(typeof_size_t& seed,
const T& arg)
const
235 static_assert(
sizeof(typeof_size_t)==8,
"hash_combiner::operator() instantiated with nonmatching type and size");
251 const typeof_size_t kMul = 0x9ddfea08eb382d69ULL;
252 typeof_size_t h = hasher(arg);
253 typeof_size_t a = (seed ^ h) * kMul;
255 typeof_size_t b = (h ^ a) * kMul;
266 struct hash_combiner<4>
269 template<
typename typeof_
size_t,
typename T>
270 void operator()(typeof_size_t& seed,
const T& arg)
const
272 static_assert(
sizeof(typeof_size_t)==4,
"hash_combiner::operator() instantiated with nonmatching type and size");
282 const typeof_size_t c1 = 0xcc9e2d51;
283 const typeof_size_t c2 = 0x1b873593;
284 const typeof_size_t c3 = 0xe6546b64;
285 typeof_size_t h = hasher(arg);
286 typeof_size_t a = seed * c1;
287 a = (a >> 17) | (a << (32 - 17));
290 h = (h >> 19) | (h << (32 - 19));
307 hash_combiner<sizeof(std::size_t)>()(seed,arg);
319 template<
typename It>
322 std::size_t seed = 0;
323 for (; first != last; ++first)
338 template<
typename It>
341 for (; first != last; ++first)
Dune namespace.
Definition: alignedallocator.hh:14
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:320
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:305
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.