You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2015/08/27 21:20:46 UTC
[2/3] mesos git commit: libprocess: Added std::hash template
specializations.
libprocess: Added std::hash template specializations.
Review: https://reviews.apache.org/r/37188
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f665d957
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f665d957
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f665d957
Branch: refs/heads/master
Commit: f665d957c79c008f20256497b784768b7d7f7d19
Parents: b091815
Author: Jan Schlicht <ja...@mesosphere.io>
Authored: Thu Aug 27 14:08:07 2015 -0400
Committer: Michael Park <mp...@apache.org>
Committed: Thu Aug 27 14:08:08 2015 -0400
----------------------------------------------------------------------
3rdparty/libprocess/include/process/address.hpp | 28 +++++++++++++-------
3rdparty/libprocess/include/process/pid.hpp | 27 ++++++++++++++++---
3rdparty/libprocess/src/pid.cpp | 12 ---------
3rdparty/libprocess/src/tests/http_tests.cpp | 28 ++++++++++++++------
4 files changed, 62 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/f665d957/3rdparty/libprocess/include/process/address.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/address.hpp b/3rdparty/libprocess/include/process/address.hpp
index df78f8e..e0fa179 100644
--- a/3rdparty/libprocess/include/process/address.hpp
+++ b/3rdparty/libprocess/include/process/address.hpp
@@ -142,17 +142,27 @@ inline std::ostream& operator<<(std::ostream& stream, const Address& address)
return stream;
}
+} // namespace network {
+} // namespace process {
+
+namespace std {
-// Address hash value (for example, to use in Boost's unordered maps).
-inline std::size_t hash_value(const Address& address)
+template <>
+struct hash<process::network::Address>
{
- size_t seed = 0;
- boost::hash_combine(seed, address.ip);
- boost::hash_combine(seed, address.port);
- return seed;
-}
+ typedef std::size_t result_type;
-} // namespace network {
-} // namespace process {
+ typedef process::network::Address argument_type;
+
+ result_type operator()(const argument_type& address) const
+ {
+ size_t seed = 0;
+ boost::hash_combine(seed, std::hash<net::IP>()(address.ip));
+ boost::hash_combine(seed, address.port);
+ return seed;
+ }
+};
+
+} // namespace std {
#endif // __PROCESS_ADDRESS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/f665d957/3rdparty/libprocess/include/process/pid.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/pid.hpp b/3rdparty/libprocess/include/process/pid.hpp
index 8d3735c..2986e85 100644
--- a/3rdparty/libprocess/include/process/pid.hpp
+++ b/3rdparty/libprocess/include/process/pid.hpp
@@ -21,6 +21,8 @@
#include <sstream>
#include <string>
+#include <boost/functional/hash.hpp>
+
#include <process/address.hpp>
#include <stout/ip.hpp>
@@ -137,7 +139,7 @@ struct PID : UPID
// Only allow upcasts!
T* t = NULL;
Base* base = t;
- (void)base; // Eliminate unused base warning.
+ (void)base; // Eliminate unused base warning.
PID<Base> pid;
pid.id = id;
pid.address = address;
@@ -150,10 +152,27 @@ struct PID : UPID
std::ostream& operator<<(std::ostream&, const UPID&);
std::istream& operator>>(std::istream&, UPID&);
+} // namespace process {
+
+namespace std {
+
+template <>
+struct hash<process::UPID>
+{
+ typedef std::size_t result_type;
+
+ typedef process::UPID argument_type;
-// UPID hash value (for example, to use in Boost's unordered maps).
-std::size_t hash_value(const UPID&);
+ result_type operator()(const argument_type& upid) const
+ {
+ size_t seed = 0;
+ boost::hash_combine(seed, upid.id);
+ boost::hash_combine(seed, std::hash<net::IP>()(upid.address.ip));
+ boost::hash_combine(seed, upid.address.port);
+ return seed;
+ }
+};
-} // namespace process {
+} // namespace std {
#endif // __PROCESS_PID_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/f665d957/3rdparty/libprocess/src/pid.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/pid.cpp b/3rdparty/libprocess/src/pid.cpp
index f5528ae..a1731ae 100644
--- a/3rdparty/libprocess/src/pid.cpp
+++ b/3rdparty/libprocess/src/pid.cpp
@@ -25,8 +25,6 @@
#include <iostream>
#include <string>
-#include <boost/unordered_map.hpp>
-
#include <process/pid.hpp>
#include <process/process.hpp>
@@ -148,14 +146,4 @@ istream& operator>>(istream& stream, UPID& pid)
return stream;
}
-
-size_t hash_value(const UPID& pid)
-{
- size_t seed = 0;
- boost::hash_combine(seed, pid.id);
- boost::hash_combine(seed, pid.address.ip);
- boost::hash_combine(seed, pid.address.port);
- return seed;
-}
-
} // namespace process {
http://git-wip-us.apache.org/repos/asf/mesos/blob/f665d957/3rdparty/libprocess/src/tests/http_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/http_tests.cpp b/3rdparty/libprocess/src/tests/http_tests.cpp
index c22f9d3..d0b9399 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -791,15 +791,27 @@ TEST(URLTest, Stringification)
query["foo"] = "bar";
query["baz"] = "bam";
- EXPECT_EQ("http://172.158.1.23:80/?baz=bam&foo=bar",
- stringify(URL("http", ip.get(), 80, "/", query)));
+ // The order of the hashmap entries may vary, hence we have
+ // to check if one of the possible outcomes is satisfied.
+ const string url1 = stringify(URL("http", ip.get(), 80, "/", query));
- EXPECT_EQ("http://172.158.1.23:80/path?baz=bam&foo=bar",
- stringify(URL("http", ip.get(), 80, "/path", query)));
+ EXPECT_TRUE(url1 == "http://172.158.1.23:80/?baz=bam&foo=bar" ||
+ url1 == "http://172.158.1.23:80/?foo=bar&baz=bam");
- EXPECT_EQ("http://172.158.1.23:80/?baz=bam&foo=bar#fragment",
- stringify(URL("http", ip.get(), 80, "/", query, "fragment")));
+ const string url2 = stringify(URL("http", ip.get(), 80, "/path", query));
- EXPECT_EQ("http://172.158.1.23:80/path?baz=bam&foo=bar#fragment",
- stringify(URL("http", ip.get(), 80, "/path", query, "fragment")));
+ EXPECT_TRUE(url2 == "http://172.158.1.23:80/path?baz=bam&foo=bar" ||
+ url2 == "http://172.158.1.23:80/path?foo=bar&baz=bam");
+
+ const string url3 =
+ stringify(URL("http", ip.get(), 80, "/", query, "fragment"));
+
+ EXPECT_TRUE(url3 == "http://172.158.1.23:80/?baz=bam&foo=bar#fragment" ||
+ url3 == "http://172.158.1.23:80/?foo=bar&baz=bam#fragment");
+
+ const string url4 =
+ stringify(URL("http", ip.get(), 80, "/path", query, "fragment"));
+
+ EXPECT_TRUE(url4 == "http://172.158.1.23:80/path?baz=bam&foo=bar#fragment" ||
+ url4 == "http://172.158.1.23:80/path?foo=bar&baz=bam#fragment");
}