Use hash algorithm name in its function's symbol
This commit is contained in:
parent
796a3d3639
commit
dc202db67e
9
hash.cpp
9
hash.cpp
@ -20,9 +20,8 @@
|
||||
#include "hash.hpp"
|
||||
|
||||
|
||||
// Thomas Wang's 32 bit mixing function
|
||||
uint32_t
|
||||
hash (uint32_t key) {
|
||||
util::wang32 (uint32_t key) {
|
||||
uint32_t c2 = 0x27d4eb2d; // a prime or an odd constant
|
||||
key = (key ^ 61) ^ (key >> 16);
|
||||
key = key + (key << 3);
|
||||
@ -33,9 +32,8 @@ hash (uint32_t key) {
|
||||
}
|
||||
|
||||
|
||||
// Thomas Wang's 64 bit mixing function
|
||||
uint64_t
|
||||
hash (uint64_t key) {
|
||||
util::wang64 (uint64_t key) {
|
||||
key = (~key) + (key << 21); // key = (key << 21) - key - 1;
|
||||
key = key ^ (key >> 24);
|
||||
key = (key + (key << 3)) + (key << 8); // key * 265
|
||||
@ -48,6 +46,3 @@ hash (uint64_t key) {
|
||||
}
|
||||
|
||||
|
||||
uintptr_t
|
||||
hash (void *const key)
|
||||
{ return hash ((uintptr_t)key); }
|
||||
|
21
hash.hpp
21
hash.hpp
@ -21,9 +21,24 @@
|
||||
#define __UTIL_HASH_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
// All hashes are unsuitable for cryptographic operations nnless noted.
|
||||
namespace util {
|
||||
// Fast integer mixing operations by Thomas Wang.
|
||||
uint32_t wang32 (uint32_t key);
|
||||
uint64_t wang64 (uint64_t key);
|
||||
|
||||
// General hashes for when you really just don't care about implementation
|
||||
inline uint32_t hash (uint32_t key) { return wang32 (key); }
|
||||
inline uint64_t hash (uint64_t key) { return wang64 (key); }
|
||||
inline uintptr_t hash (const void *key) {
|
||||
return sizeof (uintptr_t) == 32 ? wang32 (reinterpret_cast<uintptr_t> (key)) :
|
||||
wang64 (reinterpret_cast<uintptr_t> (key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t hash (uint32_t key);
|
||||
uint64_t hash (uint64_t key);
|
||||
uintptr_t hash (void * const);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user