/Users/deen/code/yugabyte-db/src/yb/gutil/hash/hash128to64.h
Line | Count | Source |
1 | | // Copyright 2010 Google Inc. All Rights Reserved. |
2 | | // Authors: jyrki@google.com (Jyrki Alakuijala), gpike@google.com (Geoff Pike) |
3 | | |
4 | | // |
5 | | // The following only applies to changes made to this file as part of YugaByte development. |
6 | | // |
7 | | // Portions Copyright (c) YugaByte, Inc. |
8 | | // |
9 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
10 | | // in compliance with the License. You may obtain a copy of the License at |
11 | | // |
12 | | // http://www.apache.org/licenses/LICENSE-2.0 |
13 | | // |
14 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
15 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
16 | | // or implied. See the License for the specific language governing permissions and limitations |
17 | | // under the License. |
18 | | // |
19 | | #ifndef UTIL_HASH_HASH128TO64_H_ |
20 | | #define UTIL_HASH_HASH128TO64_H_ |
21 | | |
22 | | #include "yb/gutil/int128.h" |
23 | | #include "yb/gutil/integral_types.h" |
24 | | |
25 | | // Hash 128 input bits down to 64 bits of output. |
26 | | // This is intended to be a reasonably good hash function. |
27 | | // It may change from time to time. |
28 | 104k | inline uint64 Hash128to64(const uint128& x) { |
29 | | // Murmur-inspired hashing. |
30 | 104k | const uint64 kMul = 0xc6a4a7935bd1e995ULL; |
31 | 104k | uint64 a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul; |
32 | 104k | a ^= (a >> 47); |
33 | 104k | uint64 b = (Uint128High64(x) ^ a) * kMul; |
34 | 104k | b ^= (b >> 47); |
35 | 104k | b *= kMul; |
36 | 104k | return b; |
37 | 104k | } |
38 | | |
39 | | #endif // UTIL_HASH_HASH128TO64_H_ |