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

llvm-svn: 20690
This commit is contained in:
Chris Lattner 2005-03-19 19:26:14 +00:00
parent f53c9e2578
commit e4d74b8d85

View File

@ -112,6 +112,19 @@ class EquivalenceClasses {
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 @@ public:
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