interpret/src/hash.h

10 lines
279 B
C

#include <stdint.h>
/** djb2 <http://www.cse.yorku.ca/~oz/hash.html> */
static uint32_t djb2(const char *s) {
const unsigned char *str = (const unsigned char *)s;
uint32_t hash = 5381, c;
while(c = *str++) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}