// -*- C++ -*- /** * \file Graph.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author Dekel Tsur * * Full author contact details are available in file CREDITS. */ #ifndef GRAPH_H #define GRAPH_H #include #include namespace lyx { /// Represents a directed graph, possibly with multiple edges /// connecting the vertices. class Graph { public: Graph() : numedges_(0) {} /// typedef std::vector EdgePath; /// \return a vector of the vertices from which "to" can be reached std::vector const getReachableTo(int to, bool clear_visited); /// \return a vector of the vertices that can be reached from "from" std::vector const getReachable(int from, bool only_viewable, bool clear_visited); /// Can "from" be reached from "to"? bool isReachable(int from, int to); /// Find a path from "from" to "to". EdgePath const getPath(int from, int to); /// Called repeatedly to build the graph. void addEdge(int from, int to); /// Reset the internal data structures. void init(int size); private: /// bool bfs_init(int, bool clear_visited = true); /// class Vertex { public: /// 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; }; /// static std::vector vertices_; /// used to keep track of which vertices we have seen std::vector visited_; /// std::queue Q_; int numedges_; }; } // namespace lyx #endif //GRAPH_H