[8] | 1 | #ifndef GRAPH_H |
---|
| 2 | #define GRAPH_H |
---|
| 3 | |
---|
| 4 | typedef char *gGeneric; |
---|
| 5 | |
---|
| 6 | typedef struct graph_struct { |
---|
| 7 | gGeneric user_data; |
---|
| 8 | } graph_t; |
---|
| 9 | |
---|
| 10 | typedef struct vertex_struct { |
---|
| 11 | gGeneric user_data; |
---|
| 12 | } vertex_t; |
---|
| 13 | |
---|
| 14 | typedef struct edge_struct { |
---|
| 15 | gGeneric user_data; |
---|
| 16 | } edge_t; |
---|
| 17 | |
---|
| 18 | typedef void (*GRAPH_PFV)(gGeneric); |
---|
| 19 | typedef gGeneric (*GRAPH_PFG)(gGeneric); |
---|
| 20 | |
---|
| 21 | EXTERN graph_t *g_alloc ARGS((void)); |
---|
| 22 | EXTERN void g_free ARGS((graph_t *, void(*)(gGeneric), void(*)(gGeneric), void(*)(gGeneric))); |
---|
| 23 | EXTERN void g_check ARGS((graph_t *)); |
---|
| 24 | EXTERN graph_t *g_dup ARGS((graph_t *, gGeneric(*)(gGeneric), gGeneric(*)(gGeneric), gGeneric(*)(gGeneric))); |
---|
| 25 | |
---|
| 26 | EXTERN lsList g_get_vertices ARGS((graph_t *)); |
---|
| 27 | |
---|
| 28 | #define foreach_vertex(g, lgen, v) \ |
---|
| 29 | for (lgen = lsStart(g_get_vertices(g)); \ |
---|
| 30 | lsNext(lgen, &v, LS_NH) == LS_OK \ |
---|
| 31 | || ((void) lsFinish(lgen), 0); ) |
---|
| 32 | |
---|
| 33 | #define foreach_edge(g, lgen, e) \ |
---|
| 34 | for (lgen = lsStart(g_get_edges(g)); \ |
---|
| 35 | lsNext(lgen, &e, LS_NH) == LS_OK \ |
---|
| 36 | || ((void) lsFinish(lgen), 0); ) |
---|
| 37 | |
---|
| 38 | EXTERN vertex_t *g_add_vertex ARGS((graph_t *)); |
---|
| 39 | EXTERN void g_delete_vertex ARGS((vertex_t *, void (*)(gGeneric), void (*)(gGeneric))); |
---|
| 40 | EXTERN graph_t *g_vertex_graph ARGS((vertex_t *)); |
---|
| 41 | |
---|
| 42 | EXTERN lsList g_get_edges ARGS((graph_t *)); |
---|
| 43 | EXTERN lsList g_get_in_edges ARGS((vertex_t *)); |
---|
| 44 | EXTERN lsList g_get_out_edges ARGS((vertex_t *)); |
---|
| 45 | |
---|
| 46 | #define foreach_in_edge(v, lgen, e) \ |
---|
| 47 | for (lgen = lsStart(g_get_in_edges(v)); \ |
---|
| 48 | lsNext(lgen, &e, LS_NH) == LS_OK \ |
---|
| 49 | || ((void) lsFinish(lgen), 0); ) |
---|
| 50 | |
---|
| 51 | #define foreach_out_edge(v, lgen, e) \ |
---|
| 52 | for (lgen = lsStart(g_get_out_edges(v)); \ |
---|
| 53 | lsNext(lgen, &e, LS_NH) == LS_OK \ |
---|
| 54 | || ((void) lsFinish(lgen), 0); ) |
---|
| 55 | |
---|
| 56 | EXTERN edge_t *g_add_edge ARGS((vertex_t *, vertex_t *)); |
---|
| 57 | EXTERN void g_delete_edge ARGS((edge_t *, void (*)(gGeneric))); |
---|
| 58 | EXTERN graph_t *g_edge_graph ARGS((edge_t *)); |
---|
| 59 | EXTERN vertex_t *g_e_source ARGS((edge_t *)); |
---|
| 60 | EXTERN vertex_t *g_e_dest ARGS((edge_t *)); |
---|
| 61 | |
---|
| 62 | EXTERN array_t *g_dfs ARGS((graph_t *)); |
---|
| 63 | EXTERN int g_is_acyclic ARGS((graph_t *)); |
---|
| 64 | EXTERN array_t *g_graph_sort ARGS((graph_t *, int (*)(const void *, const void *))); |
---|
| 65 | |
---|
| 66 | EXTERN st_table *g_reachable ARGS((graph_t *, st_table *)); |
---|
| 67 | EXTERN st_table *g_EF ARGS((graph_t *, st_table *)); |
---|
| 68 | EXTERN st_table *g_SCC ARGS((graph_t *, st_table *)); |
---|
| 69 | |
---|
| 70 | #endif |
---|