1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

CanonPath: Implement boost::hash

This commit is contained in:
Eelco Dolstra 2025-09-08 08:07:34 +02:00
parent 7f9b5226af
commit 8fbf4b9427

View file

@ -8,6 +8,8 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include <boost/container_hash/hash.hpp>
namespace nix { namespace nix {
/** /**
@ -258,11 +260,17 @@ public:
*/ */
std::string makeRelative(const CanonPath & path) const; std::string makeRelative(const CanonPath & path) const;
friend struct std::hash<CanonPath>; friend std::size_t hash_value(const CanonPath &);
}; };
std::ostream & operator<<(std::ostream & stream, const CanonPath & path); std::ostream & operator<<(std::ostream & stream, const CanonPath & path);
inline std::size_t hash_value(const CanonPath & path)
{
boost::hash<std::string_view> hasher;
return hasher(path.path);
}
} // namespace nix } // namespace nix
template<> template<>
@ -270,8 +278,8 @@ struct std::hash<nix::CanonPath>
{ {
using is_avalanching = std::true_type; using is_avalanching = std::true_type;
std::size_t operator()(const nix::CanonPath & s) const noexcept std::size_t operator()(const nix::CanonPath & path) const noexcept
{ {
return std::hash<std::string>{}(s.path); return nix::hash_value(path);
} }
}; };