mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-30 05:12:40 +00:00
Another minor change, but this should almost get us to the point that we
could return all paths, not just one. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31915 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
dfbbb87e0b
commit
ac6a58071e
@ -44,6 +44,11 @@ vector<int> const
|
|||||||
if (!bfs_init(target, clear_visited))
|
if (!bfs_init(target, clear_visited))
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
// Here's the logic, which is shared by the other routines.
|
||||||
|
// Q_ holds a list of nodes we have been able to reach (in this
|
||||||
|
// case, reach backwards). It is initailized to the current node
|
||||||
|
// by bfs_init, and then we recurse, adding the nodes we can reach
|
||||||
|
// from the current node as we go.
|
||||||
while (!Q_.empty()) {
|
while (!Q_.empty()) {
|
||||||
int const current = Q_.front();
|
int const current = Q_.front();
|
||||||
Q_.pop();
|
Q_.pop();
|
||||||
@ -142,8 +147,8 @@ Graph::EdgePath const Graph::getPath(int from, int to)
|
|||||||
if (to < 0 || !bfs_init(from))
|
if (to < 0 || !bfs_init(from))
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
vector<int> prev_edge(formats.size());
|
// pair<vertex, edge>
|
||||||
vector<int> prev_vertex(formats.size());
|
vector<pair<int, int> > prev(vertices_.size());
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
while (!Q_.empty()) {
|
while (!Q_.empty()) {
|
||||||
@ -164,8 +169,9 @@ Graph::EdgePath const Graph::getPath(int from, int to)
|
|||||||
if (!visited_[cv]) {
|
if (!visited_[cv]) {
|
||||||
visited_[cv] = true;
|
visited_[cv] = true;
|
||||||
Q_.push(cv);
|
Q_.push(cv);
|
||||||
prev_edge[cv] = cit->edge;
|
// FIXME This will not do for finding multiple paths.
|
||||||
prev_vertex[cv] = current;
|
// Perhaps we need a vector, or a set.
|
||||||
|
prev[cv] = pair<int, int>(current, cit->edge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,8 +179,8 @@ Graph::EdgePath const Graph::getPath(int from, int to)
|
|||||||
return path;
|
return path;
|
||||||
|
|
||||||
while (to != from) {
|
while (to != from) {
|
||||||
path.push_back(prev_edge[to]);
|
path.push_back(prev[to].second);
|
||||||
to = prev_vertex[to];
|
to = prev[to].first;
|
||||||
}
|
}
|
||||||
reverse(path.begin(), path.end());
|
reverse(path.begin(), path.end());
|
||||||
return path;
|
return path;
|
||||||
|
Loading…
Reference in New Issue
Block a user