Hi,
I while ago I did some experimentation with simple bit-op based string
hash
functions. I.e., no multiplications / divides in the hash loop.
The best I found was:
int hash_fn (char * p)
{
int hash = 0;
while (*p) {
hash = hash + *p;
// Rotate a 31 bit field 7 bits:
hash =
Andries,
> is very little interaction to start with. And the final AND that
truncates
> to the final size of the hash chain kills the high order bits.
> No good.
I didn't realise you were bit-masking down to the required size.
Yes, it would be pretty useless in that case.
Ralph.
>
> Andrie
Andries,
> > int hash_fn (char * p)
> > {
> > int hash = 0;
> > while (*p) {
> > hash = hash + *p;
> > // Rotate a 31 bit field 7 bits:
> > hash = ((hash << 7) | (hash >> 24)) & 0x7fff;
> > }
> > return hash;
> > }
>
> Hmm. This one goes in the "catastrophic" catego
3 matches
Mail list logo