mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add hasher functors for IPEndpoint
This commit is contained in:
@@ -144,6 +144,14 @@ public:
|
||||
operator std::string () const;
|
||||
/** @} */
|
||||
|
||||
struct hasher
|
||||
{
|
||||
std::size_t operator() (V4 const& v) const
|
||||
{
|
||||
return v.value;
|
||||
}
|
||||
};
|
||||
|
||||
/** The value as a 32 bit unsigned. */
|
||||
uint32 value;
|
||||
};
|
||||
@@ -195,6 +203,14 @@ public:
|
||||
return to_string();
|
||||
}
|
||||
/** @} */
|
||||
|
||||
struct hasher
|
||||
{
|
||||
std::size_t operator() (V6 const&) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -286,6 +302,20 @@ public:
|
||||
operator std::string () const;
|
||||
/** @} */
|
||||
|
||||
struct hasher
|
||||
{
|
||||
std::size_t operator() (IPEndpoint const& value) const
|
||||
{
|
||||
std::size_t hash (0);
|
||||
if (value.isV4())
|
||||
hash = V4::hasher() (value.v4());
|
||||
else if (value.isV6())
|
||||
hash = V6::hasher() (value.v6());
|
||||
hash += value.port();
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
uint16 m_port;
|
||||
|
||||
Reference in New Issue
Block a user