diff --git a/rtcore.h b/rtcore.h index e160e5d..1e95491 100644 --- a/rtcore.h +++ b/rtcore.h @@ -214,6 +214,9 @@ enum RTC_API void *ArenaAlloc(arena *a, isize size, isize align, isize n, int flags); +/* Compute a simple, non-cryptographic hash */ +RTC_API u64 SimpleHash(byte *data, isize len); + /* String type */ typedef struct s8 { @@ -485,6 +488,16 @@ ArenaAlloc(arena *a, isize size, isize align, isize n, int flags) return (flags & ALLOC_NOZERO) ? p : memset(p, 0, n * size); } +/* Basic hash */ +RTC_API u64 +SimpleHash(byte *data, isize len) +{ + u64 hash = 0xcbf29ce484222325; + for (isize i = 0; i < len; ++i) + hash = (hash ^ (u8)data[i]) * 0x00000100000001b3; + return hash; +} + /* S8 funcs */ RTC_API s8 S8Span(u8 *begin, u8 *end)