1 |
tim |
1856 |
#include <functional> |
2 |
|
|
#include <iterator> |
3 |
tim |
1804 |
#include <utility> |
4 |
tim |
1856 |
|
5 |
tim |
1804 |
#include "brains/Exclude.hpp" |
6 |
gezelter |
1490 |
|
7 |
tim |
1804 |
namespace oopse { |
8 |
gezelter |
1490 |
|
9 |
tim |
1727 |
int *Exclude::getExcludeList() { |
10 |
gezelter |
1490 |
|
11 |
tim |
1719 |
if (modified_) { |
12 |
tim |
1727 |
excludeList_.clear(); |
13 |
tim |
1856 |
|
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 |
tim |
1719 |
modified_ = false; |
19 |
tim |
1727 |
} |
20 |
|
|
|
21 |
tim |
1856 |
return excludeList_.size() > 0 ? &(excludeList_[0]) : NULL; |
22 |
gezelter |
1490 |
} |
23 |
|
|
|
24 |
tim |
1719 |
void Exclude::addPair(int i, int j) { |
25 |
gezelter |
1490 |
|
26 |
tim |
1856 |
if (i == j) { |
27 |
|
|
return; |
28 |
|
|
} else if (i > j) { |
29 |
|
|
std::swap(i, j); |
30 |
|
|
} |
31 |
tim |
1727 |
|
32 |
tim |
1856 |
std::set<std::pair<int, int> >::iterator iter = excludeSet_.find(std::make_pair(i, j)); |
33 |
tim |
1727 |
|
34 |
tim |
1856 |
if (iter == excludeSet_.end()) { |
35 |
tim |
1804 |
excludeSet_.insert(std::make_pair(i, j)); |
36 |
tim |
1719 |
modified_ = true; |
37 |
gezelter |
1490 |
} |
38 |
|
|
} |
39 |
|
|
|
40 |
tim |
1719 |
void Exclude::removePair(int i, int j) { |
41 |
tim |
1727 |
|
42 |
tim |
1856 |
if (i == j) { |
43 |
|
|
return; |
44 |
|
|
} else if (i > j) { |
45 |
|
|
std::swap(i, j); |
46 |
|
|
} |
47 |
tim |
1727 |
|
48 |
tim |
1856 |
|
49 |
|
|
std::set<std::pair<int, int> >::iterator iter = excludeSet_.find(std::make_pair(i, j)); |
50 |
|
|
|
51 |
tim |
1719 |
if (iter != excludeSet_.end()) { |
52 |
|
|
excludeSet_.erase(iter); |
53 |
|
|
modified_ = true; |
54 |
|
|
} |
55 |
gezelter |
1490 |
} |
56 |
|
|
|
57 |
tim |
1856 |
bool Exclude::hasPair(int i, int j) { |
58 |
gezelter |
1490 |
|
59 |
tim |
1856 |
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 |
gezelter |
1490 |
} |
68 |
|
|
|
69 |
|
|
int Exclude::getSize() { |
70 |
tim |
1727 |
return excludeSet_.size(); |
71 |
gezelter |
1490 |
} |
72 |
tim |
1719 |
|
73 |
tim |
1727 |
std::ostream& operator <<(std::ostream& o, Exclude& e) { |
74 |
|
|
std::set<std::pair<int, int> >::iterator i; |
75 |
tim |
1719 |
|
76 |
|
|
int index; |
77 |
|
|
|
78 |
|
|
index = 0; |
79 |
tim |
1727 |
|
80 |
|
|
for(i = e.excludeSet_.begin(); i != e.excludeSet_.end(); ++i) { |
81 |
|
|
o << "exclude[" << index << "] i, j: " << (*i).first << " - " |
82 |
|
|
<< (*i).second << "\n"; |
83 |
tim |
1719 |
index++; |
84 |
tim |
1727 |
} |
85 |
tim |
1719 |
|
86 |
|
|
return o; |
87 |
|
|
} |
88 |
|
|
|
89 |
tim |
1727 |
} |
90 |
tim |
1719 |
|
91 |
tim |
1727 |
|