From 8ece4f3ddc09c7647f33428bb089c4e8f90853e1 Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 12 Oct 2006 11:01:29 +1000 Subject: [PATCH] Better string hashing function darcs-hash:20061012010129-ac50b-3c420efe649e892c491d9d9830dda153ca395655.gz --- util.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 107 insertions(+), 21 deletions(-) diff --git a/util.c b/util.c index 3b3152827..3f7233175 100644 --- a/util.c +++ b/util.c @@ -465,19 +465,122 @@ void hash_foreach2( hash_table_t *h, } -int hash_str_cmp( void *a, void *b ) +/** + Helper function for hash_wcs_func +*/ +static unsigned int rotl1( unsigned int in ) { - return strcmp((char *)a,(char *)b) == 0; + return (in<<1|in>>31); } /** Helper function for hash_wcs_func */ -static unsigned long rotl5( unsigned long in ) +static unsigned int rotl5( unsigned int in ) { - return ((in<<5|in>>27))&0xffffffff; + return (in<<5|in>>27); } +/** + Helper function for hash_wcs_func +*/ +static unsigned int rotl30( unsigned int in ) +{ + return (in<<30|in>>2); +} + +#define WORD_COUNT 16 + +int hash_wcs_func( void *data ) +{ + const wchar_t *in = (const wchar_t *)data; + unsigned int a,b,c,d,e; + int t; + unsigned int k0=0x5a827999u; + unsigned int k1 =0x6ed9eba1u; + + unsigned int w[2*WORD_COUNT]; + + /* + Same constants used by sha1 + */ + a=0x67452301u; + b=0xefcdab89u; + c=0x98badcfeu; + d=0x10325476u; + e=0xc3d2e1f0u; + + if( data == 0 ) + return 0; + + while( *in ) + { + int i; + + /* + Read WORD_COUNT words of data into w + */ + for( i=0; i