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