diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-02-04 00:14:52 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-02-04 00:14:52 +0100 |
commit | ec2f079b5bdcee15213d05bd1a81e90f9175f215 (patch) | |
tree | 466141651224ee7b2ee4adfcd72fcfb1bc458f9a /src | |
parent | 8a8c3eb59aaa0f4d5eb4193ba177abd6422ba66d (diff) | |
download | eina_graph-ec2f079b5bdcee15213d05bd1a81e90f9175f215.zip eina_graph-ec2f079b5bdcee15213d05bd1a81e90f9175f215.tar.gz |
bfs: extract allocation out of eina_graph_bfs_new()
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/eina_graph_bfs.c | 51 |
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 |