The LevAWC Project
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Pages
graph.h
Go to the documentation of this file.
1 /*
2  * _____
3  * ANSI / ___/
4  * / /__
5  * \___/
6  *
7  * Filename: graph.h
8  * Author : Kyle Loudon/Dan Levin
9  * Date : Thu Jan 15 09:25:57 2015
10  * Version : 0.51
11  * ---
12  * Description: A generic graph ADT - written in ANSI C.
13  *
14  * Date Revision message
15  * 150331 This code ready for version 0.51
16  *
17  */
22 #ifndef _GRAPH_H_
23 #define _GRAPH_H_
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <malloc.h>
29 #include <assert.h>
30 
31 #include "slist.h"
32 #include "set.h"
33 #include "utils.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
42  typedef enum VertexColor_ {white, gray, black} VertexColor;
43 
50  typedef struct Vertex_ *Vertex;
57  typedef struct Graph_ *Graph;
58 
59  typedef SlistNode VertexNode;
60  typedef SlistNode EdgeNode;
61 
62  /* FUNCTION DECLARATIONS/PUBLIC INTERFACE */
63  /* --- Maintenance functions --- */
93  Graph GRAPHinit(int (*match)(const void *key1, const void *key2),
94  void (*destroy)(void *data));
95 
110  void GRAPHdestroy(Graph graph);
111 
112  /* --- Data manipulation functions --- */
129  int GRAPHinsvertex(Graph graph, const void *vtxdata);
130 
165  int GRAPHinsedge(Graph graph, const void *vtxdata, const void *adjdata);
166 
199  int GRAPHremvertex(Graph graph, void **vtxdata);
200 
228  int GRAPHremedge(Graph graph, void *vtxdata, void **edgedata);
229 
230  /* --- Getter functions --- */
238  VertexNode GRAPHgetvertexhead(Graph graph);
239 
248  EdgeNode GRAPHgetedgehead(VertexNode vtxnode);
249 
257  VertexNode GRAPHgetvertexnext(VertexNode vtxnode);
258 
267  EdgeNode GRAPHgetedgenext(EdgeNode enode);
268 
276  void *GRAPHgetvertexdata(VertexNode vtxnode);
277 
286  void *GRAPHgetedgedata(EdgeNode enode);
287 
299  int GRAPHgetedgecount(VertexNode vtxnode);
300 
307  int GRAPHvcount(Graph graph);
308 
316  int GRAPHecount(Graph graph);
317 
318  /* --- Traversal functions --- */
338  void GRAPHprint(Graph graph, void (*vtxcallback)(const void *data),
339  void (*edgecallback)(const void *data));
340 
354  void GRAPHtraverse(Graph graph, void (*vtxcallback)(const void *data), void (*edgecallback)(const void *data));
355 
356  /* --- Search functions --- */
374  VertexNode GRAPHfindvertex(const Graph graph, const void *vtxdata);
375 
408  EdgeNode GRAPHfindedge(const Graph graph, const void *vtxdata, const void *edgedata);
409 
410  /* --- Miscellaneous functions --- */
427  int GRAPHis_adjacent(const Graph graph, const void *vtxdata, const void *edgedata);
428 
444  int GRAPHis_isolated(const Graph graph, const void *vtxdata);
445 
446 #ifdef __cplusplus
447 }
448 #endif
449 
450 #endif /* _GRAPH_H_ */