54 lines
1.7 KiB
C
54 lines
1.7 KiB
C
#ifndef INCLUDED_C_TOPOLOGICAL_H
|
|
#define INCLUDED_C_TOPOLOGICAL_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_Topological_t;
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
/**
|
|
* @brief Computes a topological order for the specified digraph.
|
|
* @param allocator Explicit allocator context used to allocate internal routing objects
|
|
*/
|
|
c_err_t c_Topological_Init(c_Topological_t* self, c_Digraph_t* G, c_Allocator_t* allocator);
|
|
|
|
/**
|
|
* @brief Releases internal tracking buffers
|
|
*/
|
|
void c_Topological_Destroy(c_Topological_t* self);
|
|
|
|
/**
|
|
* @brief Does the digraph have a topological order (is it a DAG)?
|
|
*/
|
|
C_STATIC_FORCE_INLINE
|
|
c_bool_t c_Topological_HasOrder(c_Topological_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_Topological_GetOrder(c_Topological_t* self, c_VertexIdList_t* out_order);
|
|
|
|
|
|
#endif /*INCLUDED_C_TOPOLOGICAL_H*/
|