1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-01 08:29:37 +00:00

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
This commit is contained in:
uz 2011-08-12 15:32:08 +00:00
parent 434c818d20
commit b8e68bed95
5 changed files with 36 additions and 15 deletions

View File

@ -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 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -34,7 +34,7 @@
/* common */ /* 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) unsigned HashStr (const char* S)
/* Return a hash value for the given string */ /* Return a hash value for the given string */
{ {

View File

@ -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 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -33,8 +33,8 @@
#ifndef HASHSTR_H #ifndef HASHFUNC_H
#define HASHSTR_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)); unsigned HashStr (const char* S) attribute ((const));
/* Return a hash value for the given string */ /* 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 #endif

View File

@ -28,7 +28,7 @@ OBJS = abend.o \
filetype.o \ filetype.o \
fname.o \ fname.o \
fp.o \ fp.o \
hashstr.o \ hashfunc.o \
hashtab.o \ hashtab.o \
intstack.o \ intstack.o \
matchpat.o \ matchpat.o \

View File

@ -70,7 +70,7 @@ OBJS = abend.obj \
filetype.obj \ filetype.obj \
fname.obj \ fname.obj \
fp.obj \ fp.obj \
hashstr.obj \ hashfunc.obj \
hashtab.obj \ hashtab.obj \
intstack.obj \ intstack.obj \
matchpat.obj \ matchpat.obj \

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2003-2009, Ullrich von Bassewitz */ /* (C) 2003-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -46,7 +46,7 @@
/* common */ /* common */
#include "coll.h" #include "coll.h"
#include "hashstr.h" #include "hashfunc.h"
#include "strbuf.h" #include "strbuf.h"
#include "strpool.h" #include "strpool.h"
#include "xmalloc.h" #include "xmalloc.h"
@ -84,7 +84,7 @@ static StringPoolEntry* NewStringPoolEntry (const StrBuf* S, unsigned Hash, unsi
/* Initialize the fields */ /* Initialize the fields */
E->Next = 0; E->Next = 0;
E->Hash = Hash; E->Hash = Hash;
E->Id = Id; E->Id = Id;
SB_Init (&E->Buf); SB_Init (&E->Buf);
SB_Copy (&E->Buf, S); SB_Copy (&E->Buf, S);