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
23{
24 edge_t *f;
25
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
33static void
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
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
Agedge_t * virtual_edge(Agnode_t *, Agnode_t *, Agedge_t *)
Definition fastgr.c:170
void delete_fast_edge(Agedge_t *)
Definition fastgr.c:109
void merge_oneway(Agedge_t *, Agedge_t *)
Definition fastgr.c:289
Agedge_t * find_fast_edge(Agnode_t *, Agnode_t *)
Definition fastgr.c:43
#define agtail(e)
Definition cgraph.h:977
#define aghead(e)
Definition cgraph.h:978
#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:31
#define ND_mark(n)
Definition acyclic.c:30
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
void acyclic(graph_t *g)
Definition acyclic.c:58
void reverse_edge(edge_t *e)
Definition acyclic.c:22
graph or subgraph
Definition cgraph.h:424