summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/eina_graph_bfs.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/lib/eina_graph_bfs.c b/src/lib/eina_graph_bfs.c
index 2632c4a..12fa0ad 100644
--- a/src/lib/eina_graph_bfs.c
+++ b/src/lib/eina_graph_bfs.c
@@ -33,8 +33,33 @@
#include <eina_graph_bfs.h>
#include "eina_graph_private.h"
+static Eina_Graph_BFS *
+_eina_graph_bfs_allocate(_Eina_Graph *_g, unsigned int s)
+{
+ _Eina_Graph_BFS *_bfs;
+
+ _bfs = calloc(1, sizeof(_Eina_Graph_BFS));
+ if (!_bfs)
+ goto error_bfs;
+
+ _bfs->data = calloc(_g->vertices, sizeof(_Eina_Graph_BFS_Data));
+ if (!_bfs->data)
+ goto error_data;
+
+ _bfs->s = s;
+ _bfs->vertices = _g->vertices;
+
+ return (Eina_Graph_BFS *) _bfs;
+
+error_data:
+ free(_bfs);
+error_bfs:
+ ERR("calloc failed : %s", strerror(errno));
+ return NULL;
+}
+
static void
-_eina_graph_bfs_fwalk(_Eina_Graph *_g, _Eina_Graph_BFS *_bfs, unsigned int v)
+_eina_graph_bfs_walk(_Eina_Graph *_g, _Eina_Graph_BFS *_bfs, unsigned int v)
{
Eina_List *fifo = NULL;
Eina_Array *adjs;
@@ -78,29 +103,15 @@ _eina_graph_bfs_fwalk(_Eina_Graph *_g, _Eina_Graph_BFS *_bfs, unsigned int v)
EAPI Eina_Graph_BFS *
eina_graph_bfs_new(Eina_Graph *g, unsigned int s)
{
- _Eina_Graph_BFS *_bfs;
+ Eina_Graph_BFS *bfs;
_Eina_Graph * _g = (_Eina_Graph *) g;
- _bfs = calloc(1, sizeof(_Eina_Graph_BFS));
- if (!_bfs)
- goto error_bfs;
-
- _bfs->data = calloc(_g->vertices, sizeof(_Eina_Graph_BFS_Data));
- if (!_bfs->data)
- goto error_data;
-
- _bfs->s = s;
- _bfs->vertices = _g->vertices;
+ bfs = _eina_graph_bfs_allocate(_g, s);
+ if (!bfs) return NULL;
- _eina_graph_bfs_fwalk(_g, _bfs, s);
-
- return (Eina_Graph_BFS *) _bfs;
+ _eina_graph_bfs_walk(_g, (_Eina_Graph_BFS *)bfs, s);
-error_data:
- free(_bfs);
-error_bfs:
- ERR("calloc failed : %s", strerror(errno));
- return NULL;
+ return bfs;
}
EAPI void