Keep hashing '\0' until color is not black
Actually uses the rest of the hash state this way.
This commit is contained in:
		
							parent
							
								
									ed9961410e
								
							
						
					
					
						commit
						398f752322
					
				
							
								
								
									
										16
									
								
								handle.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								handle.c
									
									
									
									
									
								
							| @ -25,16 +25,22 @@ | |||||||
| #include "chat.h" | #include "chat.h" | ||||||
| 
 | 
 | ||||||
| // Adapted from <https://github.com/cbreeden/fxhash/blob/master/lib.rs>.
 | // 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) { | static int color(const char *str) { | ||||||
| 	if (!str) return IRC_GRAY; | 	if (!str) return IRC_GRAY; | ||||||
| 	uint32_t hash = 0; | 	uint32_t hash = 0; | ||||||
| 	for (; str[0]; ++str) { | 	for (; str[0]; ++str) { | ||||||
| 		hash = (hash << 5) | (hash >> 27); | 		hash = hashChar(hash, str[0]); | ||||||
| 		hash ^= str[0]; |  | ||||||
| 		hash *= 0x27220A95; |  | ||||||
| 	} | 	} | ||||||
| 	hash &= IRC_LIGHT_GRAY; | 	while (IRC_BLACK == (hash & IRC_LIGHT_GRAY)) { | ||||||
| 	return (hash == IRC_BLACK) ? IRC_GRAY : hash; | 		hash = hashChar(hash, '\0'); | ||||||
|  | 	} | ||||||
|  | 	return (hash & IRC_LIGHT_GRAY); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static char *paramField(char **params) { | static char *paramField(char **params) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user