#include "internal.h" // // hash functions (djb2) // (see http://aras-p.info/blog/2016/08/02/Hash-Functions-all-the-way-down/) // uint32_t fhp_hash_init(void) { return 5381; } uint32_t fhp_hash_push(uint32_t hash, uint8_t * const buf, size_t len) { for (size_t i = 0; i < len; i++) hash = ((hash << 5) + hash) + buf[i]; return hash; } uint32_t fhp_hash_string(char * const str) { uint32_t r = fhp_hash_init(); return fhp_hash_push(r, (uint8_t*) str, strlen(str)); } uint32_t fhp_lc_hash_push( uint32_t hash, uint8_t * const buf, size_t len ) { for (size_t i = 0; i < len; i++) { uint8_t c = buf[i]; if ((c >= 'A') && (c <= 'Z')) c = (c - 'A') + 'a'; hash = ((hash << 5) + hash) + c; } return hash; } uint32_t fhp_lc_hash_string(char * const str) { uint32_t r = fhp_hash_init(); return fhp_lc_hash_push(r, (uint8_t*) str, strlen(str)); }