Graph
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#ifndef INCLUDED_C_DEPTHFIRSTDIRECTEDPATHS_H
|
||||
#define INCLUDED_C_DEPTHFIRSTDIRECTEDPATHS_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 from s to w */
|
||||
c_size_t s; /* Source vertex */
|
||||
c_Allocator_t allocator; /* Copied allocator from the graph for isolation */
|
||||
} c_DepthFirstDirectedPaths_t;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
/**
|
||||
* @brief Computes a directed path tree from a single source vertex 's' using DFS
|
||||
*/
|
||||
c_err_t c_DepthFirstDirectedPaths_Init(c_DepthFirstDirectedPaths_t* self, const c_Digraph_t* graph, c_size_t s, c_Allocator_t* allocator);
|
||||
|
||||
/**
|
||||
* @brief Releases internal tracking buffers
|
||||
*/
|
||||
void c_DepthFirstDirectedPaths_Destroy(c_DepthFirstDirectedPaths_t* self);
|
||||
|
||||
/**
|
||||
* @brief Is there a directed path from the source 's' to vertex 'v'?
|
||||
*/
|
||||
C_STATIC_FORCE_INLINE c_bool_t c_DepthFirstDirectedPaths_HasPathTo(c_DepthFirstDirectedPaths_t* self, c_size_t v, c_size_t total_V) {
|
||||
if (!self || !self->marked || v >= total_V) return C_FALSE;
|
||||
return self->marked[v];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reconstructs the exact path from source 's' to vertex 'v' and appends it to out_path
|
||||
* @param out_path An initialized c_VertexIdList_t container to collect the sequence
|
||||
*/
|
||||
c_err_t c_DepthFirstDirectedPaths_PathTo(c_DepthFirstDirectedPaths_t* self, c_size_t v, c_size_t total_V, c_VertexIdList_t* out_path);
|
||||
|
||||
|
||||
#endif /*INCLUDED_C_DEPTHFIRSTDIRECTEDPATHS_H*/
|
||||
Reference in New Issue
Block a user