Commit 11b4d6ba authored by Tudor Bosman's avatar Tudor Bosman Committed by Peter Griess

Fix bad implementation of fnv32

Summary: See https://www.facebook.com/groups/fbcode/permalink/601496126553897/

Test Plan: contbuild

Reviewed By: ldbrandy@fb.com

FB internal diff: D1055852

@override-unit-failures
some hphp_dbg tests postponed for 1.5 days, all other hphp tests
(including some hphp_dbg ones) are passing
parent 48bc9653
......@@ -190,7 +190,7 @@ inline uint32_t jenkins_rev_unmix32(uint32_t key) {
* http://www.isthe.com/chongo/tech/comp/fnv/
*/
const uint32_t FNV_32_HASH_START = 216613626UL;
const uint32_t FNV_32_HASH_START = 2166136261UL;
const uint64_t FNV_64_HASH_START = 14695981039346656037ULL;
inline uint32_t fnv32(const char* s,
......@@ -218,7 +218,7 @@ inline uint32_t fnv32_buf(const void* buf,
}
inline uint32_t fnv32(const std::string& str,
uint64_t hash = FNV_32_HASH_START) {
uint32_t hash = FNV_32_HASH_START) {
return fnv32_buf(str.data(), str.size(), hash);
}
......
......@@ -25,17 +25,17 @@ using namespace folly::hash;
TEST(Hash, Fnv32) {
const char* s1 = "hello, world!";
const uint32_t s1_res = 3180823791ul;
const uint32_t s1_res = 3605494790UL;
EXPECT_EQ(fnv32(s1), s1_res);
EXPECT_EQ(fnv32(s1), fnv32_buf(s1, strlen(s1)));
const char* s2 = "monkeys! m0nk3yz! ev3ry \\/\\/here~~~~";
const uint32_t s2_res = 194407565ul;
const uint32_t s2_res = 1270448334UL;
EXPECT_EQ(fnv32(s2), s2_res);
EXPECT_EQ(fnv32(s2), fnv32_buf(s2, strlen(s2)));
const char* s3 = "";
const uint32_t s3_res = 216613626ul;
const uint32_t s3_res = 2166136261UL;
EXPECT_EQ(fnv32(s3), s3_res);
EXPECT_EQ(fnv32(s3), fnv32_buf(s3, strlen(s3)));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment