Skip to content

Commit

Permalink
feat: define std::hash for field
Browse files Browse the repository at this point in the history
  • Loading branch information
fcarreiro committed Nov 29, 2024
1 parent 2367c62 commit 4752774
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,13 @@ template <typename B, typename Params> void write(B& buf, field<Params> const& v
}

} // namespace bb

// Define hash function for field elements, e.g., so that it can be used in maps.
// See https://en.cppreference.com/w/cpp/utility/hash .
template <typename Params> struct std::hash<bb::field<Params>> {
std::size_t operator()(const bb::field<Params>& ff) const noexcept
{
return std::hash<uint64_t>()(ff.data[0]) ^ (std::hash<uint64_t>()(ff.data[1]) << 1) ^
(std::hash<uint64_t>()(ff.data[2]) << 2) ^ (std::hash<uint64_t>()(ff.data[3]) << 3);
}
};

0 comments on commit 4752774

Please sign in to comment.