You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by ja...@apache.org on 2020/01/13 06:43:15 UTC

[incubator-brpc] branch master updated: Make butil::HashInts32 more consistent

This is an automated email from the ASF dual-hosted git repository.

jamesge pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 8eabe51  Make butil::HashInts32 more consistent
8eabe51 is described below

commit 8eabe5131355c7c9670f75974333666dac6b9029
Author: jamesge <jg...@gmail.com>
AuthorDate: Mon Jan 13 14:42:56 2020 +0800

    Make butil::HashInts32 more consistent
---
 src/butil/containers/hash_tables.h | 22 +---------------------
 1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/src/butil/containers/hash_tables.h b/src/butil/containers/hash_tables.h
index 88766cc..39ac3d1 100644
--- a/src/butil/containers/hash_tables.h
+++ b/src/butil/containers/hash_tables.h
@@ -121,30 +121,10 @@ using BUTIL_HASH_NAMESPACE::hash_multiset;
 using BUTIL_HASH_NAMESPACE::hash_set;
 
 // Implement hashing for pairs of at-most 32 bit integer values.
-// When size_t is 32 bits, we turn the 64-bit hash code into 32 bits by using
-// multiply-add hashing. This algorithm, as described in
-// Theorem 4.3.3 of the thesis "Über die Komplexität der Multiplikation in
-// eingeschränkten Branchingprogrammmodellen" by Woelfel, is:
-//
-//   h32(x32, y32) = (h64(x32, y32) * rand_odd64 + rand16 * 2^16) % 2^64 / 2^32
-//
-// Contact danakj@chromium.org for any questions.
 inline std::size_t HashInts32(uint32_t value1, uint32_t value2) {
   uint64_t value1_64 = value1;
   uint64_t hash64 = (value1_64 << 32) | value2;
-
-  hash64 = fmix64(hash64);
-
-  if (sizeof(std::size_t) >= sizeof(uint64_t))
-    return static_cast<std::size_t>(hash64);
-
-  uint64_t odd_random = 481046412LL << 32 | 1025306955LL;
-  uint32_t shift_random = 10121U << 16;
-
-  hash64 = hash64 * odd_random + shift_random;
-  std::size_t high_bits = static_cast<std::size_t>(
-      hash64 >> (8 * (sizeof(uint64_t) - sizeof(std::size_t))));
-  return high_bits;
+  return static_cast<size_t>(fmix64(hash64));
 }
 
 // Implement hashing for pairs of up-to 64-bit integer values.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org