souffle
2.0.2-371-g6315b36
|
Go to the documentation of this file.
33 template <
typename Vertex,
typename Compare = std::less<Vertex>>
39 void insert(
const Vertex& from,
const Vertex& to) {
49 void insert(
const Vertex& vertex) {
52 _successors.insert(std::make_pair(vertex, std::set<Vertex, Compare>()));
53 _predecessors.insert(std::make_pair(vertex, std::set<Vertex, Compare>()));
58 const std::set<Vertex, Compare>&
vertices()
const {
63 const std::set<Vertex, Compare>&
successors(
const Vertex& from)
const {
68 const std::set<Vertex, Compare>&
predecessors(
const Vertex& to)
const {
73 bool contains(
const Vertex& vertex)
const {
78 bool contains(
const Vertex& from,
const Vertex& to)
const {
83 auto p2 = pos->second.find(to);
84 return p2 != pos->second.end();
88 bool reaches(
const Vertex& from,
const Vertex& to)
const {
98 found = !first && (found || cur == to);
105 const std::set<Vertex, Compare>
clique(
const Vertex& vertex)
const {
106 std::set<Vertex, Compare> res;
108 for (
const auto& cur :
vertices()) {
117 template <
typename Lambda>
118 void visitDepthFirst(
const Vertex& vertex,
const Lambda& lambda)
const {
119 std::set<Vertex, Compare> visited;
124 void print(std::ostream& out)
const {
128 for (
const auto& trg : cur.second) {
132 out << cur.first <<
"->" << trg;
147 std::map<Vertex, std::set<Vertex, Compare>>
_successors;
151 template <
typename Lambda>
153 const Vertex& vertex,
const Lambda& lambda, std::set<Vertex, Compare>& visited)
const {
159 for (
const auto& cur : pos->second) {
160 if (visited.insert(cur).second) {
168 static const std::vector<char> table = {
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
169 'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'a',
'b',
'c',
'd',
'e',
'f',
170 'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
171 'z',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'+',
'/'};
174 unsigned int padding = 0;
175 if (
data.size() % 3 == 2) {
177 }
else if (
data.size() % 3 == 1) {
181 for (
unsigned int i = 0;
i < padding;
i++) {
184 for (
unsigned int i = 0;
i < tmp.size();
i += 3) {
185 auto c1 =
static_cast<unsigned char>(tmp[
i]);
186 auto c2 =
static_cast<unsigned char>(tmp[
i + 1]);
187 auto c3 =
static_cast<unsigned char>(tmp[
i + 2]);
188 unsigned char index1 = c1 >> 2;
189 unsigned char index2 = ((c1 & 0x03) << 4) | (c2 >> 4);
190 unsigned char index3 = ((c2 & 0x0F) << 2) | (c3 >> 6);
191 unsigned char index4 = c3 & 0x3F;
193 result.push_back(table[index1]);
194 result.push_back(table[index2]);
195 result.push_back(table[index3]);
196 result.push_back(table[index4]);
199 result[result.size() - 1] =
'=';
200 }
else if (padding == 2) {
201 result[result.size() - 1] =
'=';
202 result[result.size() - 2] =
'=';
209 std::string cmd =
which(
"dot");
220 inline void printHTMLGraph(std::ostream& out,
const std::string& dotSpec,
const std::string&
id) {
223 if (
data.find(
"<svg") != std::string::npos) {
224 out <<
"<img alt='graph image' src='data:image/svg+xml;base64," <<
toBase64(
data) <<
"'><br/>\n";
226 out <<
"<div class='" <<
id <<
"-source"
227 <<
"'>\n<pre>" << dotSpec <<
"</pre>\n";
std::stringstream execStdOut(char const *cmd)
void insert(const Vertex &from, const Vertex &to)
Adds a new edge from the given vertex to the target vertex.
void visitDepthFirst(const Vertex &vertex, const Lambda &lambda) const
A generic utility for depth-first visits.
std::string toBase64(const std::string &data)
const std::set< Vertex, Compare > & successors(const Vertex &from) const
Returns the set of vertices the given vertex has edges to.
void print(std::ostream &out) const
Enables graphs to be printed (e.g.
std::string const & getFileName() const
void printHTMLGraph(std::ostream &out, const std::string &dotSpec, const std::string &id)
std::map< Vertex, std::set< Vertex, Compare > > _successors
A simple graph structure for graph-based operations.
const std::set< Vertex, Compare > & predecessors(const Vertex &to) const
Returns the set of vertices the given vertex has edges from.
bool isExecutable(const std::string &name)
Check whether a given file exists and it is an executable.
std::string which(const std::string &name)
Simple implementation of a which tool.
std::map< Vertex, std::set< Vertex, Compare > > _predecessors
std::string convertDotToSVG(const std::string &dotSpec)
friend std::ostream & operator<<(std::ostream &out, const Graph &g)
bool contains(const Vertex &from, const Vertex &to) const
Determines whether the given edge is present.
const std::set< Vertex, Compare > clique(const Vertex &vertex) const
Obtains the set of all vertices in the same clique than the given vertex.
bool reaches(const Vertex &from, const Vertex &to) const
Determines whether there is a directed path between the two vertices.
constexpr auto data(C &c) -> decltype(c.data())
std::set< Vertex, Compare > _vertices
const std::set< Vertex, Compare > & vertices() const
Obtains a reference to the set of all vertices.
bool contains(const Vertex &vertex) const
Determines whether the given vertex is present.