#ifndef INCLUDED_C_NONRECURSIVETARJANSCC_H #define INCLUDED_C_NONRECURSIVETARJANSCC_H #ifndef INCLUDED_C_DIGRAPH_H #include #endif /*INCLUDED_C_DIGRAPH_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* pre; /* pre[v] = preorder index of vertex v */ c_size_t* low; /* low[v] = low link of vertex v */ c_size_t* stack; /* Explicit vertex stack buffer for component mapping tracking */ c_size_t stack_size; /* Current active elements size in stack tracker */ c_bool_t* on_stack; /* Quick boolean lookup mapping for stack memberships */ c_size_t pre_counter; /* Preorder index sequencing index variable counter */ c_size_t count; /* Total number of strongly connected components discovered */ c_size_t V; /* Stored vertex count for safe boundary check lookups */ c_Allocator_t allocator; /* Deep copy of the user-provided allocator */ } c_NonrecursiveTarjanSCC_t; /* ------------------------------------------------------------------------------------------------------------------ */ /* */ /** * @brief Non-recursively computes strongly connected components for the specified digraph using Tarjan's algorithm. * @param allocator Explicit allocator context used to allocate internal routing arrays */ c_err_t c_NonrecursiveTarjanSCC_Init(c_NonrecursiveTarjanSCC_t* self, c_Digraph_t* graph, c_Allocator_t* allocator); /** * @brief Releases internal tracking buffers */ void c_NonrecursiveTarjanSCC_Destroy(c_NonrecursiveTarjanSCC_t* self); /** * @brief Are vertices 'v' and 'w' strongly connected (belong to the same SCC)? */ C_STATIC_FORCE_INLINE c_bool_t c_NonrecursiveTarjanSCC_StronglyConnected(c_NonrecursiveTarjanSCC_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_NonrecursiveTarjanSCC_GetId(c_NonrecursiveTarjanSCC_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_NonrecursiveTarjanSCC_GetCount(c_NonrecursiveTarjanSCC_t* self) { return self ? self->count : 0; } #endif /*INCLUDED_C_NONRECURSIVETARJANSCC_H*/