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