From: Richard Heck Date: Mon, 9 Nov 2009 03:02:11 +0000 (+0000) Subject: More cleanup. We introduce a struct here to keep the relevant X-Git-Tag: 2.0.0~5192 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=dfbbb87e0b2fcc2b711bd50c8205dd21a6df1732;p=features.git 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 --- diff --git a/src/Graph.cpp b/src/Graph.cpp index fe0f28aa5c..cf5c8559c3 100644 --- a/src/Graph.cpp +++ b/src/Graph.cpp @@ -38,7 +38,7 @@ bool Graph::bfs_init(int s, bool clear_visited) vector const -Graph::getReachableTo(int target, bool clear_visited) + Graph::getReachableTo(int target, bool clear_visited) { vector result; if (!bfs_init(target, clear_visited)) @@ -47,9 +47,8 @@ Graph::getReachableTo(int target, bool clear_visited) while (!Q_.empty()) { int const current = Q_.front(); Q_.pop(); - if (current != target || formats.get(target).name() != "lyx") { + if (current != target || formats.get(target).name() != "lyx") result.push_back(current); - } vector::iterator it = vertices_[current].in_vertices.begin(); vector::iterator end = vertices_[current].in_vertices.end(); @@ -66,35 +65,37 @@ Graph::getReachableTo(int target, bool clear_visited) vector const -Graph::getReachable(int from, bool only_viewable, - bool clear_visited) + Graph::getReachable(int from, bool only_viewable, + bool clear_visited) { vector result; if (!bfs_init(from, clear_visited)) return result; while (!Q_.empty()) { - int const i = Q_.front(); + int const current = Q_.front(); Q_.pop(); - Format const & format = formats.get(i); + Format const & format = formats.get(current); if (!only_viewable || !format.viewer().empty()) - result.push_back(i); + result.push_back(current); else if (format.isChildFormat()) { Format const * const parent = formats.getFormat(format.parentFormat()); if (parent && !parent->viewer().empty()) - result.push_back(i); + result.push_back(current); } - vector::const_iterator cit = - vertices_[i].out_vertices.begin(); - vector::const_iterator end = - vertices_[i].out_vertices.end(); - for (; cit != end; ++cit) - if (!visited_[*cit]) { - visited_[*cit] = true; - Q_.push(*cit); + vector::const_iterator cit = + vertices_[current].out_arrows.begin(); + vector::const_iterator end = + vertices_[current].out_arrows.end(); + for (; cit != end; ++cit) { + int const cv = cit->vertex; + if (!visited_[cv]) { + visited_[cv] = true; + Q_.push(cv); } + } } return result; @@ -115,14 +116,15 @@ bool Graph::isReachable(int from, int to) if (current == to) return true; - vector::const_iterator cit = - vertices_[current].out_vertices.begin(); - vector::const_iterator end = - vertices_[current].out_vertices.end(); + vector::const_iterator cit = + vertices_[current].out_arrows.begin(); + vector::const_iterator end = + vertices_[current].out_arrows.end(); for (; cit != end; ++cit) { - if (!visited_[*cit]) { - visited_[*cit] = true; - Q_.push(*cit); + int const cv = cit->vertex; + if (!visited_[cv]) { + visited_[cv] = true; + Q_.push(cv); } } } @@ -152,20 +154,20 @@ Graph::EdgePath const Graph::getPath(int from, int to) break; } - vector::const_iterator const beg = - vertices_[current].out_vertices.begin(); - vector::const_iterator cit = beg; - vector::const_iterator end = - vertices_[current].out_vertices.end(); - for (; cit != end; ++cit) - if (!visited_[*cit]) { - int const j = *cit; - visited_[j] = true; - Q_.push(j); - int const k = cit - beg; - prev_edge[j] = vertices_[current].out_edges[k]; - prev_vertex[j] = current; + vector::const_iterator const beg = + vertices_[current].out_arrows.begin(); + vector::const_iterator cit = beg; + vector::const_iterator end = + vertices_[current].out_arrows.end(); + for (; cit != end; ++cit) { + int const cv = cit->vertex; + if (!visited_[cv]) { + visited_[cv] = true; + Q_.push(cv); + prev_edge[cv] = cit->edge; + prev_vertex[cv] = current; } + } } if (!found) return path; @@ -190,8 +192,7 @@ void Graph::init(int size) void Graph::addEdge(int from, int to) { vertices_[to].in_vertices.push_back(from); - vertices_[from].out_vertices.push_back(to); - vertices_[from].out_edges.push_back(numedges_++); + vertices_[from].out_arrows.push_back(OutEdge(to, numedges_++)); } diff --git a/src/Graph.h b/src/Graph.h index 46cbaf062e..0114402094 100644 --- a/src/Graph.h +++ b/src/Graph.h @@ -45,14 +45,17 @@ private: bool bfs_init(int, bool clear_visited = true); /// - class Vertex { - public: + struct OutEdge { + OutEdge(int v, int e): vertex(v), edge(e) {} + int vertex; + int edge; + }; + /// + struct Vertex { /// vertices that point at this one std::vector in_vertices; - /// vertices immediately accessible from this one - std::vector out_vertices; - /// a set of indices corresponding to the out_vertices - std::vector out_edges; + /// paths out from here + std::vector out_arrows; }; /// static std::vector vertices_;