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