Subject: Re: New hash algorithm - FNV - for use in the kernel
To: None <tech-perform@netbsd.org, tech-kern@netbsd.org>
From: Tom Spindler <dogcow@babymeat.com>
List: tech-kern
Date: 11/27/2001 13:25:43
> > There is a potential issue however; FNV uses multiply (*) and xor (^),
> > whereas a lot of the existing hashes on strings and buffers just use
> > addition (+). Whilst FNV has much better distribution than the latter,
> > it will be slower on platforms without hardware multiply. The question
> > is as to whether the reduction in hash collisions (and the subsequent
> > following of collision list chains) is effective on these systems.
Perl uses the following for hashing strings; while it contains a
multiply (* 33), it could be converted into a shift and an add pretty
easily. (IIRC, there's been some discussion about the various hash
algorithms on the p5p mailing list in the past, but there hasn't been
any attempts to try the various "new" kinds of hashes.)
#define PERL_HASH(hash,str,len) \
STMT_START { \
register const char *s_PeRlHaSh = str; \
register I32 i_PeRlHaSh = len; \
register U32 hash_PeRlHaSh = 0; \
while (i_PeRlHaSh--) \
hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \
(hash) = hash_PeRlHaSh + (hash_PeRlHaSh>>5); \
} STMT_END