Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys



David Laight <david%l8s.co.uk@localhost> writes:
> On Mon, Sep 29, 2008 at 10:02:32PM +1000, Simon Burge wrote:
>> Reinoud Zandijk wrote:
>> 
>> > [ ... dirhash stuff ... ]
>> 
>> +static uint32_t
>> +dirhash_hash(const char *str, int namelen)
>> +{
>> +       uint32_t hash = 5381;
>> +        int i, c;
>> +
>> +       for (i = 0; i < namelen; i++) {
>> +               c = *str++;
>> +               hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
>> +       }
>> +        return hash;
>> +}
>> 
>> Any reason you can't reuse hash32_strn() from <sys/hash.h> here?  That
>> does add a final "hash + (hash >> 5)" at the end, and I'm not sure what
>> difference to the distribution that change makes.
>
> Dunno, but in either case it doesn't look like a very good hash!

This is the DJB hash. It is known to be excellent for strings like
this, and very fast. Try an experiment if you don't believe me.

Perry
-- 
Perry E. Metzger                perry%piermont.com@localhost


Home | Main Index | Thread Index | Old Index