diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-01-10 10:14:45 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-01-10 10:14:45 +0100 |
commit | 5e8e882c7092feaaf4a56506dbda611ed7755d28 (patch) | |
tree | a47d7137b90f719773c1efc253cd40f4d85a42bd /src/lib/eina_graph.c | |
parent | b9cc34a3cc89992ad211bd6e5d6da61c435f46c7 (diff) | |
download | eina_graph-5e8e882c7092feaaf4a56506dbda611ed7755d28.zip eina_graph-5e8e882c7092feaaf4a56506dbda611ed7755d28.tar.gz |
use eina_array for adjacents list instead of custom implementation
Diffstat (limited to 'src/lib/eina_graph.c')
-rw-r--r-- | src/lib/eina_graph.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/lib/eina_graph.c b/src/lib/eina_graph.c index ac42012..4cea67f 100644 --- a/src/lib/eina_graph.c +++ b/src/lib/eina_graph.c @@ -36,18 +36,19 @@ EAPI Eina_Graph * eina_graph_new(unsigned int v, unsigned int step) { + unsigned int i; _Eina_Graph *_g; - _g = calloc(1, sizeof(_Eina_Graph) + (v * sizeof(_Eina_Graph_Adjacents))); + _g = calloc(1, sizeof(_Eina_Graph) + (v * sizeof(Eina_Array *))); if (!_g) { ERR("calloc failed : %s", strerror(errno)); return NULL; } - _g->step = step; _g->vertices = v; - _g->adjs = (_Eina_Graph_Adjacents *) ((char *) _g + sizeof(_Eina_Graph)); + for (i = 0; i < v; i++) + _g->adjs[i] = eina_array_new(step); return (Eina_Graph *) _g; } @@ -59,7 +60,7 @@ eina_graph_free(Eina_Graph *g) _Eina_Graph * _g = (_Eina_Graph *) g; for (i = 0; i< _g->vertices; i++) - eina_graph_adjacents_free(&_g->adjs[i]); + eina_array_free(_g->adjs[i]); free(_g); } @@ -91,7 +92,7 @@ eina_graph_degree(const Eina_Graph *g, unsigned int v) return 0; } - return _g->adjs[v].count; + return eina_array_count_get(_g->adjs[v]); } EAPI unsigned int @@ -103,7 +104,7 @@ eina_graph_degree_max(const Eina_Graph *g) max = 0; for (i = 0; i< _g->vertices; i++) { - n = _g->adjs[i].count; + n = eina_array_count_get(_g->adjs[i]); if ( n > max ) max = n; } @@ -121,18 +122,18 @@ eina_graph_degree_avg(const Eina_Graph *g) EAPI unsigned int eina_graph_self_loops(const Eina_Graph *g) { - unsigned int *data; unsigned int i, j, n, loops; + Eina_Array *ar; _Eina_Graph * _g = (_Eina_Graph *) g; loops = 0; for (i = 0; i< _g->vertices; i++) { - n = _g->adjs[i].count; - data = _g->adjs[i].data; + ar = _g->adjs[i]; + n = eina_array_count_get(ar); for (j = 0; j < n; j++) { - if(i == data[j]) loops++; + if(i == eina_array_uint_nth_get(ar, j)) loops++; } } @@ -150,9 +151,9 @@ eina_graph_edge_add(Eina_Graph *g, unsigned int v, unsigned int w) return EINA_FALSE; } - if(!eina_graph_adjacents_push(&_g->adjs[v], w, _g->step)) return EINA_FALSE; + if (!eina_array_push_uint(_g->adjs[v], w)) return EINA_FALSE; if (v != w ) - if(!eina_graph_adjacents_push(&_g->adjs[w], v, _g->step)) return EINA_FALSE; + if (!eina_array_push_uint(_g->adjs[w], v)) return EINA_FALSE; _g->edges++; |