Kernighan and Ritchie hash algorithm. More...

Kernighan and Ritchie hash algorithm.

HISTORY This hash function appeared in K&R (1st ed) but at least the reader was warned:

 "This is not the best possible algorithm, but it has the merit
 of extreme simplicity."

This is an understatement. It is a terrible hashing algorithm, and it could have been much better without sacrificing its "extreme simplicity." [see the second edition!]

Many C programmers use this function without actually testing it, or checking something like Knuth's Sorting and Searching, so it stuck. It is now found mixed with otherwise respectable code, eg. cnews. sigh. [see also: tpop]

Parameters
bufinput buffer to hash
lenlength of buffer
Returns
32 bit sized hash