24 lines
515 B
C
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;
|
|
} |