From 8b3bcd2c4c2949c6e91853d9d91fec3f59a0e232 Mon Sep 17 00:00:00 2001 From: axel Date: Thu, 19 Oct 2006 09:02:46 +1000 Subject: [PATCH] Tweak initial capacity calculations to always be a Mersenne number darcs-hash:20061018230246-ac50b-3da6ada42423f5bba3f8c3fdb366ce1f352cffde.gz --- util.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/util.c b/util.c index b2e28130a..5f00c54b8 100644 --- a/util.c +++ b/util.c @@ -168,8 +168,16 @@ void hash_init2( hash_table_t *h, size_t capacity) { int i; - size_t sz = capacity*4/3+1; + size_t sz = 32; + while( sz < (capacity*4/3) ) + sz*=2; + /* + Make sure the size is a Mersenne number. Should hopfully be a + reasonably good size with regard to avoiding patterns of collisions. + */ + sz--; + h->arr = malloc( sizeof(hash_struct_t)*sz ); h->size = sz; for( i=0; i< sz; i++ ) @@ -489,6 +497,10 @@ static unsigned int rotl30( unsigned int in ) return (in<<30|in>>2); } +/** + The number of words of input used in each lap by the sha-like + string hashing algorithm. +*/ #define WORD_COUNT 16 int hash_wcs_func( void *data )