mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Don't convert IPv6Address to string when hashing
This commit is contained in:
@@ -32,10 +32,10 @@
|
||||
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
#include <functional>
|
||||
#include <stdint.h>
|
||||
#include <tins/cxxstd.h>
|
||||
#include <tins/macros.h>
|
||||
#include <functional>
|
||||
|
||||
namespace Tins {
|
||||
|
||||
@@ -224,9 +224,14 @@ namespace std {
|
||||
|
||||
template<>
|
||||
struct hash<Tins::IPv6Address> {
|
||||
size_t operator()(const Tins::IPv6Address& addr) const
|
||||
{
|
||||
return std::hash<string>()(addr.to_string());
|
||||
// Implementation taken from boost.functional
|
||||
size_t operator()(const Tins::IPv6Address& addr) const {
|
||||
std::size_t output = Tins::IPv6Address::address_size;
|
||||
Tins::IPv6Address::const_iterator iter = addr.begin();
|
||||
for (; iter != addr.end(); ++iter) {
|
||||
output ^= *iter + 0x9e3779b9 + (output << 6) + (output >> 2);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user