From 2a9171c6231a0c1db145ec8174fe4510368ae60a Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 3 Nov 2013 12:50:17 -0800 Subject: [PATCH] Improve hasher for IPAddress --- src/beast/beast/net/IPAddress.h | 50 +++++++++++++++------ src/ripple/peerfinder/ripple_peerfinder.cpp | 1 + 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/beast/beast/net/IPAddress.h b/src/beast/beast/net/IPAddress.h index fb91f82e9..c4b6c3941 100644 --- a/src/beast/beast/net/IPAddress.h +++ b/src/beast/beast/net/IPAddress.h @@ -27,6 +27,18 @@ #include "../CStdInt.h" #include "../mpl/IfCond.h" +namespace std { + +template +struct hash; + +//template <> +//struct hash ; + +} + +//------------------------------------------------------------------------------ + namespace beast { /** Represents an IP address (v4 or v6) and port combination. */ @@ -309,19 +321,7 @@ public: operator std::string () const; /** @} */ - struct hasher - { - std::size_t operator() (IPAddress 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; - } - }; + typedef std::hash hasher; struct key_equal; @@ -374,4 +374,28 @@ struct IPAddress::key_equal } +//------------------------------------------------------------------------------ + +namespace std { + +template +struct hash; + +template <> +struct hash +{ + std::size_t operator() (beast::IPAddress const& value) const + { + std::size_t hash (0); + if (value.isV4()) + hash = beast::IPAddress::V4::hasher() (value.v4()); + else if (value.isV6()) + hash = beast::IPAddress::V6::hasher() (value.v6()); + hash += value.port(); + return hash; + } +}; + +} + #endif diff --git a/src/ripple/peerfinder/ripple_peerfinder.cpp b/src/ripple/peerfinder/ripple_peerfinder.cpp index e255fd1e9..f67103014 100644 --- a/src/ripple/peerfinder/ripple_peerfinder.cpp +++ b/src/ripple/peerfinder/ripple_peerfinder.cpp @@ -43,6 +43,7 @@ namespace ripple { using namespace beast; } +#include "impl/BootstrapCache.h" #include "impl/PrivateTypes.h" # include "impl/Tuning.h" # include "impl/Checker.h"