1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-10 13:57:47 +03:00

Use djb-algorithm string hash - faster than the tdb one we used to use.

Jeremy.
(This used to be commit f094555ed9d4f72841869e79037d6ff980ebe324)
This commit is contained in:
Jeremy Allison 2003-09-06 21:43:23 +00:00
parent dc7ea5851c
commit c4b69a9ca1

View File

@ -84,21 +84,20 @@ BOOL hash_table_init(hash_table *table, unsigned num_buckets, compare_function c
* For the last few chars that cannot be int'ed, use char instead.
* The function returns the bucket index number for the hashed
* key.
* JRA. Use a djb-algorithm hash for speed.
**************************************************************
*/
static int string_hash(int hash_size, const char *key)
{
u32 value; /* Used to compute the hash value. */
u32 i; /* Used to cycle through random values. */
for (value = 0x238F13AF, i=0; key[i]; i++)
value = (value + (key[i] << (i*5 % 24)));
return (1103515243 * value + 12345) % hash_size;
u32 n = 0;
const char *p;
for (p = key; *p != '\0'; p++) {
n = ((n << 5) + n) ^ (u32)(*p++);
}
return (n % hash_size);
}
/* *************************************************************************
* Search the hash table for the entry in the hash chain.
* The function returns the pointer to the