Source-Changes archive

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

Re: CVS commit: src/sys



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!
(Since the filename chars are only likely to vary in the 5 lsb).

The 5 lsb bits are (losely) the sum of the characters,
the next 5 are the sum excluding the last character (etc).
Added in is a constant multiplied by the string length.

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index