forked from shaobohou/madios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchPath.cpp
71 lines (55 loc) · 1.51 KB
/
SearchPath.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "SearchPath.h"
#include <cassert>
using std::string;
using std::vector;
using std::ostream;
using std::ostringstream;
using std::endl;
SearchPath::SearchPath()
{
}
SearchPath::SearchPath(const vector<unsigned int> &path)
:vector<unsigned int>(path)
{
}
SearchPath::~SearchPath()
{
}
bool SearchPath::operator==(const SearchPath &other) const
{
if(size() != other.size())
return false;
for(unsigned int i = 0; i < size(); i++)
if(at(i) != other[i])
return false;
return true;
}
void SearchPath::rewire(unsigned int start, unsigned int finish, unsigned int node)
{
erase( begin()+start, begin()+finish+1);
insert(begin()+start, node);
}
vector<unsigned int> SearchPath::operator()(unsigned int start, unsigned int finish) const
{
assert(start <= finish);
assert(finish< size());
return vector<unsigned int>(begin() + start, begin() + finish + 1);
}
vector<unsigned int> SearchPath::substitute(unsigned int start, unsigned int finish, const vector<unsigned int> &segment) const
{
assert(start <= finish);
assert(finish < size());
vector<unsigned int> new_path(begin(), begin()+start);
new_path.insert(new_path.end(), segment.begin(), segment.end());
new_path.insert(new_path.end(), begin()+finish+1, end());
return new_path;
}
string SearchPath::toString() const
{
ostringstream sout;
sout << "[";
for(unsigned int i = 0; i < size() - 1; i++)
sout << at(i) << " --> ";
sout << back() << "]";
return sout.str();
}