mesos: Added std::hash template specializations.

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


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

Branch: refs/heads/master
Commit: f7045ffb46da5165d0cbe4a5138e1cf70ca02cd6
Parents: f665d95
Author: Jan Schlicht <[email protected]>
Authored: Thu Aug 27 14:08:26 2015 -0400
Committer: Michael Park <[email protected]>
Committed: Thu Aug 27 14:08:27 2015 -0400

----------------------------------------------------------------------
 include/mesos/type_utils.hpp    | 266 ++++++++++++++++++++++++++---------
 include/mesos/v1/mesos.hpp      | 189 ++++++++++++++++---------
 src/linux/cgroups.hpp           |  18 +++
 src/linux/routing/filter/ip.hpp |  29 ++--
 src/master/metrics.hpp          |   1 +
 src/messages/log.hpp            |  18 +++
 src/module/manager.cpp          |   8 +-
 src/module/manager.hpp          |   9 +-
 src/tests/containerizer.hpp     |   1 +
 src/tests/fetcher_tests.cpp     |   1 +
 src/tests/module.hpp            |  18 +++
 11 files changed, 410 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/include/mesos/type_utils.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/type_utils.hpp b/include/mesos/type_utils.hpp
index 92a0b46..8d27ef4 100644
--- a/include/mesos/type_utils.hpp
+++ b/include/mesos/type_utils.hpp
@@ -203,71 +203,6 @@ inline bool operator<(const TaskID& left, const TaskID& 
right)
 }
 
 
-inline std::size_t hash_value(const CommandInfo::URI& uri)
-{
-  size_t seed = 0;
-
-  if (uri.extract()) {
-    seed += 11;
-  }
-
-  if (uri.executable()) {
-    seed += 2003;
-  }
-
-  boost::hash_combine(seed, uri.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const ContainerID& containerId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, containerId.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const ExecutorID& executorId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, executorId.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const FrameworkID& frameworkId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, frameworkId.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const OfferID& offerId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, offerId.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const SlaveID& slaveId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, slaveId.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const TaskID& taskId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, taskId.value());
-  return seed;
-}
-
-
 inline std::ostream& operator<<(
     std::ostream& stream,
     const ContainerID& containerId)
@@ -436,4 +371,205 @@ inline std::ostream& operator<<(
 
 } // namespace mesos {
 
+namespace std {
+
+template <>
+struct hash<mesos::CommandInfo_URI>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::CommandInfo_URI argument_type;
+
+  result_type operator()(const argument_type& uri) const
+  {
+    size_t seed = 0;
+
+    if (uri.extract()) {
+      seed += 11;
+    }
+
+    if (uri.executable()) {
+      seed += 2003;
+    }
+
+    boost::hash_combine(seed, uri.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::ContainerID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::ContainerID argument_type;
+
+  result_type operator()(const argument_type& containerId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, containerId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::ExecutorID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::ExecutorID argument_type;
+
+  result_type operator()(const argument_type& executorId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, executorId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::FrameworkID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::FrameworkID argument_type;
+
+  result_type operator()(const argument_type& frameworkId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, frameworkId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::OfferID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::OfferID argument_type;
+
+  result_type operator()(const argument_type& offerId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, offerId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::SlaveID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::SlaveID argument_type;
+
+  result_type operator()(const argument_type& slaveId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, slaveId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::TaskID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::TaskID argument_type;
+
+  result_type operator()(const argument_type& taskId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, taskId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::TaskState>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::TaskState argument_type;
+
+  result_type operator()(const argument_type& taskState) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<std::size_t>(taskState);
+  }
+};
+
+
+template <>
+struct hash<mesos::TaskStatus_Source>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::TaskStatus_Source argument_type;
+
+  result_type operator()(const argument_type& source) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<std::size_t>(source);
+  }
+};
+
+
+template <>
+struct hash<mesos::TaskStatus_Reason>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::TaskStatus_Reason argument_type;
+
+  result_type operator()(const argument_type& reason) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<std::size_t>(reason);
+  }
+};
+
+
+template <>
+struct hash<mesos::Image_Type>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::Image_Type argument_type;
+
+  result_type operator()(const argument_type& imageType) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<std::size_t>(imageType);
+  }
+};
+
+
+template <>
+struct hash<std::pair<mesos::FrameworkID, mesos::ExecutorID>>
+{
+  typedef std::size_t result_type;
+
+  typedef std::pair<mesos::FrameworkID, mesos::ExecutorID> argument_type;
+
+  result_type operator()(const argument_type& pair) const
+  {
+    std::size_t seed = 0;
+    boost::hash_combine(seed, std::hash<mesos::FrameworkID>()(pair.first));
+    boost::hash_combine(seed, std::hash<mesos::ExecutorID>()(pair.second));
+    return seed;
+  }
+};
+
+} // namespace std {
+
 #endif // __MESOS_TYPE_UTILS_H__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/include/mesos/v1/mesos.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/v1/mesos.hpp b/include/mesos/v1/mesos.hpp
index d06875e..70f63a3 100644
--- a/include/mesos/v1/mesos.hpp
+++ b/include/mesos/v1/mesos.hpp
@@ -185,71 +185,6 @@ inline bool operator<(const TaskID& left, const TaskID& 
right)
 }
 
 
-inline std::size_t hash_value(const CommandInfo::URI& uri)
-{
-  size_t seed = 0;
-
-  if (uri.extract()) {
-    seed += 11;
-  }
-
-  if (uri.executable()) {
-    seed += 2003;
-  }
-
-  boost::hash_combine(seed, uri.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const ContainerID& containerId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, containerId.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const ExecutorID& executorId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, executorId.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const FrameworkID& frameworkId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, frameworkId.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const OfferID& offerId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, offerId.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const AgentID& agentId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, agentId.value());
-  return seed;
-}
-
-
-inline std::size_t hash_value(const TaskID& taskId)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, taskId.value());
-  return seed;
-}
-
-
 inline std::ostream& operator<<(std::ostream& stream, const ACLs& acls)
 {
   return stream << acls.DebugString();
@@ -387,4 +322,128 @@ inline std::ostream& operator<<(
 } // namespace v1 {
 } // namespace mesos {
 
+namespace std {
+
+template <>
+struct hash<mesos::v1::CommandInfo::URI>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::v1::CommandInfo::URI argument_type;
+
+  result_type operator()(const argument_type& uri) const
+  {
+    size_t seed = 0;
+
+    if (uri.extract()) {
+      seed += 11;
+    }
+
+    if (uri.executable()) {
+      seed += 2003;
+    }
+
+    boost::hash_combine(seed, uri.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::v1::ContainerID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::v1::ContainerID argument_type;
+
+  result_type operator()(const argument_type& containerId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, containerId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::v1::ExecutorID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::v1::ExecutorID argument_type;
+
+  result_type operator()(const argument_type& executorId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, executorId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::v1::FrameworkID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::v1::FrameworkID argument_type;
+
+  result_type operator()(const argument_type& frameworkId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, frameworkId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::v1::OfferID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::v1::OfferID argument_type;
+
+  result_type operator()(const argument_type& offerId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, offerId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::v1::AgentID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::v1::AgentID argument_type;
+
+  result_type operator()(const argument_type& agentId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, agentId.value());
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::v1::TaskID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::v1::TaskID argument_type;
+
+  result_type operator()(const argument_type& taskId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, taskId.value());
+    return seed;
+  }
+};
+
+} // namespace std {
+
 #endif // __MESOS_V1_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/src/linux/cgroups.hpp
----------------------------------------------------------------------
diff --git a/src/linux/cgroups.hpp b/src/linux/cgroups.hpp
index 91ccfd0..f0e56b3 100644
--- a/src/linux/cgroups.hpp
+++ b/src/linux/cgroups.hpp
@@ -651,4 +651,22 @@ process::Future<Nothing> thaw(
 
 } // namespace cgroups {
 
+namespace std {
+
+template <>
+struct hash<cgroups::memory::pressure::Level>
+{
+  typedef std::size_t result_type;
+
+  typedef cgroups::memory::pressure::Level argument_type;
+
+  result_type operator()(const argument_type& level) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<std::size_t>(level);
+  }
+};
+
+} // namespace std {
+
 #endif // __CGROUPS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/src/linux/routing/filter/ip.hpp
----------------------------------------------------------------------
diff --git a/src/linux/routing/filter/ip.hpp b/src/linux/routing/filter/ip.hpp
index 0a77861..29e0e6d 100644
--- a/src/linux/routing/filter/ip.hpp
+++ b/src/linux/routing/filter/ip.hpp
@@ -92,15 +92,6 @@ inline std::ostream& operator<<(
 }
 
 
-inline size_t hash_value(const PortRange& range)
-{
-  size_t seed = 0;
-  boost::hash_combine(seed, range.begin());
-  boost::hash_combine(seed, range.end());
-  return seed;
-}
-
-
 struct Classifier
 {
   Classifier(
@@ -217,4 +208,24 @@ Result<std::vector<Classifier>> classifiers(
 } // namespace filter {
 } // namespace routing {
 
+namespace std {
+
+template <>
+struct hash<routing::filter::ip::PortRange>
+{
+  typedef std::size_t result_type;
+
+  typedef routing::filter::ip::PortRange argument_type;
+
+  result_type operator()(const argument_type& range) const
+  {
+    std::size_t seed = 0;
+    boost::hash_combine(seed, range.begin());
+    boost::hash_combine(seed, range.end());
+    return seed;
+  }
+};
+
+} // namespace std {
+
 #endif // __LINUX_ROUTING_FILTER_IP_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/src/master/metrics.hpp
----------------------------------------------------------------------
diff --git a/src/master/metrics.hpp b/src/master/metrics.hpp
index c51887e..2d07a16 100644
--- a/src/master/metrics.hpp
+++ b/src/master/metrics.hpp
@@ -29,6 +29,7 @@
 #include <stout/hashmap.hpp>
 
 #include "mesos/mesos.hpp"
+#include "mesos/type_utils.hpp"
 
 namespace mesos {
 namespace internal {

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/src/messages/log.hpp
----------------------------------------------------------------------
diff --git a/src/messages/log.hpp b/src/messages/log.hpp
index 94e38c1..01f295e 100644
--- a/src/messages/log.hpp
+++ b/src/messages/log.hpp
@@ -50,4 +50,22 @@ inline std::ostream& operator<<(
 } // namespace internal {
 } // namespace mesos {
 
+namespace std {
+
+template <>
+struct hash<mesos::internal::log::Metadata_Status>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::internal::log::Metadata_Status argument_type;
+
+  result_type operator()(const argument_type& status) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<std::size_t>(status);
+  }
+};
+
+} // namespace std {
+
 #endif // __MESSAGES_LOG_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/src/module/manager.cpp
----------------------------------------------------------------------
diff --git a/src/module/manager.cpp b/src/module/manager.cpp
index 862b71f..f9a0643 100644
--- a/src/module/manager.cpp
+++ b/src/module/manager.cpp
@@ -46,10 +46,10 @@ using namespace mesos::internal;
 using namespace mesos::modules;
 
 std::mutex ModuleManager::mutex;
-hashmap<const string, string> ModuleManager::kindToVersion;
-hashmap<const string, ModuleBase*> ModuleManager::moduleBases;
-hashmap<const string, Owned<DynamicLibrary>> ModuleManager::dynamicLibraries;
-hashmap<const std::string, Parameters> ModuleManager::moduleParameters;
+hashmap<string, string> ModuleManager::kindToVersion;
+hashmap<string, ModuleBase*> ModuleManager::moduleBases;
+hashmap<string, Owned<DynamicLibrary>> ModuleManager::dynamicLibraries;
+hashmap<string, Parameters> ModuleManager::moduleParameters;
 
 
 void ModuleManager::initialize()

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/src/module/manager.hpp
----------------------------------------------------------------------
diff --git a/src/module/manager.hpp b/src/module/manager.hpp
index cab67a8..302eb40 100644
--- a/src/module/manager.hpp
+++ b/src/module/manager.hpp
@@ -144,21 +144,20 @@ private:
 
   static std::mutex mutex;
 
-  static hashmap<const std::string, std::string> kindToVersion;
+  static hashmap<std::string, std::string> kindToVersion;
 
   // Mapping from "module name" to the actual ModuleBase. If two
   // modules from different libraries have the same name then the last
   // one specified in the protobuf Modules will be picked.
-  static hashmap<const std::string, ModuleBase*> moduleBases;
+  static hashmap<std::string, ModuleBase*> moduleBases;
 
   // Module-specific command-line parameters.
-  static hashmap<const std::string, Parameters> moduleParameters;
+  static hashmap<std::string, Parameters> moduleParameters;
 
   // A list of dynamic libraries to keep the object from getting
   // destructed. Destroying the DynamicLibrary object could result in
   // unloading the library from the process memory.
-  static hashmap<const std::string, process::Owned<DynamicLibrary>>
-    dynamicLibraries;
+  static hashmap<std::string, process::Owned<DynamicLibrary>> dynamicLibraries;
 };
 
 } // namespace modules {

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/src/tests/containerizer.hpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer.hpp b/src/tests/containerizer.hpp
index 24b014f..dfa2c5b 100644
--- a/src/tests/containerizer.hpp
+++ b/src/tests/containerizer.hpp
@@ -38,6 +38,7 @@
 #include "mesos/executor.hpp"
 #include "mesos/mesos.hpp"
 #include "mesos/resources.hpp"
+#include "mesos/type_utils.hpp"
 
 #include "slave/containerizer/containerizer.hpp"
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/src/tests/fetcher_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/fetcher_tests.cpp b/src/tests/fetcher_tests.cpp
index 81e7036..8d13352 100644
--- a/src/tests/fetcher_tests.cpp
+++ b/src/tests/fetcher_tests.cpp
@@ -40,6 +40,7 @@
 #include <stout/try.hpp>
 
 #include <mesos/fetcher/fetcher.hpp>
+#include <mesos/type_utils.hpp>
 
 #include "slave/containerizer/fetcher.hpp"
 #include "slave/flags.hpp"

http://git-wip-us.apache.org/repos/asf/mesos/blob/f7045ffb/src/tests/module.hpp
----------------------------------------------------------------------
diff --git a/src/tests/module.hpp b/src/tests/module.hpp
index 850c200..682734a 100644
--- a/src/tests/module.hpp
+++ b/src/tests/module.hpp
@@ -83,4 +83,22 @@ public:
 } // namespace internal {
 } // namespace mesos {
 
+namespace std {
+
+template <>
+struct hash<mesos::internal::tests::ModuleID>
+{
+  typedef std::size_t result_type;
+
+  typedef mesos::internal::tests::ModuleID argument_type;
+
+  result_type operator()(const argument_type& moduleId) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<std::size_t>(moduleId);
+  }
+};
+
+} // namespace std {
+
 #endif // __TESTS_MODULE_HPP__

Reply via email to