mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 02:14:50 +00:00
A bit more re-organization.
Next to go will be the prev vector. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31925 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
bd47bb4fd5
commit
db42cac3ab
@ -50,7 +50,7 @@ vector<int> const
|
|||||||
|
|
||||||
// Here's the logic, which is shared by the other routines.
|
// 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
|
// Q_ holds a list of nodes we have been able to reach (in this
|
||||||
// case, reach backwards). It is initailized to the current node
|
// case, reach backwards). It is initialized to the current node
|
||||||
// by bfs_init, and then we recurse, adding the nodes we can reach
|
// by bfs_init, and then we recurse, adding the nodes we can reach
|
||||||
// from the current node as we go. That makes it a breadth-first
|
// from the current node as we go. That makes it a breadth-first
|
||||||
// search.
|
// search.
|
||||||
@ -60,12 +60,13 @@ vector<int> const
|
|||||||
if (current != target || formats.get(target).name() != "lyx")
|
if (current != target || formats.get(target).name() != "lyx")
|
||||||
result.push_back(current);
|
result.push_back(current);
|
||||||
|
|
||||||
vector<int>::iterator it = vertices_[current].in_vertices.begin();
|
vector<Arrow>::iterator it = vertices_[current].in_arrows.begin();
|
||||||
vector<int>::iterator end = vertices_[current].in_vertices.end();
|
vector<Arrow>::iterator const end = vertices_[current].in_arrows.end();
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
if (!vertices_[*it].visited) {
|
const int cv = it->vertex;
|
||||||
vertices_[*it].visited = true;
|
if (!vertices_[cv].visited) {
|
||||||
Q_.push(*it);
|
vertices_[cv].visited = true;
|
||||||
|
Q_.push(cv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,9 +96,9 @@ vector<int> const
|
|||||||
result.push_back(current);
|
result.push_back(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<OutEdge>::const_iterator cit =
|
vector<Arrow>::const_iterator cit =
|
||||||
vertices_[current].out_arrows.begin();
|
vertices_[current].out_arrows.begin();
|
||||||
vector<OutEdge>::const_iterator end =
|
vector<Arrow>::const_iterator end =
|
||||||
vertices_[current].out_arrows.end();
|
vertices_[current].out_arrows.end();
|
||||||
for (; cit != end; ++cit) {
|
for (; cit != end; ++cit) {
|
||||||
int const cv = cit->vertex;
|
int const cv = cit->vertex;
|
||||||
@ -126,9 +127,9 @@ bool Graph::isReachable(int from, int to)
|
|||||||
if (current == to)
|
if (current == to)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
vector<OutEdge>::const_iterator cit =
|
vector<Arrow>::const_iterator cit =
|
||||||
vertices_[current].out_arrows.begin();
|
vertices_[current].out_arrows.begin();
|
||||||
vector<OutEdge>::const_iterator end =
|
vector<Arrow>::const_iterator end =
|
||||||
vertices_[current].out_arrows.end();
|
vertices_[current].out_arrows.end();
|
||||||
for (; cit != end; ++cit) {
|
for (; cit != end; ++cit) {
|
||||||
int const cv = cit->vertex;
|
int const cv = cit->vertex;
|
||||||
@ -160,10 +161,10 @@ Graph::EdgePath const Graph::getPath(int from, int to)
|
|||||||
int const current = Q_.front();
|
int const current = Q_.front();
|
||||||
Q_.pop();
|
Q_.pop();
|
||||||
|
|
||||||
vector<OutEdge>::const_iterator const beg =
|
vector<Arrow>::const_iterator const beg =
|
||||||
vertices_[current].out_arrows.begin();
|
vertices_[current].out_arrows.begin();
|
||||||
vector<OutEdge>::const_iterator cit = beg;
|
vector<Arrow>::const_iterator cit = beg;
|
||||||
vector<OutEdge>::const_iterator end =
|
vector<Arrow>::const_iterator end =
|
||||||
vertices_[current].out_arrows.end();
|
vertices_[current].out_arrows.end();
|
||||||
for (; cit != end; ++cit) {
|
for (; cit != end; ++cit) {
|
||||||
int const cv = cit->vertex;
|
int const cv = cit->vertex;
|
||||||
@ -193,7 +194,7 @@ Graph::EdgePath const Graph::getPath(int from, int to)
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Graph::init(int size)
|
void Graph::init(int size)
|
||||||
{
|
{
|
||||||
vertices_ = vector<Vertex>(size);
|
vertices_ = vector<Vertex>(size);
|
||||||
@ -203,8 +204,9 @@ void Graph::init(int size)
|
|||||||
|
|
||||||
void Graph::addEdge(int from, int to)
|
void Graph::addEdge(int from, int to)
|
||||||
{
|
{
|
||||||
vertices_[to].in_vertices.push_back(from);
|
vertices_[to].in_arrows.push_back(Arrow(from, numedges_));
|
||||||
vertices_[from].out_arrows.push_back(OutEdge(to, numedges_++));
|
vertices_[from].out_arrows.push_back(Arrow(to, numedges_));
|
||||||
|
++numedges_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
13
src/Graph.h
13
src/Graph.h
@ -44,18 +44,21 @@ private:
|
|||||||
///
|
///
|
||||||
bool bfs_init(int, bool clear_visited = true);
|
bool bfs_init(int, bool clear_visited = true);
|
||||||
|
|
||||||
///
|
///
|
||||||
struct OutEdge {
|
struct Arrow {
|
||||||
OutEdge(int v, int e): vertex(v), edge(e) {}
|
///
|
||||||
|
Arrow(int v, int e): vertex(v), edge(e) {}
|
||||||
|
///
|
||||||
int vertex;
|
int vertex;
|
||||||
|
///
|
||||||
int edge;
|
int edge;
|
||||||
};
|
};
|
||||||
///
|
///
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
/// vertices that point at this one
|
/// vertices that point at this one
|
||||||
std::vector<int> in_vertices;
|
std::vector<Arrow> in_arrows;
|
||||||
/// paths out from here
|
/// paths out from here
|
||||||
std::vector<OutEdge> out_arrows;
|
std::vector<Arrow> out_arrows;
|
||||||
///
|
///
|
||||||
bool visited;
|
bool visited;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user