Files

69 lines
2.5 KiB
C
Raw Permalink Normal View History

2026-09-07 18:48:16 +08:00
#ifndef INCLUDED_C_DIJKSTRAALLPAIRSSP_H
#define INCLUDED_C_DIJKSTRAALLPAIRSSP_H
#ifndef INCLUDED_C_EDGEWEIGHTEDDIGRAPH_H
#include <c_EdgeWeightedDigraph.h>
#endif /*INCLUDED_C_EDGEWEIGHTEDDIGRAPH_H*/
#ifndef INCLUDED_C_DIJKSTRASP_H
#include <c_DijkstraSP.h>
#endif /*INCLUDED_C_DIJKSTRASP_H*/
#ifndef INCLUDED_C_VERTEXIDLIST_H
#include <c_VertexIdList.h>
#endif /*INCLUDED_C_VERTEXIDLIST_H*/
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
typedef struct {
c_DijkstraSP_t* sp_matrix; /* Dynamic array of DijkstraSP engines (size of graph->V) */
c_size_t V; /* Total number of vertices in the digraph */
c_Allocator_t allocator; /* Deep copy of the user-provided allocator */
} c_DijkstraAllPairsSP_t;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
/**
* @brief Computes all-pairs shortest paths in an edge-weighted digraph.
* @param allocator Explicit allocator context used to configure internal tracking state memory
*/
c_err_t c_DijkstraAllPairsSP_Init(c_DijkstraAllPairsSP_t* self, c_EdgeWeightedDigraph_t* graph, c_Allocator_t* allocator);
/**
* @brief Releases internal tracking buffers and all embedded single-source engines safely.
*/
void c_DijkstraAllPairsSP_Destroy(c_DijkstraAllPairsSP_t* self);
/**
* @brief Is there a directed path from vertex 'u' to vertex 'v'?
*/
C_STATIC_FORCE_INLINE
c_bool_t c_DijkstraAllPairsSP_HasPath(c_DijkstraAllPairsSP_t* self, c_size_t u, c_size_t v) {
if (!self || !self->sp_matrix || u >= self->V || v >= self->V) return C_FALSE;
return c_DijkstraSP_HasPathTo(&self->sp_matrix[u], v);
}
/**
* @brief Returns the distance of the shortest path from vertex 'u' to vertex 'v'.
* @return Distance value, or DBL_MAX if unreachable / parameter error
*/
C_STATIC_FORCE_INLINE
double c_DijkstraAllPairsSP_Dist(c_DijkstraAllPairsSP_t* self, c_size_t u, c_size_t v) {
if (!self || !self->sp_matrix || u >= self->V || v >= self->V) return DBL_MAX;
return c_DijkstraSP_DistTo(&self->sp_matrix[u], v);
}
/**
* @brief Reconstructs the exact shortest path from vertex 'u' to vertex 'v' and appends it to out_path.
* @param out_path An initialized c_VertexIdList_t container to collect the sequence of global directed edge_ids.
*/
c_err_t c_DijkstraAllPairsSP_Path(c_DijkstraAllPairsSP_t* self, c_size_t u, c_size_t v, c_VertexIdList_t* out_path);
#endif /*INCLUDED_C_DIJKSTRAALLPAIRSSP_H*/