2004-10-12 02:44:47 +00:00
|
|
|
#include <lladd/hash.h>
|
2004-10-17 02:17:00 +00:00
|
|
|
/*#include <math.h> */
|
2004-10-12 02:44:47 +00:00
|
|
|
/*static int thomasWangs32BitMixFunction(int key);
|
|
|
|
static unsigned long thomasWangs64BitMixFunction(unsigned long key);*/
|
|
|
|
|
|
|
|
/** @todo replace powl in hash with something more efficient, if hash() becomes a bottleneck. */
|
|
|
|
|
2004-10-17 02:17:00 +00:00
|
|
|
#define twoToThe(x) (1 << (x))
|
2004-10-12 02:44:47 +00:00
|
|
|
|
2004-10-17 02:17:00 +00:00
|
|
|
unsigned int hash(void * val, long val_length, unsigned char tableBits, unsigned long nextExtension) {
|
|
|
|
unsigned int oldTableLength = /*powl(2, tableBits - 1); */ twoToThe(tableBits - 1);
|
|
|
|
unsigned int unmixed = crc32(val, val_length, (unsigned long)-1L);
|
|
|
|
unsigned int ret = unmixed & (oldTableLength - 1);
|
2004-10-12 02:44:47 +00:00
|
|
|
|
|
|
|
/* What would the low hash value be? */
|
|
|
|
if(ret < nextExtension) { /* Might be too low. */
|
2004-10-17 02:17:00 +00:00
|
|
|
unsigned int tableLength = /* powl(2, tableBits); */ twoToThe(tableBits);
|
2004-10-12 02:44:47 +00:00
|
|
|
ret = unmixed & (tableLength - 1);
|
|
|
|
}
|
|
|
|
return (int) ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static unsigned long thomasWangs64BitMixFunction(unsigned long key)
|
|
|
|
{
|
|
|
|
key += ~(key << 32L);
|
|
|
|
key ^= (key >> 22L);
|
|
|
|
key += ~(key << 13L);
|
|
|
|
key ^= (key >> 8L);
|
|
|
|
key += (key << 3L);
|
|
|
|
key ^= (key >> 15L);
|
|
|
|
key += ~(key << 27L);
|
|
|
|
key ^= (key >> 31L);
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int thomasWangs32BitMixFunction(int key)
|
|
|
|
{
|
|
|
|
key += ~(key << 15);
|
|
|
|
key ^= (key >> 10);
|
|
|
|
key += (key << 3);
|
|
|
|
key ^= (key >> 6);
|
|
|
|
key += ~(key << 11);
|
|
|
|
key ^= (key >> 16);
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|