summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/Eina_Graph.h5
-rw-r--r--src/lib/eina_graph_dfs.c12
-rw-r--r--src/lib/eina_graph_private.h5
-rw-r--r--src/tests/eina_graph_suite.c4
4 files changed, 18 insertions, 8 deletions
diff --git a/src/lib/Eina_Graph.h b/src/lib/Eina_Graph.h
index 84e4abf..16a1282 100644
--- a/src/lib/Eina_Graph.h
+++ b/src/lib/Eina_Graph.h
@@ -60,4 +60,9 @@ eina_graph_shutdown(void);
#include <eina_graph.h>
#include <eina_graph_dfs.h>
+/**
+ * To cast Eina_List data into a vertex number.
+ */
+#define CAST_D(_d) ((unsigned int) (uintptr_t) _d)
+
#endif /* _EINA_GRAPH_MAIN_H */
diff --git a/src/lib/eina_graph_dfs.c b/src/lib/eina_graph_dfs.c
index 263be74..df272b4 100644
--- a/src/lib/eina_graph_dfs.c
+++ b/src/lib/eina_graph_dfs.c
@@ -41,12 +41,12 @@ _eina_graph_dfs_swalk(_Eina_Graph *_g, _Eina_Graph_DFS *_dfs, unsigned int v)
unsigned int p, w, n, i;
p = v;
- stack = eina_list_prepend(stack, (void *) v);
+ stack = eina_list_prepend(stack, CAST_V(v));
while (eina_list_count(stack) > 0)
{
- w = (unsigned int) eina_list_data_get(stack);
- stack = eina_list_remove(stack, (void *) w);
+ w = CAST_D(eina_list_data_get(stack));
+ stack = eina_list_remove(stack, CAST_V(w));
if(_dfs->marked[w]) continue;
_dfs->marked[w] = EINA_TRUE;
@@ -60,7 +60,7 @@ _eina_graph_dfs_swalk(_Eina_Graph *_g, _Eina_Graph_DFS *_dfs, unsigned int v)
w = adjs->data[i];
if (!_dfs->marked[w])
{
- stack = eina_list_prepend(stack, (void *) w);
+ stack = eina_list_prepend(stack, CAST_V(w));
}
}
}
@@ -174,10 +174,10 @@ eina_graph_dfs_path_to(Eina_Graph_DFS *dfs, unsigned int v)
while (w != _dfs->s)
{
- path = eina_list_prepend(path, (void *) w);
+ path = eina_list_prepend(path, CAST_V(w));
w = _dfs->edge_to[w];
}
- path = eina_list_prepend(path, (void *) _dfs->s);
+ path = eina_list_prepend(path, CAST_V(_dfs->s));
return path;
}
diff --git a/src/lib/eina_graph_private.h b/src/lib/eina_graph_private.h
index 25a6e73..36cfa09 100644
--- a/src/lib/eina_graph_private.h
+++ b/src/lib/eina_graph_private.h
@@ -90,6 +90,11 @@ eina_graph_adjacents_push(Eina_Graph_Adjacents *adjs, unsigned int v, unsigned i
return EINA_TRUE;
}
+/*+
+ * To cast a vertex number into Eina_List data.
+ */
+#define CAST_V(_v) ((void *) (uintptr_t) _v)
+
typedef struct _Eina_Graph
{
unsigned int vertices;
diff --git a/src/tests/eina_graph_suite.c b/src/tests/eina_graph_suite.c
index dea46e9..c187159 100644
--- a/src/tests/eina_graph_suite.c
+++ b/src/tests/eina_graph_suite.c
@@ -50,7 +50,7 @@ START_TEST (test_eina_graph_simple_dfs)
i = 0;
EINA_LIST_FOREACH(path, l, data)
{
- ck_assert(vsr[i] == (unsigned int) data);
+ ck_assert(vsr[i] == CAST_D(data));
i++;
}
eina_graph_dfs_free(dfs);
@@ -67,7 +67,7 @@ START_TEST (test_eina_graph_simple_dfs)
i = 0;
EINA_LIST_FOREACH(path, l, data)
{
- ck_assert(vss[i] == (unsigned int) data);
+ ck_assert(vss[i] == CAST_D(data));
i++;
}
eina_graph_dfs_free(dfs);