56 lines
1.8 KiB
C
56 lines
1.8 KiB
C
#ifndef INCLUDED_C_DIRECTEDDFS_H
|
|||
|
|
#define INCLUDED_C_DIRECTEDDFS_H
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_DIGRAPH_H
|
||
|
|
#include <c_Digraph.h>
|
||
|
|
#endif /*INCLUDED_C_DIGRAPH_H*/
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
c_bool_t* marked; /* Visited tracking array (size of graph->V) */
|
||
|
|
c_size_t count; /* Total number of vertices reachable from source(s) */
|
||
|
|
c_Allocator_t allocator;
|
||
|
|
}c_DirectedDFS_t;
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Computes vertices reachable from a single source vertex 's'
|
||
|
|
*/
|
||
|
|
c_err_t c_DirectedDFS_Init(c_DirectedDFS_t* self, const c_Digraph_t* graph, c_size_t s, c_Allocator_t* allocator);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Computes vertices reachable from a list of multiple source vertices
|
||
|
|
*/
|
||
|
|
c_err_t c_DirectedDFS_InitMulti(c_DirectedDFS_t* self, const c_Digraph_t* graph, const c_size_t* sources, c_size_t source_count, c_Allocator_t* allocator);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Releases internal tracking buffers
|
||
|
|
*/
|
||
|
|
void c_DirectedDFS_Destroy(c_DirectedDFS_t* self);
|
||
|
|
|
||
|
|
/* ================================================================================================================== */
|
||
|
|
/* Inline Query Interfaces */
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Is there a directed path from the source(s) to vertex 'v'?
|
||
|
|
*/
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
c_bool_t c_DirectedDFS_HasPathTo(const c_DirectedDFS_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 Returns the total count of reachable vertices
|
||
|
|
*/
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
c_size_t c_DirectedDFS_GetCount(const c_DirectedDFS_t* self) {
|
||
|
|
return self ? self->count : 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif /*INCLUDED_C_DIRECTEDDFS_H*/
|