diff options
Diffstat (limited to 'src/lib/eina_graph.c')
-rw-r--r-- | src/lib/eina_graph.c | 23 |
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); } } |