|
Graphviz
2.29.20120523.0446
|
00001 /* $Id$ $Revision$ */ 00002 /* vim:set shiftwidth=4 ts=8: */ 00003 00004 /************************************************************************* 00005 * Copyright (c) 2011 AT&T Intellectual Property 00006 * All rights reserved. This program and the accompanying materials 00007 * are made available under the terms of the Eclipse Public License v1.0 00008 * which accompanies this distribution, and is available at 00009 * http://www.eclipse.org/legal/epl-v10.html 00010 * 00011 * Contributors: See CVS logs. Details at http://www.graphviz.org/ 00012 *************************************************************************/ 00013 00014 00015 /* 00016 * Break cycles in a directed graph by depth-first search. 00017 */ 00018 00019 #include "dot.h" 00020 00021 void reverse_edge(edge_t * e) 00022 { 00023 edge_t *f; 00024 00025 delete_fast_edge(e); 00026 if ((f = find_fast_edge(aghead(e), agtail(e)))) 00027 merge_oneway(e, f); 00028 else 00029 virtual_edge(aghead(e), agtail(e), e); 00030 } 00031 00032 static void 00033 dfs(node_t * n) 00034 { 00035 int i; 00036 edge_t *e; 00037 node_t *w; 00038 00039 if (ND_mark(n)) 00040 return; 00041 ND_mark(n) = TRUE; 00042 ND_onstack(n) = TRUE; 00043 for (i = 0; (e = ND_out(n).list[i]); i++) { 00044 w = aghead(e); 00045 if (ND_onstack(w)) { 00046 reverse_edge(e); 00047 i--; 00048 } else { 00049 if (ND_mark(w) == FALSE) 00050 dfs(w); 00051 } 00052 } 00053 ND_onstack(n) = FALSE; 00054 } 00055 00056 00057 void acyclic(graph_t * g) 00058 { 00059 int c; 00060 node_t *n; 00061 00062 for (c = 0; c < GD_comp(g).size; c++) { 00063 GD_nlist(g) = GD_comp(g).list[c]; 00064 for (n = GD_nlist(g); n; n = ND_next(n)) 00065 ND_mark(n) = FALSE; 00066 for (n = GD_nlist(g); n; n = ND_next(n)) 00067 dfs(n); 00068 } 00069 } 00070
1.7.5