Graphviz
16.1.3~dev.20261128.0221
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 v2.0
5
* which accompanies this distribution, and is available at
6
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
7
*
8
* Contributors: Details at https://graphviz.org
9
*************************************************************************/
10
11
/*
12
* Break cycles in a directed graph by depth-first search.
13
*/
14
15
#include "config.h"
16
17
#include <
dotgen/dot.h
>
18
#include <stdbool.h>
19
#include <stddef.h>
20
21
void
reverse_edge
(
edge_t
*e) {
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
dfs
(
node_t
*n) {
32
int
i;
33
edge_t
*e;
34
node_t
*w;
35
36
if
(
ND_mark
(n))
37
return
;
38
ND_mark
(n) =
true
;
39
ND_onstack
(n) =
true
;
40
for
(i = 0; (e =
ND_out
(n).list[i]); i++) {
41
w =
aghead
(e);
42
if
(
ND_onstack
(w)) {
43
reverse_edge
(e);
44
i--;
45
}
else
{
46
if
(!
ND_mark
(w))
47
dfs
(w);
48
}
49
}
50
ND_onstack
(n) =
false
;
51
}
52
53
void
acyclic
(
graph_t
*g) {
54
node_t
*n;
55
56
for
(
size_t
c = 0; c <
GD_comp
(g).size; c++) {
57
GD_nlist
(g) =
GD_comp
(g).list[c];
58
for
(n =
GD_nlist
(g); n; n =
ND_next
(n))
59
ND_mark
(n) =
false
;
60
for
(n =
GD_nlist
(g); n; n =
ND_next
(n))
61
dfs
(n);
62
}
63
}
dot.h
virtual_edge
Agedge_t * virtual_edge(Agnode_t *, Agnode_t *, Agedge_t *)
Definition
fastgr.c:156
delete_fast_edge
void delete_fast_edge(Agedge_t *)
Definition
fastgr.c:103
merge_oneway
void merge_oneway(Agedge_t *, Agedge_t *)
Definition
fastgr.c:223
find_fast_edge
Agedge_t * find_fast_edge(Agnode_t *, Agnode_t *)
Definition
fastgr.c:43
agtail
#define agtail(e)
Definition
cgraph.h:982
aghead
#define aghead(e)
Definition
cgraph.h:983
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:31
ND_mark
#define ND_mark(n)
Definition
acyclic.c:30
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:54
acyclic
void acyclic(graph_t *g)
Definition
acyclic.c:53
reverse_edge
void reverse_edge(edge_t *e)
Definition
acyclic.c:21
Agedge_s
Definition
cgraph.h:268
Agnode_s
Definition
cgraph.h:259
Agraph_s
graph or subgraph
Definition
cgraph.h:424
lib
dotgen
acyclic.c
Generated by
1.9.8