add some inline methods for infix operators on sparse vectors,
authorChris Lattner <sabre@nondot.org>
Sat, 21 Mar 2009 05:40:09 +0000 (05:40 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 21 Mar 2009 05:40:09 +0000 (05:40 +0000)
tidy some df iteration stuff, patch by John Mosby!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67428 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/DepthFirstIterator.h
include/llvm/ADT/SparseBitVector.h

index b00f585d86fcc7080422d767d65795567bce8405..517768f402df9caf03f440906fd06b8c5af258ee 100644 (file)
@@ -200,14 +200,12 @@ struct idf_iterator : public df_iterator<Inverse<T>, SetTy, External> {
 
 template <class T>
 idf_iterator<T> idf_begin(const T& G) {
 
 template <class T>
 idf_iterator<T> idf_begin(const T& G) {
-  Inverse<T> DummyG;
-  return idf_iterator<T>::begin(DummyG);
+  return idf_iterator<T>::begin(Inverse<T>(G));
 }
 
 template <class T>
 idf_iterator<T> idf_end(const T& G){
 }
 
 template <class T>
 idf_iterator<T> idf_end(const T& G){
-  Inverse<T> DummyG;
-  return idf_iterator<T>::end(DummyG);
+  return idf_iterator<T>::end(Inverse<T>(G));
 }
 
 // Provide global definitions of external inverse depth first iterators...
 }
 
 // Provide global definitions of external inverse depth first iterators...
@@ -221,14 +219,12 @@ struct idf_ext_iterator : public idf_iterator<T, SetTy, true> {
 
 template <class T, class SetTy>
 idf_ext_iterator<T, SetTy> idf_ext_begin(const T& G, SetTy &S) {
 
 template <class T, class SetTy>
 idf_ext_iterator<T, SetTy> idf_ext_begin(const T& G, SetTy &S) {
-  Inverse<T> DummyG(G);
-  return idf_ext_iterator<T, SetTy>::begin(DummyG, S);
+  return idf_ext_iterator<T, SetTy>::begin(Inverse<T>(G), S);
 }
 
 template <class T, class SetTy>
 idf_ext_iterator<T, SetTy> idf_ext_end(const T& G, SetTy &S) {
 }
 
 template <class T, class SetTy>
 idf_ext_iterator<T, SetTy> idf_ext_end(const T& G, SetTy &S) {
-  Inverse<T> DummyG(G);
-  return idf_ext_iterator<T, SetTy>::end(DummyG, S);
+  return idf_ext_iterator<T, SetTy>::end(Inverse<T>(G), S);
 }
 
 } // End llvm namespace
 }
 
 } // End llvm namespace
index 027bde8e38e484c5887b33267715b442d263a843..dabcb028e99868660285aff61415b7c9bee004ff 100644 (file)
@@ -460,6 +460,11 @@ public:
     CurrElementIter = Elements.begin ();
   }
 
     CurrElementIter = Elements.begin ();
   }
 
+  // Clear.
+  void clear() {
+    Elements.clear();
+  }
+
   // Assignment
   SparseBitVector& operator=(const SparseBitVector& RHS) {
     Elements.clear();
   // Assignment
   SparseBitVector& operator=(const SparseBitVector& RHS) {
     Elements.clear();
@@ -836,7 +841,36 @@ inline bool operator &=(SparseBitVector<ElementSize> *LHS,
 template <unsigned ElementSize>
 inline bool operator &=(SparseBitVector<ElementSize> &LHS,
                         const SparseBitVector<ElementSize> *RHS) {
 template <unsigned ElementSize>
 inline bool operator &=(SparseBitVector<ElementSize> &LHS,
                         const SparseBitVector<ElementSize> *RHS) {
-  return LHS &= (*RHS);
+  return LHS &= *RHS;
+}
+
+// Convenience functions for infix union, intersection, difference operators.
+
+template <unsigned ElementSize>
+inline SparseBitVector<ElementSize>
+operator|(const SparseBitVector<ElementSize> &LHS,
+          const SparseBitVector<ElementSize> &RHS) {
+  SparseBitVector<ElementSize> Result(LHS);
+  Result |= RHS;
+  return Result;
+}
+
+template <unsigned ElementSize>
+inline SparseBitVector<ElementSize>
+operator&(const SparseBitVector<ElementSize> &LHS,
+          const SparseBitVector<ElementSize> &RHS) {
+  SparseBitVector<ElementSize> Result(LHS);
+  Result &= RHS;
+  return Result;
+}
+
+template <unsigned ElementSize>
+inline SparseBitVector<ElementSize>
+operator-(const SparseBitVector<ElementSize> &LHS,
+          const SparseBitVector<ElementSize> &RHS) {
+  SparseBitVector<ElementSize> Result;
+  Result.intersectWithComplement(LHS, RHS);
+  return Result;
 }
 
 
 }
 
 
@@ -849,10 +883,8 @@ void dump(const SparseBitVector<ElementSize> &LHS, llvm::OStream &out) {
   for (bi = LHS.begin(); bi != LHS.end(); ++bi) {
     out << *bi << " ";
   }
   for (bi = LHS.begin(); bi != LHS.end(); ++bi) {
     out << *bi << " ";
   }
-    out << " ]\n";
-}
+  out << " ]\n";
 }
 }
-
-
+} // end namespace llvm
 
 #endif
 
 #endif