-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[ADT] Update hash function of uint64_t for DenseMap #95734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,7 +137,10 @@ template<> struct DenseMapInfo<unsigned long> { | |
static inline unsigned long getTombstoneKey() { return ~0UL - 1L; } | ||
|
||
static unsigned getHashValue(const unsigned long& Val) { | ||
return (unsigned)(Val * 37UL); | ||
if constexpr (sizeof(Val) == 4) | ||
return DenseMapInfo<unsigned>::getHashValue(Val); | ||
else | ||
return detail::combineHashValue(Val >> 32, Val); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ChuanqiXu9 To silence MSVC warnings, could we change this to:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. You can land that directly to make the build green. But I don't understand in what cases it is a problem. I think I've already handled the case for its size is 4. I don't feel it is possible that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MSVC has a tendency to analyze additional paths such as the non-constexpr else clause - we've hit similar problems before :( |
||
} | ||
|
||
static bool isEqual(const unsigned long& LHS, const unsigned long& RHS) { | ||
|
@@ -151,7 +154,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 detail::combineHashValue(Val >> 32, Val); | ||
} | ||
|
||
static bool isEqual(const unsigned long long& LHS, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we have
densemap::detail::mix
with very low latency, we can use it unconditionally for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's best to keep the conditional so you get the same hashing behavior if you use a different spelling for what is essentially the same type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd like to keep the condition too.