mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
kernel: move fnv1a hash from hashtable.c to util.h
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define _UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define UTIL_ZEROBUFFERSIZE (1024 * 64)
|
||||
|
||||
@@ -20,6 +21,23 @@ static inline long min(long x, long y) {
|
||||
return x > y ? y : x;
|
||||
}
|
||||
|
||||
#define FNV1PRIME 0x100000001b3ull
|
||||
#define FNV1OFFSET 0xcbf29ce484222325ull
|
||||
|
||||
// FNV-1a hash implementation
|
||||
static inline uint64_t fnv1ahash(void *buffer, size_t size) {
|
||||
uint8_t *ptr = buffer;
|
||||
uint8_t *top = ptr + size;
|
||||
uint64_t h = FNV1OFFSET;
|
||||
|
||||
while (ptr < top) {
|
||||
h ^= *ptr++;
|
||||
h *= FNV1PRIME;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
extern uint8_t util_zerobuffer[];
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user