[llvm] [ADT] Update hash function of uint64_t for DenseMap (PR #95734)

Anton Korobeynikov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 17 10:02:40 PDT 2024


================
@@ -151,7 +151,7 @@ template<> struct DenseMapInfo<unsigned long long> {
   static inline unsigned long long getTombstoneKey() { return ~0ULL - 1ULL; }
 
   static unsigned getHashValue(const unsigned long long& Val) {
-    return (unsigned)(Val * 37ULL);
+    return DenseMapInfo<unsigned>(Val) ^ DenseMapInfo<unsigned>(Val >> 32);
----------------
asl wrote:

> That looks good too. But I am not a hashing expert so I don't have an opinion here. Let's see what others propose.

Here is the easy thing to reason about this just in case. `^` mixes very poor: single bit change of input changes only single bit of output. Ideally when we mix / combine hash values (or do similar things) should produce values that are not dependent on the original hash values being combined. This greatly reduce the possibility of collisions from "related" inputs.

https://github.com/llvm/llvm-project/pull/95734


More information about the llvm-commits mailing list