Add hasher functors for IPEndpoint

This commit is contained in:
Vinnie Falco
2013-09-29 07:43:31 -07:00
parent a1ec423235
commit 0e46762962

View File

@@ -144,6 +144,14 @@ public:
operator std::string () const; operator std::string () const;
/** @} */ /** @} */
struct hasher
{
std::size_t operator() (V4 const& v) const
{
return v.value;
}
};
/** The value as a 32 bit unsigned. */ /** The value as a 32 bit unsigned. */
uint32 value; uint32 value;
}; };
@@ -195,6 +203,14 @@ public:
return to_string(); return to_string();
} }
/** @} */ /** @} */
struct hasher
{
std::size_t operator() (V6 const&) const
{
return 0;
}
};
}; };
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@@ -286,6 +302,20 @@ public:
operator std::string () const; 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: private:
Type m_type; Type m_type;
uint16 m_port; uint16 m_port;