Skip to content

Commit

Permalink
] chage comment
Browse files Browse the repository at this point in the history
Summary:
I found "we don't trust the top bit" comment confusing.
What I believe is happening, is that tag could be 0 for a non-zero element.
And then things would break.

As a consequence the code also relies on top bit being 1 for set values.

Differential Revision: D66307350
  • Loading branch information
DenisYaroshevskiy authored and facebook-github-bot committed Nov 21, 2024
1 parent 98c8bfb commit bc8e202
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions folly/container/detail/F14Table.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,18 @@ std::pair<std::size_t, std::size_t> splitHashImpl(std::size_t hash) {
// with less than 16.7 million entries, it's safe to have a 32-bit hash,
// and use the bottom 24 bits for the index and leave the top 8 for the
// tag.
//
// | 0x80 sets the top bit in the tag.
// We need to avoid 0 tag for a non-empty value.
// Because we do this already, in some places we rely on the top bit
// being 1 for all non-empty values.
if (ShouldAssume32BitHash<Hasher>::value) {
// we don't trust the top bit
tag = ((hash >> 24) | 0x80) & 0xFF;
// Explicitly mask off the top 32-bits so that the compiler can
// optimize away whatever is populating the top 32-bits, which is likely
// just the lower 32-bits duplicated.
hash = hash & 0xFFFF'FFFF;
} else {
// we don't trust the top bit
tag = (hash >> 56) | 0x80;
}
}
Expand Down

0 comments on commit bc8e202

Please sign in to comment.