54 lines
1.8 KiB
C
54 lines
1.8 KiB
C
#ifndef INCLUDED_C_CYCLE_H
|
|
#define INCLUDED_C_CYCLE_H
|
|
|
|
#ifndef INCLUDED_C_GRAPH_H
|
|
#include <c_Graph.h>
|
|
#endif /*INCLUDED_C_GRAPH_H*/
|
|
|
|
|
|
#ifndef INCLUDED_C_VERTEXIDLIST_H
|
|
#include <c_VertexIdList.h>
|
|
#endif /*INCLUDED_C_VERTEXIDLIST_H*/
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
typedef struct {
|
|
c_bool_t* marked; // marked[v] = has vertex v been visited?
|
|
c_size_t* edge_to; // edge_to[v] = previous vertex on DFS path to v
|
|
c_VertexIdList_t cycle; // Stores the path sequence of the detected cycle
|
|
c_bool_t has_cycle; // Global structural cycle status flag
|
|
c_size_t V; // Cached local vertex dimension boundary
|
|
c_Allocator_t allocator; // Memory allocator copy
|
|
} c_Cycle_t;
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
/**
|
|
* @brief Computes whether the undirected graph contains a cycle.
|
|
* @param self Pointer to the uninitialized cycle tracking structure.
|
|
* @param G Pointer to the constant target graph object to verify.
|
|
* @param allocator Memory allocator instance pointer to deploy.
|
|
* @return C_SUCCESS on success, or an error status code on allocation failure.
|
|
*/
|
|
c_err_t c_Cycle_Init(c_Cycle_t* self, const c_Graph_t* G, c_Allocator_t* allocator);
|
|
|
|
/**
|
|
* @brief Drops all internal allocation states within the cycle instance safely.
|
|
*/
|
|
void c_Cycle_Destroy(c_Cycle_t* self);
|
|
|
|
/**
|
|
* @brief Does the graph contain at least one cycle?
|
|
*/
|
|
c_bool_t c_Cycle_HasCycle(const c_Cycle_t* self);
|
|
|
|
/**
|
|
* @brief Returns the vertex sequence forming the cycle path, or empty if acyclic.
|
|
*/
|
|
const c_VertexIdList_t* c_Cycle_Path(const c_Cycle_t* self);
|
|
|
|
#endif /*INCLUDED_C_CYCLE_H*/
|