kernel: implement string hashing with FNV

This commit is contained in:
2023-04-09 16:39:08 +01:00
parent 981a5f2a0d
commit c7fdb81ef9
2 changed files with 15 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
extern "C" { extern "C" {
#endif #endif
extern uint64_t hash_string(const char *s);
extern void data_size_to_string(size_t value, char *out, size_t outsz); extern void data_size_to_string(size_t value, char *out, size_t outsz);
static inline bool power_of_2(size_t x) { return (x > 0 && (x & (x - 1)) == 0); } static inline bool power_of_2(size_t x) { return (x > 0 && (x & (x - 1)) == 0); }
static inline unsigned long long div64_pow2(unsigned long long x, unsigned long long y) static inline unsigned long long div64_pow2(unsigned long long x, unsigned long long y)

14
util/hash.c Normal file
View File

@@ -0,0 +1,14 @@
#include <stdint.h>
uint64_t hash_string(const char *s)
{
uint64_t h = 0xcbf29ce484222325;
while (*s) {
h ^= *(unsigned char *)s;
h *= 0x100000001b3;
s++;
}
return h;
}