blob: 32cb5381d4c4555168c38d2037d290b19d4af1e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <fnv1a.h>
#include <assert.h>
#define FNV_PRIME 2166136261
#define FNV_OFFSET_BASIS 16777619
uint32_t fnv1a_32(const void* buffer, size_t size) {
assert(buffer);
return fnv1a32_update(fnv1a32_begin(), buffer, size);
}
uint32_t fnv1a32_begin() { return FNV_PRIME; }
uint32_t fnv1a32_update(uint32_t hash, const void* buffer, size_t size) {
assert(buffer);
const uint8_t* bytes = buffer;
for (size_t i = 0; i < size; i++) {
hash = hash ^ bytes[i];
hash = hash * FNV_OFFSET_BASIS;
}
return hash;
}
|