[Freeciv-Dev] Better string hashing function
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Hello,
i saw the string hashing function in hash.c and since in the function
comment it said "Anyone know a good one?" here is one:
unsigned int hash_fval_string(const void *vkey, unsigned int num_buckets)
{
register const char *key = (const char *)vkey;
register unsigned result=0;
register int i;
for(i=0; *key && i<32; i++)
result = result * 33U + *key++;
return (result % num_buckets);
}
It's been ripped off from Perl.
---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa
- [Freeciv-Dev] Better string hashing function,
Vasco Alexandre Da Silva Costa <=
|
|