diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-02-14 12:28:18 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-02-21 19:15:31 +0000 |
| commit | 34b814349b58480b235674f892b70b41cd728652 (patch) | |
| tree | 5a870004dffc78db1268a4f9869e54564364ebe7 /util.h | |
| parent | term_osc8_close(): the URL *end* column is inclusive (diff) | |
util: add a sdbm hash implementation
Diffstat (limited to 'util.h')
| -rw-r--r-- | util.h | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -1,5 +1,6 @@ #pragma once +#include <stdint.h> #include <threads.h> #define ALEN(v) (sizeof(v) / sizeof((v)[0])) @@ -21,3 +22,16 @@ thrd_err_as_string(int thrd_err) return "unknown error"; } + +static inline uint64_t +sdbm_hash(const char *s) +{ + uint64_t hash = 0; + + for (; *s != '\0'; s++) { + int c = *s; + hash = c + (hash << 6) + (hash << 16) - hash; + } + + return hash; +} |
