9 http://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function
10 http://www.isthe.com/chongo/tech/comp/fnv/index.html
13 uint32_t hash32(const void *data, unsigned size, unsigned bits)
15 if(bits==0 || bits>32)
16 throw invalid_argument("hash32");
18 static const unsigned prime = 16777619;
19 static const unsigned offset = 2166136261U;
21 unsigned result = offset;
22 for(unsigned i=0; i<size; ++i)
23 result = (result^*(reinterpret_cast<const unsigned char *>(data)+i))*prime;
26 result = (result>>bits ^ result) & ((1<<bits)-1);
31 uint64_t hash64(const void *data, unsigned size, unsigned bits)
33 if(bits==0 || bits>64)
34 throw invalid_argument("hash64");
36 static const uint64_t prime = 1099511628211ULL;
37 static const uint64_t offset = 14695981039346656037ULL;
39 uint64_t result = offset;
40 for(unsigned i=0; i<size; ++i)
41 result = (result^*(reinterpret_cast<const unsigned char *>(data)+i))*prime;
44 result = (result>>bits ^ result) & ((1ULL<<bits)-1);