* @param str
* @return unsigned int
*/
-uint32_t
-strhash_32(unsigned char* str, uint32_t truncate_to)
+u32_t
+strhash_32(const char* str, u32_t truncate_to)
{
- uint32_t hash = 5381;
+ if (!str)
+ return 0;
+
+ u32_t hash = 5381;
int c;
- while (c = *str++)
+ while ((c = *str++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash >> (HASH_SIZE_BITS - truncate_to);