#ifndef INCLUDED_C_EDGEWEIGHTEDDIGRAPH_H #define INCLUDED_C_EDGEWEIGHTEDDIGRAPH_H #ifndef INCLUDED_C_DIRECTEDEDGE_H #include #endif /*INCLUDED_C_DIRECTEDEDGE_H*/ #ifndef INCLUDED_C_ADJLIST_H #include #endif /*INCLUDED_C_ADJLIST_H*/ #ifndef INCLUDED_C_ALLOCATOR_H #include #endif /*INCLUDED_C_ALLOCATOR_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 global edge_ids exiting each vertex */ c_DirectedEdge_t* edges_pool; /* Global contiguous array pool housing raw directed edge objects */ c_size_t edges_cap; /* Allocated edge pool tracking capacity boundary */ c_size_t* indegree; /* O(1) in-degree array cache for runtime optimization */ c_Allocator_t allocator; /* Embedded custom allocator structure instance */ } c_EdgeWeightedDigraph_t; /* ------------------------------------------------------------------------------------------------------------------ */ /* */ /** * @brief Initializes an empty edge-weighted digraph with V vertices. * @param allocator Explicit allocator context used to configure memory regions */ c_err_t c_EdgeWeightedDigraph_Init(c_EdgeWeightedDigraph_t* self, c_size_t V, c_Allocator_t* alloc); /** * @brief Destroys the digraph and releases all inner heap allocations safely. */ void c_EdgeWeightedDigraph_Destroy(c_EdgeWeightedDigraph_t* self); /** * @brief Adds a directed weighted edge from vertex 'from' to vertex 'to'. */ c_err_t c_EdgeWeightedDigraph_AddEdge(c_EdgeWeightedDigraph_t* self, c_size_t from, c_size_t to, double weight); c_err_t c_EdgeWeightedDigraph_GetEdge(c_EdgeWeightedDigraph_t* self, c_size_t edge_idx, c_DirectedEdge_t* edge); c_err_t c_EdgeWeightedDigraph_RemoveEdge(c_EdgeWeightedDigraph_t* self, c_size_t edge_id); /* ================================================================================================================== */ /* Inline Inspection Hooks */ C_STATIC_FORCE_INLINE c_size_t c_EdgeWeightedDigraph_GetV(c_EdgeWeightedDigraph_t* self) { return self ? self->V : 0; } C_STATIC_FORCE_INLINE c_size_t c_EdgeWeightedDigraph_GetE(c_EdgeWeightedDigraph_t* self) { return self ? self->E : 0; } C_STATIC_FORCE_INLINE c_size_t c_EdgeWeightedDigraph_GetOutDegree(c_EdgeWeightedDigraph_t* self, c_size_t v) { if (!self || v >= self->V) return 0; return (c_size_t)c_AdjList_GetSize(&self->adj_list[v]); } C_STATIC_FORCE_INLINE c_size_t c_EdgeWeightedDigraph_GetInDegree(c_EdgeWeightedDigraph_t* self, c_size_t v) { if (!self || v >= self->V) return 0; return self->indegree[v]; } #endif /*INCLUDED_C_EDGEWEIGHTEDDIGRAPH_H*/