diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-01-24 17:33:12 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-07 12:39:05 +0100 |
commit | db63d128743adc838e1b658e0d475d37d33a7aa5 (patch) | |
tree | 9094564a6be6eddf4280bd2cddd8443728cde309 /src/buildtool/execution_api/common/content_blob_container.hpp | |
parent | 21fadd2e516497b02c641594ffd648a0e7f91f71 (diff) | |
download | justbuild-db63d128743adc838e1b658e0d475d37d33a7aa5.tar.gz |
ContentBlob: Support hashing
Diffstat (limited to 'src/buildtool/execution_api/common/content_blob_container.hpp')
-rw-r--r-- | src/buildtool/execution_api/common/content_blob_container.hpp | 21 |
1 files changed, 21 insertions, 0 deletions
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 <cstddef> +#include <functional> #include <memory> #include <string> #include <unordered_map> @@ -23,6 +24,7 @@ #include <vector> #include "gsl/gsl" +#include "src/utils/cpp/hash_combine.hpp" #include "src/utils/cpp/transformed_range.hpp" template <typename TDigest> @@ -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<TDigest>{}(digest, other.digest) and + is_exec == other.is_exec; + } + TDigest digest; std::shared_ptr<std::string> data; bool is_exec = false; }; +namespace std { +template <typename TDigest> +struct hash<ContentBlob<TDigest>> { + [[nodiscard]] auto operator()( + ContentBlob<TDigest> 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 <typename TDigest> class ContentBlobContainer final { public: |