2003-02-28 09:49:49 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Graph.h
|
2003-02-28 09:49:49 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Dekel Tsur
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-28 09:49:49 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-23 00:17:00 +00:00
|
|
|
#ifndef GRAPH_H
|
|
|
|
#define GRAPH_H
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
#include <queue>
|
|
|
|
#include <vector>
|
|
|
|
|
2003-09-07 21:25:37 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2009-11-09 02:19:02 +00:00
|
|
|
/// Represents a directed graph, possibly with multiple edges
|
|
|
|
/// connecting the vertices.
|
2003-02-28 09:49:49 +00:00
|
|
|
class Graph {
|
2003-03-04 09:27:27 +00:00
|
|
|
public:
|
2009-11-09 02:19:02 +00:00
|
|
|
Graph() : numedges_(0) {}
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
typedef std::vector<int> EdgePath;
|
2009-11-09 00:55:37 +00:00
|
|
|
/// \return a vector of the vertices from which "to" can be reached
|
|
|
|
std::vector<int> const getReachableTo(int to, bool clear_visited);
|
|
|
|
/// \return a vector of the vertices that can be reached from "from"
|
2003-02-28 09:49:49 +00:00
|
|
|
std::vector<int> const
|
2009-11-09 00:55:37 +00:00
|
|
|
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.
|
2003-02-28 09:49:49 +00:00
|
|
|
void init(int size);
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
2009-11-09 02:19:02 +00:00
|
|
|
bool bfs_init(int, bool clear_visited = true);
|
2003-02-28 09:49:49 +00:00
|
|
|
|
2009-11-09 17:56:34 +00:00
|
|
|
///
|
|
|
|
struct Arrow {
|
|
|
|
///
|
|
|
|
Arrow(int v, int e): vertex(v), edge(e) {}
|
|
|
|
///
|
2009-11-09 03:02:11 +00:00
|
|
|
int vertex;
|
2009-11-09 17:56:34 +00:00
|
|
|
///
|
2009-11-09 03:02:11 +00:00
|
|
|
int edge;
|
|
|
|
};
|
|
|
|
///
|
|
|
|
struct Vertex {
|
2009-11-09 02:19:02 +00:00
|
|
|
/// vertices that point at this one
|
2009-11-09 17:56:34 +00:00
|
|
|
std::vector<Arrow> in_arrows;
|
2009-11-09 03:02:11 +00:00
|
|
|
/// paths out from here
|
2009-11-09 17:56:34 +00:00
|
|
|
std::vector<Arrow> out_arrows;
|
2009-11-09 04:02:45 +00:00
|
|
|
///
|
|
|
|
bool visited;
|
2003-02-28 09:49:49 +00:00
|
|
|
};
|
|
|
|
///
|
2009-11-09 04:02:45 +00:00
|
|
|
std::vector<Vertex> vertices_;
|
2003-02-28 09:49:49 +00:00
|
|
|
///
|
|
|
|
std::queue<int> Q_;
|
|
|
|
|
|
|
|
int numedges_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
#endif //GRAPH_H
|