22 #define MARKED(stk,n) ((stk)->markfn(n,-1))
23 #define MARK(stk,n) ((stk)->markfn(n,1))
24 #define UNMARK(stk,n) ((stk)->markfn(n,0))
26 typedef struct blk_t {
42 #define BIGBUF 1000000
56 static void freeBlk (
blk_t* bp)
62 static void freeStk (
stk_t* sp)
119 while ((n =
pop(stk))) {
123 if ((other =
agtail(e)) == n)
132 static int isLegal(
char *p)
136 while ((c = *(
unsigned char *) p++)) {
137 if ((c !=
'_') && !isalnum(c))
146 static void insertFn(
Agnode_t * n,
void *state)
153 static int markFn (
Agnode_t* n,
int v)
165 setPrefix (
char* pfx,
int* lenp,
char* buf,
int buflen)
170 if (!pfx || !isLegal(pfx)) {
174 if (len + 25 <= buflen)
177 if (!(name = (
char *)
gmalloc(len + 25)))
return NULL;
216 name = setPrefix (pfx, &len, buffer,
SMALLBUF);
220 initStk (&stk, &blk, base, insertFn, markFn);
233 sprintf(name + len,
"%d", c_cnt);
240 dfs (g, n, out, &stk);
247 sprintf(name + len,
"%d", c_cnt);
250 dfs(g, n, out, &stk);
265 for (i=0; i < c_cnt; i++) {
306 name = setPrefix (pfx, &len, buffer,
SMALLBUF);
309 initStk (&stk, &blk, base, insertFn, markFn);
324 sprintf(name + len,
"%d", c_cnt);
327 dfs(g, n, out, &stk);
358 #define GRECNAME "ccgraphinfo"
359 #define NRECNAME "ccgnodeinfo"
360 #define GD_cc_subg(g) (((ccgraphinfo_t*)aggetrec(g, GRECNAME, FALSE))->cc_subg)
368 fprintf (stderr,
"nodeinfo undefined\n");
377 #define dnodeOf(v) (((ccgnodeinfo_t*)aggetrec(v, NRECNAME, FALSE))->ptr.n)
378 #define dnodeSet(v,w) (((ccgnodeinfo_t*)aggetrec(v, NRECNAME, FALSE))->ptr.n=w)
381 #define ptrOf(np) (((ccgnodeinfo_t*)((np)->base.data))->ptr.v)
382 #define nodeOf(np) (((ccgnodeinfo_t*)((np)->base.data))->ptr.n)
383 #define clustOf(np) (((ccgnodeinfo_t*)((np)->base.data))->ptr.g)
384 #define clMark(n) (((ccgnodeinfo_t*)(n->base.data))->mark)
389 #define isCluster(g) (strncmp(agnameof(g), "cluster", 7) == 0)
409 fprintf (stderr,
"Error: node \"%s\" belongs to two non-nested clusters \"%s\" and \"%s\"\n",
416 deriveClusters (dg, subg);
434 deriveClusters (dg, g);
486 static int clMarkFn (
Agnode_t* n,
int v)
489 if (v < 0)
return clMark(n);
523 #define ORIG_REC "orig"
556 if (!proj && inCluster) {
586 if ((proj = projectG(subg, g, inCluster))) {
587 in_cluster = (inCluster ||
isCluster(subg));
588 subgInduce(subg, proj, in_cluster);
596 subgInduce(g, out, 0);
611 long n_cnt, c_cnt, e_cnt;
634 name = setPrefix (pfx, &len, buffer,
SMALLBUF);
639 initStk (&stk, &blk, base, insertFn, clMarkFn);
645 sprintf(name + len,
"%ld", c_cnt);
646 dout =
agsubg(dg, name, 1);
650 n_cnt = dfs(dg, dn, dout, &stk);
651 unionNodes(dout, out);
657 fprintf(stderr,
"(%4ld) %7ld nodes %7ld edges\n",
658 c_cnt, n_cnt, e_cnt);
663 fprintf(stderr,
" %7d nodes %7d edges %7ld components %s\n",
694 initStk (&stk, &blk, base,
NULL, markFn);
CGRAPH_API void agclean(Agraph_t *g, int kind, char *rec_name)
union ccgnodeinfo_t::@25 ptr
CGRAPH_API Agnode_t * agnode(Agraph_t *g, char *name, int createflag)
#define RALLOC(size, ptr, type)
CGRAPH_API Agraph_t * agopen(char *name, Agdesc_t desc, Agdisc_t *disc)
int nodeInduce(Agraph_t *g)
void(* actionfn)(Agnode_t *, void *)
CGRAPH_API Agdesc_t Agstrictundirected
void * gmalloc(size_t nbytes)
CGRAPH_API Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
CGRAPH_API int agdelete(Agraph_t *g, void *obj)
Agraph_t ** pccomps(Agraph_t *g, int *ncc, char *pfx, boolean *pinned)
int agerr(agerrlevel_t level, const char *fmt,...)
Agraph_t ** cccomps(Agraph_t *g, int *ncc, char *pfx)
CGRAPH_API Agraph_t * agfstsubg(Agraph_t *g)
CGRAPH_API Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
int node_induce(Agraph_t *g, Agraph_t *eg)
CGRAPH_API Agraph_t * agnxtsubg(Agraph_t *subg)
CGRAPH_API Agnode_t * agtail(Agedge_t *e)
CGRAPH_API Agraph_t * agsubg(Agraph_t *g, char *name, int cflag)
CGRAPH_API Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
CGRAPH_API Agnode_t * aghead(Agedge_t *e)
CGRAPH_API int agclose(Agraph_t *g)
CGRAPH_API char * agnameof(void *)
CGRAPH_API Agedge_t * agsubedge(Agraph_t *g, Agedge_t *e, int createflag)
CGRAPH_API Agnode_t * agfstnode(Agraph_t *g)
CGRAPH_API void aginit(Agraph_t *g, int kind, char *rec_name, int rec_size, int move_to_front)
CGRAPH_API Agrec_t * aggetrec(void *obj, char *name, int move_to_front)
int agcopyattr(void *oldobj, void *newobj)
CGRAPH_API Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
EXTERN unsigned char Verbose
CGRAPH_API int agnnodes(Agraph_t *g)
CGRAPH_API Agedge_t * agedge(Agraph_t *g, Agnode_t *t, Agnode_t *h, char *name, int createflag)
CGRAPH_API void * agbindrec(void *obj, char *name, unsigned int size, int move_to_front)
int(* markfn)(Agnode_t *, int)
CGRAPH_API int agnedges(Agraph_t *g)
Agraph_t ** ccomps(Agraph_t *g, int *ncc, char *pfx)
CGRAPH_API Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
int isConnected(Agraph_t *g)
CGRAPH_API Agnode_t * agsubnode(Agraph_t *g, Agnode_t *n, int createflag)
Agraph_t * mapClust(Agraph_t *cl)