summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-08-14 14:04:20 -0400
committerJune McEnroe <june@causal.agency>2018-08-14 14:04:20 -0400
commit398f752322f5199c6f25bde57e2befd1b570862b (patch)
tree2ae4eb950abadeba8536d9fabe59d6d0e4fc6ba1
parentSet title to tag name (diff)
downloadcatgirl-398f752322f5199c6f25bde57e2befd1b570862b.tar.gz
catgirl-398f752322f5199c6f25bde57e2befd1b570862b.zip
Keep hashing '\0' until color is not black
Actually uses the rest of the hash state this way.
-rw-r--r--handle.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/handle.c b/handle.c
index 16a416c..c93522e 100644
--- a/handle.c
+++ b/handle.c
@@ -25,16 +25,22 @@
 #include "chat.h"
 
 // Adapted from <https://github.com/cbreeden/fxhash/blob/master/lib.rs>.
+static uint32_t hashChar(uint32_t hash, char ch) {
+	hash = (hash << 5) | (hash >> 27);
+	hash ^= ch;
+	hash *= 0x27220A95;
+	return hash;
+}
 static int color(const char *str) {
 	if (!str) return IRC_GRAY;
 	uint32_t hash = 0;
 	for (; str[0]; ++str) {
-		hash = (hash << 5) | (hash >> 27);
-		hash ^= str[0];
-		hash *= 0x27220A95;
+		hash = hashChar(hash, str[0]);
+	}
+	while (IRC_BLACK == (hash & IRC_LIGHT_GRAY)) {
+		hash = hashChar(hash, '\0');
 	}
-	hash &= IRC_LIGHT_GRAY;
-	return (hash == IRC_BLACK) ? IRC_GRAY : hash;
+	return (hash & IRC_LIGHT_GRAY);
 }
 
 static char *paramField(char **params) {
wJune McEnroe 2019-02-22Move IRC formatting reset to C-sJune McEnroe 2019-02-22Disable terminal flow controlJune McEnroe 2019-02-22Bind up and down arrows to scrollJune McEnroe 2019-02-22Remove topic TODOJune McEnroe 2019-02-22Add /znc commandJune McEnroe 2019-02-22Update status line after scrolling and term eventsJune McEnroe 2019-02-22Reorganize input.cJune McEnroe 2019-02-22Fix name of <raw> window in man pageJune McEnroe 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe 2019-02-21Replace "view" with "window"June McEnroe 2019-02-21Remove ROT13June McEnroe 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe