/root/doris/be/src/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 | | #pragma once |
5 | | |
6 | | #include "gutil/int128.h" |
7 | | #include "gutil/integral_types.h" |
8 | | |
9 | | // Hash 128 input bits down to 64 bits of output. |
10 | | // This is intended to be a reasonably good hash function. |
11 | | // It may change from time to time. |
12 | 23.6k | inline uint64 Hash128to64(const uint128& x) { |
13 | | // Murmur-inspired hashing. |
14 | 23.6k | const uint64 kMul = 0xc6a4a7935bd1e995ULL; |
15 | 23.6k | uint64 a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul; |
16 | 23.6k | a ^= (a >> 47); |
17 | 23.6k | uint64 b = (Uint128High64(x) ^ a) * kMul; |
18 | 23.6k | b ^= (b >> 47); |
19 | 23.6k | b *= kMul; |
20 | 23.6k | return b; |
21 | 23.6k | } |