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 2013/04/09 19:53:36 UTC

svn commit: r1466157 - in /incubator/mesos/trunk/third_party/libprocess/third_party/stout: include/stout/multihashmap.hpp include/stout/multimap.hpp tests/multimap_tests.cpp

Author: bmahler
Date: Tue Apr  9 17:53:36 2013
New Revision: 1466157

URL: http://svn.apache.org/r1466157
Log:
Fixed Mutlimap and multihashmap by removing the ordering requirement
on values.

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

Modified:
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/multihashmap.hpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/multimap.hpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/multimap_tests.cpp

Modified: incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/multihashmap.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/multihashmap.hpp?rev=1466157&r1=1466156&r2=1466157&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/multihashmap.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/multihashmap.hpp Tue Apr  9 17:53:36 2013
@@ -1,12 +1,12 @@
 #ifndef __STOUT_MULTIHASHMAP_HPP__
 #define __STOUT_MULTIHASHMAP_HPP__
 
+#include <algorithm> // For find.
+#include <list>
 #include <utility>
 
 #include <boost/unordered_map.hpp>
 
-#include "hashset.hpp"
-
 
 // Implementation of a hash multimap via Boost's 'unordered_multimap'
 // but with a better interface. The rationale for creating this is
@@ -18,7 +18,7 @@ class multihashmap : public boost::unord
 {
 public:
   void put(const K& key, const V& value);
-  hashset<V> get(const K& key) const;
+  std::list<V> get(const K& key) const;
   bool remove(const K& key);
   bool remove(const K& key, const V& value);
   bool contains(const K& key) const;
@@ -34,9 +34,9 @@ void multihashmap<K, V>::put(const K& ke
 
 
 template <typename K, typename V>
-hashset<V> multihashmap<K, V>::get(const K& key) const
+std::list<V> multihashmap<K, V>::get(const K& key) const
 {
-  hashset<V> values; // Values to return.
+  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;
@@ -45,7 +45,7 @@ hashset<V> multihashmap<K, V>::get(const
 
   typename boost::unordered_multimap<K, V>::const_iterator i;
   for (i = range.first; i != range.second; ++i) {
-    values.insert(i->second);
+    values.push_back(i->second);
   }
 
   return values;
@@ -89,8 +89,8 @@ bool multihashmap<K, V>::contains(const 
 template <typename K, typename V>
 bool multihashmap<K, V>::contains(const K& key, const V& value) const
 {
-  const hashset<V>& values = get(key);
-  return values.count(value) > 0;
+  const std::list<V>& values = get(key);
+  return std::find(values.begin(), values.end(), value) != values.end();
 }
 
 #endif // __STOUT_MULTIHASHMAP_HPP__

Modified: incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/multimap.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/multimap.hpp?rev=1466157&r1=1466156&r2=1466157&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/multimap.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/include/stout/multimap.hpp Tue Apr  9 17:53:36 2013
@@ -1,9 +1,9 @@
 #ifndef __STOUT_MULTIMAP_HPP__
 #define __STOUT_MULTIMAP_HPP__
 
+#include <algorithm>
+#include <list>
 #include <map>
-#include <set>
-
 #include <utility>
 
 // Implementation of a multimap via std::multimap but with a better
@@ -16,7 +16,7 @@ class Multimap : public std::multimap<K,
 {
 public:
   void put(const K& key, const V& value);
-  std::set<V> get(const K& key) const;
+  std::list<V> get(const K& key) const;
   bool remove(const K& key);
   bool remove(const K& key, const V& value);
   bool contains(const K& key) const;
@@ -32,9 +32,9 @@ void Multimap<K, V>::put(const K& key, c
 
 
 template <typename K, typename V>
-std::set<V> Multimap<K, V>::get(const K& key) const
+std::list<V> Multimap<K, V>::get(const K& key) const
 {
-  std::set<V> values; // Values to return.
+  std::list<V> values; // Values to return.
 
   std::pair<typename std::multimap<K, V>::const_iterator,
     typename std::multimap<K, V>::const_iterator> range;
@@ -43,7 +43,7 @@ std::set<V> Multimap<K, V>::get(const K&
 
   typename std::multimap<K, V>::const_iterator i;
   for (i = range.first; i != range.second; ++i) {
-    values.insert(i->second);
+    values.push_back(i->second);
   }
 
   return values;
@@ -87,8 +87,8 @@ bool Multimap<K, V>::contains(const K& k
 template <typename K, typename V>
 bool Multimap<K, V>::contains(const K& key, const V& value) const
 {
-  const std::set<V>& values = get(key);
-  return values.count(value) > 0;
+  const std::list<V>& values = get(key);
+  return std::find(values.begin(), values.end(), value) != values.end();
 }
 
 #endif // __STOUT_MULTIMAP_HPP__

Modified: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/multimap_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/multimap_tests.cpp?rev=1466157&r1=1466156&r2=1466157&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/multimap_tests.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/multimap_tests.cpp Tue Apr  9 17:53:36 2013
@@ -4,6 +4,7 @@
 
 #include <string>
 
+#include <stout/foreach.hpp>
 #include <stout/multimap.hpp>
 #include <stout/multihashmap.hpp>