ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/brains/Exclude.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/brains/Exclude.cpp (file contents):
Revision 1930 by gezelter, Wed Jan 12 22:41:40 2005 UTC vs.
Revision 2448 by tim, Wed Nov 16 23:10:02 2005 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
# Line 47 | Line 47 | int *Exclude::getExcludeList() {
47  
48   namespace oopse {
49  
50 < int *Exclude::getExcludeList() {
50 >  int *Exclude::getExcludeList() {
51  
52      if (modified_) {
53 <        excludeList_.clear();
53 >      excludeList_.clear();
54  
55 <        for (std::set<std::pair<int,int> >::iterator i = excludeSet_.begin();i != excludeSet_.end(); ++i) {
56 <            excludeList_.push_back(i->first + 1);
57 <            excludeList_.push_back(i->second + 1);            
58 <        }
59 <        modified_ = false;
55 >      for (std::set<std::pair<int,int> >::iterator i = excludeSet_.begin();i != excludeSet_.end(); ++i) {
56 >        excludeList_.push_back(i->first + 1);
57 >        excludeList_.push_back(i->second + 1);            
58 >      }
59 >      modified_ = false;
60      }
61  
62      return excludeList_.size() > 0 ? &(excludeList_[0]) : NULL;    
63 < }
63 >  }
64  
65 < void Exclude::addPair(int i, int j) {
65 >  void Exclude::addPair(int i, int j) {
66  
67      if (i == j) {
68 <        return;
68 >      return;
69      } else if (i > j) {
70 <        std::swap(i, j);
70 >      std::swap(i, j);
71      }
72  
73      std::set<std::pair<int, int> >::iterator iter = excludeSet_.find(std::make_pair(i, j));
74  
75      if (iter == excludeSet_.end()) {
76 <        excludeSet_.insert(std::make_pair(i, j));
77 <        modified_ = true;
76 >      excludeSet_.insert(std::make_pair(i, j));
77 >      modified_ = true;
78      }
79 +  }
80 +
81 + void Exclude::addPairs(std::set<int>& set1, std::set<int>& set2) {
82 +    for (std::set<int>::iterator iter1 = set1.begin(); iter1 !=  set1.end(); ++ iter1) {
83 +        for(std::set<int>::iterator iter2 = set2.begin(); iter2 != set2.end(); ++ iter2) {
84 +            this->addPair(*iter1, * iter2);
85 +        }
86 +    }    
87   }
88  
89 < void Exclude::removePair(int i, int j) {
89 > template<typename IterType1, typename IterType2>
90 > void Exclude::addPairs(IterType1 iter1_first, IterType1 iter1_last, IterType2 iter2_first, IterType2 iter2_last) {
91 >    for (IterType1 iter1 = iter1_first; iter1 != iter1_last; ++ iter1) {
92 >        for(IterType2 iter2 = iter2_first; iter2 != iter2_last; ++ iter2) {
93 >            this->addPair(*iter1, * iter2);
94 >        }
95 >    }
96 > }
97  
98 +  void Exclude::removePair(int i, int j) {
99 +
100      if (i == j) {
101 <        return;
101 >      return;
102      } else if (i > j) {
103 <        std::swap(i, j);
103 >      std::swap(i, j);
104      }
105  
106  
107      std::set<std::pair<int, int> >::iterator iter = excludeSet_.find(std::make_pair(i, j));
108  
109      if (iter != excludeSet_.end()) {
110 <        excludeSet_.erase(iter);
111 <        modified_ = true;
110 >      excludeSet_.erase(iter);
111 >      modified_ = true;
112      }
113 +  }
114 +
115 + void Exclude::removePairs(std::set<int>& set1, std::set<int>& set2) {
116 +    for (std::set<int>::iterator iter1 = set1.begin(); iter1 !=  set1.end(); ++ iter1) {
117 +        for(std::set<int>::iterator iter2 = set2.begin(); iter2 != set2.end(); ++ iter2) {
118 +            this->removePair(*iter1, * iter2);
119 +        }
120 +    }    
121   }
122  
123 < bool Exclude::hasPair(int i, int j) {
123 > template<typename IterType1, typename IterType2>
124 > void Exclude::removePairs(IterType1 iter1_first, IterType1 iter1_last, IterType2 iter2_first, IterType2 iter2_last) {
125 >    for (IterType1 iter1 = iter1_first; iter1 != iter1_last; ++ iter1) {
126 >        for(IterType2 iter2 = iter2_first; iter2 != iter2_last; ++ iter2) {
127 >            this->removePair(*iter1, * iter2);
128 >        }
129 >    }
130 > }
131  
132 +  bool Exclude::hasPair(int i, int j) {
133 +
134      if (i == j) {
135 <        return false;
135 >      return false;
136      } else if (i > j) {
137 <        std::swap(i, j);
137 >      std::swap(i, j);
138      }
139  
140      std::set<std::pair<int, int> >::iterator  iter = excludeSet_.find(std::make_pair(i, j));
141      return iter == excludeSet_.end() ? false : true;
142 < }
142 >  }
143  
144 < int Exclude::getSize() {
144 >  int Exclude::getSize() {
145      return excludeSet_.size();
146 < }
146 >  }
147  
148 < std::ostream& operator <<(std::ostream& o, Exclude& e) {
148 >  std::ostream& operator <<(std::ostream& o, Exclude& e) {
149      std::set<std::pair<int, int> >::iterator i;
150  
151      int index;
# Line 119 | Line 153 | std::ostream& operator <<(std::ostream& o, Exclude& e)
153      index = 0;
154  
155      for(i = e.excludeSet_.begin(); i != e.excludeSet_.end(); ++i) {
156 <        o << "exclude[" << index << "] i, j: " << (*i).first << " - "
157 <            << (*i).second << "\n";
158 <        index++;
156 >      o << "exclude[" << index << "] i, j: " << (*i).first << " - "
157 >        << (*i).second << "\n";
158 >      index++;
159      }
160  
161      return o;
162 < }
162 >  }
163  
164   }
165  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines