Add a helper class (APSInt) which can represent an APInt along with sign
[oota-llvm.git] / include / llvm / ADT / SmallPtrSet.h
index b9f7b1fc2650aab553002a03ef90d971110c0018..6bd4d0927fe4444238256efef1b59e995ba4022a 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <cassert>
 #include <cstring>
+#include "llvm/Support/DataTypes.h"
 
 namespace llvm {
 
@@ -50,6 +51,7 @@ protected:
   
   // If small, this is # elts allocated consequtively
   unsigned NumElements;
+  unsigned NumTombstones;
   void *SmallArray[1];  // Must be last ivar.
 public:
   SmallPtrSetImpl(unsigned SmallSize) {
@@ -67,6 +69,9 @@ public:
       delete[] CurArray;
   }
   
+  bool empty() const { return size() == 0; }
+  unsigned size() const { return NumElements; }
+  
   static void *getTombstoneMarker() { return reinterpret_cast<void*>(-2); }
   static void *getEmptyMarker() {
     // Note that -1 is chosen to make clear() efficiently implementable with
@@ -78,12 +83,19 @@ public:
     // Fill the array with empty markers.
     memset(CurArray, -1, CurArraySize*sizeof(void*));
     NumElements = 0;
+    NumTombstones = 0;
   }
   
   /// insert - This returns true if the pointer was new to the set, false if it
   /// was already in the set.
   bool insert(void *Ptr);
   
+  template <typename IterT>
+  void insert(IterT I, IterT E) {
+    for (; I != E; ++I)
+      insert((void*)*I);
+  }
+  
   /// erase - If the set contains the specified pointer, remove it and return
   /// true, otherwise return false.
   bool erase(void *Ptr);
@@ -181,8 +193,7 @@ struct NextPowerOfTwoH<N, false> {
   enum {
     // We could just use NextVal = N+1, but this converges faster.  N|(N-1) sets
     // the right-most zero bits to one all at once, e.g. 0b0011000 -> 0b0011111.
-    NextVal = (N|(N-1)) + 1,
-    Val = NextPowerOfTwo<NextVal>::Val
+    Val = NextPowerOfTwo<(N|(N-1)) + 1>::Val
   };
 };
 
@@ -204,6 +215,12 @@ class SmallPtrSet : public SmallPtrSetImpl {
 public:
   SmallPtrSet() : SmallPtrSetImpl(NextPowerOfTwo<SmallSizePowTwo>::Val) {}
   
+  template<typename It>
+  SmallPtrSet(It I, It E)
+    : SmallPtrSetImpl(NextPowerOfTwo<SmallSizePowTwo>::Val) {
+    insert(I, E);
+  }
+  
   typedef SmallPtrSetIterator<PtrType> iterator;
   typedef SmallPtrSetIterator<PtrType> const_iterator;
   inline iterator begin() const {