56 lines
2.0 KiB
C
56 lines
2.0 KiB
C
#ifndef INCLUDED_C_NONRECURSIVEDIRECTEDCYCLE_H
|
|
#define INCLUDED_C_NONRECURSIVEDIRECTEDCYCLE_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 mocked DFS stack */
|
|
c_VertexIdList_t cycle; /* Stores the cycle sequence if found */
|
|
c_Allocator_t allocator; /* Deep copy of the user-provided allocator */
|
|
} c_NonrecursiveDirectedCycle_t;
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
/**
|
|
* @brief Non-recursively 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_NonrecursiveDirectedCycle_Init(c_NonrecursiveDirectedCycle_t* self, const c_Digraph_t* graph, c_Allocator_t* allocator);
|
|
|
|
/**
|
|
* @brief Releases internal tracking buffers
|
|
*/
|
|
void c_NonrecursiveDirectedCycle_Destroy(c_NonrecursiveDirectedCycle_t* self);
|
|
|
|
/**
|
|
* @brief Does the digraph have a directed cycle?
|
|
*/
|
|
C_STATIC_FORCE_INLINE
|
|
c_bool_t c_NonrecursiveDirectedCycle_HasCycle(c_NonrecursiveDirectedCycle_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_NonrecursiveDirectedCycle_GetCycle(c_NonrecursiveDirectedCycle_t* self, c_VertexIdList_t* out_cycle);
|
|
|
|
|
|
#endif /*INCLUDED_C_NONRECURSIVEDIRECTEDCYCLE_H*/
|