mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-05 17:09:56 +00:00
More cleanup. We introduce a struct here to keep the relevant
information together. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31914 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
a79722b1c0
commit
dfbbb87e0b
@ -47,9 +47,8 @@ Graph::getReachableTo(int target, bool clear_visited)
|
|||||||
while (!Q_.empty()) {
|
while (!Q_.empty()) {
|
||||||
int const current = Q_.front();
|
int const current = Q_.front();
|
||||||
Q_.pop();
|
Q_.pop();
|
||||||
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<int>::iterator it = vertices_[current].in_vertices.begin();
|
||||||
vector<int>::iterator end = vertices_[current].in_vertices.end();
|
vector<int>::iterator end = vertices_[current].in_vertices.end();
|
||||||
@ -74,26 +73,28 @@ Graph::getReachable(int from, bool only_viewable,
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
while (!Q_.empty()) {
|
while (!Q_.empty()) {
|
||||||
int const i = Q_.front();
|
int const current = Q_.front();
|
||||||
Q_.pop();
|
Q_.pop();
|
||||||
Format const & format = formats.get(i);
|
Format const & format = formats.get(current);
|
||||||
if (!only_viewable || !format.viewer().empty())
|
if (!only_viewable || !format.viewer().empty())
|
||||||
result.push_back(i);
|
result.push_back(current);
|
||||||
else if (format.isChildFormat()) {
|
else if (format.isChildFormat()) {
|
||||||
Format const * const parent =
|
Format const * const parent =
|
||||||
formats.getFormat(format.parentFormat());
|
formats.getFormat(format.parentFormat());
|
||||||
if (parent && !parent->viewer().empty())
|
if (parent && !parent->viewer().empty())
|
||||||
result.push_back(i);
|
result.push_back(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int>::const_iterator cit =
|
vector<OutEdge>::const_iterator cit =
|
||||||
vertices_[i].out_vertices.begin();
|
vertices_[current].out_arrows.begin();
|
||||||
vector<int>::const_iterator end =
|
vector<OutEdge>::const_iterator end =
|
||||||
vertices_[i].out_vertices.end();
|
vertices_[current].out_arrows.end();
|
||||||
for (; cit != end; ++cit)
|
for (; cit != end; ++cit) {
|
||||||
if (!visited_[*cit]) {
|
int const cv = cit->vertex;
|
||||||
visited_[*cit] = true;
|
if (!visited_[cv]) {
|
||||||
Q_.push(*cit);
|
visited_[cv] = true;
|
||||||
|
Q_.push(cv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,14 +116,15 @@ bool Graph::isReachable(int from, int to)
|
|||||||
if (current == to)
|
if (current == to)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
vector<int>::const_iterator cit =
|
vector<OutEdge>::const_iterator cit =
|
||||||
vertices_[current].out_vertices.begin();
|
vertices_[current].out_arrows.begin();
|
||||||
vector<int>::const_iterator end =
|
vector<OutEdge>::const_iterator end =
|
||||||
vertices_[current].out_vertices.end();
|
vertices_[current].out_arrows.end();
|
||||||
for (; cit != end; ++cit) {
|
for (; cit != end; ++cit) {
|
||||||
if (!visited_[*cit]) {
|
int const cv = cit->vertex;
|
||||||
visited_[*cit] = true;
|
if (!visited_[cv]) {
|
||||||
Q_.push(*cit);
|
visited_[cv] = true;
|
||||||
|
Q_.push(cv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,19 +154,19 @@ Graph::EdgePath const Graph::getPath(int from, int to)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int>::const_iterator const beg =
|
vector<OutEdge>::const_iterator const beg =
|
||||||
vertices_[current].out_vertices.begin();
|
vertices_[current].out_arrows.begin();
|
||||||
vector<int>::const_iterator cit = beg;
|
vector<OutEdge>::const_iterator cit = beg;
|
||||||
vector<int>::const_iterator end =
|
vector<OutEdge>::const_iterator end =
|
||||||
vertices_[current].out_vertices.end();
|
vertices_[current].out_arrows.end();
|
||||||
for (; cit != end; ++cit)
|
for (; cit != end; ++cit) {
|
||||||
if (!visited_[*cit]) {
|
int const cv = cit->vertex;
|
||||||
int const j = *cit;
|
if (!visited_[cv]) {
|
||||||
visited_[j] = true;
|
visited_[cv] = true;
|
||||||
Q_.push(j);
|
Q_.push(cv);
|
||||||
int const k = cit - beg;
|
prev_edge[cv] = cit->edge;
|
||||||
prev_edge[j] = vertices_[current].out_edges[k];
|
prev_vertex[cv] = current;
|
||||||
prev_vertex[j] = current;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
@ -190,8 +192,7 @@ 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_vertices.push_back(from);
|
||||||
vertices_[from].out_vertices.push_back(to);
|
vertices_[from].out_arrows.push_back(OutEdge(to, numedges_++));
|
||||||
vertices_[from].out_edges.push_back(numedges_++);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
15
src/Graph.h
15
src/Graph.h
@ -45,14 +45,17 @@ private:
|
|||||||
bool bfs_init(int, bool clear_visited = true);
|
bool bfs_init(int, bool clear_visited = true);
|
||||||
|
|
||||||
///
|
///
|
||||||
class Vertex {
|
struct OutEdge {
|
||||||
public:
|
OutEdge(int v, int e): vertex(v), edge(e) {}
|
||||||
|
int vertex;
|
||||||
|
int edge;
|
||||||
|
};
|
||||||
|
///
|
||||||
|
struct Vertex {
|
||||||
/// vertices that point at this one
|
/// vertices that point at this one
|
||||||
std::vector<int> in_vertices;
|
std::vector<int> in_vertices;
|
||||||
/// vertices immediately accessible from this one
|
/// paths out from here
|
||||||
std::vector<int> out_vertices;
|
std::vector<OutEdge> out_arrows;
|
||||||
/// a set of indices corresponding to the out_vertices
|
|
||||||
std::vector<int> out_edges;
|
|
||||||
};
|
};
|
||||||
///
|
///
|
||||||
static std::vector<Vertex> vertices_;
|
static std::vector<Vertex> vertices_;
|
||||||
|
Loading…
Reference in New Issue
Block a user