Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
acyclic.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11
12/*
13 * Break cycles in a directed graph by depth-first search.
14 */
15
16#include <dotgen/dot.h>
17#include <stdbool.h>
18#include <stddef.h>
19
21{
22 edge_t *f;
23
25 if ((f = find_fast_edge(aghead(e), agtail(e))))
26 merge_oneway(e, f);
27 else
28 virtual_edge(aghead(e), agtail(e), e);
29}
30
31static void
33{
34 int i;
35 edge_t *e;
36 node_t *w;
37
38 if (ND_mark(n))
39 return;
40 ND_mark(n) = true;
41 ND_onstack(n) = true;
42 for (i = 0; (e = ND_out(n).list[i]); i++) {
43 w = aghead(e);
44 if (ND_onstack(w)) {
45 reverse_edge(e);
46 i--;
47 } else {
48 if (!ND_mark(w))
49 dfs(w);
50 }
51 }
52 ND_onstack(n) = false;
53}
54
55
57{
58 node_t *n;
59
60 for (size_t c = 0; c < GD_comp(g).size; c++) {
61 GD_nlist(g) = GD_comp(g).list[c];
62 for (n = GD_nlist(g); n; n = ND_next(n))
63 ND_mark(n) = false;
64 for (n = GD_nlist(g); n; n = ND_next(n))
65 dfs(n);
66 }
67}
68
Agedge_t * virtual_edge(Agnode_t *, Agnode_t *, Agedge_t *)
Definition fastgr.c:172
void delete_fast_edge(Agedge_t *)
Definition fastgr.c:108
void merge_oneway(Agedge_t *, Agedge_t *)
Definition fastgr.c:291
Agedge_t * find_fast_edge(Agnode_t *, Agnode_t *)
Definition fastgr.c:41
#define agtail(e)
Definition cgraph.h:880
#define aghead(e)
Definition cgraph.h:881
#define GD_nlist(g)
Definition types.h:393
#define GD_comp(g)
Definition types.h:362
#define ND_next(n)
Definition types.h:510
#define ND_out(n)
Definition types.h:515
#define ND_onstack(n)
Definition acyclic.c:29
#define ND_mark(n)
Definition acyclic.c:28
static bool dfs(Agraph_t *g, Agnode_t *t, bool hasCycle, size_t *num_rev)
Return true if the graph has a cycle.
Definition acyclic.c:52
void acyclic(graph_t *g)
Definition acyclic.c:56
void reverse_edge(edge_t *e)
Definition acyclic.c:20
graph or subgraph
Definition cgraph.h:425