Skip to content

Commit 9cd0b83

Browse files
ChuanqiXu9nikic
authored andcommitted
Update hash function of uint64_t for DenseMap
1 parent 3ca1744 commit 9cd0b83

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

llvm/include/llvm/ADT/DenseMapInfo.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ template<> struct DenseMapInfo<unsigned long> {
137137
static inline unsigned long getTombstoneKey() { return ~0UL - 1L; }
138138

139139
static unsigned getHashValue(const unsigned long& Val) {
140-
return (unsigned)(Val * 37UL);
140+
if constexpr (sizeof(Val) == 4)
141+
return DenseMapInfo<unsigned>::getHashValue(Val);
142+
else
143+
return detail::combineHashValue(
144+
DenseMapInfo<unsigned>::getHashValue(Val),
145+
DenseMapInfo<unsigned>::getHashValue(Val >> 32));
141146
}
142147

143148
static bool isEqual(const unsigned long& LHS, const unsigned long& RHS) {
@@ -151,7 +156,9 @@ template<> struct DenseMapInfo<unsigned long long> {
151156
static inline unsigned long long getTombstoneKey() { return ~0ULL - 1ULL; }
152157

153158
static unsigned getHashValue(const unsigned long long& Val) {
154-
return (unsigned)(Val * 37ULL);
159+
return detail::combineHashValue(
160+
DenseMapInfo<unsigned>::getHashValue(Val),
161+
DenseMapInfo<unsigned>::getHashValue(Val >> 32));
155162
}
156163

157164
static bool isEqual(const unsigned long long& LHS,

0 commit comments

Comments
 (0)