/* adjacency list implementation */
-struct vertex;
struct edge;
-struct graph;
-struct edge
+struct vertex
{
- struct vertex *to;
- struct edge *next;
+ struct edge *adj; /* edges linked list */
};
-struct vertex
+struct edge /* probably not a good name for this */
{
- struct edge *adj;
+ struct vertex *to; /* other vertex in edge */
+ struct edge *next;
};
struct graph
{
- struct vertex *v;
- unsigned int nv;
+ struct vertex *v; /* array of vertices */
+ unsigned int nv; /* number of vertices */
};
struct graph *new_graph (unsigned int nv);
+void free_graph (struct graph *g);
+
+int add_arc (struct graph *g, unsigned int vi, unsigned int vj);
+void del_arc (struct graph *g, unsigned int vi, unsigned int vj);
-int new_arc (struct graph *g, unsigned int vi, unsigned int vj);
+int add_edge (struct graph *g, unsigned int vi, unsigned int vj);
+void del_edge (struct graph *g, unsigned int vi, unsigned int vj);
-int new_edge (struct graph *g, unsigned int vi, unsigned int vj);
+static __inline__ unsigned int
+vertex_id (struct graph *g, struct vertex *v)
+{
+ return (unsigned int)(v - g->v);
+}
#endif /* GRAPH_H */