From 3c824684e5f262c2b2fab3f8009b29382277d086 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 2 Feb 2020 02:31:20 -0500 Subject: [PATCH] Add color hashing function --- chat.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/chat.h b/chat.h index be3952c..fc5043d 100644 --- a/chat.h +++ b/chat.h @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -93,6 +94,16 @@ enum Color { Yellow, LightGreen, Cyan, LightCyan, LightBlue, Pink, Gray, LightGray, Default = 99, }; +static inline enum Color hash(const char *str) { + if (*str == '~') str++; + uint32_t hash = 0; + for (; *str; ++str) { + hash = (hash << 5) | (hash >> 27); + hash ^= *str; + hash *= 0x27220A95; + } + return 2 + hash % 14; +} void ircConfig(bool insecure, const char *cert, const char *priv); int ircConnect(const char *host, const char *port);