]> wirehaze git hosting - graph-theory.git/blob - graph/adj.h

wirehaze git hosting

refac
[graph-theory.git] / graph / adj.h
1 #ifndef GRAPH_H
2 #define GRAPH_H
3
4 /* adjacency list implementation */
5
6 struct edge;
7
8 struct vertex
9 {
10 struct edge *adj; /* edges linked list */
11 };
12
13 struct edge /* probably not a good name for this */
14 {
15 struct vertex *to; /* other vertex in edge */
16 struct edge *next;
17 };
18
19 struct graph
20 {
21 struct vertex *v; /* array of vertices */
22 unsigned int nv; /* number of vertices */
23 };
24
25 struct graph *new_graph (unsigned int nv);
26 void free_graph (struct graph *g);
27
28 int add_arc (struct graph *g, unsigned int vi, unsigned int vj);
29 void del_arc (struct graph *g, unsigned int vi, unsigned int vj);
30
31 int add_edge (struct graph *g, unsigned int vi, unsigned int vj);
32 void del_edge (struct graph *g, unsigned int vi, unsigned int vj);
33
34 static __inline__ unsigned int
35 vertex_id (struct graph *g, struct vertex *v)
36 {
37 return (unsigned int)(v - g->v);
38 }
39
40 #endif /* GRAPH_H */