From: Emden Gansner Date: Wed, 5 Sep 2012 19:07:48 +0000 (-0400) Subject: Add opp() helper function to make it simpler to get the "other side" of X-Git-Tag: LAST_LIBGRAPH~32^2~321 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2dd95ec0e26cb736dafb847b8b859557d2f3ac13;p=graphviz Add opp() helper function to make it simpler to get the "other side" of an edge. --- diff --git a/cmd/gvpr/gvpr.1 b/cmd/gvpr/gvpr.1 index 7833480a3..cb7b8f65e 100644 --- a/cmd/gvpr/gvpr.1 +++ b/cmd/gvpr/gvpr.1 @@ -471,6 +471,12 @@ returns the next edge after \fIe\fP in the root graph. .TP \fBnxtedge_sg\fP(\fIsg\fP : \fBgraph_t\fP, \fIe\fP : \fBedge_t\fP, \fBnode_t\fP) : \fBedge_t\fP returns the next edge after \fIe\fP in the graph \fIsg\fP. +.TP +\fBopp\fP(\fIe\fP : \fBedge_t\fP, \fBnode_t\fP) : \fBnode_t\fP +returns the node on the edge \fIe\fP not equal to \fIn\fP. +Returns NULL if \fIn\fP is not a node of \fIe\fP. +This can be useful when using \fBfstedge\fP and \fBnxtedge\fP +to enumerate the neighbors of \fIn\fP. .SS "Graph I/O" .TP \fBwrite\fP(\fIg\fP : \fBgraph_t\fP) : \fBvoid\fP diff --git a/lib/gvpr/compile.c b/lib/gvpr/compile.c index 73041c839..18cd13eaa 100644 --- a/lib/gvpr/compile.c +++ b/lib/gvpr/compile.c @@ -888,6 +888,23 @@ getval(Expr_t * pgm, Exnode_t * node, Exid_t * sym, Exref_t * ref, } else v.integer = PTR2INT(addEdge(gp, ep, 1)); break; + case F_opp: + ep = INT2PTR(Agedge_t *, args[0].integer); + np = INT2PTR(Agnode_t *, args[1].integer); + if (!ep) { + error(ERROR_WARNING, "NULL edge passed to opp()"); + v.integer = 0; + } else if (!np) { + error(ERROR_WARNING, "NULL node passed to opp()"); + v.integer = 0; + } else { + if (aghead(ep) == np) + np = agtail(ep); + else + np = aghead(ep); + v.integer = PTR2INT(np); + } + break; case F_isedge: key = args[2].string; if (*key == '\0') diff --git a/lib/gvpr/gprdata b/lib/gvpr/gprdata index 595a7729e..b02fc39f4 100644 --- a/lib/gvpr/gprdata +++ b/lib/gvpr/gprdata @@ -47,6 +47,7 @@ F_isin "isIn" FUNCTION I|A(1,G)|A(2,O) F_edge "edge" FUNCTION E|A(1,V)|A(2,V)|A(3,S) F_edgesg "edge_sg" FUNCTION E|A(1,G)|A(2,V)|A(3,V)|A(4,S) F_addedge "subedge" FUNCTION E|A(1,G)|A(2,E) +F_opp "opp" FUNCTION V|A(1,E)|A(2,V) F_fstout "fstout" FUNCTION E|A(1,V) F_nxtout "nxtout" FUNCTION E|A(1,E) F_fstin "fstin" FUNCTION E|A(1,V)