Make SmallPtrSet iterators real iterators
[oota-llvm.git] / include / llvm / ADT / SmallSet.h
index d78813c6151172e8f36de26c7d76157f23a1a7c2..caaa96c045f73423881f3ac5931639710e839485 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -15,6 +15,7 @@
 #define LLVM_ADT_SMALLSET_H
 
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include <set>
 
 namespace llvm {
@@ -42,7 +43,7 @@ public:
   unsigned size() const {
     return isSmall() ? Vector.size() : Set.size();
   }
-  
+
   /// count - Return true if the element is in the set.
   bool count(const T &V) const {
     if (isSmall()) {
@@ -52,12 +53,12 @@ public:
       return Set.count(V);
     }
   }
-  
+
   /// insert - Insert an element into the set if it isn't already there.
   bool insert(const T &V) {
     if (!isSmall())
       return Set.insert(V).second;
-    
+
     VIterator I = vfind(V);
     if (I != Vector.end())    // Don't reinsert if it already exists.
       return false;
@@ -74,10 +75,16 @@ public:
     Set.insert(V);
     return true;
   }
+
+  template <typename IterT>
+  void insert(IterT I, IterT E) {
+    for (; I != E; ++I)
+      insert(*I);
+  }
   
   bool erase(const T &V) {
     if (!isSmall())
-      return Set.erase(V).second;
+      return Set.erase(V);
     for (mutable_iterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
       if (*I == V) {
         Vector.erase(I);
@@ -85,14 +92,14 @@ public:
       }
     return false;
   }
-  
+
   void clear() {
     Vector.clear();
     Set.clear();
   }
 private:
   bool isSmall() const { return Set.empty(); }
-    
+
   VIterator vfind(const T &V) const {
     for (VIterator I = Vector.begin(), E = Vector.end(); I != E; ++I)
       if (*I == V)
@@ -101,6 +108,10 @@ private:
   }
 };
 
+/// If this set is of pointer values, transparently switch over to using
+/// SmallPtrSet for performance.
+template <typename PointeeType, unsigned N>
+class SmallSet<PointeeType*, N> : public SmallPtrSet<PointeeType*, N> {};
 
 } // end namespace llvm