[Glacier] Move hashmap to a real hash implementation.
This commit is contained in:
parent
76fd3fc176
commit
28d9e37b87
4 changed files with 60 additions and 26 deletions
30
lib/glacier/util/hash.cpp
Normal file
30
lib/glacier/util/hash.cpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include "util/hash.h"
|
||||
|
||||
#include "string/string.h"
|
||||
|
||||
namespace glcr {
|
||||
namespace {
|
||||
|
||||
const uint64_t kFnvOffset = 0xcbf29ce484222325;
|
||||
const uint64_t kFnvPrime = 0x100000001b3;
|
||||
|
||||
} // namespace
|
||||
|
||||
uint64_t Hash<uint64_t>::operator()(const uint64_t& value) {
|
||||
uint64_t hash = kFnvOffset;
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
hash *= kFnvPrime;
|
||||
hash ^= (value >> (8 * i)) & 0xFF;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
uint64_t Hash<String>::operator()(const String& value) {
|
||||
uint64_t hash = kFnvOffset;
|
||||
for (uint8_t i = 0; i < value.length(); i++) {
|
||||
hash *= kFnvPrime;
|
||||
hash ^= value[i];
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
} // namespace glcr
|
||||
Loading…
Add table
Add a link
Reference in a new issue