From cbcbbc4c25126fae22369286eef75b3b0973d6ec Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Sun, 1 Feb 2026 03:38:20 -0500 Subject: include a good hash function --- map.c | 9 +++++++++ map.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/map.c b/map.c index 927fd66..ab7f922 100644 --- a/map.c +++ b/map.c @@ -5,6 +5,15 @@ #define DEFAULT_CAPACITY 16 +size_t hash_bytes(const void* start, size_t size) { + size_t hash = 0; + const char* raw_data = start; + for (size_t i = 0; i < size; i++) { + hash = (hash << 5) - hash + raw_data[i]; + } + return hash; +} + void map_init( map_t* map, hash_func_t hash_func, diff --git a/map.h b/map.h index 19c8df5..bca8c1e 100644 --- a/map.h +++ b/map.h @@ -1,6 +1,8 @@ #ifndef __SAFEC_MAP_H #include "types.h" +size_t hash_bytes(const void* start, size_t size); + typedef size_t (*hash_func_t)(const void*); typedef bool (*eq_func_t)(const void*, const void*); -- cgit v1.2.3