[llvm-commits] CVS: llvm/include/llvm/ADT/EquivalenceClasses.h

Chris Lattner lattner at cs.uiuc.edu
Sat Mar 19 11:26:30 PST 2005



Changes in directory llvm/include/llvm/ADT:

EquivalenceClasses.h updated: 1.9 -> 1.10
---
Log message:

implement a proper copy ctor, operator= and add a helper method.


---
Diffs of the changes:  (+24 -0)

 EquivalenceClasses.h |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+)


Index: llvm/include/llvm/ADT/EquivalenceClasses.h
diff -u llvm/include/llvm/ADT/EquivalenceClasses.h:1.9 llvm/include/llvm/ADT/EquivalenceClasses.h:1.10
--- llvm/include/llvm/ADT/EquivalenceClasses.h:1.9	Fri Mar 18 23:14:29 2005
+++ llvm/include/llvm/ADT/EquivalenceClasses.h	Sat Mar 19 13:26:14 2005
@@ -112,6 +112,19 @@
   std::set<ECValue> TheMapping;
 
 public:
+  EquivalenceClasses() {}
+  EquivalenceClasses(const EquivalenceClasses &RHS) {
+    operator=(RHS);
+  }
+
+  const EquivalenceClasses &operator=(const EquivalenceClasses &RHS) {
+    for (iterator I = RHS.begin(), E = RHS.end(); I != E; ++I)
+      if (I->isLeader())
+        insert(I->getData());
+      else
+        unionSets(I->getData(), *RHS.findLeader(I));
+    return *this;
+  }
   
   //===--------------------------------------------------------------------===//
   // Inspection methods
@@ -133,6 +146,17 @@
     return member_iterator(0);
   }
 
+  /// getNumClasses - Return the number of equivalence classes in this set.
+  /// Note that this is a linear time operation.
+  unsigned getNumClasses() const {
+    unsigned NC = 0;
+    for (iterator I = begin(), E = end(); I != E; ++I)
+      if (I->isLeader()) ++NC;
+    return NC;
+  }
+
+
+
   //===--------------------------------------------------------------------===//
   // Mutation methods
 






More information about the llvm-commits mailing list