Graph
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#ifndef INCLUDED_C_DIRECTEDCYCLE_H
|
||||
#define INCLUDED_C_DIRECTEDCYCLE_H
|
||||
|
||||
#ifndef INCLUDED_C_DIGRAPH_H
|
||||
#include <c_Digraph.h>
|
||||
#endif /*INCLUDED_C_DIGRAPH_H*/
|
||||
|
||||
#ifndef INCLUDED_C_VERTEXIDLIST_H
|
||||
#include <c_VertexIdList.h>
|
||||
#endif /*INCLUDED_C_VERTEXIDLIST_H*/
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
typedef struct {
|
||||
c_bool_t* marked; /* Visited tracking array (size of graph->V) */
|
||||
c_size_t* edge_to; /* edge_to[w] = last edge on path to w */
|
||||
c_bool_t* on_stack; /* Keeps track of vertices currently on the recursive DFS stack */
|
||||
c_VertexIdList_t cycle; /* Stores the cycle sequence if found */
|
||||
c_Allocator_t allocator; /* Deep copy of the user-provided allocator */
|
||||
} c_DirectedCycle_t;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
/**
|
||||
* @brief Determines if the digraph has a directed cycle, and if so, finds one.
|
||||
* @param allocator Explicit allocator context used to allocate internal routing arrays
|
||||
*/
|
||||
c_err_t c_DirectedCycle_Init(c_DirectedCycle_t* self, const c_Digraph_t* graph, c_Allocator_t* allocator);
|
||||
|
||||
/**
|
||||
* @brief Releases internal tracking buffers
|
||||
*/
|
||||
void c_DirectedCycle_Destroy(c_DirectedCycle_t* self);
|
||||
|
||||
/**
|
||||
* @brief Does the digraph have a directed cycle?
|
||||
*/
|
||||
C_STATIC_FORCE_INLINE c_bool_t c_DirectedCycle_HasCycle(c_DirectedCycle_t* self) {
|
||||
if (!self) return C_FALSE;
|
||||
return !c_VertexIdList_IsEmpty(&self->cycle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the vertices on a directed cycle.
|
||||
* @param out_cycle An initialized c_VertexIdList_t container to collect the sequence.
|
||||
*/
|
||||
c_err_t c_DirectedCycle_GetCycle(c_DirectedCycle_t* self, c_VertexIdList_t* out_cycle);
|
||||
|
||||
|
||||
#endif /*INCLUDED_C_DIRECTEDCYCLE_H*/
|
||||
Reference in New Issue
Block a user