X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FHash.h;h=77ba5878f17e6502c0c89a0e2fbe42f8c4dc757f;hp=1df1ff67fc04eea30d50ab8deffb30ce43016b3c;hb=22d531a8fe503001a51672750dc09daae252fbf6;hpb=713e429835eb97113f52baa77f59a7787338c32a diff --git a/folly/Hash.h b/folly/Hash.h index 1df1ff67..77ba5878 100644 --- a/folly/Hash.h +++ b/folly/Hash.h @@ -215,8 +215,10 @@ inline uint32_t jenkins_rev_unmix32(uint32_t key) { const uint32_t FNV_32_HASH_START = 2166136261UL; const uint64_t FNV_64_HASH_START = 14695981039346656037ULL; -inline uint32_t fnv32(const char* s, - uint32_t hash = FNV_32_HASH_START) { +inline uint32_t fnv32(const char* buf, uint32_t hash = FNV_32_HASH_START) { + // forcing signed char, since other platforms can use unsigned + const signed char* s = reinterpret_cast(buf); + for (; *s; ++s) { hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24); @@ -245,8 +247,10 @@ inline uint32_t fnv32(const std::string& str, return fnv32_buf(str.data(), str.size(), hash); } -inline uint64_t fnv64(const char* s, - uint64_t hash = FNV_64_HASH_START) { +inline uint64_t fnv64(const char* buf, uint64_t hash = FNV_64_HASH_START) { + // forcing signed char, since other platforms can use unsigned + const signed char* s = reinterpret_cast(buf); + for (; *s; ++s) { hash += (hash << 1) + (hash << 4) + (hash << 5) + (hash << 7) + (hash << 8) + (hash << 40);