61 lines
2.1 KiB
C
61 lines
2.1 KiB
C
#ifndef INCLUDED_C_EDGEWEIGHTEDGRAPH_H
|
|
#define INCLUDED_C_EDGEWEIGHTEDGRAPH_H
|
|
|
|
#ifndef INCLUDED_C_EDGE_H
|
|
#include <c_Edge.h>
|
|
#endif /*INCLUDED_C_EDGE_H*/
|
|
|
|
#ifndef INCLUDED_C_ADJLIST_H
|
|
#include <c_AdjList.h>
|
|
#endif /*INCLUDED_C_ADJLIST_H*/
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
|
/* */
|
|
|
|
typedef struct {
|
|
c_size_t V; /* Total number of vertices */
|
|
c_size_t E; /* Total number of edges */
|
|
c_AdjList_t* adj_list; /* Array of dynamic lists storing indices to a global edge pool */
|
|
c_Edge_t* edges_pool; /* Global continuous array pool housing raw edge objects */
|
|
c_size_t edges_cap; /* Allocated edge pool tracking capacity boundary */
|
|
c_Allocator_t allocator; /* Embedded custom allocator structure instance */
|
|
} c_EdgeWeightedGraph_t;
|
|
|
|
|
|
/**
|
|
* @brief Initializes an empty edge-weighted graph with V vertices.
|
|
* @param allocator Explicit allocator context used to configure memory regions
|
|
*/
|
|
c_err_t c_EdgeWeightedGraph_Init(c_EdgeWeightedGraph_t* self, c_size_t V, c_Allocator_t* alloc);
|
|
|
|
/**
|
|
* @brief Destroys the graph and releases all inner heap allocations safely.
|
|
*/
|
|
void c_EdgeWeightedGraph_Destroy(c_EdgeWeightedGraph_t* self);
|
|
|
|
/**
|
|
* @brief Adds an undirected weighted edge between vertex v and w.
|
|
*/
|
|
c_err_t c_EdgeWeightedGraph_AddEdge(c_EdgeWeightedGraph_t* self, c_size_t v, c_size_t w, double weight);
|
|
|
|
c_err_t c_EdgeWeightedGraph_GetEdge(c_EdgeWeightedGraph_t* self, c_size_t edge_idx, c_Edge_t* edge);
|
|
|
|
c_err_t c_EdgeWeightedGraph_RemoveEdge(c_EdgeWeightedGraph_t* self, c_size_t edge_idx);
|
|
|
|
/* ================================================================================================================== */
|
|
/* Inline Inspection Hooks */
|
|
|
|
C_STATIC_FORCE_INLINE
|
|
c_size_t c_EdgeWeightedGraph_GetV(const c_EdgeWeightedGraph_t* self) {
|
|
return self ? self->V : 0;
|
|
}
|
|
|
|
C_STATIC_FORCE_INLINE
|
|
c_size_t c_EdgeWeightedGraph_GetE(const c_EdgeWeightedGraph_t* self) {
|
|
return self ? self->E : 0;
|
|
}
|
|
|
|
|
|
#endif /*INCLUDED_C_EDGEWEIGHTEDGRAPH_H*/
|