Lines Matching defs:gr

21 	Graph_t		*gr = GRSTRUCTOF(Graph_t, nddc, disc);
25 { if(gr->disc && gr->disc->eventf)
26 (*gr->disc->eventf)(gr, GR_NODE|GR_CLOSING, node, gr->disc );
54 Graph_t *gr = GRSTRUCTOF(Graph_t, eddc, disc);
58 { if(gr->disc && gr->disc->eventf)
59 (*gr->disc->eventf)(gr, GR_EDGE|GR_CLOSING, edge, gr->disc );
71 Grnode_t* grnode(Graph_t* gr, Void_t* label, int type)
77 if(!gr)
82 nd = dtsearch(gr->nodes, &node);
88 gredge(gr, e->tail, e->head, e->label, -1);
92 gredge(gr, e->tail, e->head, e->label, -1);
94 dtdelete(gr->nodes, nd);
103 if((sz = gr->disc ? gr->disc->nodesz : 0) < sizeof(Grnode_t) )
111 if(gr->disc && gr->disc->eventf)
112 (*gr->disc->eventf)(gr, GR_NODE|GR_OPENING, nd, gr->disc);
114 return (Grnode_t*)dtinsert(gr->nodes, nd);
118 Gredge_t* gredge(Graph_t* gr, Grnode_t* tail, Grnode_t* head, Void_t* label, int type)
124 if(gr->type == GR_UNDIRECTED) /* enforce tail <= head */
133 ed = dtsearch(gr->edges, &edge);
154 dtdelete(gr->edges, ed);
162 if((sz = gr->disc ? gr->disc->edgesz : 0) < sizeof(Gredge_t))
173 if(gr->disc && gr->disc->eventf)
174 (*gr->disc->eventf)(gr, GR_EDGE|GR_OPENING, ed, gr->disc);
176 return (Gredge_t*)dtinsert(gr->edges, ed);
205 int grrestore(Graph_t* gr)
210 for(nd = (Grnode_t*)dtflatten(gr->nodes); nd; nd = (Grnode_t*)dtlink(gr,nd))
215 for(ed = (Gredge_t*)dtflatten(gr->edges); ed; ed = (Gredge_t*)dtlink(gr,ed))
225 int grclose(Graph_t* gr)
229 if(!gr)
232 if(gr->disc && gr->disc->eventf )
233 if((*gr->disc->eventf)(gr, GR_GRAPH|GR_CLOSING, 0, gr->disc) < 0)
236 if(gr->nodes)
237 dtclose(gr->nodes);
238 if(gr->edges)
239 dtclose(gr->edges);
241 for(dt = gr->data; dt; dt = next)
246 free(gr);
252 Graph_t *gr;
257 if(!(gr = (Graph_t*)calloc(1,sz)) )
260 gr->type = type;
262 DTDISC(&gr->nddc, 0, 0, 0, 0, nodefree, nodecmp, 0, 0, 0);
263 DTDISC(&gr->eddc, 0, 0, 0, 0, edgefree, edgecmp, 0, 0, 0);
265 if(!(gr->nodes = dtopen(&gr->nddc, Dtoset)) ||
266 !(gr->edges = dtopen(&gr->eddc, Dtoset)) )
267 { grclose(gr);
271 if((gr->disc = disc) && (*gr->disc->eventf)(gr, GR_GRAPH|GR_OPENING, 0, gr->disc) < 0)
272 { grclose(gr);
276 return gr;