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