12 #ifndef G3D_HashTrait_h
13 #define G3D_HashTrait_h
23 #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
24 || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
25 #define get16bits(d) (*((const uint16_t *) (d)))
28 #if !defined (get16bits)
29 #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
30 +(uint32_t)(((const uint8_t *)(d))[0]) )
36 const char* data = (
const char*)_data;
41 if ((numBytes <= 0) || (data ==
NULL)) {
49 for (;numBytes > 0; --numBytes) {
52 hash = (hash << 16) ^ tmp;
61 hash ^= data[
sizeof (
uint16_t)] << 18;
68 case 1: hash += *data;
91 key = (~key) + (key << 18);
92 key = key ^ (key >> 31);
94 key = key ^ (key >> 11);
95 key = key + (key << 6);
108 static size_t hashCode(
const void* k) {
return reinterpret_cast<size_t>(k) >> 1; }
113 static size_t hashCode(
const std::type_info*
const t) {
115 return t->hash_code();
117 return reinterpret_cast<size_t>(t) >> 1;
139 template <>
struct HashTrait <long unsigned int> {
166 #if 0 // Really slow under gcc
168 static const G3D::uint128 FNV_PRIME_128(1 << 24, 0x159);
169 static const G3D::uint128 FNV_OFFSET_128(0xCF470AAC6CB293D2ULL, 0xF52F88BF32307F8FULL);
173 for (
int i = 0; i < 16; ++i) {
174 hash *= FNV_PRIME_128;
175 hash ^= (mask & key);
180 return static_cast<size_t>((foldedHash >> 32) ^ (foldedHash & 0xFFFFFFFF));
static size_t hashCode(G3D::uint32 k)
Definition: HashTrait.h:135
static size_t hashCode(G3D::uint16 k)
Definition: HashTrait.h:127
int16_t int16
Definition: g3dmath.h:165
size_t hashCode() const
Definition: Vector2unorm16.h:76
#define hash
Definition: private_namespace.h:186
static size_t hashCode(const std::string &k)
Definition: HashTrait.h:155
int64_t int64
Definition: Define.h:145
static size_t hashCode(G3D::int64 k)
Definition: HashTrait.h:150
static size_t hashCode(G3D::uint128 key)
Definition: HashTrait.h:162
G3D::uint64 hi
Definition: uint128.h:23
uint32_t superFastHash(const void *_data, size_t numBytes)
A hash function that is faster than CRC32 for arbitrary long strings http://www.azillionmonkeys.com/qed/hash.html by Paul Hsieh.
Definition: HashTrait.h:35
static size_t hashCode(G3D::uint64 k)
Definition: HashTrait.h:146
Definition: HashTrait.h:105
arena_t NULL
Definition: jemalloc_internal.h:624
uint64_t uint64
Definition: g3dmath.h:170
uint16_t uint16
Definition: g3dmath.h:166
unsigned int uint32_t
Definition: stdint.h:80
static size_t hashCode(G3D::int16 k)
Definition: HashTrait.h:123
uint32_t wangHash6432Shift(int64 key)
Definition: HashTrait.h:90
static size_t hashCode(const void *k)
Definition: HashTrait.h:108
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
#define get16bits(d)
Definition: HashTrait.h:29
uint16_t uint16
Definition: Define.h:151
int64_t int64
Definition: g3dmath.h:169
int32_t int32
Definition: g3dmath.h:167
G3D::uint64 lo
Definition: uint128.h:24
int16_t int16
Definition: Define.h:147
uint32_t uint32
Definition: g3dmath.h:168
#define const
Definition: zconf.h:217
static size_t hashCode(G3D::int32 k)
Definition: HashTrait.h:131
static size_t hashCode(const std::type_info *const t)
Definition: HashTrait.h:113
unsigned short uint16_t
Definition: stdint.h:79