From b8e68bed955d909762713c51edcc18b0aaa3314d Mon Sep 17 00:00:00 2001 From: uz Date: Fri, 12 Aug 2011 15:32:08 +0000 Subject: [PATCH] Renamed hashstr to hashfunc and added an integer hash function. git-svn-id: svn://svn.cc65.org/cc65/trunk@5155 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/{hashstr.c => hashfunc.c} | 26 ++++++++++++++++++++++---- src/common/{hashstr.h => hashfunc.h} | 15 +++++++++------ src/common/make/gcc.mak | 2 +- src/common/make/watcom.mak | 2 +- src/common/strpool.c | 6 +++--- 5 files changed, 36 insertions(+), 15 deletions(-) rename src/common/{hashstr.c => hashfunc.c} (80%) rename src/common/{hashstr.h => hashfunc.h} (88%) diff --git a/src/common/hashstr.c b/src/common/hashfunc.c similarity index 80% rename from src/common/hashstr.c rename to src/common/hashfunc.c index 4b50731c3..a26d1635b 100644 --- a/src/common/hashstr.c +++ b/src/common/hashfunc.c @@ -1,12 +1,12 @@ /*****************************************************************************/ /* */ -/* hashstr.c */ +/* hashfunc.c */ /* */ -/* Hash function for strings */ +/* Hash functions */ /* */ /* */ /* */ -/* (C) 1998-2008 Ullrich von Bassewitz */ +/* (C) 1998-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -34,7 +34,7 @@ /* common */ -#include "hashstr.h" +#include "hashfunc.h" @@ -44,6 +44,24 @@ +unsigned HashInt (unsigned V) +/* Return a hash value for the given integer. The function uses Robert + * Jenkins' 32 bit integer hash function taken from + * http://www.concentric.net/~ttwang/tech/inthash.htm + * For 16 bit integers, the function may be suboptimal. + */ +{ + V = (V + 0x7ed55d16) + (V << 12); + V = (V ^ 0xc761c23c) ^ (V >> 19); + V = (V + 0x165667b1) + (V << 5); + V = (V + 0xd3a2646c) ^ (V << 9); + V = (V + 0xfd7046c5) + (V << 3); + V = (V ^ 0xb55a4f09) ^ (V >> 16); + return V; +} + + + unsigned HashStr (const char* S) /* Return a hash value for the given string */ { diff --git a/src/common/hashstr.h b/src/common/hashfunc.h similarity index 88% rename from src/common/hashstr.h rename to src/common/hashfunc.h index ba591c108..22bd599fe 100644 --- a/src/common/hashstr.h +++ b/src/common/hashfunc.h @@ -1,12 +1,12 @@ /*****************************************************************************/ /* */ -/* hashstr.h */ +/* hashfunc.h */ /* */ -/* Hash function for strings */ +/* Hash functions */ /* */ /* */ /* */ -/* (C) 1998-2008 Ullrich von Bassewitz */ +/* (C) 1998-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -33,8 +33,8 @@ -#ifndef HASHSTR_H -#define HASHSTR_H +#ifndef HASHFUNC_H +#define HASHFUNC_H @@ -50,6 +50,9 @@ +unsigned HashInt (unsigned V) attribute ((const)); +/* Return a hash value for the given integer. */ + unsigned HashStr (const char* S) attribute ((const)); /* Return a hash value for the given string */ @@ -58,7 +61,7 @@ unsigned HashBuf (const StrBuf* S) attribute ((const)); -/* End of hashstr.h */ +/* End of hashfunc.h */ #endif diff --git a/src/common/make/gcc.mak b/src/common/make/gcc.mak index 58fd1b7f8..558c97337 100644 --- a/src/common/make/gcc.mak +++ b/src/common/make/gcc.mak @@ -28,7 +28,7 @@ OBJS = abend.o \ filetype.o \ fname.o \ fp.o \ - hashstr.o \ + hashfunc.o \ hashtab.o \ intstack.o \ matchpat.o \ diff --git a/src/common/make/watcom.mak b/src/common/make/watcom.mak index d870c3f02..8b59787ba 100644 --- a/src/common/make/watcom.mak +++ b/src/common/make/watcom.mak @@ -70,7 +70,7 @@ OBJS = abend.obj \ filetype.obj \ fname.obj \ fp.obj \ - hashstr.obj \ + hashfunc.obj \ hashtab.obj \ intstack.obj \ matchpat.obj \ diff --git a/src/common/strpool.c b/src/common/strpool.c index 0387de403..9157a73a8 100644 --- a/src/common/strpool.c +++ b/src/common/strpool.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2003-2009, Ullrich von Bassewitz */ +/* (C) 2003-2011, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -46,7 +46,7 @@ /* common */ #include "coll.h" -#include "hashstr.h" +#include "hashfunc.h" #include "strbuf.h" #include "strpool.h" #include "xmalloc.h" @@ -84,7 +84,7 @@ static StringPoolEntry* NewStringPoolEntry (const StrBuf* S, unsigned Hash, unsi /* Initialize the fields */ E->Next = 0; E->Hash = Hash; - E->Id = Id; + E->Id = Id; SB_Init (&E->Buf); SB_Copy (&E->Buf, S); -- 2.39.5