--- trunk/OOPSE-2.0/src/brains/Exclude.cpp 2005/01/12 22:41:40 1930 +++ trunk/OOPSE-2.0/src/brains/Exclude.cpp 2005/11/16 23:10:02 2448 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -47,71 +47,105 @@ namespace oopse { namespace oopse { -int *Exclude::getExcludeList() { + int *Exclude::getExcludeList() { if (modified_) { - excludeList_.clear(); + excludeList_.clear(); - for (std::set >::iterator i = excludeSet_.begin();i != excludeSet_.end(); ++i) { - excludeList_.push_back(i->first + 1); - excludeList_.push_back(i->second + 1); - } - modified_ = false; + for (std::set >::iterator i = excludeSet_.begin();i != excludeSet_.end(); ++i) { + excludeList_.push_back(i->first + 1); + excludeList_.push_back(i->second + 1); + } + modified_ = false; } return excludeList_.size() > 0 ? &(excludeList_[0]) : NULL; -} + } -void Exclude::addPair(int i, int j) { + void Exclude::addPair(int i, int j) { if (i == j) { - return; + return; } else if (i > j) { - std::swap(i, j); + std::swap(i, j); } std::set >::iterator iter = excludeSet_.find(std::make_pair(i, j)); if (iter == excludeSet_.end()) { - excludeSet_.insert(std::make_pair(i, j)); - modified_ = true; + excludeSet_.insert(std::make_pair(i, j)); + modified_ = true; } + } + +void Exclude::addPairs(std::set& set1, std::set& set2) { + for (std::set::iterator iter1 = set1.begin(); iter1 != set1.end(); ++ iter1) { + for(std::set::iterator iter2 = set2.begin(); iter2 != set2.end(); ++ iter2) { + this->addPair(*iter1, * iter2); + } + } } -void Exclude::removePair(int i, int j) { +template +void Exclude::addPairs(IterType1 iter1_first, IterType1 iter1_last, IterType2 iter2_first, IterType2 iter2_last) { + for (IterType1 iter1 = iter1_first; iter1 != iter1_last; ++ iter1) { + for(IterType2 iter2 = iter2_first; iter2 != iter2_last; ++ iter2) { + this->addPair(*iter1, * iter2); + } + } +} + void Exclude::removePair(int i, int j) { + if (i == j) { - return; + return; } else if (i > j) { - std::swap(i, j); + std::swap(i, j); } std::set >::iterator iter = excludeSet_.find(std::make_pair(i, j)); if (iter != excludeSet_.end()) { - excludeSet_.erase(iter); - modified_ = true; + excludeSet_.erase(iter); + modified_ = true; } + } + +void Exclude::removePairs(std::set& set1, std::set& set2) { + for (std::set::iterator iter1 = set1.begin(); iter1 != set1.end(); ++ iter1) { + for(std::set::iterator iter2 = set2.begin(); iter2 != set2.end(); ++ iter2) { + this->removePair(*iter1, * iter2); + } + } } -bool Exclude::hasPair(int i, int j) { +template +void Exclude::removePairs(IterType1 iter1_first, IterType1 iter1_last, IterType2 iter2_first, IterType2 iter2_last) { + for (IterType1 iter1 = iter1_first; iter1 != iter1_last; ++ iter1) { + for(IterType2 iter2 = iter2_first; iter2 != iter2_last; ++ iter2) { + this->removePair(*iter1, * iter2); + } + } +} + bool Exclude::hasPair(int i, int j) { + if (i == j) { - return false; + return false; } else if (i > j) { - std::swap(i, j); + std::swap(i, j); } std::set >::iterator iter = excludeSet_.find(std::make_pair(i, j)); return iter == excludeSet_.end() ? false : true; -} + } -int Exclude::getSize() { + int Exclude::getSize() { return excludeSet_.size(); -} + } -std::ostream& operator <<(std::ostream& o, Exclude& e) { + std::ostream& operator <<(std::ostream& o, Exclude& e) { std::set >::iterator i; int index; @@ -119,13 +153,13 @@ std::ostream& operator <<(std::ostream& o, Exclude& e) index = 0; for(i = e.excludeSet_.begin(); i != e.excludeSet_.end(); ++i) { - o << "exclude[" << index << "] i, j: " << (*i).first << " - " - << (*i).second << "\n"; - index++; + o << "exclude[" << index << "] i, j: " << (*i).first << " - " + << (*i).second << "\n"; + index++; } return o; -} + } }