diff --git a/core/hash.c b/core/hash.c new file mode 100644 index 0000000..a77c107 --- /dev/null +++ b/core/hash.c @@ -0,0 +1,16 @@ +#include + +#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; +} diff --git a/core/include/blue/core/hash.h b/core/include/blue/core/hash.h new file mode 100644 index 0000000..7fa1158 --- /dev/null +++ b/core/include/blue/core/hash.h @@ -0,0 +1,9 @@ +#ifndef BLUELIB_CORE_HASH_H_ +#define BLUELIB_CORE_HASH_H_ + +#include +#include + +BLUE_API uint64_t b_hash_string(const char *s); + +#endif \ No newline at end of file