Skip to content

Commit

Permalink
] chage comment (#2342)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2342

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.

Reviewed By: Gownta

Differential Revision: D66307350

fbshipit-source-id: 6e6cd2613098493c1414fdf9419f7f54ed11c8bf
  • Loading branch information
DenisYaroshevskiy authored and facebook-github-bot committed Nov 22, 2024
1 parent d14f774 commit ec6d9c9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 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.
// In some places we also 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 Expand Up @@ -394,7 +397,10 @@ std::pair<std::size_t, std::size_t> splitHashImpl(std::size_t hash) {
tag = static_cast<uint8_t>(~(hash >> 25));
#endif
} else {
// we don't trust the top bit
// | 0x80 sets the top bit in the tag.
// We need to avoid 0 tag for a non-empty value.
// In some places we also rely on the top bit
// being 1 for all non-empty values.
tag = (hash >> 24) | 0x80;
}
return std::make_pair(hash, tag);
Expand Down

0 comments on commit ec6d9c9

Please sign in to comment.