forked from msinilo/rdestl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rhash.h
39 lines (34 loc) · 980 Bytes
/
rhash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef RDESTL_HASH_H
#define RDESTL_HASH_H
namespace rde
{
typedef unsigned long hash_value_t;
// Default implementations, just casts to hash_value.
template<typename T>
hash_value_t extract_int_key_value(const T& t)
{
return (hash_value_t)t;
}
// Default implementation of hasher.
// Works for keys that can be converted to 32-bit integer
// with extract_int_key_value.
// Algorithm by Robert Jenkins.
// (see http://www.cris.com/~Ttwang/tech/inthash.htm for example).
template<typename T>
struct hash
{
hash_value_t operator()(const T& t) const
{
hash_value_t a = extract_int_key_value(t);
a = (a+0x7ed55d16) + (a<<12);
a = (a^0xc761c23c) ^ (a>>19);
a = (a+0x165667b1) + (a<<5);
a = (a+0xd3a2646c) ^ (a<<9);
a = (a+0xfd7046c5) + (a<<3);
a = (a^0xb55a4f09) ^ (a>>16);
return a;
}
};
} // namespace rde
//-----------------------------------------------------------------------------
#endif // #ifndef RDESTL_HASH_H