From 4752774bae35f50694038870b97ccf469ee25f15 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Fri, 29 Nov 2024 16:39:31 +0000 Subject: [PATCH] feat: define std::hash for field --- .../src/barretenberg/ecc/fields/field_declarations.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp index af1643bdc1b..7ebfcb7d56e 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp @@ -707,3 +707,13 @@ template void write(B& buf, field 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 struct std::hash> { + std::size_t operator()(const bb::field& ff) const noexcept + { + return std::hash()(ff.data[0]) ^ (std::hash()(ff.data[1]) << 1) ^ + (std::hash()(ff.data[2]) << 2) ^ (std::hash()(ff.data[3]) << 3); + } +}; \ No newline at end of file