Reduce hash value collision probability in src/main.c
authorHomer Hsing <homer.xing@intel.com>
Fri, 14 Sep 2012 02:06:39 +0000 (10:06 +0800)
committerDamien Lespiau <damien.lespiau@intel.com>
Mon, 4 Mar 2013 15:54:32 +0000 (15:54 +0000)
Original code use "hash_value = *name++", which may produce
hash value collision for word permutations like "abc", "bac" and "cba".

assembler/src/main.c

index 30c9018..d16d271 100644 (file)
@@ -78,10 +78,10 @@ static void usage(void)
 
 static int hash(char *name)
 {
-    int ret = 0;
+    unsigned ret = 0;
     while(*name)
-       ret += *name++;
-    return ret%HASHSZ;
+        ret = (ret << 1) + (*name++);
+    return ret % HASHSZ;
 }
 
 struct declared_register *find_register(char *name)