Skip to content

Commit 752bc59

Browse files
authored
feat(bb): define std::hash for field (#10312)
1 parent 5a04ca8 commit 752bc59

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -707,3 +707,13 @@ template <typename B, typename Params> void write(B& buf, field<Params> const& v
707707
}
708708

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

0 commit comments

Comments
 (0)