Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Doc + use all arguments in free function.
[simgrid.git] / src / xbt / graph.c
index 61aee25..b106f50 100644 (file)
@@ -119,14 +119,17 @@ void xbt_graph_edge_set_data(xbt_edge_t edge, void *data)
 }
 
 /** @brief Destructor
- *  @param l: poor victim
+ *  @param g: poor victim
+ *  @param node_free_function: function to use to free data associated to each node
+ *  @param edge_free_function: function to use to free data associated to each edge
+ *  @param graph_free_function: function to use to free data associated to g
  *
  * Free the graph structure. 
  */
 void xbt_graph_free_graph(xbt_graph_t g,
-                         void node_free_function(void *ptr),
-                         void edge_free_function(void *ptr),
-                         void graph_free_function(void *ptr))
+                         void_f_pvoid_t * node_free_function,
+                         void_f_pvoid_t * edge_free_function,
+                         void_f_pvoid_t * graph_free_function)
 {
   int cursor = 0;
   xbt_node_t node = NULL;
@@ -137,12 +140,12 @@ void xbt_graph_free_graph(xbt_graph_t g,
     xbt_dynar_free(&(node->out));
     xbt_dynar_free(&(node->in));
     if (node_free_function)
-      node_free_function(node->data);
+      (*node_free_function)(node->data);
   }
 
   xbt_dynar_foreach(g->edges, cursor, edge) {
     if (edge_free_function)
-      edge_free_function(edge->data);
+      (*edge_free_function)(edge->data);
   }
 
   xbt_dynar_foreach(g->nodes, cursor, node)
@@ -152,7 +155,7 @@ void xbt_graph_free_graph(xbt_graph_t g,
   xbt_dynar_foreach(g->edges, cursor, edge)
       free(edge);
   xbt_dynar_free(&(g->edges));
-
+  if(graph_free_function) (*graph_free_function)(g->data);
   free(g);
 
   return;
@@ -173,12 +176,12 @@ void xbt_graph_free_node(xbt_graph_t g, xbt_node_t n,
   nbr = xbt_dynar_length(g->edges);
   cursor = 0;
   for (i = 0; i < nbr; i++) {
-    xbt_dynar_cursor_get(g->edges, &cursor, &edge);
+    xbt_dynar_get_cpy(g->edges, cursor, &edge);
 
     if ((edge->dst == n) || (edge->src == n)) {
       xbt_graph_free_edge(g, edge, edge_free_function);
     } else
-      xbt_dynar_cursor_step(g->edges, &cursor);
+      cursor ++;
   }
 
   if ((node_free_function) && (n->data))
@@ -199,14 +202,14 @@ void xbt_graph_free_node(xbt_graph_t g, xbt_node_t n,
 
 /** @brief remove the given edge from the given graph */
 void xbt_graph_free_edge(xbt_graph_t g, xbt_edge_t e,
-                        void free_function(void *ptr))
+                        void_f_pvoid_t *free_function)
 {
   int idx;
   int cursor = 0;
   xbt_edge_t edge = NULL;
 
   if ((free_function) && (e->data))
-    free_function(e->data);
+    (*free_function)(e->data);
 
   xbt_dynar_foreach(g->edges, cursor, edge) {
     if (edge == e) {