Skip to content

Commit b7f3eb3

Browse files
committed
Add hash_combine64.
Extracted from a larger patch by Amul Sul, with some comment additions by me. Discussion: http://postgr.es/m/20171024113004.hn5qajypin4dy5sw@alap3.anarazel.de
1 parent 60651e4 commit b7f3eb3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/include/utils/hashutils.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#define HASHUTILS_H
99

1010
/*
11-
* Combine two hash values, resulting in another hash value, with decent bit
12-
* mixing.
11+
* Combine two 32-bit hash values, resulting in another hash value, with
12+
* decent bit mixing.
1313
*
1414
* Similar to boost's hash_combine().
1515
*/
@@ -20,6 +20,18 @@ hash_combine(uint32 a, uint32 b)
2020
return a;
2121
}
2222

23+
/*
24+
* Combine two 64-bit hash values, resulting in another hash value, using the
25+
* same kind of technique as hash_combine(). Testing shows that this also
26+
* produces good bit mixing.
27+
*/
28+
static inline uint64
29+
hash_combine64(uint64 a, uint64 b)
30+
{
31+
/* 0x49a0f4dd15e5a8e3 is 64bit random data */
32+
a ^= b + 0x49a0f4dd15e5a8e3 + (a << 54) + (a >> 7);
33+
return a;
34+
}
2335

2436
/*
2537
* Simple inline murmur hash implementation hashing a 32 bit integer, for

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy