mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mp...@apache.org
Subject [1/3] mesos git commit: Updated hash containers (e.g. hashmap) to inherit from their standard counterparts (e.g. std::unordered_map) rather than boost.
Date Thu, 27 Aug 2015 19:20:45 GMT
Repository: mesos
Updated Branches:
  refs/heads/master 3b91e35b4 -> f7045ffb4


Updated hash containers (e.g. hashmap) to inherit from their standard
counterparts (e.g. std::unordered_map) rather than boost.

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


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

Branch: refs/heads/master
Commit: b091815794cecf7dd3173575bb37711453b4a310
Parents: 3b91e35
Author: Jan Schlicht <jan@mesosphere.io>
Authored: Thu Aug 27 14:05:48 2015 -0400
Committer: Michael Park <mpark@apache.org>
Committed: Thu Aug 27 14:05:49 2015 -0400

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/cache.hpp      |  7 ++--
 .../3rdparty/stout/include/stout/hashmap.hpp    | 33 ++++++++---------
 .../3rdparty/stout/include/stout/hashset.hpp    | 27 +++++++-------
 .../3rdparty/stout/include/stout/ip.hpp         | 39 +++++++++++++-------
 .../stout/include/stout/multihashmap.hpp        | 29 +++++++--------
 .../3rdparty/stout/include/stout/uuid.hpp       | 17 +++++++++
 .../3rdparty/stout/tests/hashset_tests.cpp      |  2 +
 .../3rdparty/stout/tests/multimap_tests.cpp     | 30 ---------------
 8 files changed, 90 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b0918157/3rdparty/libprocess/3rdparty/stout/include/stout/cache.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/cache.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/cache.hpp
index 25684a4..0d51c8d 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/cache.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/cache.hpp
@@ -18,10 +18,9 @@
 #include <iostream>
 #include <list>
 #include <map>
+#include <unordered_map>
 #include <utility>
 
-#include <boost/unordered_map.hpp>
-
 #include <glog/logging.h>
 
 #include "none.hpp"
@@ -43,8 +42,8 @@ class Cache
 {
 public:
   typedef std::list<Key> list;
-  typedef boost::unordered_map<
-    Key, std::pair<Value, typename list::iterator> > map;
+  typedef std::unordered_map<
+    Key, std::pair<Value, typename list::iterator>> map;
 
   explicit Cache(size_t _capacity) : capacity(_capacity) {}
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/b0918157/3rdparty/libprocess/3rdparty/stout/include/stout/hashmap.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/hashmap.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/hashmap.hpp
index ecab60a..f09bea1 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/hashmap.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/hashmap.hpp
@@ -17,10 +17,10 @@
 #include <functional>
 #include <list>
 #include <map>
+#include <unordered_map>
 #include <utility>
 
 #include <boost/get_pointer.hpp>
-#include <boost/unordered_map.hpp>
 
 #include "foreach.hpp"
 #include "hashset.hpp"
@@ -28,16 +28,15 @@
 #include "option.hpp"
 
 
-// Provides a hash map via Boost's 'unordered_map'. For most purposes
-// this could be accomplished with a templated typedef, but those
-// don't exist (until C++-11). Also, doing it this way allows us to
-// add functionality, or better naming of existing functionality, etc.
+// Provides a hash map via 'std::unordered_map'. We inherit from it to add
+// new functions as well as to provide better names for some of the
+// existing functions.
 
 template <typename Key,
           typename Value,
-          typename Hash = boost::hash<Key>,
+          typename Hash = std::hash<Key>,
           typename Equal = std::equal_to<Key>>
-class hashmap : public boost::unordered_map<Key, Value, Hash, Equal>
+class hashmap : public std::unordered_map<Key, Value, Hash, Equal>
 {
 public:
   // An explicit default constructor is needed so
@@ -50,10 +49,10 @@ public:
   // 'end()' passed into the specified 'emplace'?
   hashmap(const std::map<Key, Value>& map)
   {
-    boost::unordered_map<Key, Value, Hash, Equal>::reserve(map.size());
+    std::unordered_map<Key, Value, Hash, Equal>::reserve(map.size());
 
     for (auto iterator = map.begin(); iterator != map.end(); ++iterator) {
-      boost::unordered_map<Key, Value, Hash, Equal>::emplace(
+      std::unordered_map<Key, Value, Hash, Equal>::emplace(
           iterator->first,
           iterator->second);
     }
@@ -67,7 +66,7 @@ public:
   {
     // NOTE: We're using 'insert' here with a move iterator in order
     // to avoid copies because we know we have an r-value paramater.
-    boost::unordered_map<Key, Value, Hash, Equal>::insert(
+    std::unordered_map<Key, Value, Hash, Equal>::insert(
         std::make_move_iterator(map.begin()),
         std::make_move_iterator(map.end()));
   }
@@ -75,10 +74,10 @@ public:
   // Allow simple construction via initializer list.
   hashmap(std::initializer_list<std::pair<Key, Value>> list)
   {
-    boost::unordered_map<Key, Value, Hash, Equal>::reserve(list.size());
+    std::unordered_map<Key, Value, Hash, Equal>::reserve(list.size());
 
     for (auto iterator = list.begin(); iterator != list.end(); ++iterator) {
-      boost::unordered_map<Key, Value, Hash, Equal>::emplace(
+      std::unordered_map<Key, Value, Hash, Equal>::emplace(
           iterator->first,
           iterator->second);
     }
@@ -87,7 +86,7 @@ public:
   // Checks whether this map contains a binding for a key.
   bool contains(const Key& key) const
   {
-    return boost::unordered_map<Key, Value, Hash, Equal>::count(key) > 0;
+    return std::unordered_map<Key, Value, Hash, Equal>::count(key) > 0;
   }
 
   // Checks whether there exists a bound value in this map.
@@ -105,16 +104,16 @@ public:
   // if the key is already present.
   void put(const Key& key, const Value& value)
   {
-    boost::unordered_map<Key, Value, Hash, Equal>::erase(key);
-    boost::unordered_map<Key, Value, Hash, Equal>::insert(
+    std::unordered_map<Key, Value, Hash, Equal>::erase(key);
+    std::unordered_map<Key, Value, Hash, Equal>::insert(
         std::pair<Key, Value>(key, value));
   }
 
   // Returns an Option for the binding to the key.
   Option<Value> get(const Key& key) const
   {
-    auto it = boost::unordered_map<Key, Value, Hash, Equal>::find(key);
-    if (it == boost::unordered_map<Key, Value, Hash, Equal>::end()) {
+    auto it = std::unordered_map<Key, Value, Hash, Equal>::find(key);
+    if (it == std::unordered_map<Key, Value, Hash, Equal>::end()) {
       return None();
     }
     return it->second;

http://git-wip-us.apache.org/repos/asf/mesos/blob/b0918157/3rdparty/libprocess/3rdparty/stout/include/stout/hashset.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/hashset.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/hashset.hpp
index 2dd1905..1839d28 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/hashset.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/hashset.hpp
@@ -15,23 +15,22 @@
 #define __STOUT_HASHSET_HPP__
 
 #include <set>
+#include <unordered_set>
 #include <utility>
 
 #include <boost/get_pointer.hpp>
-#include <boost/unordered_set.hpp>
 
 #include "foreach.hpp"
 
 
-// Provides a hash set via Boost's 'unordered_set'. For most purposes
-// this could be accomplished with a templated typedef, but those
-// don't exist (until C++-11). Also, doing it this way allows us to
-// add functionality, or better naming of existing functionality, etc.
+// Provides a hash set via 'std::unordered_set'. We inherit from it to add
+// new functions as well as to provide better naming for some of the
+// existing functions.
 
 template <typename Elem,
-          typename Hash = boost::hash<Elem>,
+          typename Hash = std::hash<Elem>,
           typename Equal = std::equal_to<Elem>>
-class hashset : public boost::unordered_set<Elem, Hash, Equal>
+class hashset : public std::unordered_set<Elem, Hash, Equal>
 {
 public:
   static const hashset<Elem, Hash, Equal>& EMPTY;
@@ -46,10 +45,10 @@ public:
   // and 'end()' passed into the specified 'emplace'?
   hashset(const std::set<Elem>& set)
   {
-    boost::unordered_set<Elem, Hash, Equal>::reserve(set.size());
+    std::unordered_set<Elem, Hash, Equal>::reserve(set.size());
 
     for (auto iterator = set.begin(); iterator != set.end(); ++iterator) {
-      boost::unordered_set<Elem, Hash, Equal>::emplace(*iterator);
+      std::unordered_set<Elem, Hash, Equal>::emplace(*iterator);
     }
   }
 
@@ -62,27 +61,27 @@ public:
     // An implementation based on the move constructor of 'hashmap'
     // fails to compile on all major compilers except gcc 5.1 and up.
     // See http://stackoverflow.com/q/31051466/118750?sem=2.
-    boost::unordered_set<Elem, Hash, Equal>::reserve(set.size());
+    std::unordered_set<Elem, Hash, Equal>::reserve(set.size());
 
     for (auto iterator = set.begin(); iterator != set.end(); ++iterator) {
-      boost::unordered_set<Elem, Hash, Equal>::emplace(std::move(*iterator));
+      std::unordered_set<Elem, Hash, Equal>::emplace(std::move(*iterator));
     }
   }
 
   // Allow simple construction via initializer list.
   hashset(std::initializer_list<Elem> list)
   {
-    boost::unordered_set<Elem, Hash, Equal>::reserve(list.size());
+    std::unordered_set<Elem, Hash, Equal>::reserve(list.size());
 
     for (auto iterator = list.begin(); iterator != list.end(); ++iterator) {
-      boost::unordered_set<Elem, Hash, Equal>::emplace(*iterator);
+      std::unordered_set<Elem, Hash, Equal>::emplace(*iterator);
     }
   }
 
   // Checks whether this map contains a binding for a key.
   bool contains(const Elem& elem) const
   {
-    return boost::unordered_set<Elem, Hash, Equal>::count(elem) > 0;
+    return std::unordered_set<Elem, Hash, Equal>::count(elem) > 0;
   }
 
   // Checks whether there exists a value in this set that returns the

http://git-wip-us.apache.org/repos/asf/mesos/blob/b0918157/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
index 0b74586..1a8b38b 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/ip.hpp
@@ -258,20 +258,6 @@ inline std::ostream& operator<<(std::ostream& stream, const
IP& ip)
 }
 
 
-inline std::size_t hash_value(const IP& ip)
-{
-  size_t seed = 0;
-
-  switch (ip.family()) {
-     case AF_INET:
-       boost::hash_combine(seed, htonl(ip.in().get().s_addr));
-       return seed;
-     default:
-       UNREACHABLE();
-  }
-}
-
-
 // Represents an IP network. We store the IP address and the IP
 // netmask which defines the subnet.
 class IPNetwork
@@ -496,4 +482,29 @@ inline std::ostream& operator<<(std::ostream& stream, const
IPNetwork& network)
 
 } // namespace net {
 
+namespace std {
+
+template <>
+struct hash<net::IP>
+{
+  typedef std::size_t result_type;
+
+  typedef net::IP argument_type;
+
+  result_type operator()(const argument_type& ip) const
+  {
+    size_t seed = 0;
+
+    switch (ip.family()) {
+      case AF_INET:
+        boost::hash_combine(seed, htonl(ip.in().get().s_addr));
+        return seed;
+      default:
+        UNREACHABLE();
+    }
+  }
+};
+
+} // namespace std {
+
 #endif // __STOUT_IP_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/b0918157/3rdparty/libprocess/3rdparty/stout/include/stout/multihashmap.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/multihashmap.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/multihashmap.hpp
index a8573ed..d9e4031 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/multihashmap.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/multihashmap.hpp
@@ -17,18 +17,17 @@
 #include <algorithm> // For find.
 #include <list>
 #include <set>
+#include <unordered_map>
 #include <utility>
 
-#include <boost/unordered_map.hpp>
 
-
-// Implementation of a hash multimap via Boost's 'unordered_multimap'
+// Implementation of a hash multimap via 'std::unordered_multimap'
 // but with a better interface. The rationale for creating this is
 // that the std::multimap interface is painful to use (requires lots
 // of iterator garbage, as well as the use of 'equal_range' which
 // makes for cluttered code).
 template <typename K, typename V>
-class multihashmap : public boost::unordered_multimap<K, V>
+class multihashmap : public std::unordered_multimap<K, V>
 {
 public:
   void put(const K& key, const V& value);
@@ -44,7 +43,7 @@ public:
 template <typename K, typename V>
 void multihashmap<K, V>::put(const K& key, const V& value)
 {
-  boost::unordered_multimap<K, V>::insert(std::pair<K, V>(key, value));
+  std::unordered_multimap<K, V>::insert(std::pair<K, V>(key, value));
 }
 
 
@@ -53,12 +52,12 @@ std::list<V> multihashmap<K, V>::get(const K& key) const
 {
   std::list<V> values; // Values to return.
 
-  std::pair<typename boost::unordered_multimap<K, V>::const_iterator,
-    typename boost::unordered_multimap<K, V>::const_iterator> range;
+  std::pair<typename std::unordered_multimap<K, V>::const_iterator,
+    typename std::unordered_multimap<K, V>::const_iterator> range;
 
-  range = boost::unordered_multimap<K, V>::equal_range(key);
+  range = std::unordered_multimap<K, V>::equal_range(key);
 
-  typename boost::unordered_multimap<K, V>::const_iterator i;
+  typename std::unordered_multimap<K, V>::const_iterator i;
   for (i = range.first; i != range.second; ++i) {
     values.push_back(i->second);
   }
@@ -81,22 +80,22 @@ std::set<K> multihashmap<K, V>::keys() const
 template <typename K, typename V>
 bool multihashmap<K, V>::remove(const K& key)
 {
-  return boost::unordered_multimap<K, V>::erase(key) > 0;
+  return std::unordered_multimap<K, V>::erase(key) > 0;
 }
 
 
 template <typename K, typename V>
 bool multihashmap<K, V>::remove(const K& key, const V& value)
 {
-  std::pair<typename boost::unordered_multimap<K, V>::iterator,
-    typename boost::unordered_multimap<K, V>::iterator> range;
+  std::pair<typename std::unordered_multimap<K, V>::iterator,
+    typename std::unordered_multimap<K, V>::iterator> range;
 
-  range = boost::unordered_multimap<K, V>::equal_range(key);
+  range = std::unordered_multimap<K, V>::equal_range(key);
 
-  typename boost::unordered_multimap<K, V>::iterator i;
+  typename std::unordered_multimap<K, V>::iterator i;
   for (i = range.first; i != range.second; ++i) {
     if (i->second == value) {
-      boost::unordered_multimap<K, V>::erase(i);
+      std::unordered_multimap<K, V>::erase(i);
       return true;
     }
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/b0918157/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
index e8ebe0b..b9138ff 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
@@ -64,4 +64,21 @@ private:
     : boost::uuids::uuid(uuid) {}
 };
 
+namespace std {
+
+template <>
+struct hash<UUID>
+{
+  typedef std::size_t result_type;
+
+  typedef UUID argument_type;
+
+  result_type operator()(const argument_type& uuid) const
+  {
+    return boost::uuids::hash_value(uuid);
+  }
+};
+
+} // namespace std {
+
 #endif // __STOUT_UUID_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/b0918157/3rdparty/libprocess/3rdparty/stout/tests/hashset_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/hashset_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/hashset_tests.cpp
index 3802a29..f830142 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/hashset_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/hashset_tests.cpp
@@ -15,6 +15,8 @@
 #include <string>
 #include <utility>
 
+#include <boost/functional/hash.hpp>
+
 #include <stout/hashset.hpp>
 
 #include <gtest/gtest.h>

http://git-wip-us.apache.org/repos/asf/mesos/blob/b0918157/3rdparty/libprocess/3rdparty/stout/tests/multimap_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/multimap_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/multimap_tests.cpp
index b625ffa..535cd2d 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/multimap_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/multimap_tests.cpp
@@ -127,36 +127,6 @@ TYPED_TEST(MultimapTest, Keys)
 }
 
 
-TYPED_TEST(MultimapTest, Iterator)
-{
-  typedef TypeParam Map;
-
-  Map map;
-
-  map.put("foo", 1024);
-  map.put("foo", 1025);
-  ASSERT_EQ(2u, map.get("foo").size());
-  ASSERT_TRUE(map.contains("foo", 1024));
-  ASSERT_TRUE(map.contains("foo", 1025));
-
-  typename Map::iterator i = map.begin();
-
-  ASSERT_TRUE(i != map.end());
-
-  ASSERT_EQ("foo", i->first);
-  ASSERT_EQ(1024, i->second);
-
-  ++i;
-  ASSERT_TRUE(i != map.end());
-
-  ASSERT_EQ("foo", i->first);
-  ASSERT_EQ(1025, i->second);
-
-  ++i;
-  ASSERT_TRUE(i == map.end());
-}
-
-
 TYPED_TEST(MultimapTest, Foreach)
 {
   typedef TypeParam Map;


Mime
View raw message