Re-commit r247683: Replace Triple with a new TargetTuple in MCTargetDesc/* and relate...
[oota-llvm.git] / include / llvm / ADT / SmallSet.h
index 5dfe924f6d783e105561f73f48c65a6d18bc6aa7..39a57b87b2a71acc9b53341201c37410fdf203f9 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef LLVM_ADT_SMALLSET_H
 #define LLVM_ADT_SMALLSET_H
 
+#include "llvm/ADT/None.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include <set>
@@ -36,19 +37,24 @@ class SmallSet {
   std::set<T, C> Set;
   typedef typename SmallVector<T, N>::const_iterator VIterator;
   typedef typename SmallVector<T, N>::iterator mutable_iterator;
+
 public:
+  typedef size_t size_type;
   SmallSet() {}
 
-  bool empty() const { return Vector.empty() && Set.empty(); }
-  unsigned size() const {
+  bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {
+    return Vector.empty() && Set.empty();
+  }
+
+  size_type size() const {
     return isSmall() ? Vector.size() : Set.size();
   }
 
-  /// count - Return true if the element is in the set.
-  bool count(const T &V) const {
+  /// count - Return 1 if the element is in the set, 0 otherwise.
+  size_type count(const T &V) const {
     if (isSmall()) {
       // Since the collection is small, just do a linear search.
-      return vfind(V) != Vector.end();
+      return vfind(V) == Vector.end() ? 0 : 1;
     } else {
       return Set.count(V);
     }
@@ -56,16 +62,21 @@ public:
 
   /// insert - Insert an element into the set if it isn't already there.
   /// Returns true if the element is inserted (it was not in the set before).
-  bool insert(const T &V) {
+  /// The first value of the returned pair is unused and provided for
+  /// partial compatibility with the standard library self-associative container
+  /// concept.
+  // FIXME: Add iterators that abstract over the small and large form, and then
+  // return those here.
+  std::pair<NoneType, bool> insert(const T &V) {
     if (!isSmall())
-      return Set.insert(V).second;
+      return std::make_pair(None, Set.insert(V).second);
 
     VIterator I = vfind(V);
     if (I != Vector.end())    // Don't reinsert if it already exists.
-      return false;
+      return std::make_pair(None, false);
     if (Vector.size() < N) {
       Vector.push_back(V);
-      return true;
+      return std::make_pair(None, true);
     }
 
     // Otherwise, grow from vector to set.
@@ -74,7 +85,7 @@ public:
       Vector.pop_back();
     }
     Set.insert(V);
-    return true;
+    return std::make_pair(None, true);
   }
 
   template <typename IterT>
@@ -82,7 +93,7 @@ public:
     for (; I != E; ++I)
       insert(*I);
   }
-  
+
   bool erase(const T &V) {
     if (!isSmall())
       return Set.erase(V);
@@ -98,6 +109,7 @@ public:
     Vector.clear();
     Set.clear();
   }
+
 private:
   bool isSmall() const { return Set.empty(); }