Skip to content

Commit cfe7913

Browse files
ezbrcopybara-github
authored andcommitted
Make bool true hash be ~size_t{} instead of 1 so that all bits are different between true/false instead of only one.
PiperOrigin-RevId: 772950705 Change-Id: I9ac8aa01c87684544b1d21bb7237680711ba64b0
1 parent 23d40c5 commit cfe7913

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

absl/hash/internal/hash.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,10 @@ H hash_weakly_mixed_integer(H hash_state, WeaklyMixedInteger value) {
409409
template <typename H, typename B>
410410
typename std::enable_if<std::is_same<B, bool>::value, H>::type AbslHashValue(
411411
H hash_state, B value) {
412+
// We use ~size_t{} instead of 1 so that all bits are different between
413+
// true/false instead of only 1.
412414
return H::combine(std::move(hash_state),
413-
static_cast<unsigned char>(value ? 1 : 0));
415+
static_cast<size_t>(value ? ~size_t{} : 0));
414416
}
415417

416418
// AbslHashValue() for hashing enum values

0 commit comments

Comments
 (0)