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
20
void
reverse_edge
(
edge_t
* e)
21
{
22
edge_t
*f;
23
24
delete_fast_edge
(e);
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
31
static
void
32
dfs
(
node_t
* n)
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
56
void
acyclic
(
graph_t
* g)
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
dot.h
virtual_edge
Agedge_t * virtual_edge(Agnode_t *, Agnode_t *, Agedge_t *)
Definition
fastgr.c:172
delete_fast_edge
void delete_fast_edge(Agedge_t *)
Definition
fastgr.c:108
merge_oneway
void merge_oneway(Agedge_t *, Agedge_t *)
Definition
fastgr.c:291
find_fast_edge
Agedge_t * find_fast_edge(Agnode_t *, Agnode_t *)
Definition
fastgr.c:41
agtail
#define agtail(e)
Definition
cgraph.h:880
aghead
#define aghead(e)
Definition
cgraph.h:881
GD_nlist
#define GD_nlist(g)
Definition
types.h:393
GD_comp
#define GD_comp(g)
Definition
types.h:362
ND_next
#define ND_next(n)
Definition
types.h:510
ND_out
#define ND_out(n)
Definition
types.h:515
ND_onstack
#define ND_onstack(n)
Definition
acyclic.c:29
ND_mark
#define ND_mark(n)
Definition
acyclic.c:28
dfs
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
acyclic
void acyclic(graph_t *g)
Definition
acyclic.c:56
reverse_edge
void reverse_edge(edge_t *e)
Definition
acyclic.c:20
Agedge_s
Definition
cgraph.h:268
Agnode_s
Definition
cgraph.h:259
Agraph_s
graph or subgraph
Definition
cgraph.h:425
lib
dotgen
acyclic.c
Generated by
1.9.8