summaryrefslogtreecommitdiff
path: root/source3/lib/hash.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2003-09-09 04:07:32 +0000
committerGerald Carter <jerry@samba.org>2003-09-09 04:07:32 +0000
commit4093bf7ff8c8861cf7b941945ede53a8ec5bb6c8 (patch)
treedd0a9f32d9933e1f75d919b5083e007d7453f9c4 /source3/lib/hash.c
parent3d7cb49747a9a7f5cdec0ee05c6270ec3604202f (diff)
downloadsamba-4093bf7ff8c8861cf7b941945ede53a8ec5bb6c8.tar.gz
samba-4093bf7ff8c8861cf7b941945ede53a8ec5bb6c8.tar.bz2
samba-4093bf7ff8c8861cf7b941945ede53a8ec5bb6c8.zip
sync 3.0 into HEAD for the last time
(This used to be commit c17a7dc9a190156a069da3e861c18fd3f81224ad)
Diffstat (limited to 'source3/lib/hash.c')
-rw-r--r--source3/lib/hash.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/source3/lib/hash.c b/source3/lib/hash.c
index c7b1493b4c..18b6534dec 100644
--- a/source3/lib/hash.c
+++ b/source3/lib/hash.c
@@ -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