diff options
| author | Carson Fleming <[email protected]> | 2026-02-01 03:38:20 -0500 |
|---|---|---|
| committer | Carson Fleming <[email protected]> | 2026-02-01 03:38:20 -0500 |
| commit | cbcbbc4c25126fae22369286eef75b3b0973d6ec (patch) | |
| tree | f361e9716481626849be64cabd2ad707ca88b4e2 | |
| parent | 9500e54b874794bd1d9fb5702aa423c6f1794f27 (diff) | |
| download | safec-cbcbbc4c25126fae22369286eef75b3b0973d6ec.tar.gz | |
include a good hash function
| -rw-r--r-- | map.c | 9 | ||||
| -rw-r--r-- | map.h | 2 |
2 files changed, 11 insertions, 0 deletions
@@ -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, @@ -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*); |
