summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/eina_graph.c23
-rw-r--r--src/lib/eina_graph.h13
-rw-r--r--src/lib/eina_graph_private.h1
3 files changed, 32 insertions, 5 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);
}
}
diff --git a/src/lib/eina_graph.h b/src/lib/eina_graph.h
index 3297a22..c47c66a 100644
--- a/src/lib/eina_graph.h
+++ b/src/lib/eina_graph.h
@@ -46,11 +46,12 @@ typedef struct _Eina_Graph_Opaque Eina_Graph;
*
* @param v the number of vertices.
* @param step grow step for the adjacent lists.
+ * @param directed graph or not.
*
* @return a pointer to the Eina_Graph.
*/
EAPI Eina_Graph *
-eina_graph_new(unsigned int v, unsigned int step);
+eina_graph_new(unsigned int v, unsigned int step, Eina_Bool directed);
/**
* free the given graph.
@@ -61,6 +62,16 @@ EAPI void
eina_graph_free(Eina_Graph *g);
/**
+ * returns true if it is a directed graph.
+ *
+ * @param g the graph to consider.
+ *
+ * @retur true if this is a directed graph.
+ */
+EAPI Eina_Bool
+eina_graph_directed(const Eina_Graph *g);
+
+/**
* returns the number of vertices of the graph.
*
* @param g the graph to consider.
diff --git a/src/lib/eina_graph_private.h b/src/lib/eina_graph_private.h
index 1925cf7..e8138a9 100644
--- a/src/lib/eina_graph_private.h
+++ b/src/lib/eina_graph_private.h
@@ -95,6 +95,7 @@ typedef struct _Eina_Graph
{
unsigned int vertices;
unsigned int edges;
+ Eina_Bool directed;
Eina_Array *adjs[];
} _Eina_Graph;