* Generic hash function to calculate a hash code from the given string.
*
* For each byte of the string, this function left-shifts the value in an
* accumulator and then adds the byte into the accumulator. The contents of
* the accumulator is returned after the entire string has been processed.
* It is assumed that this result will be used as the "hashcode" parameter in
* calls to other functions in this package. These functions automatically
* adjust the hashcode for the size of each hashtable.
*
* This algorithm probably works best when the hash table size is a prime
* number.
*
* Hopefully, this function is better than the previous one which returned
* the sum of the squares of all the bytes. I'm still open to other
* suggestions for a default hash function. The programmer is more than
* welcome to supply his/her own hash function as that is one of the design
* features of this package.
点击(此处)折叠或打开
unsigned long
hash_HashFunction_s(const unsigned char *string, unsigned long len)