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

Comparing branches/new_design/OOPSE-4/src/brains/Exclude.cpp (file contents):
Revision 1855 by tim, Thu Dec 2 16:04:19 2004 UTC vs.
Revision 1856 by tim, Mon Dec 6 04:49:53 2004 UTC

# Line 1 | Line 1
1 + #include <functional>
2 + #include <iterator>
3   #include <utility>
4 +
5   #include "brains/Exclude.hpp"
3 #include <iterator>
6  
7   namespace oopse {
8  
# Line 8 | Line 10 | int *Exclude::getExcludeList() {
10  
11      if (modified_) {
12          excludeList_.clear();
13 <        std::copy(excludeSet_.begin(), excludeSet_.end(),
14 <                  std::back_inserter(excludeList_));
13 >
14 >        for (std::set<std::pair<int,int> >::iterator i = excludeSet_.begin();i != excludeSet_.end(); ++i) {
15 >            excludeList_.push_back(i->first + 1);
16 >            excludeList_.push_back(i->second + 1);            
17 >        }
18          modified_ = false;
19      }
20  
21 <    return excludeList_.size() > 0 ? &(excludeList_[0].first) : NULL;    
21 >    return excludeList_.size() > 0 ? &(excludeList_[0]) : NULL;    
22   }
23  
24   void Exclude::addPair(int i, int j) {
20    std::set<std::pair<int, int> >::iterator iter;
25  
26 <    iter = findPair(i, j);
26 >    if (i == j) {
27 >        return;
28 >    } else if (i > j) {
29 >        std::swap(i, j);
30 >    }
31  
32 <    if (iter != excludeSet_.end()) {
25 <        if (i == j) {
26 <            return;
27 <        } else if (i > j) {
28 <            std::swap(i, j);
29 <        }
32 >    std::set<std::pair<int, int> >::iterator iter = excludeSet_.find(std::make_pair(i, j));
33  
34 +    if (iter == excludeSet_.end()) {
35          excludeSet_.insert(std::make_pair(i, j));
36          modified_ = true;
37      }
38   }
39  
40   void Exclude::removePair(int i, int j) {
37    std::set<std::pair<int, int> >::iterator iter;
41  
42 <    iter = findPair(i, j);
42 >    if (i == j) {
43 >        return;
44 >    } else if (i > j) {
45 >        std::swap(i, j);
46 >    }
47  
48 +
49 +    std::set<std::pair<int, int> >::iterator iter = excludeSet_.find(std::make_pair(i, j));
50 +
51      if (iter != excludeSet_.end()) {
52          excludeSet_.erase(iter);
53          modified_ = true;
54      }
55   }
56  
57 < std::set<std::pair<int, int> >::iterator Exclude::findPair(int i, int j) {
48 <    std::set<std::pair<int, int> >::iterator position;
57 > bool Exclude::hasPair(int i, int j) {
58  
59 <    if (i != j) {
60 <        if (i < j) {
61 <            position = excludeSet_.find(std::make_pair(i, j));
62 <        } else {
63 <            position = excludeSet_.find(std::make_pair(j, i));
64 <        }
65 <        return position;
66 <    } else
58 <        return excludeSet_.end();
59 >    if (i == j) {
60 >        return false;
61 >    } else if (i > j) {
62 >        std::swap(i, j);
63 >    }
64 >
65 >    std::set<std::pair<int, int> >::iterator  iter = excludeSet_.find(std::make_pair(i, j));
66 >    return iter == excludeSet_.end() ? false : true;
67   }
68  
69   int Exclude::getSize() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines