Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2000:
[Freeciv-Dev] Better string hashing function
Home

[Freeciv-Dev] Better string hashing function

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Better string hashing function
From: Vasco Alexandre Da Silva Costa <vasc@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 26 Mar 2000 14:33:14 +0100 (WET DST)

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




[Prev in Thread] Current Thread [Next in Thread]