core: implement string hashing using FNV-1a
This commit is contained in:
16
core/hash.c
Normal file
16
core/hash.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <blue/core/hash.h>
|
||||
|
||||
#define FNV1_OFFSET_BASIS 0xcbf29ce484222325
|
||||
#define FNV1_PRIME 0x100000001b3
|
||||
|
||||
uint64_t b_hash_string(const char *s)
|
||||
{
|
||||
uint64_t hash = FNV1_OFFSET_BASIS;
|
||||
|
||||
for (size_t i = 0; s[i]; i++) {
|
||||
hash ^= s[i];
|
||||
hash *= FNV1_PRIME;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
9
core/include/blue/core/hash.h
Normal file
9
core/include/blue/core/hash.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef BLUELIB_CORE_HASH_H_
|
||||
#define BLUELIB_CORE_HASH_H_
|
||||
|
||||
#include <blue/core/misc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
BLUE_API uint64_t b_hash_string(const char *s);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user