5#ifndef DUNE_COMMON_HASH_HH
6#define DUNE_COMMON_HASH_HH
100#define DUNE_DEFINE_HASH(template_args,type)
109#define DUNE_HASH_TEMPLATE_ARGS(...)
117#define DUNE_HASH_TYPE(...)
137#define DUNE_DEFINE_STD_HASH(template_args,type) \
140 template<template_args> \
144 typedef type argument_type; \
145 typedef std::size_t result_type; \
147 std::size_t operator()(const type& arg) const \
149 return hash_value(arg); \
153 template<template_args> \
154 struct hash<const type> \
157 typedef type argument_type; \
158 typedef std::size_t result_type; \
160 std::size_t operator()(const type& arg) const \
162 return hash_value(arg); \
178#define DUNE_HASH_TEMPLATE_ARGS(...) (__VA_ARGS__)
182#define DUNE_HASH_TYPE(...) (__VA_ARGS__)
186#define DUNE_HASH_EXPAND_VA_ARGS(...) __VA_ARGS__
189#define DUNE_DEFINE_HASH(template_args,type) \
190 DUNE_DEFINE_STD_HASH(DUNE_HASH_EXPAND_VA_ARGS template_args, DUNE_HASH_EXPAND_VA_ARGS type) \
225 template<
int sizeof_
size_t>
226 struct hash_combiner;
231 struct hash_combiner<8>
234 template<
typename typeof_
size_t,
typename T>
235 void operator()(typeof_size_t& seed,
const T& arg)
const
237 static_assert(
sizeof(typeof_size_t)==8,
"hash_combiner::operator() instantiated with nonmatching type and size");
253 const typeof_size_t kMul = 0x9ddfea08eb382d69ULL;
254 typeof_size_t h = hasher(arg);
255 typeof_size_t a = (seed ^ h) * kMul;
257 typeof_size_t b = (h ^ a) * kMul;
268 struct hash_combiner<4>
271 template<
typename typeof_
size_t,
typename T>
272 void operator()(typeof_size_t& seed,
const T& arg)
const
274 static_assert(
sizeof(typeof_size_t)==4,
"hash_combiner::operator() instantiated with nonmatching type and size");
284 const typeof_size_t c1 = 0xcc9e2d51;
285 const typeof_size_t c2 = 0x1b873593;
286 const typeof_size_t c3 = 0xe6546b64;
287 typeof_size_t h = hasher(arg);
288 typeof_size_t a = seed * c1;
289 a = (a >> 17) | (a << (32 - 17));
292 h = (h >> 19) | (h << (32 - 19));
309 hash_combiner<sizeof(std::size_t)>()(seed,arg);
321 template<
typename It>
324 std::size_t seed = 0;
325 for (; first != last; ++first)
340 template<
typename It>
343 for (; first != last; ++first)
Traits for type conversions and type information.
Dune namespace.
Definition: alignedallocator.hh:13
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:322
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:307
Functor for hashing objects of type T.
Definition: hash.hh:40
std::size_t operator()(const T &t) const
Calculates the hash of t.
Definition: hash.hh:43