diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-01-05 11:24:35 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-01-05 11:24:35 +0100 |
commit | b9cc34a3cc89992ad211bd6e5d6da61c435f46c7 (patch) | |
tree | b57341bd9e1a8a1254a736c5fd476f130f54dd47 /src/lib/eina_graph_dfs.c | |
parent | b43b4531002dacecd5127ab3acdcef8373052ef7 (diff) | |
download | eina_graph-b9cc34a3cc89992ad211bd6e5d6da61c435f46c7.zip eina_graph-b9cc34a3cc89992ad211bd6e5d6da61c435f46c7.tar.gz |
use enhanced eina_array for DFS stack
Diffstat (limited to 'src/lib/eina_graph_dfs.c')
-rw-r--r-- | src/lib/eina_graph_dfs.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/lib/eina_graph_dfs.c b/src/lib/eina_graph_dfs.c index 1b9a61a..2b1cc73 100644 --- a/src/lib/eina_graph_dfs.c +++ b/src/lib/eina_graph_dfs.c @@ -34,20 +34,22 @@ #include "eina_graph_private.h" static void -_eina_graph_dfs_swalk(_Eina_Graph *_g, _Eina_Graph_DFS *_dfs, unsigned int v) +_eina_graph_dfs_swalk(_Eina_Graph *_g, _Eina_Graph_DFS *_dfs, + unsigned int v, unsigned int step) { - Eina_List *stack = NULL; + Eina_Array *stack = NULL; _Eina_Graph_Adjacents *adjs; _Eina_Graph_DFS_Data *vd; unsigned int p, w, n, i; p = v; - stack = eina_list_prepend(stack, CAST_V(v)); + stack = eina_array_new(step); + eina_array_push_uint(stack, v); - while (eina_list_count(stack) > 0) + while (eina_array_count_get(stack) > 0) { - w = CAST_D(eina_list_data_get(stack)); - stack = eina_list_remove(stack, CAST_V(w)); + w = eina_array_top_uint_get(stack); + eina_array_pop(stack); vd = &_dfs->data[w]; if(vd->m) continue; @@ -61,11 +63,11 @@ _eina_graph_dfs_swalk(_Eina_Graph *_g, _Eina_Graph_DFS *_dfs, unsigned int v) { w = adjs->data[i]; if (!_dfs->data[w].m) - { - stack = eina_list_prepend(stack, CAST_V(w)); - } + eina_array_push_uint(stack, w); } } + + eina_array_free(stack); } static void @@ -111,7 +113,7 @@ eina_graph_dfs_new(Eina_Graph *g, unsigned int s, Eina_Bool r) if (r) _eina_graph_dfs_rwalk(_g, _dfs, s); else - _eina_graph_dfs_swalk(_g, _dfs, s); + _eina_graph_dfs_swalk(_g, _dfs, s, eina_graph_degree_max(g) * 2); return (Eina_Graph_DFS *) _dfs; |