37#define ON_STACK(ninfo, n) (ninfo[AGSEQ(n)].on_stack)
38#define DISTANCE(ninfo, n) (ninfo[AGSEQ(n)].dist)
39#define agrootof(n) ((n)->root)
41static unsigned char uchar_min(
unsigned char a,
unsigned char b) {
55 edge_stack_push_back(sp, ep);
60 if (edge_stack_is_empty(sp)) {
65 Agedge_t *e = edge_stack_pop_back(sp);
75 if (edge_stack_is_empty(sp)) {
79 return *edge_stack_back(sp);
117 edge_stack_t estk = {0};
118 push(&estk, &dummy.
out, ninfo);
121 while ((link =
top(&estk))) {
127 for (; next; next =
agnxtout(g, next)) {
137 "warning: %s has cycle(s), transitive reduction not unique\n",
139 fprintf(
opts->err,
"cycle involves edge %s -> %s\n",
agnameof(v),
143 }
else if (
DISTANCE(ninfo, hd) == 0) {
146 }
else if (
DISTANCE(ninfo, hd) == 1) {
151 push(&estk, next, ninfo);
158 for (e =
agfstout(g, n); e; e = f) {
171 fprintf(
opts->err,
"removed edge: %s: \"%s\" -> \"%s\"\n",
agnameof(g),
176 edge_stack_free(&estk);
188 time_t total_secs = 0;
196 fprintf(stderr,
"Processing graph %s\n",
agnameof(g));
198 memset(ninfo, 0, infosize);
199 const time_t start = time(
NULL);
200 warn =
dfs(n, ninfo, warn,
opts);
202 secs = time(
NULL) - start;
206 fprintf(
opts->err,
"[%d]\n",
cnt);
211 fprintf(
opts->err,
"Finished graph %s: %lld.00 secs.\n",
agnameof(g),
212 (
long long)total_secs);
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
static int cnt(Dict_t *d, Dtlink_t **set)
int agnnodes(Agraph_t *g)
void graphviz_tred(Agraph_t *g, const graphviz_tred_options_t *opts)
programmatic access to tred - transitive reduction
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
int agwrite(Agraph_t *g, void *chan)
Return 0 on success, EOF on failure.
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Agnode_t * agfstnode(Agraph_t *g)
char * agnameof(void *)
returns a string descriptor for the object.
int agdelete(Agraph_t *g, void *obj)
deletes object. Equivalent to agclose, agdelnode, and agdeledge for obj being a graph,...
static int dfs(Agnode_t *n, nodeinfo_t *ninfo, int warn, const graphviz_tred_options_t *opts)
static unsigned char uchar_min(unsigned char a, unsigned char b)
static void push(edge_stack_t *sp, Agedge_t *ep, nodeinfo_t *ninfo)
#define ON_STACK(ninfo, n)
#define DISTANCE(ninfo, n)
static Agedge_t * top(edge_stack_t *sp)
#define DEFINE_LIST(name, type)
Agtag_t tag
access with AGTAG
unsigned objtype
access with AGTYPE
options for passing to graphviz_tred