From e8481585f4e778fd70d5bb62258c8975ef53538c Mon Sep 17 00:00:00 2001 From: Henrik Forsten Date: Sun, 23 Jun 2013 00:09:44 +0200 Subject: [PATCH] inpsymt.c, use "Daniel J. Bernstein" hash function instead of a simple sum. just for note, there is a wealth of newer hash functions. For example "The FNV Non-Cryptographic Hash Algorithm" from http://tools.ietf.org/html/draft-eastlake-fnv-03 --- src/spicelib/parser/inpsymt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/spicelib/parser/inpsymt.c b/src/spicelib/parser/inpsymt.c index c56f0779d..d77b23265 100644 --- a/src/spicelib/parser/inpsymt.c +++ b/src/spicelib/parser/inpsymt.c @@ -273,10 +273,11 @@ void INPtabEnd(INPtables * tab) static int hash(char *name, int tsize) { - char *s; - register int i = 0; + unsigned int hash = 5381; + char c; - for (s = name; *s; s++) - i += *s; - return (i % tsize); + while ((c = *name++) != '\0') + hash = (hash * 33) ^ (unsigned) c; + + return (int) (hash % (unsigned) tsize); }