From ac6a58071e642c787c0d84027ff31d11972e08f2 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Mon, 9 Nov 2009 03:43:48 +0000 Subject: [PATCH] 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 --- src/Graph.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Graph.cpp b/src/Graph.cpp index cf5c8559c3..8893aecfc9 100644 --- a/src/Graph.cpp +++ b/src/Graph.cpp @@ -44,6 +44,11 @@ vector const if (!bfs_init(target, clear_visited)) 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()) { int const current = Q_.front(); Q_.pop(); @@ -142,8 +147,8 @@ Graph::EdgePath const Graph::getPath(int from, int to) if (to < 0 || !bfs_init(from)) return path; - vector prev_edge(formats.size()); - vector prev_vertex(formats.size()); + // pair + vector > prev(vertices_.size()); bool found = false; while (!Q_.empty()) { @@ -164,8 +169,9 @@ Graph::EdgePath const Graph::getPath(int from, int to) if (!visited_[cv]) { visited_[cv] = true; Q_.push(cv); - prev_edge[cv] = cit->edge; - prev_vertex[cv] = current; + // FIXME This will not do for finding multiple paths. + // Perhaps we need a vector, or a set. + prev[cv] = pair(current, cit->edge); } } } @@ -173,8 +179,8 @@ Graph::EdgePath const Graph::getPath(int from, int to) return path; while (to != from) { - path.push_back(prev_edge[to]); - to = prev_vertex[to]; + path.push_back(prev[to].second); + to = prev[to].first; } reverse(path.begin(), path.end()); return path;