Mercurial > hg > camir-aes2014
comparison toolboxes/graph_visualisation/share/man/man3/cgraph.3 @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 .de P0 | |
2 .nf | |
3 \f5 | |
4 .. | |
5 .de P1 | |
6 \fP | |
7 .fi | |
8 .. | |
9 .de Ss | |
10 .fl | |
11 .ne 2 | |
12 .SS "\\$1" | |
13 .. | |
14 .TH LIBCGRAPH 3 "30 JULY 2007" | |
15 .SH "NAME" | |
16 \fBlibcgraph\fR \- abstract graph library | |
17 .SH "SYNOPSIS" | |
18 ."ta .75i 1.5i 2.25i 3i 3.75i 4.5i 5.25i 6i | |
19 .PP | |
20 .nf | |
21 .P0 | |
22 #include <graphviz/cgraph.h> | |
23 .P1 | |
24 .SS "TYPES" | |
25 .P0 | |
26 Agraph_t; | |
27 Agnode_t; | |
28 Agedge_t; | |
29 Agdesc_t; | |
30 Agdisc_t; | |
31 Agsym_t; | |
32 .P1 | |
33 .SS "GRAPHS" | |
34 .P0 | |
35 Agraph_t *agopen(char *name, Agdesc_t kind, Agdisc_t *disc); | |
36 int agclose(Agraph_t *g); | |
37 Agraph_t *agread(void *channel, Agdisc_t *); | |
38 void agreadline(int line_no); | |
39 void agsetfile(char *file_name); | |
40 Agraph_t *agconcat(Agraph_t *g, void *channel, Agdisc_t *disc) | |
41 int agwrite(Agraph_t *g, void *channel); | |
42 int agnnodes(Agraph_t *g),agnedges(Agraph_t *g); | |
43 int agisdirected(Agraph_t * g),agisundirected(Agraph_t * g),agisstrict(Agraph_t * g), agissimple(Agraph_t * g); | |
44 .SS "SUBGRAPHS" | |
45 .P0 | |
46 Agraph_t *agsubg(Agraph_t *g, char *name, int createflag); | |
47 Agraph_t *agidsubg(Agraph_t * g, unsigned long id, int cflag); | |
48 Agraph_t *agfstsubg(Agraph_t *g), agnxtsubg(Agraph_t *); | |
49 Agraph_t *agparent(Agraph_t *g); | |
50 int agdelsubg(Agraph_t * g, Agraph_t * sub); /* same as agclose() */ | |
51 .P1 | |
52 .SS "NODES" | |
53 .P0 | |
54 Agnode_t *agnode(Agraph_t *g, char *name, int createflag); | |
55 Agnode_t *agidnode(Agraph_t *g, ulong id, int createflag); | |
56 Agnode_t *agsubnode(Agraph_t *g, Agnode_t *n, int createflag); | |
57 Agnode_t *agfstnode(Agraph_t *g); | |
58 Agnode_t *agnxtnode(Agraph_t *g, Agnode_t *n); | |
59 Agnode_t *agprvnode(Agraph_t *g, Agnode_t *n); | |
60 Agnode_t *aglstnode(Agraph_t *g); | |
61 int agdelnode(Agraph_t *g, Agnode_t *n); | |
62 int agdegree(Agnode_t *n, int use_inedges, int use_outedges); | |
63 .P1 | |
64 .SS "EDGES" | |
65 .P0 | |
66 Agedge_t *agedge(Agraph_t* g, Agnode_t *t, Agnode_t *h, char *name, int createflag); | |
67 Agedge_t *agidedge(Agraph_t * g, Agnode_t * t, Agnode_t * h, unsigned long id, int createflag); | |
68 Agedge_t *agsubedge(Agraph_t *g, Agedge_t *e, int createflag); | |
69 Agnode_t *aghead(Agedge_t *e), *agtail(Agedge_t *e); | |
70 Agedge_t *agfstedge(Agraph_t* g, Agnode_t *n); | |
71 Agedge_t *agnxtedge(Agraph_t* g, Agedge_t *e, Agnode_t *n); | |
72 Agedge_t *agfstin(Agraph_t* g, Agnode_t *n); | |
73 Agedge_t *agnxtin(Agraph_t* g, Agedge_t *e); | |
74 Agedge_t *agfstout(Agraph_t* g, Agnode_t *n); | |
75 Agedge_t *agnxtout(Agraph_t* g, Agedge_t *e); | |
76 int agdeledge(Agraph_t *g, Agedge_t *e); | |
77 .SS "STRING ATTRIBUTES" | |
78 .P0 | |
79 Agsym_t *agattr(Agraph_t *g, int kind, char *name, char *value); | |
80 Agsym_t *agattrsym(void *obj, char *name); | |
81 Agsym_t *agnxtattr(Agraph_t *g, int kind, Agsym_t *attr); | |
82 char *agget(void *obj, char *name); | |
83 char *agxget(void *obj, Agsym_t *sym); | |
84 int agset(void *obj, char *name, char *value); | |
85 int agxset(void *obj, Agsym_t *sym, char *value); | |
86 int agsafeset(void *obj, char *name, char *value, char *def); | |
87 .P1 | |
88 .SS "RECORDS" | |
89 .P0 | |
90 void *agbindrec(void *obj, char *name, unsigned int size, move_to_front); | |
91 Agrec_t *aggetrec(void *obj, char *name, int move_to_front); | |
92 int agdelrec(Agraph_t *g, void *obj, char *name); | |
93 int agcopyattr(void *, void *); | |
94 void aginit(Agraph_t * g, int kind, char *rec_name, int rec_size, int move_to_front); | |
95 void agclean(Agraph_t * g, int kind, char *rec_name); | |
96 .P1 | |
97 .SS "CALLBACKS" | |
98 .P0 | |
99 Agcbdisc_t *agpopdisc(Agraph_t *g); | |
100 void agpushdisc(Agraph_t *g, Agcbdisc_t *disc); | |
101 void agmethod(Agraph_t *g, void *obj, Agcbdisc_t *disc, int initflag); | |
102 .P1 | |
103 .SS "MEMORY" | |
104 .P0 | |
105 void *agalloc(Agraph_t *g, size_t request); | |
106 void *agrealloc(Agraph_t *g, void *ptr, size_t oldsize, size_t newsize); | |
107 void agfree(Agraph_t *g, void *ptr); | |
108 .P1 | |
109 .SS "STRINGS" | |
110 .P0 | |
111 char *agstrdup(Agraph_t *, char *); | |
112 char *agstrdup_html(Agraph_t *, char *); | |
113 int aghtmlstr(char *); | |
114 char *agstrbind(Agraph_t * g, char *); | |
115 int strfree(Agraph_t *, char *); | |
116 char *agcanonStr(char *); | |
117 char *agstrcanon(char *, char *); | |
118 .P1 | |
119 .SS "GENERIC OBJECTS" | |
120 .P0 | |
121 Agraph_t *agraphof(void*); | |
122 Agraph_t *agroot(void*); | |
123 int agcontains(Agraph_t*, void*); | |
124 char *agnameof(void*); | |
125 void agdelete(Agraph_t *g, void *obj); | |
126 int agobjkind(void *obj); | |
127 Agrec_t *AGDATA(void *obj); | |
128 ulong AGID(void *obj); | |
129 int AGTYPE(void *obj); | |
130 .P1 | |
131 .SH "DESCRIPTION" | |
132 Libcgraph supports graph programming by maintaining graphs in memory | |
133 and reading and writing graph files. | |
134 Graphs are composed of nodes, edges, and nested subgraphs. | |
135 These graph objects may be attributed with string name-value pairs | |
136 and programmer-defined records (see Attributes). | |
137 .PP | |
138 All of Libcgraph's global symbols have the prefix \fBag\fR (case varying). | |
139 .SH "GRAPH AND SUBGRAPHS" | |
140 .PP | |
141 A ``main'' or ``root'' graph defines a namespace for a collection of | |
142 graph objects (subgraphs, nodes, edges) and their attributes. | |
143 Objects may be named by unique strings or by 32-bit IDs. | |
144 .PP | |
145 \fBagopen\fP creates a new graph with the given name and kind. | |
146 (Graph kinds are \fBAgdirected\fP, \fBAgundirected\fP, | |
147 \fBAgstrictdirected\fP, and \fBAgstrictundirected\fP. | |
148 A strict graph cannot have multi-edges or self-arcs.) | |
149 \fBagclose\fP deletes a graph, freeing its associated storage. | |
150 \fBagread\fP, \fBagwrite\fP, and \fBagconcat\fP perform file I/O | |
151 using the graph file language described below. \fBagread\fP | |
152 constructs a new graph while \fBagconcat\fP merges the file | |
153 contents with a pre-existing graph. Though I/O methods may | |
154 be overridden, the default is that the channel argument is | |
155 a stdio FILE pointer. \fBagsetfile\fP and \fBagreadline\fP | |
156 are helper functions that simply set the current file name | |
157 and input line number for subsequent error reporting. | |
158 .PP | |
159 \fBagsubg\fP finds or creates | |
160 a subgraph by name. A new subgraph is is initially empty and | |
161 is of the same kind as its parent. Nested subgraph trees may be created. | |
162 A subgraph's name is only interpreted relative to its parent. | |
163 A program can scan subgraphs under a given graph | |
164 using \fBagfstsubg\fP and \fRagnxtsubg\fP. A subgraph is | |
165 deleted with \fBagdelsubg\fP (or \fBagclose\fP). | |
166 .PP | |
167 By default, nodes are stored in ordered sets for efficient random | |
168 access to insert, find, and delete nodes. | |
169 The edges of a node are also stored in ordered sets. | |
170 The sets are maintained internally as splay tree dictionaries | |
171 using Phong Vo's cdt library. | |
172 .PP | |
173 \fBagnnodes\fP, \fBagnedges\fP, and \fBagdegree\fP return the | |
174 sizes of node and edge sets of a graph. The \fBagdegree\fP returns | |
175 the size of the edge set of a nodes, and takes flags | |
176 to select in-edges, out-edges, or both. | |
177 .PP | |
178 An \fBAgdisc_t\fP defines callbacks to be invoked by libcgraph when | |
179 initializing, modifying, or finalizing graph objects. (Casual users can ignore | |
180 the following.) Disciplines are kept on a stack. Libcgraph automatically | |
181 calls the methods on the stack, top-down. Callbacks are installed | |
182 with \fBagpushdisc\fP, uninstalled with \fBagpopdisc\fP, and | |
183 can be held pending or released via \fBagcallbacks\fP. | |
184 .PP | |
185 (Casual users may ignore the following. | |
186 When Libcgraph is compiled with Vmalloc (which is not the default), | |
187 each graph has its own heap. | |
188 Programmers may allocate application-dependent data within the | |
189 same heap as the rest of the graph. The advantage is that | |
190 a graph can be deleted by atomically freeing its entire heap | |
191 without scanning each individual node and edge. | |
192 .SH "NODES" | |
193 A node is created by giving a unique string name or | |
194 programmer defined 32-bit ID, and is represented by a | |
195 unique internal object. (Node equality can checked | |
196 by pointer comparison.) | |
197 .PP | |
198 \fBagnode\fP searches in a graph or subgraph for a node | |
199 with the given name, and returns it if found. | |
200 If not found, if \fBcreateflag\fP is boolean true | |
201 a new node is created and returned, otherwise a nil | |
202 pointer is returned. | |
203 \fBagidnode\fP allows a programmer to specify the node | |
204 by a unique 32-bit ID. | |
205 \fBagsubnode\fP performs a similar operation on | |
206 an existing node and a subgraph. | |
207 .Pp | |
208 \fBagfstnode\fP and \fBagnxtnode\fP scan node lists. | |
209 \fBagprvnode\fP and \fPaglstnode\fP are symmetric but scan backward. | |
210 The default sequence is order of creation (object timestamp.) | |
211 \fBagdelnode\fP removes a node from a graph or subgraph. | |
212 .SH "EDGES" | |
213 .PP | |
214 An abstract edge has two endpoint nodes called tail and head | |
215 where the all outedges of the same node have it as the tail | |
216 value and similarly all inedges have it as the head. | |
217 In an undirected graph, head and tail are interchangable. | |
218 If a graph has multi-edges between the same pair of nodes, | |
219 the edge's string name behaves as a secondary key. | |
220 .Pp | |
221 \fBagedge\fP searches in a graph of subgraph for an | |
222 edge between the given endpoints (with an optional | |
223 multi-edge selector name) and returns it if found. | |
224 Otherwise, if \fBcreateflag\fP is boolean true, | |
225 a new edge is created and returned: otherwise | |
226 a nil pointer is returned. If the \fBname\fP | |
227 is NULL, then an anonymous internal | |
228 value is generated. \fBagidedge\fP allows a programmer | |
229 to create an edge by giving its unique 32-bit ID. | |
230 \fBagfstin\fP, \fBagnxtint\fP, \fBagfstout\fP, and | |
231 \fBagnxtout\fP visit directed in- and out- edge lists, | |
232 and ordinarily apply only in directed graphs. | |
233 \fBagfstedge\fP and \fBagnxtedge\fP visit all edges | |
234 incident to a node. \fBagtail\fP and \fBaghead\fP | |
235 get the endpoint of an edge. | |
236 .SH "INTERNAL ATTRIBUTES" | |
237 Programmer-defined values may be dynamically | |
238 attached to graphs, subgraphs, nodes, and edges. | |
239 Such values are either uninterpreted binary records | |
240 (for implementing efficient algorithms) | |
241 or character string data (for I/O). | |
242 .SH "STRING ATTRIBUTES" | |
243 String attributes are handled automatically in reading | |
244 and writing graph files. | |
245 A string attribute is identified by name and by | |
246 an internal symbol table entry (\fBAgsym_t\fP) created by Libcgraph. | |
247 Attributes of nodes, edges, and graphs (with their subgraphs) | |
248 have separate namespaces. The contents of an \fBAgsym_t\fP | |
249 is listed below, followed by primitives to operate on string | |
250 attributes. | |
251 .P0 | |
252 typedef struct Agsym_s { /* symbol in one of the above dictionaries */ | |
253 Dtlink_t link; | |
254 char *name; /* attribute's name */ | |
255 char *defval; /* its default value for initialization */ | |
256 int id; /* its index in attr[] */ | |
257 unsigned char kind; /* referent object type */ | |
258 unsigned char fixed; /* immutable value */ | |
259 } Agsym_t; | |
260 .P1 | |
261 .PP | |
262 \fBagattr\fP creates or looks up attributes. | |
263 \fBkind\fP may be \fBAGRAPH\fP, \fBAGNODE\fP, or \fBAGEDGE\fP. | |
264 If \fBvalue\fP is \fB(char*)0)\fP, the request is to search | |
265 for an existing attribute of the given kind and name. | |
266 Otherwise, if the attribute already exists, its default | |
267 for creating new objects is set to the given value; | |
268 if it does not exist, a new attribute is created with the | |
269 given default, and the default is applied to all pre-existing | |
270 objects of the given kind. If \fBg\fP is NIL, the default is | |
271 set for all graphs created subsequently. | |
272 \fBagattrsym\fP is a helper function | |
273 that looks up an attribute for a graph object given as an argument. | |
274 \fBagnxtattr\fP permits traversing the list of attributes of | |
275 a given type. If \fBNIL\fP is passed as an argument it gets | |
276 the first attribute, otherwise it returns the next one in | |
277 succession or returns \fBNIL\fP at the end of the list. | |
278 \fBagget\fP and \fPagset\fP allow fetching and updating a | |
279 string attribute for an object taking the attribute name as | |
280 an argument. \fBagxget\fP and \fBagxset\fP do this but with | |
281 an attribute symbol table entry as an argument (to avoid | |
282 the cost of the string lookup). \fBagsafeset\fP is a | |
283 convenience function that ensures the given attribute is | |
284 declared before setting it locally on an object. | |
285 | |
286 .SH "STRINGS" | |
287 Libcgraph performs its own storage management of strings as | |
288 reference-counted strings. | |
289 The caller does not need to dynamically allocate storage. | |
290 .PP | |
291 \fBagstrdup\fP returns a pointer to a reference-counted copy of | |
292 the argument string, creating one if necessary. \fBagstrbind\fP | |
293 returns a pointer to a reference-counted string if it exists, or NULL if not. | |
294 All uses of cgraph strings need to be freed using \fBagstrfree\fP | |
295 in order to correctly maintain the reference count. | |
296 .PP | |
297 \fBagcanonStr\fP returns a pointer to a version of the input string | |
298 canonicalized for output for later re-parsing. This includes quoting | |
299 special characters and keywords. It uses its own internal buffer, so | |
300 the value will be lost on the next call to \fBagcanonStr\fP. | |
301 \fBagstrcanon\fP is an unsafe version of \fBagcanonStr\fP, in which | |
302 the application passes in a buffer as the second argument. Note that | |
303 the buffer may not be used; if the input string is in canonical form, | |
304 the function will just return a pointer to it. | |
305 .PP | |
306 The cgraph parser handles HTML-like strings. These should be | |
307 indistinguishable from other strings for most purposes. To create | |
308 an HTML-like string, use \fBagstrdup_html\fP. The \fBaghtmlstr\fP | |
309 function can be used to query if a string is an ordinary string or | |
310 an HTML-like string. | |
311 .SH "RECORDS" | |
312 Uninterpreted records may be attached to graphs, subgraphs, nodes, | |
313 and edges for efficient operations on values such as marks, weights, | |
314 counts, and pointers needed by algorithms. Application programmers | |
315 define the fields of these records, but they must be declared with | |
316 a common header as shown below. | |
317 .P0 | |
318 typedef struct Agrec_s { | |
319 Agrec_t header; | |
320 /* programmer-defined fields follow */ | |
321 } Agrec_t; | |
322 .P1 | |
323 Records are created and managed by Libcgraph. A programmer must | |
324 explicitly attach them to the objects in a graph, either to | |
325 individual objects one at a time via \fBagbindrec\fP, or to | |
326 all the objects of the same class in a graph via \fBaginit\fP. | |
327 The \fBname\fP argument a record distinguishes various types of records, | |
328 and is programmer defined (Libcgraph reserves the prefix \fB_ag\fR). | |
329 If size is 0, the call to \fBagbindrec\fP is simply a lookup. | |
330 \fBagdelrec\fP is the deletes records one at a time. | |
331 \fBagclean\fP does the same for all objects of the same | |
332 class in an entire graph. | |
333 | |
334 Internally, records are maintained in circular linked lists | |
335 attached to graph objects. | |
336 To allow referencing application-dependent data without function | |
337 calls or search, Libcgraph allows setting and locking the list | |
338 pointer of a graph, node, or edge on a particular record. | |
339 This pointer can be obtained with the macro \fBAGDATA(obj)\fP. | |
340 A cast, generally within a macro or inline function, | |
341 is usually applied to convert the list pointer to | |
342 an appropriate programmer-defined type. | |
343 | |
344 To control the setting of this pointer, | |
345 the \fBmove_to_front\fP flag may be \fBAG_MTF_FALSE\fP, | |
346 \fBAG_MTF_SOFT\fP, or \fBAG_MTF_HARD\fP accordingly. | |
347 The \fBAG_MTF_SOFT\fP field is only a hint that decreases | |
348 overhead in subsequent calls of \fBaggetrec\fP; | |
349 \fBAG_MTF_HARD\fP guarantees that a lock was obtained. | |
350 To release locks, use \fBAG_MTF_SOFT\fP or \fBAG_MTF_FALSE\fP. | |
351 Use of this feature implies cooperation or at least isolation | |
352 from other functions also using the move-to-front convention. | |
353 | |
354 .SH "DISCIPLINES" | |
355 (The following is not intended for casual users.) | |
356 Programmer-defined disciplines customize certain resources- | |
357 ID namespace, memory, and I/O - needed by Libcgraph. | |
358 A discipline struct (or NIL) is passed at graph creation time. | |
359 .P0 | |
360 struct Agdisc_s { /* user's discipline */ | |
361 Agmemdisc_t *mem; | |
362 Agiddisc_t *id; | |
363 Agiodisc_t *io; | |
364 } ; | |
365 .P1 | |
366 A default discipline is supplied when NIL is given for | |
367 any of these fields. | |
368 | |
369 An ID allocator discipline allows a client to control assignment | |
370 of IDs (uninterpreted 32-bit values) to objects, and possibly how | |
371 they are mapped to and from strings. | |
372 | |
373 .P0 | |
374 struct Agiddisc_s { /* object ID allocator */ | |
375 void *(*open)(Agraph_t *g); /* associated with a graph */ | |
376 int (*map)(void *state, int objtype, char *str, ulong *id, int createflag); | |
377 int (*alloc)(void *state, int objtype, ulong id); | |
378 void (*free)(void *state, int objtype, ulong id); | |
379 char *(*print)(void *state, int objtype, ulong id); | |
380 void (*close)(void *state); | |
381 } ; | |
382 .P1 | |
383 | |
384 \f5open\fP permits the ID discipline to initialize any data | |
385 structures that maintains per individual graph. | |
386 Its return value is then passed as the first argument to | |
387 all subsequent ID manager calls. | |
388 | |
389 \f5alloc\fP informs the ID manager that Libcgraph is attempting | |
390 to create an object with a specific ID that was given by a client. | |
391 The ID manager should return TRUE (nonzero) if the ID can be | |
392 allocated, or FALSE (which aborts the operation). | |
393 | |
394 \f5free\fP is called to inform the ID manager that the | |
395 object labeled with the given ID is about to go out of existence. | |
396 | |
397 \f5map\fP is called to create or look-up IDs by string name | |
398 (if supported by the ID manager). Returning TRUE (nonzero) | |
399 in all cases means that the request succeeded (with a valid | |
400 ID stored through \f5result\fP. There are four cases: | |
401 .PP | |
402 \f5name != NULL\fP and \f5createflag == 1\fP: | |
403 This requests mapping a string (e.g. a name in a graph file) into a new ID. | |
404 If the ID manager can comply, then it stores the result and returns TRUE. | |
405 It is then also responsible for being able to \f5print\fP the ID again | |
406 as a string. Otherwise the ID manager may return FALSE but it must | |
407 implement the following (at least for graph file reading and writing to work): | |
408 .PP | |
409 \f5name == NULL\fP and \f5createflag == 1\fP: | |
410 The ID manager creates a unique new ID of its own choosing. | |
411 Although it may return FALSE if it does not support anonymous objects, | |
412 but this is strongly discouraged (to support "local names" in graph files.) | |
413 .PP | |
414 \f5name != NULL\fP and \f5createflag == 0\fP: | |
415 This is a namespace probe. If the name was previously mapped into | |
416 an allocated ID by the ID manager, then the manager must return this ID. | |
417 Otherwise, the ID manager may either return FALSE, or may store | |
418 any unallocated ID into result. (This is convenient, for example, | |
419 if names are known to be digit strings that are directly converted into 32 bit values.) | |
420 .PP | |
421 \f5name == NULL\fP and \f5createflag == 0\fP: forbidden. | |
422 .PP | |
423 \f5print\fP is allowed to return a pointer to a static buffer; | |
424 a caller must copy its value if needed past subsequent calls. | |
425 \f5NULL\fP should be returned by ID managers that do not map names. | |
426 .PP | |
427 The \f5map\fP and \f5alloc\fP calls do not pass a pointer to the | |
428 newly allocated object. If a client needs to install object | |
429 pointers in a handle table, it can obtain them via | |
430 new object callbacks. | |
431 .P0 | |
432 struct Agiodisc_s { | |
433 int (*fread)(void *chan, char *buf, int bufsize); | |
434 int (*putstr)(void *chan, char *str); | |
435 int (*flush)(void *chan); /* sync */ | |
436 /* error messages? */ | |
437 } ; | |
438 | |
439 struct Agmemdisc_s { /* memory allocator */ | |
440 void *(*open)(void); /* independent of other resources */ | |
441 void *(*alloc)(void *state, size_t req); | |
442 void *(*resize)(void *state, void *ptr, size_t old, size_t req); | |
443 void (*free)(void *state, void *ptr); | |
444 void (*close)(void *state); | |
445 } ; | |
446 .P1 | |
447 | |
448 .SH "EXAMPLE PROGRAM" | |
449 .P0 | |
450 #include <graphviz/cgraph.h> | |
451 typedef struct mydata_s {Agrec_t hdr; int x,y,z;} mydata; | |
452 | |
453 main(int argc, char **argv) | |
454 { | |
455 Agraph_t *g; | |
456 Agnode_t *v; | |
457 Agedge_t *e; | |
458 Agsym_t *attr; | |
459 Dict_t *d | |
460 int cnt; | |
461 mydata *p; | |
462 | |
463 if (g = agread(stdin,NIL(Agdisc_t*))) { | |
464 cnt = 0; attr = 0; | |
465 while (attr = agnxtattr(g, AGNODE, attr)) cnt++; | |
466 printf("The graph %s has %d attributes\n",agnameof(g),cnt); | |
467 | |
468 /* make the graph have a node color attribute, default is blue */ | |
469 attr = agattr(g,AGNODE,"color","blue"); | |
470 | |
471 /* create a new graph of the same kind as g */ | |
472 h = agopen("tmp",g->desc); | |
473 | |
474 /* this is a way of counting all the edges of the graph */ | |
475 cnt = 0; | |
476 for (v = agfstnode(g); v; v = agnxtnode(g,v)) | |
477 for (e = agfstout(g,v); e; e = agnxtout(g,e)) | |
478 cnt++; | |
479 | |
480 /* attach records to edges */ | |
481 for (v = agfstnode(g); v; v = agnxtnode(g,v)) | |
482 for (e = agfstout(g,v); e; e; = agnxtout(g,e)) { | |
483 p = (mydata*) agbindrec(g,e,"mydata",sizeof(mydata),TRUE); | |
484 p->x = 27; /* meaningless data access example */ | |
485 ((mydata*)(AGDATA(e)))->y = 999; /* another example */ | |
486 } | |
487 } | |
488 } | |
489 .P1 | |
490 .SH "EXAMPLE GRAPH FILES" | |
491 .P0 | |
492 digraph G { | |
493 a -> b; | |
494 c [shape=box]; | |
495 a -> c [weight=29,label="some text]; | |
496 subgraph anything { | |
497 /* the following affects only x,y,z */ | |
498 node [shape=circle]; | |
499 a; x; y -> z; y -> z; /* multiple edges */ | |
500 } | |
501 } | |
502 | |
503 strict graph H { | |
504 n0 -- n1 -- n2 -- n0; /* a cycle */ | |
505 n0 -- {a b c d}; /* a star */ | |
506 n0 -- n3; | |
507 n0 -- n3 [weight=1]; /* same edge because graph is strict */ | |
508 } | |
509 .P1 | |
510 .SH "SEE ALSO" | |
511 Libcdt(3) | |
512 | |
513 .SH "BUGS" | |
514 It is difficult to change endpoints of edges, delete string attributes or | |
515 modify edge keys. The work-around is to create a new object and copy the | |
516 contents of an old one (but new object obviously has a different ID, | |
517 internal address, and object creation timestamp). | |
518 | |
519 The API lacks convenient functions to substitute programmer-defined ordering of | |
520 nodes and edges but in principle this can be supported. | |
521 .SH "AUTHOR" | |
522 Stephen North, north@research.att.com, AT&T Research. |