Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reset the xbtdata at the and of topologicalsort (forgotten)
authordimitrov <dimitrov@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 30 Mar 2006 11:10:06 +0000 (11:10 +0000)
committerdimitrov <dimitrov@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 30 Mar 2006 11:10:06 +0000 (11:10 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2014 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/xbt/graph.c

index 02e32bc..34e454b 100644 (file)
@@ -438,6 +438,58 @@ xbt_edge_t* xbt_graph_spanning_tree_prim(xbt_graph_t g)
   return tree;
 }
 
   return tree;
 }
 
+xbt_node_t* xbt_graph_topo_sort(xbt_graph_t g)
+{
+  xbt_node_t* sorted;
+  int cursor,idx;
+  xbt_node_t node;
+ unsigned long n;
+
+ n= xbt_dynar_length(g->nodes); 
+ idx=n-1;
+
+  sorted=xbt_malloc(n*sizeof(xbt_node_t));
+  xbt_dynar_foreach(g->nodes,cursor , node)
+    {
+      node->xbtdata=xbt_new0(int,1);
+    }
+
+  xbt_dynar_foreach(g->nodes,cursor , node) 
+    { 
+      xbt_graph_depth_visit(g,node,sorted,&idx);   
+    }
+  xbt_dynar_foreach(g->nodes, cursor, node) 
+   {
+    node->xbtdata = NULL;
+   }     
+  return sorted; 
+
+
+void xbt_graph_depth_visit(xbt_graph_t g,xbt_node_t n,xbt_node_t* sorted,int* idx )
+{
+  int cursor;
+  xbt_edge_t edge;
+  if (*((int*)(n->xbtdata))==ALREADY_EXPLORED)
+    return;
+  else if (*((int*)(n->xbtdata))==CURRENTLY_EXPLORING)
+    THROW0(0,0,"There is a cycle");
+  else
+    {
+      *((int*)(n->xbtdata))=CURRENTLY_EXPLORING;
+
+      xbt_dynar_foreach(n->out,cursor, edge)
+       {
+         xbt_graph_depth_visit(g,edge->dst,sorted,idx);
+       }
+      *((int*)(n->xbtdata))=ALREADY_EXPLORED;
+      sorted[(*idx)--]=n;
+    }       
+}
+
+
 /********************* Import and Export ******************/
 static xbt_graph_t parsed_graph = NULL;
 static xbt_dict_t parsed_nodes = NULL;
 /********************* Import and Export ******************/
 static xbt_graph_t parsed_graph = NULL;
 static xbt_dict_t parsed_nodes = NULL;
@@ -600,50 +652,3 @@ void xbt_graph_export_graphxml(xbt_graph_t g, const char *filename,
   fclose(file);
 }
 
   fclose(file);
 }
 
-xbt_node_t* xbt_graph_topo_sort(xbt_graph_t g)
-{
-  xbt_node_t* sorted;
-  int cursor,idx;
-  xbt_node_t node;
- unsigned long n;
-
- n= xbt_dynar_length(g->nodes); 
- idx=n-1;
-
-  sorted=xbt_malloc(n*sizeof(xbt_node_t));
-  xbt_dynar_foreach(g->nodes,cursor , node)
-    {
-      node->xbtdata=xbt_new0(int,1);
-    }
-
-  xbt_dynar_foreach(g->nodes,cursor , node) 
-    { 
-      xbt_graph_depth_visit(g,node,sorted,&idx);   
-    }
-         
-  return sorted; 
-}
-
-void xbt_graph_depth_visit(xbt_graph_t g,xbt_node_t n,xbt_node_t* sorted,int* idx )
-{
-  int cursor;
-  xbt_edge_t edge;
-  if (*((int*)(n->xbtdata))==ALREADY_EXPLORED)
-    return;
-  else if (*((int*)(n->xbtdata))==CURRENTLY_EXPLORING)
-    THROW0(0,0,"There is a cycle");
-  else
-    {
-      *((int*)(n->xbtdata))=CURRENTLY_EXPLORING;
-
-      xbt_dynar_foreach(n->out,cursor, edge)
-       {
-         xbt_graph_depth_visit(g,edge->dst,sorted,idx);
-       }
-      *((int*)(n->xbtdata))=ALREADY_EXPLORED;
-      sorted[(*idx)--]=n;
-    }       
-}