From db63d128743adc838e1b658e0d475d37d33a7aa5 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Fri, 24 Jan 2025 17:33:12 +0100 Subject: ContentBlob: Support hashing --- .../execution_api/common/content_blob_container.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/buildtool/execution_api/common/content_blob_container.hpp') diff --git a/src/buildtool/execution_api/common/content_blob_container.hpp b/src/buildtool/execution_api/common/content_blob_container.hpp index 1788d229..bc546ac4 100644 --- a/src/buildtool/execution_api/common/content_blob_container.hpp +++ b/src/buildtool/execution_api/common/content_blob_container.hpp @@ -16,6 +16,7 @@ #define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_CONTENT_BLOB_CONTAINER_HPP #include +#include #include #include #include @@ -23,6 +24,7 @@ #include #include "gsl/gsl" +#include "src/utils/cpp/hash_combine.hpp" #include "src/utils/cpp/transformed_range.hpp" template @@ -37,11 +39,30 @@ struct ContentBlob final { bool is_exec) noexcept : digest{std::move(mydigest)}, data(mydata), is_exec{is_exec} {} + [[nodiscard]] auto operator==(ContentBlob const& other) const noexcept + -> bool { + return std::equal_to{}(digest, other.digest) and + is_exec == other.is_exec; + } + TDigest digest; std::shared_ptr data; bool is_exec = false; }; +namespace std { +template +struct hash> { + [[nodiscard]] auto operator()( + ContentBlob const& blob) const noexcept -> std::size_t { + std::size_t seed{}; + hash_combine(&seed, blob.digest); + hash_combine(&seed, blob.is_exec); + return seed; + } +}; +} // namespace std + template class ContentBlobContainer final { public: -- cgit v1.2.3