Files
cKit/Graph/c_PrimMST.h
T
2026-09-07 18:48:16 +08:00

55 lines
1.9 KiB
C

#ifndef INCLUDED_C_PRIMMST_H
#define INCLUDED_C_PRIMMST_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_size_t* edge_to; /* edge_to[v] = shortest edge connecting v to the MST */
double* dist_to; /* dist_to[v] = weight of that shortest edge */
c_bool_t* marked; /* marked[v] = C_TRUE if v is already in the MST */
c_VertexIdList_t mst_edges; /* Final optimized list of edge_ids inside the tree */
double weight; /* Total minimum weight summation of the MST */
c_size_t V; /* Stored graph vertex limit count */
c_Allocator_t allocator; /* Deep copy of the user-provided allocator */
} c_PrimMST_t;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
/**
* @brief Computes a minimum spanning tree of an edge-weighted graph using Eager Prim's algorithm.
* @param allocator Explicit allocator context used to configure internal tracking state memory
*/
c_err_t c_PrimMST_Init(c_PrimMST_t* self, c_EdgeWeightedGraph_t* graph, c_Allocator_t* allocator);
/**
* @brief Releases internal tracking buffers
*/
void c_PrimMST_Destroy(c_PrimMST_t* self);
/**
* @brief Gets a copy of the edge ids included in the Minimum Spanning Tree.
*/
c_err_t c_PrimMST_GetEdges(c_PrimMST_t* self, c_VertexIdList_t* out_edges);
/**
* @brief Returns the total weight summation of the MST.
*/
C_STATIC_FORCE_INLINE
double c_PrimMST_Weight(c_PrimMST_t* self) {
return self ? self->weight : 0.0;
}
#endif /*INCLUDED_C_PRIMMST_H*/