From 11b4d6ba2cc621adfbfb22476c0e1fff4353c435 Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Wed, 13 Nov 2013 15:01:33 -0800 Subject: [PATCH] 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 --- folly/Hash.h | 4 ++-- folly/test/HashTest.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/folly/Hash.h b/folly/Hash.h index cbd07b56..cc66e145 100644 --- a/folly/Hash.h +++ b/folly/Hash.h @@ -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); } diff --git a/folly/test/HashTest.cpp b/folly/test/HashTest.cpp index 5b8840f5..0b33eb36 100644 --- a/folly/test/HashTest.cpp +++ b/folly/test/HashTest.cpp @@ -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))); } -- 2.34.1