54 lines
1.9 KiB
C
54 lines
1.9 KiB
C
#ifndef INCLUDED_C_NONRECURSIVETOPOLOGICAL_H
|
|
#define INCLUDED_C_NONRECURSIVETOPOLOGICAL_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_VertexIdList_t order; /* Stores the topological order sequence if found */
|
|
c_bool_t has_order; /* Is the graph a DAG (has a valid topological order)? */
|
|
c_Allocator_t allocator; /* Deep copy of the user-provided allocator */
|
|
} c_NonrecursiveTopological_t;
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
/**
|
|
* @brief Non-recursively computes a topological order for the specified digraph using Kahn's algorithm.
|
|
* @param allocator Explicit allocator context used to allocate internal routing objects
|
|
*/
|
|
c_err_t c_NonrecursiveTopological_Init(c_NonrecursiveTopological_t* self, c_Digraph_t* graph, c_Allocator_t* allocator);
|
|
|
|
/**
|
|
* @brief Releases internal tracking buffers
|
|
*/
|
|
void c_NonrecursiveTopological_Destroy(c_NonrecursiveTopological_t* self);
|
|
|
|
/**
|
|
* @brief Does the digraph have a topological order (is it a DAG)?
|
|
*/
|
|
C_STATIC_FORCE_INLINE
|
|
c_bool_t c_NonrecursiveTopological_HasOrder(c_NonrecursiveTopological_t* self) {
|
|
return self ? self->has_order : C_FALSE;
|
|
}
|
|
|
|
/**
|
|
* @brief Gets the topological order sequence of vertices.
|
|
* @param out_order An initialized c_VertexIdList_t container to collect the sequence.
|
|
* @return C_SUCCESS on success, C_ERR_FAIL if no order exists (not a DAG), or parameter error.
|
|
*/
|
|
c_err_t c_NonrecursiveTopological_GetOrder(c_NonrecursiveTopological_t* self, c_VertexIdList_t* out_order);
|
|
|
|
|
|
#endif /*INCLUDED_C_NONRECURSIVETOPOLOGICAL_H*/
|