From c71040e6106563a99bba12bae1a1a0c019a7351a Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 19 Jan 2011 14:09:44 +0000 Subject: [PATCH] Simplify the new graph code just a bit. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37260 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Graph.cpp | 19 ++++++++++--------- src/Graph.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Graph.cpp b/src/Graph.cpp index 874bbb7f08..09db31e5f2 100644 --- a/src/Graph.cpp +++ b/src/Graph.cpp @@ -24,12 +24,13 @@ using namespace std; namespace lyx { -bool Graph::bfs_init(int s, bool clear_visited, queue* Q) +bool Graph::bfs_init(int s, bool clear_visited, queue & Q) { - if (s < 0 || !Q) + if (s < 0) return false; - - *Q = queue(); + + if (!Q.empty()) + Q = queue(); if (clear_visited) { vector::iterator it = vertices_.begin(); @@ -38,7 +39,7 @@ bool Graph::bfs_init(int s, bool clear_visited, queue* Q) it->visited = false; } if (!vertices_[s].visited) { - Q->push(s); + Q.push(s); vertices_[s].visited = true; } return true; @@ -50,7 +51,7 @@ vector const { vector result; queue Q; - if (!bfs_init(target, clear_visited, &Q)) + if (!bfs_init(target, clear_visited, Q)) return result; // Here's the logic, which is shared by the other routines. @@ -86,7 +87,7 @@ vector const { vector result; queue Q; - if (!bfs_init(from, clear_visited, &Q)) + if (!bfs_init(from, clear_visited, Q)) return result; while (!Q.empty()) { @@ -125,7 +126,7 @@ bool Graph::isReachable(int from, int to) return true; queue Q; - if (to < 0 || !bfs_init(from, true, &Q)) + if (to < 0 || !bfs_init(from, true, Q)) return false; while (!Q.empty()) { @@ -157,7 +158,7 @@ Graph::EdgePath const Graph::getPath(int from, int to) return EdgePath(); queue Q; - if (to < 0 || !bfs_init(from, true, &Q)) + if (to < 0 || !bfs_init(from, true, Q)) return EdgePath(); vector pathes; diff --git a/src/Graph.h b/src/Graph.h index e999f39a33..305cf70dcf 100644 --- a/src/Graph.h +++ b/src/Graph.h @@ -46,7 +46,7 @@ public: private: /// - bool bfs_init(int, bool clear_visited, std::queue* Q); + bool bfs_init(int, bool clear_visited, std::queue & Q); /// used to recover a marked path void getMarkedPath(int from, int to, EdgePath & path); /// these represent the arrows connecting the nodes of the graph. -- 2.39.5