53 lines
1.6 KiB
C
53 lines
1.6 KiB
C
#ifndef INCLUDED_C_KRUSKALMST_H
|
|
#define INCLUDED_C_KRUSKALMST_H
|
|
|
|
#ifndef INCLUDED_C_EDGEWEIGHTEDGRAPH_H
|
|
#include <c_EdgeWeightedGraph.h>
|
|
#endif /*INCLUDED_C_EDGEWEIGHTEDGRAPH_H*/
|
|
|
|
|
|
#ifndef INCLUDED_C_VERTEXIDLIST_H
|
|
#include <c_VertexIdList.h>
|
|
#endif /*INCLUDED_C_VERTEXIDLIST_H*/
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
typedef struct {
|
|
c_VertexIdList_t mst_edges; /* Final optimized list of edge_ids inside the tree */
|
|
double weight; /* Total minimum weight summation of the MST */
|
|
c_Allocator_t allocator; /* Deep copy of the user-provided allocator */
|
|
} c_KruskalMST_t;
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
/**
|
|
* @brief Computes a minimum spanning tree of an edge-weighted graph using Kruskal's algorithm.
|
|
* @param allocator Explicit allocator context used to configure internal tracking state memory
|
|
*/
|
|
c_err_t c_KruskalMST_Init(c_KruskalMST_t* self, c_EdgeWeightedGraph_t* graph, c_Allocator_t* allocator);
|
|
|
|
/**
|
|
* @brief Releases internal tracking buffers
|
|
*/
|
|
void c_KruskalMST_Destroy(c_KruskalMST_t* self);
|
|
|
|
/**
|
|
* @brief Gets a copy of the edge ids included in the Minimum Spanning Tree.
|
|
*/
|
|
c_err_t c_KruskalMST_GetEdges(c_KruskalMST_t* self, c_VertexIdList_t* out_edges);
|
|
|
|
/**
|
|
* @brief Returns the total weight summation of the MST.
|
|
*/
|
|
C_STATIC_FORCE_INLINE
|
|
double c_KruskalMST_Weight(c_KruskalMST_t* self) {
|
|
return self ? self->weight : 0.0;
|
|
}
|
|
|
|
|
|
#endif /*INCLUDED_C_KRUSKALMST_H*/
|