Add std::hash<PosIdx>

This commit is contained in:
Robert Hensing 2024-07-16 16:46:41 +02:00
parent 6c9d62dceb
commit 64b46000ad

View file

@ -2,12 +2,15 @@
#include <cinttypes> #include <cinttypes>
#include "util.hh"
namespace nix { namespace nix {
class PosIdx class PosIdx
{ {
friend struct LazyPosAcessors; friend struct LazyPosAcessors;
friend class PosTable; friend class PosTable;
friend class std::hash<PosIdx>;
private: private:
uint32_t id; uint32_t id;
@ -37,8 +40,28 @@ public:
{ {
return id == other.id; return id == other.id;
} }
size_t hash() const noexcept
{
size_t h = 854125;
hash_combine(h, id);
return h;
}
}; };
inline PosIdx noPos = {}; inline PosIdx noPos = {};
} }
namespace std {
template<>
struct hash<nix::PosIdx>
{
std::size_t operator()(nix::PosIdx pos) const noexcept
{
return pos.hash();
}
};
} // namespace std