summaryrefslogtreecommitdiffstats
path: root/src/lib/eina_graph.c
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-01-10 16:46:46 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-01-10 16:46:46 +0100
commitef6d10c4980eaf0feeb8569bc983075cc023ad83 (patch)
tree4f82e80470706ecd53aa5ef0824479e357d6f0d7 /src/lib/eina_graph.c
parentfb3483672193c2fc360d3c6e450dc051541556e5 (diff)
downloadeina_graph-ef6d10c4980eaf0feeb8569bc983075cc023ad83.zip
eina_graph-ef6d10c4980eaf0feeb8569bc983075cc023ad83.tar.gz
add eina_graph supports directed graphs
Diffstat (limited to 'src/lib/eina_graph.c')
-rw-r--r--src/lib/eina_graph.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/lib/eina_graph.c b/src/lib/eina_graph.c
index e3bf209..8d887cf 100644
--- a/src/lib/eina_graph.c
+++ b/src/lib/eina_graph.c
@@ -34,7 +34,7 @@
#include "eina_graph_private.h"
EAPI Eina_Graph *
-eina_graph_new(unsigned int v, unsigned int step)
+eina_graph_new(unsigned int v, unsigned int step, Eina_Bool directed)
{
unsigned int i;
_Eina_Graph *_g;
@@ -47,6 +47,7 @@ eina_graph_new(unsigned int v, unsigned int step)
}
_g->vertices = v;
+ _g->directed = directed;
for (i = 0; i < v; i++)
_g->adjs[i] = eina_array_new(step);
@@ -65,6 +66,14 @@ eina_graph_free(Eina_Graph *g)
free(_g);
}
+EAPI Eina_Bool
+eina_graph_directed(const Eina_Graph *g)
+{
+ _Eina_Graph * _g = (_Eina_Graph *) g;
+
+ return _g->directed;
+}
+
EAPI unsigned int
eina_graph_vertices_count(const Eina_Graph *g)
{
@@ -152,7 +161,7 @@ eina_graph_edge_add(Eina_Graph *g, unsigned int v, unsigned int w)
}
if (!eina_array_push_uint(_g->adjs[v], w)) return EINA_FALSE;
- if (v != w )
+ if (!_g->directed && (v != w))
if (!eina_array_push_uint(_g->adjs[w], v)) return EINA_FALSE;
_g->edges++;
@@ -169,7 +178,10 @@ eina_graph_dot_write(Eina_Graph *g, FILE *f)
Eina_Array *ar;
_Eina_Graph * _g = (_Eina_Graph *) g;
- fwrite("digraph {\n", 10, 1, f);
+ if (_g->directed)
+ fwrite("digraph {\n", 10, 1, f);
+ else
+ fwrite("strict graph {\n", 15, 1, f);
for (i = 0; i< _g->vertices; i++)
{
@@ -177,7 +189,10 @@ eina_graph_dot_write(Eina_Graph *g, FILE *f)
n = eina_array_count_get(ar);
for (j = 0; j < n; j++)
{
- r = snprintf(buf, 32, "%u -> %u;\n", i, eina_array_uint_nth_get(ar, j));
+ if (_g->directed)
+ r = snprintf(buf, 32, "%u -> %u;\n", i, eina_array_uint_nth_get(ar, j));
+ else
+ r = snprintf(buf, 32, "%u -- %u;\n", i, eina_array_uint_nth_get(ar, j));
fwrite(buf, r, 1, f);
}
}