From 4151827ce8651873e4d4c889337fe3f69c36eb6e Mon Sep 17 00:00:00 2001
From: Benjamin Mahler <benjamin.mahler@gmail.com>
Date: Tue, 9 Dec 2014 12:41:33 -0800
Subject: [PATCH] *** Modified for 0.21.0-tw11 *** Added a hash function for
 Node.

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

Conflicts:
	3rdparty/libprocess/include/process/node.hpp
---
 3rdparty/libprocess/include/process/node.hpp | 39 ++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/3rdparty/libprocess/include/process/node.hpp b/3rdparty/libprocess/include/process/node.hpp
index 7a96894..3b4cbf5 100644
--- a/3rdparty/libprocess/include/process/node.hpp
+++ b/3rdparty/libprocess/include/process/node.hpp
@@ -1,10 +1,17 @@
 #ifndef __PROCESS_NODE_HPP__
 #define __PROCESS_NODE_HPP__
 
+#include <stdint.h>
 #include <unistd.h>
 
+#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).
@@ -28,10 +35,42 @@ public:
     return stream;
   }
 
+  bool operator == (const Node& that) const
+  {
+    return (ip == that.ip && port == that.port);
+  }
+
+  bool operator != (const Node& that) const
+  {
+    return !(*this == that);
+  }
+
   uint32_t ip;
   uint16_t port;
 };
 
+
+inline std::ostream& operator << (std::ostream& stream, const Node& node)
+{
+  char ip[INET_ADDRSTRLEN];
+  if (inet_ntop(AF_INET, (in_addr*) &node.ip, ip, INET_ADDRSTRLEN) == NULL) {
+    PLOG(FATAL) << "Failed to get human-readable IP address for '"
+                << node.ip << "'";
+  }
+  stream << ip << ":" << node.port;
+  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__
-- 
2.0.4.218.g7ec489f-twtrsrc

