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