#ifndef INCLUDED_C_DIGRAPH_H #define INCLUDED_C_DIGRAPH_H #ifndef INCLUDED_C_TYPES_H #include #endif /*INCLUDED_C_TYPES_H*/ #ifndef INCLUDED_C_ALLOCATOR_H #include #endif /*INCLUDED_C_ALLOCATOR_H*/ #ifndef INCLUDED_C_ADJLIST_H #include #endif /*INCLUDED_C_ADJLIST_H*/ /* ------------------------------------------------------------------------------------------------------------------ */ /* */ typedef struct { c_size_t V; c_size_t E; c_AdjList_t* adj_list; c_size_t* indegree; c_Allocator_t allocator; }c_Digraph_t; /* ------------------------------------------------------------------------------------------------------------------ */ /* */ c_err_t c_Digraph_Init(c_Digraph_t* self, c_size_t V, c_Allocator_t* alloc); void c_Digraph_Destroy(c_Digraph_t* self); c_err_t c_Digraph_AddEdge(c_Digraph_t* self, c_size_t from, c_size_t to); c_err_t c_Digraph_RemoveEdge(c_Digraph_t* self, c_size_t from, c_size_t to); c_err_t c_Digraph_GetEdge(c_Digraph_t* self, c_size_t from, c_size_t to, c_size_t * edge_idx); c_bool_t c_Digraph_HasEdge(const c_Digraph_t* self, c_size_t from, c_size_t to); c_err_t c_Digraph_Resize(c_Digraph_t* self, c_size_t new_V); c_size_t c_Digraph_GetDegree(c_Digraph_t* self, c_size_t v, c_bool_t out_degree_only); c_err_t c_Digraph_Reverse(c_Digraph_t* self, c_Digraph_t* out_reversed); C_STATIC_FORCE_INLINE c_size_t c_Digraph_GetV(const c_Digraph_t* self) { return self ? self->V : 0; } C_STATIC_FORCE_INLINE c_size_t c_Digraph_GetE(const c_Digraph_t* self) { return self ? self->E : 0; } C_STATIC_FORCE_INLINE c_AdjList_t* c_Digraph_GetAdj(const c_Digraph_t* self, c_size_t v) { if (!self || v >= self->V) return NULL; return &(self->adj_list[v]); } C_STATIC_FORCE_INLINE c_size_t c_Digraph_GetOutDegree(c_Digraph_t* self, c_size_t v) { if (!self || v >=self->V) return 0; return c_AdjList_GetSize(&self->adj_list[v]); } C_STATIC_FORCE_INLINE c_size_t c_Digraph_GetInDegree(c_Digraph_t* self, c_size_t v) { if (!self || v >=self->V) return 0; return self->indegree[v]; } #endif /*INCLUDED_C_DIGRAPH_H*/