Fix bad implementation of fnv32
authorTudor Bosman <tudorb@fb.com>
Wed, 13 Nov 2013 23:01:33 +0000 (15:01 -0800)
committerPeter Griess <pgriess@fb.com>
Tue, 26 Nov 2013 15:05:17 +0000 (07:05 -0800)
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
folly/test/HashTest.cpp

index cbd07b56ba126cd81efceb2ef1684f1944c87f12..cc66e145205e9223b8b3af923e36b5b9b5ebbc1d 100644 (file)
@@ -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);
 }
 
index 5b8840f5f24b6d3bc18725a37af7406b3635d0e2..0b33eb36ecebc500c494442913b02ed6c10ad5bf 100644 (file)
@@ -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)));
 }