diff options
| author | Curtis McEnroe | 2018-08-14 14:04:20 -0400 | 
|---|---|---|
| committer | Curtis McEnroe | 2018-08-14 14:04:20 -0400 | 
| commit | 398f752322f5199c6f25bde57e2befd1b570862b (patch) | |
| tree | 2ae4eb950abadeba8536d9fabe59d6d0e4fc6ba1 | |
| parent | ed9961410e3f9e4a23244446a4d2cfd2f1a79584 (diff) | |
Keep hashing '\0' until color is not black
Actually uses the rest of the hash state this way.
| -rw-r--r-- | handle.c | 16 | 
1 files changed, 11 insertions, 5 deletions
@@ -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) {  | 
