You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2014/12/09 23:07:06 UTC

[2/2] mesos git commit: Added a hash function for Node.

Added a hash function for Node.

Review: https://reviews.apache.org/r/28869


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f1537180
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f1537180
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f1537180

Branch: refs/heads/master
Commit: f1537180747774bbb2e02062f89614be208327d7
Parents: e6be445
Author: Benjamin Mahler <be...@gmail.com>
Authored: Tue Dec 9 12:41:33 2014 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Tue Dec 9 14:02:39 2014 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/node.hpp | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f1537180/3rdparty/libprocess/include/process/node.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/node.hpp b/3rdparty/libprocess/include/process/node.hpp
index eb48c54..173eb8a 100644
--- a/3rdparty/libprocess/include/process/node.hpp
+++ b/3rdparty/libprocess/include/process/node.hpp
@@ -1,13 +1,17 @@
 #ifndef __PROCESS_NODE_HPP__
 #define __PROCESS_NODE_HPP__
 
-#include <arpa/inet.h>
+#include <stdint.h>
 #include <unistd.h>
 
-#include <sstream>
+#include <arpa/inet.h>
 
 #include <glog/logging.h>
 
+#include <sstream>
+
+#include <boost/functional/hash.hpp>
+
 namespace process {
 
 // Represents a remote "node" (encapsulates IP address and port).
@@ -41,6 +45,7 @@ public:
   uint16_t port;
 };
 
+
 inline std::ostream& operator << (std::ostream& stream, const Node& node)
 {
   char ip[INET_ADDRSTRLEN];
@@ -52,6 +57,16 @@ inline std::ostream& operator << (std::ostream& stream, const Node& node)
   return stream;
 }
 
+
+// UPID hash value (for example, to use in Boost's unordered maps).
+inline std::size_t hash_value(const Node& node)
+{
+  size_t seed = 0;
+  boost::hash_combine(seed, node.ip);
+  boost::hash_combine(seed, node.port);
+  return seed;
+}
+
 } // namespace process {
 
 #endif // __PROCESS_NODE_HPP__