diff options
author | Robert Haas | 2017-10-29 07:11:43 +0000 |
---|---|---|
committer | Robert Haas | 2017-10-29 07:11:43 +0000 |
commit | b7f3eb31405f1dbbf086e5a8f88569a6dc85157a (patch) | |
tree | 4506596ea007f31e4e04977b8a03d4c570ce17c6 | |
parent | 60651e4cddbb77e8f1a0c7fc0be6a7e7bf626fe0 (diff) |
Add hash_combine64.
Extracted from a larger patch by Amul Sul, with some comment additions
by me.
Discussion: http://postgr.es/m/[email protected]
-rw-r--r-- | src/include/utils/hashutils.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/include/utils/hashutils.h b/src/include/utils/hashutils.h index 366bd0e78b..3a5c21f523 100644 --- a/src/include/utils/hashutils.h +++ b/src/include/utils/hashutils.h @@ -8,8 +8,8 @@ #define HASHUTILS_H /* - * Combine two hash values, resulting in another hash value, with decent bit - * mixing. + * Combine two 32-bit hash values, resulting in another hash value, with + * decent bit mixing. * * Similar to boost's hash_combine(). */ @@ -20,6 +20,18 @@ hash_combine(uint32 a, uint32 b) return a; } +/* + * Combine two 64-bit hash values, resulting in another hash value, using the + * same kind of technique as hash_combine(). Testing shows that this also + * produces good bit mixing. + */ +static inline uint64 +hash_combine64(uint64 a, uint64 b) +{ + /* 0x49a0f4dd15e5a8e3 is 64bit random data */ + a ^= b + 0x49a0f4dd15e5a8e3 + (a << 54) + (a >> 7); + return a; +} /* * Simple inline murmur hash implementation hashing a 32 bit integer, for |