~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to graph/graph.3

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.TH LIBGRAPH 3 "01 MARCH 1993"
 
2
.SH NAME
 
3
\fBlibgraph\fR \- abstract graph library
 
4
.SH SYNOPSIS
 
5
.ta .75i 1.5i 2.25i 3i 3.75i 4.5i 5.25i 6i
 
6
.PP
 
7
.nf
 
8
\f5
 
9
#include <graph.h>
 
10
void        aginit();
 
11
Agraph_t    *agread(FILE*);
 
12
int         agwrite(Agraph_t*, FILE*);
 
13
int         agerrors();
 
14
Agraph_t    *agopen(char *name, int kind);
 
15
void        agclose(Agraph_t *g);
 
16
Agraph_t    *agsubg(Agraph_t *g, char *name);
 
17
Agraph_t    *agfindsubg(Agraph_t *g, char *name);
 
18
Agnode_t    *agmetanode(Agraph_t *g);
 
19
Agraph_t    *agusergraph(Agnode_t *metanode);
 
20
int         agnnodes(Agraph_t *g), agnedges(Agraph_t *g);
 
21
.sp .i1
 
22
int         agcontains(Agraph_t *g, void *obj);
 
23
int         aginsert(Agraph_t *g, void *obj);
 
24
int         agdelete(Agraph_t *g, void *obj);
 
25
.sp .1i
 
26
Agnode_t    *agnode(Agraph_t *g, char *name);
 
27
Agnode_t    *agfindnode(Agraph_t *g, char *name);
 
28
Agnode_t    *agfstnode(Agraph_t *g);
 
29
Agnode_t    *agnxtnode(Agraph_t *g, Agnode_t *n);
 
30
.sp .1i
 
31
Agedge_t    *agedge(Agraph_t *g, Agnode_t *tail, Agnode_t *head);
 
32
Agedge_t    *agfindedge(Agraph_t *g, Agnode_t *tail, Agnode_t *head);
 
33
Agedge_t    *agfstedge(Agraph_t *g, Agnode_t *n);
 
34
Agedge_t    *agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n);
 
35
Agedge_t    *agfstin(Agraph_t *g, Agnode_t *n);
 
36
Agedge_t    *agnxtin(Agraph_t *g, Agedge_t *e);
 
37
Agedge_t    *agfstout(Agraph_t *g, Agnode_t *n);
 
38
Agedge_t    *agnxtout(Agraph_t *g, Agedge_t *e);
 
39
.sp .1i
 
40
char        *agget(void *obj, char *name);
 
41
char        *agxget(void *obj, int index);
 
42
void        agset(void *obj, char *name, char *value);
 
43
void        agxset(void *obj, int index, char *value);
 
44
int         agindex(void *obj, char *name);
 
45
.sp .1i
 
46
Agsym_t*    agraphattr(Agraph_t *g,char *name,char *value);
 
47
Agsym_t*    agnodeattr(Agraph_t *g,char *name,char *value);
 
48
Agsym_t*    agedgeattr(Agraph_t *g,char *name,char *value);
 
49
Agsym_t*    agfindattr(void *obj,char *name);
 
50
\fP
 
51
.fi
 
52
.SH DESCRIPTION
 
53
\fIlibgraph\fP maintains directed and undirected attributed graphs
 
54
in memory and reads and writes graph files.  Graphs are composed of
 
55
nodes, edges, and nested subgraphs.   A subgraph may contain any
 
56
nodes and edges of its parents, and may be passed to any
 
57
\fIlibgraph\fP function taking a graph pointer, except the three
 
58
that create new attributes (where a main graph is required).
 
59
 
 
60
Attributes are internal or external.
 
61
Internal attributes are fields in the graph, node and edge structs
 
62
defined at compile time.
 
63
These allow efficient representation and direct access to values
 
64
such as marks, weights, and pointers for writing graph algorithms.
 
65
External attributes, on the other hand, are character strings
 
66
(name-value pairs) dynamically allocated at runtime and accessed
 
67
through \fIlibgraph\fP calls.  External attributes are used in
 
68
graph file I/O; internal attributes are not.  Conversion between
 
69
internal and external attributes must be explicitly programmed.
 
70
 
 
71
The subgraphs in a main graph are represented by an auxiliary directed
 
72
graph (a meta-graph).  Meta-nodes correspond to subgraphs, and meta-edges
 
73
signify containment of one subgraph in another. 
 
74
\f5agmetanode\fP and \f5agusergraph\fP map between
 
75
subgraphs and meta-nodes.  The nodes and edges of the meta-graph may
 
76
be traversed by the usual \fIlibgraph\fP functions for this purpose.
 
77
 
 
78
.SH USE
 
79
1. Define types \f5Agraphinfo_t\fP, \f5Agnodeinfo_t\fP,
 
80
and \f5Agedgeinfo_t\fP (usually in a header file) before
 
81
including \f5<graph.h>\fP. 
 
82
 
 
83
2. Call \f5aginit()\fP before any other \fIlibgraph\fP functions.
 
84
(This is a macro that calls \f5aginitlib()\fP to define the sizes
 
85
of Agraphinfo_t, Agnodeinfo_t, and Agedgeinfo_t.)
 
86
 
 
87
3. Compile with -lgraph -lcdt.
 
88
 
 
89
Except for the \fBu\fP fields, \fIlibgraph\fP
 
90
data structures must be considered read-only.
 
91
Corrupting their contents by direct updates can cause
 
92
catastrophic errors.
 
93
 
 
94
.SH "GRAPHS"
 
95
.nf
 
96
\f5
 
97
typedef struct Agraph_t {
 
98
    char                 kind;
 
99
    char                *name;
 
100
    Agraph_t             *root;
 
101
    char                **attr;
 
102
    graphdata_t         *univ;
 
103
    Dict_t              *nodes,*inedges,*outedges;
 
104
    proto_t             *proto;
 
105
    Agraphinfo_t         u;
 
106
} Agraph_t;
 
107
 
 
108
typedef struct graphdata_t {
 
109
    Dict_t              *node_dict;
 
110
    attrdict_t          *nodeattr, *edgeattr, *globattr;
 
111
} graphdata_t;
 
112
 
 
113
typedef struct proto_t {
 
114
    Agnode_t            *n;
 
115
    Agedge_t            *e;
 
116
    proto_t             *prev;
 
117
} proto_t;
 
118
\fP
 
119
.fi
 
120
A graph \fIkind\fP is one of:
 
121
AGRAPH, AGRAPHSTRICT, AGDIGRAPH, or AGDIGRAPHSTRICT.
 
122
There are related macros for testing the properties of a graph:
 
123
AG_IS_DIRECTED(g) and AG_IS_STRICT(g).
 
124
Strict graphs cannot have self-arcs or multi-edges.
 
125
\fBattr\fP is the array of external attribute values.
 
126
\fBuniv\fP points to values shared by all subgraphs of a main graph.
 
127
\fBnodes\fP, \fBinedges\fP, and \fBoutedges\fP are sets maintained
 
128
by \fBcdt(3)\fP.  Normally you don't access these dictionaries
 
129
directly, though the edge dictionaries may be re-ordered to support
 
130
programmer-defined ordered edges (see \f5dtreorder\fP in \fIcdt(3)\fP).
 
131
\fBproto\fP is a stack of templates for node and edge initialization.
 
132
The attributes of these nodes and edges are set in the usual way (\f5agget\fP,
 
133
\f5agset\fP, etc.) to set defaults.
 
134
.PP
 
135
\f5agread\fP reads a file and returns a new graph if one
 
136
was succesfully parsed, otherwise returns NULL if
 
137
\f5EOF\fP or a syntax error was encountered.
 
138
Errors are reported on stderr and a count is returned from
 
139
\g5agerrors()\fP.
 
140
\f5write_graph\fP prints a graph on a file.
 
141
\f5agopen\fP and \f5agsubg\fP create new empty graph and subgraphs.
 
142
\f5agfindsubg\fP searches for a subgraph by name, returning NULL
 
143
when the search fails.
 
144
 
 
145
.SH ALL OBJECTS
 
146
\f5agcontains\fP, \f5aginsert\fP, \f5agdelete\fP are generic functions
 
147
for nodes, edges, and graphs.  \f5gcontains\fP is a predicate that tests
 
148
if an object belongs to the given graph.  \f5aginsert\fP inserts an
 
149
object in a graph and \f5agdelete\fP undoes this operation.
 
150
A node or edge is destroyed (and its storage freed) at the time it
 
151
is deleted from the main graph.  Likewise a subgraph is destroyed
 
152
when it is deleted from its last parent or when its last parent is deleted.
 
153
 
 
154
.SH NODES
 
155
.nf
 
156
\f5
 
157
typedef struct Agnode_t {
 
158
    char                *name;
 
159
    Agraph_t            *graph;
 
160
    char                **attr;
 
161
    Agnodeinfo_t        u;
 
162
} Agnode_t;
 
163
\fP
 
164
.fi
 
165
 
 
166
\f5agnode\fP attempts to create a node.
 
167
If one with the requested name already exists, the old node 
 
168
is returned unmodified.
 
169
Otherwise a new node is created, with attributed copied from g->proto->n.
 
170
\f5agfstnode\fP (\f5agnxtnode\fP) return the first (next) element
 
171
in the node set of a graph, respectively, or NULL.
 
172
 
 
173
.SH EDGES
 
174
.nf
 
175
\f5
 
176
typedef struct Agedge_t {
 
177
    Agnode_t            *head,*tail;
 
178
    char                **attr;
 
179
    Agedgeinfo_t        u;
 
180
} Agedge_t;
 
181
\fP
 
182
.fi
 
183
\f5agedge\fP creates a new edge with the attributes of g->proto->e
 
184
including its key if not empty.
 
185
\f5agfindedge\fP finds the first (u,v) edge in \f5g\fP.
 
186
\f5agfstedge\fP (\f5agnxtedge\fP) return the first (next) element
 
187
in the edge set of a graph, respectively, or NULL.
 
188
\f5agfstin\fP, \f5agnxtin\fP, \f5agfstout\fP, \f5agnxtout\fP
 
189
refer to in- or out-edge sets.
 
190
The idiomatic usage in a directed graph is:
 
191
.sp
 
192
\f5    for (e = agfstout(g,n); e; e = agnextout(g,e)) your_fun(e);\fP
 
193
.P
 
194
An edge is uniquely identified by its endpoints and its \f5key\fP
 
195
attribute (if there are multiple edges).
 
196
If the \f5key\fP of \f5g->proto->e\fP is empty,
 
197
new edges are assigned an internal value.
 
198
Edges also have \f5tailport\fP and \f5headport\fP values.
 
199
These have special syntax in the graph file language but are
 
200
not otherwise interpreted.
 
201
.PP
 
202
.SH ATTRIBUTES
 
203
.nf
 
204
\f5
 
205
typedef struct attrsym_t {
 
206
    char                *name,*value;
 
207
    int                 index;
 
208
    unsigned char       printed;
 
209
} attrsym_t;
 
210
.bp
 
211
typedef struct attrdict_t  {
 
212
    char                *name;
 
213
    Dict_t              *dict;
 
214
    attrsym_t           **list;
 
215
} attrdict_t;
 
216
\fP
 
217
.fi
 
218
\f5agraphattr\fP, \f5agnodeattr\fP, and \f5agedgeattr\fP make new attributes.
 
219
\f5g\fP should be a main graph, or \f5NULL\fP for declarations
 
220
applying to all graphs subsequently read or created.
 
221
\f5agfindattr\fP searches for an existing attribute.
 
222
.PP
 
223
External attributes are accessed by \f5agget\fP and \f5agset\fP
 
224
These take a pointer to any graph, node, or edge, and an attribute name.
 
225
Also, each attribute has an integer index.  For efficiency this index
 
226
may be passed instead of the name, by calling \f5agxget\fP and \f5agxset\fP.
 
227
The \f5printed\fP flag of an attribute may be set to 0 to skip it
 
228
when writing a graph file.
 
229
.PP
 
230
The \f5list\fP in an attribute dictionary is maintained in order of creation
 
231
and is NULL terminated.
 
232
Here is a program fragment to print node attribute names:
 
233
.nf
 
234
    \f5attrsym_t *aptr;
 
235
    for (i = 0; aptr = g->univ->nodedict->list[i]; i++) puts(aptr->name);\fP
 
236
.fi
 
237
.SH EXAMPLE GRAPH FILES
 
238
.nf
 
239
graph any_name {            /* an undirected graph */
 
240
    a -- b;                 /* a simple edge */
 
241
    a -- x1 -- x2 -- x3;    /* a chain of edges */
 
242
    "x3.a!" -- a;           /* quotes protect special characters */
 
243
    b -- {q r s t};         /* edges that fan out */
 
244
    b [color="red",size=".5,.5"];   /* set various node attributes */
 
245
    node [color=blue];      /* set default attributes */
 
246
    b -- c [weight=25];     /* set edge attributes */
 
247
    subgraph sink_nodes {a b c};    /* make a subgraph */
 
248
}
 
249
 
 
250
digraph G {
 
251
    bb="8.5,11";            /* sets a graph attribute */
 
252
    a -> b;                 /* makes a directed edge */
 
253
    chip12.pin1 -> chip28.pin3; /* uses named node "ports" */
 
254
}
 
255
.fi
 
256
 
 
257
.SH SEE ALSO
 
258
.BR dot (1),
 
259
.BR neato (1),
 
260
.BR libdict (3)
 
261
.br
 
262
S. C. North and K. P. Vo, "Dictionary and Graph Libraries''
 
263
1993 Winter USENIX Conference Proceedings, pp. 1-11.
 
264
 
 
265
.SH AUTHOR
 
266
Stephen North (north@ulysses.att.com), AT&T Bell Laboratories.