interpret/src/hash.h

10 lines
279 B
C
Raw Normal View History

2023-02-03 19:50:10 +00:00
#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;
}