Add a new (simple) StringMap::clear method, patch by Pratik
[oota-llvm.git] / include / llvm / ADT / SparseBitVector.h
index 8dbf0c7001f7988ef7d8519f2256c284a164f162..adeb541d3d0acb9a124a7e9b958c452ffc3f4aa9 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Daniel Berlin 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.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -21,7 +21,7 @@
 #include "llvm/Support/DataTypes.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/ADT/ilist"
+#include "llvm/ADT/ilist.h"
 namespace llvm {
 
 /// SparseBitVector is an implementation of a bitvector that is sparse by only
@@ -70,7 +70,7 @@ private:
   BitWord Bits[BITWORDS_PER_ELEMENT];
   // Needed for sentinels
   SparseBitVectorElement() {
-    ElementIndex = ~0UL;
+    ElementIndex = ~0U;
     memset(&Bits[0], 0, sizeof (BitWord) * BITWORDS_PER_ELEMENT);
   }
 
@@ -89,6 +89,14 @@ public:
     ElementIndex = RHS.ElementIndex;
     std::copy(&RHS.Bits[0], &RHS.Bits[BITWORDS_PER_ELEMENT], Bits);
   }
+  
+  // Assignment 
+  SparseBitVectorElement& operator=(const SparseBitVectorElement& RHS) {
+    ElementIndex = RHS.ElementIndex;
+    std::copy(&RHS.Bits[0], &RHS.Bits[BITWORDS_PER_ELEMENT], Bits);
+    
+    return *this;
+  }
 
   // Comparison.
   bool operator==(const SparseBitVectorElement &RHS) const {
@@ -166,6 +174,7 @@ public:
           assert(0 && "Unsupported!");
       }
     assert(0 && "Illegal empty element");
+    return 0; // Not reached
   }
 
   /// find_next - Returns the index of the next set bit starting from the
@@ -482,6 +491,21 @@ public:
 
     CurrElementIter = Elements.begin ();
   }
+  
+  // Assignment
+  SparseBitVector& operator=(const SparseBitVector& RHS) {
+    Elements.clear();
+    
+    ElementListConstIter ElementIter = RHS.Elements.begin();
+    while (ElementIter != RHS.Elements.end()) {
+      Elements.push_back(SparseBitVectorElement<ElementSize>(*ElementIter));
+      ++ElementIter;
+    }
+
+    CurrElementIter = Elements.begin ();
+    
+    return *this;
+  }
 
   // Test, Reset, and Set a bit in the bitmap.
   bool test(unsigned Idx) {