This commit is contained in:
2026-09-07 18:48:16 +08:00
parent 1564716731
commit c945aa211f
138 changed files with 10337 additions and 150 deletions
+46
View File
@@ -0,0 +1,46 @@
#ifndef INCLUDED_C_TRANSITIVECLOSURE_H
#define INCLUDED_C_TRANSITIVECLOSURE_H
#ifndef INCLUDED_C_DIGRAPH_H
#include <c_Digraph.h>
#endif /*INCLUDED_C_DIGRAPH_H*/
#ifndef INCLUDED_C_NONRECURSIVEDIRECTEDDFS
#include <c_NonrecursiveDirectedDFS.h>
#endif /*INCLUDED_C_NONRECURSIVEDIRECTEDDFS*/
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
typedef struct {
c_NonrecursiveDirectedDFS_t* dfs_matrix; /* Array of DFS instances (size of graph->V) */
c_size_t V; /* Stored vertex count for boundary safe checks */
c_Allocator_t allocator; /* Deep copy of the user-provided allocator */
} c_TransitiveClosure_t;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
/**
* @brief Computes the transitive closure of a digraph to support all-pairs reachability queries.
* @param allocator Explicit allocator context used to allocate internal search objects
*/
c_err_t c_TransitiveClosure_Init(c_TransitiveClosure_t* self, c_Digraph_t* graph, c_Allocator_t* allocator);
/**
* @brief Releases internal tracking buffers and all embedded search matrices
*/
void c_TransitiveClosure_Destroy(c_TransitiveClosure_t* self);
/**
* @brief Is vertex 'v' reachable from vertex 'u'?
* @return C_TRUE if there is a directed path from 'u' to 'v', C_FALSE otherwise
*/
C_STATIC_FORCE_INLINE
c_bool_t c_TransitiveClosure_Reachable(c_TransitiveClosure_t* self, c_size_t u, c_size_t v) {
if (!self || !self->dfs_matrix || u >= self->V || v >= self->V) return C_FALSE;
return c_NonrecursiveDirectedDFS_HasPathTo(&self->dfs_matrix[u], v, self->V);
}
#endif /*INCLUDED_C_TRANSITIVECLOSURE_H*/