ref: 0f7ab686171677c9d8e7e6d6c5c518038c8e25cb
parent: b206061137fe1f86fd9669679e055bc826816f99
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue May 26 04:16:00 EDT 2015
Improve hash function This is the hash function found in k&r second edition mixed with djb2 because it uses xor instead of adding. This new version gets a better distribution of the symbols in the hash table.
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -7,7 +7,7 @@
#include "../inc/sizes.h"
#include "cc1.h"
-#define NR_SYM_HASH 32
+#define NR_SYM_HASH 64
static unsigned curctx;
static short localcnt;
@@ -19,11 +19,11 @@
static inline unsigned
hash(const char *s)
{
- unsigned h, ch;
+ unsigned c, h;
- for (h = 0; ch = *s++; h += ch)
- /* nothing */;
- return h & NR_SYM_HASH - 1;
+ for (h = 0; c = *s; ++s)
+ h ^= 33 * c;
+ return h & NR_SYM_HASH-1;
}
void