Add Imagination Technologies to the vendors in llvm::Triple
[oota-llvm.git] / include / llvm / ADT / SmallSet.h
index d03f1bef15b11d98e8e4bb30c1fede7aa676c564..bb1971eb7c5d09465bd9b1943f9ea5f55302483c 100644 (file)
@@ -14,8 +14,8 @@
 #ifndef LLVM_ADT_SMALLSET_H
 #define LLVM_ADT_SMALLSET_H
 
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
 #include <set>
 
 namespace llvm {
@@ -27,34 +27,39 @@ namespace llvm {
 ///
 /// Note that this set does not provide a way to iterate over members in the
 /// set.
-template <typename T, unsigned N>
+template <typename T, unsigned N,  typename C = std::less<T> >
 class SmallSet {
   /// Use a SmallVector to hold the elements here (even though it will never
   /// reach its 'large' stage) to avoid calling the default ctors of elements
   /// we will never use.
   SmallVector<T, N> Vector;
-  std::set<T> Set;
+  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);
     }
   }
 
   /// 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) {
     if (!isSmall())
       return Set.insert(V).second;