#ifndef INCLUDED_C_KOSARAJUSHARIRSCC_H #define INCLUDED_C_KOSARAJUSHARIRSCC_H #ifndef INCLUDED_C_DIGRAPH_H #include #endif /*INCLUDED_C_DIGRAPH_H*/ #ifndef INCLUDED_C_VERTEXIDLIST_H #include #endif /*INCLUDED_C_VERTEXIDLIST_H*/ /* ------------------------------------------------------------------------------------------------------------------ */ /* */ typedef struct { c_bool_t* marked; /* Visited tracking array (size of graph->V) */ c_size_t* id; /* id[v] = component identifier containing v (0 to count-1) */ c_size_t count; /* Total number of strongly connected components discovered */ c_size_t V; c_Allocator_t allocator; /* Deep copy of the user-provided allocator */ } c_KosarajuSharirSCC_t; /* ------------------------------------------------------------------------------------------------------------------ */ /* */ /** * @brief Computes strongly connected components for the specified digraph. * @param allocator Explicit allocator context used to allocate internal arrays */ c_err_t c_KosarajuSharirSCC_Init(c_KosarajuSharirSCC_t* self, c_Digraph_t* graph, c_Allocator_t* allocator); /** * @brief Releases internal tracking buffers */ void c_KosarajuSharirSCC_Destroy(c_KosarajuSharirSCC_t* self); /** * @brief Are vertices 'v' and 'w' strongly connected (belong to the same SCC)? */ C_STATIC_FORCE_INLINE c_bool_t c_KosarajuSharirSCC_StronglyConnected(c_KosarajuSharirSCC_t* self, c_size_t v, c_size_t w) { if (!self || !self->id || v >= self->V || w >= self->V) return C_FALSE; return self->id[v] == self->id[w]; } /** * @brief Returns the component id containing vertex 'v' * @return Component integer ID (0 to count-1), or C_SIZE_MAX on boundary check failures */ C_STATIC_FORCE_INLINE c_size_t c_KosarajuSharirSCC_GetId(c_KosarajuSharirSCC_t* self, c_size_t v) { if (!self || !self->id || v >= self->V) return C_SIZE_MAX; return self->id[v]; } /** * @brief Returns the total number of strongly connected components */ C_STATIC_FORCE_INLINE c_size_t c_KosarajuSharirSCC_GetCount(c_KosarajuSharirSCC_t* self) { return self ? self->count : 0; } #endif /*INCLUDED_C_KOSARAJUSHARIRSCC_H*/