diff options
Diffstat (limited to '')
-rw-r--r-- | database.h | 12 | ||||
-rw-r--r-- | litterbox.c | 10 | ||||
-rw-r--r-- | scoop.c | 9 |
3 files changed, 14 insertions, 17 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; diff --git a/litterbox.c b/litterbox.c index 2ab2bf1..88f342e 100644 --- a/litterbox.c +++ b/litterbox.c @@ -18,7 +18,6 @@ #include <err.h> #include <signal.h> #include <stdarg.h> -#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -192,14 +191,7 @@ static void handleReplyEndOfMOTD(struct Message *msg) { } static int color(const char *user) { - if (*user == '~') user++; - uint32_t hash = 0; - for (; *user; ++user) { - hash = (hash << 5) | (hash >> 27); - hash ^= *user; - hash *= 0x27220A95; - } - return 2 + hash % 14; + return 2 + hash(user) % 14; } static void querySearch(struct Message *msg) { diff --git a/scoop.c b/scoop.c index d21d77e..6caafe9 100644 --- a/scoop.c +++ b/scoop.c @@ -79,14 +79,7 @@ static const int Colors[] = { }; static int color(const char *user) { - if (*user == '~') user++; - uint32_t hash = 0; - for (; *user; ++user) { - hash = (hash << 5) | (hash >> 27); - hash ^= *user; - hash *= 0x27220A95; - } - return Colors[hash % ARRAY_LEN(Colors)]; + return Colors[hash(user) % ARRAY_LEN(Colors)]; } static void formatColor(bool group, struct Event e) { |