diff options
author | June McEnroe <june@causal.agency> | 2020-01-01 16:53:39 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-01-01 16:54:04 -0500 |
commit | 0b0393afc109ec5fbc2d2ce5bcd4b2ebc9e2e9eb (patch) | |
tree | 7750cc80d1fd6d8f81c651ea4baefbbfe280c3d4 /database.h | |
parent | Add option for custom where expression to scoop (diff) | |
download | litterbox-0b0393afc109ec5fbc2d2ce5bcd4b2ebc9e2e9eb.tar.gz litterbox-0b0393afc109ec5fbc2d2ce5bcd4b2ebc9e2e9eb.zip |
Factor out hashing function
Diffstat (limited to 'database.h')
-rw-r--r-- | database.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/database.h b/database.h index d02bc28..26ae57e 100644 --- a/database.h +++ b/database.h @@ -19,6 +19,7 @@ #include <limits.h> #include <sqlite3.h> #include <stdbool.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -49,6 +50,17 @@ enum Type { #undef X }; +static inline uint32_t hash(const char *user) { + if (*user == '~') user++; + uint32_t hash = 0; + for (; *user; ++user) { + hash = (hash << 5) | (hash >> 27); + hash ^= *user; + hash *= 0x27220A95; + } + return hash; +} + static bool verbose; static sqlite3 *db; |