hydroforth/src/hydroforth/hash.c
2023-08-04 21:42:01 +02:00

24 lines
515 B
C

#include "hydroforth/hydroforth.h"
// based on http://www.cse.yorku.ca/~oz/hash.html
hf__hash_t hf__hash_mem(const unsigned char *start,
const unsigned char *const end) {
hf__hash_t hash = 5381;
int c;
while ((c = *start++) && start <= (end + 1)) {
hash = ((hash << 5) + hash) + c;
}
return hash;
}
hf__hash_t hf__hash_str(const char *str) {
hf__hash_t hash = 5381;
int c;
while (c = *str++)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}