Graphviz
14.1.3~dev.20260124.0732
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 "config.h"
17
18
#include <
dotgen/dot.h
>
19
#include <stdbool.h>
20
#include <stddef.h>
21
22
void
reverse_edge
(
edge_t
* e)
23
{
24
edge_t
*f;
25
26
delete_fast_edge
(e);
27
if
((f =
find_fast_edge
(
aghead
(e),
agtail
(e))))
28
merge_oneway
(e, f);
29
else
30
virtual_edge
(
aghead
(e),
agtail
(e), e);
31
}
32
33
static
void
34
dfs
(
node_t
* n)
35
{
36
int
i;
37
edge_t
*e;
38
node_t
*w;
39
40
if
(
ND_mark
(n))
41
return
;
42
ND_mark
(n) =
true
;
43
ND_onstack
(n) =
true
;
44
for
(i = 0; (e =
ND_out
(n).list[i]); i++) {
45
w =
aghead
(e);
46
if
(
ND_onstack
(w)) {
47
reverse_edge
(e);
48
i--;
49
}
else
{
50
if
(!
ND_mark
(w))
51
dfs
(w);
52
}
53
}
54
ND_onstack
(n) =
false
;
55
}
56
57
58
void
acyclic
(
graph_t
* g)
59
{
60
node_t
*n;
61
62
for
(
size_t
c = 0; c <
GD_comp
(g).size; c++) {
63
GD_nlist
(g) =
GD_comp
(g).list[c];
64
for
(n =
GD_nlist
(g); n; n =
ND_next
(n))
65
ND_mark
(n) =
false
;
66
for
(n =
GD_nlist
(g); n; n =
ND_next
(n))
67
dfs
(n);
68
}
69
}
70
dot.h
virtual_edge
Agedge_t * virtual_edge(Agnode_t *, Agnode_t *, Agedge_t *)
Definition
fastgr.c:170
delete_fast_edge
void delete_fast_edge(Agedge_t *)
Definition
fastgr.c:109
merge_oneway
void merge_oneway(Agedge_t *, Agedge_t *)
Definition
fastgr.c:289
find_fast_edge
Agedge_t * find_fast_edge(Agnode_t *, Agnode_t *)
Definition
fastgr.c:43
agtail
#define agtail(e)
Definition
cgraph.h:977
aghead
#define aghead(e)
Definition
cgraph.h:978
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:58
reverse_edge
void reverse_edge(edge_t *e)
Definition
acyclic.c:22
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