Browse Source

[core] fix incorrect hash algorithm impl

fix incorrect implementation of djb hash algorithm
personal/stbuehler/fix-fdevent
Glenn Strauss 3 years ago
parent
commit
758d24142b
  1. 5
      src/stat_cache.c

5
src/stat_cache.c

@ -88,9 +88,8 @@ typedef struct stat_cache {
/* the famous DJB hash function for strings */
static uint32_t hashme(buffer *str) {
uint32_t hash = 5381;
const char *s;
for (s = str->ptr; *s; s++) {
hash = ((hash << 5) + hash) + *s;
for (const unsigned char *s = (unsigned char *)str->ptr; *s; ++s) {
hash = ((hash << 5) + hash) ^ *s;
}
hash &= ~(((uint32_t)1) << 31); /* strip the highest bit */

Loading…
Cancel
Save