66 lines
2.5 KiB
C
66 lines
2.5 KiB
C
#ifndef INCLUDED_C_DIJKSTRAUNDIRECTEDSP_H
|
|||
|
|
#define INCLUDED_C_DIJKSTRAUNDIRECTEDSP_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[w] = entering edge_id on shortest path to w */
|
||
|
|
c_size_t* from_vertex; /* from_vertex[w] = source vertex parent link on path to w */
|
||
|
|
double* dist_to; /* dist_to[w] = cumulative distance from source to w */
|
||
|
|
c_size_t s; /* The starting source vertex index */
|
||
|
|
c_size_t V; /* Total number of vertices in the graph */
|
||
|
|
c_Allocator_t allocator; /* Deep copy of the user-provided allocator */
|
||
|
|
} c_DijkstraUndirectedSP_t;
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Computes a shortest-paths tree from the source vertex 's' in the edge-weighted undirected graph.
|
||
|
|
* @param allocator Explicit allocator context used to configure internal tracking state memory
|
||
|
|
*/
|
||
|
|
c_err_t c_DijkstraUndirectedSP_Init(c_DijkstraUndirectedSP_t* self, c_EdgeWeightedGraph_t* graph, c_size_t s, c_Allocator_t* allocator);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Releases internal tracking buffers safely.
|
||
|
|
*/
|
||
|
|
void c_DijkstraUndirectedSP_Destroy(c_DijkstraUndirectedSP_t* self);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Is there a path from the source vertex 's' to vertex 'v'?
|
||
|
|
*/
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
c_bool_t c_DijkstraUndirectedSP_HasPathTo(c_DijkstraUndirectedSP_t* self, c_size_t v) {
|
||
|
|
if (!self || v >= self->V || !self->dist_to) return C_FALSE;
|
||
|
|
return self->dist_to[v] < DBL_MAX;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Returns the distance of the shortest path from the source vertex 's' to vertex 'v'.
|
||
|
|
*/
|
||
|
|
C_STATIC_FORCE_INLINE
|
||
|
|
double c_DijkstraUndirectedSP_DistTo(c_DijkstraUndirectedSP_t* self, c_size_t v) {
|
||
|
|
if (!self || v >= self->V || !self->dist_to) return DBL_MAX;
|
||
|
|
return self->dist_to[v];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Reconstructs the exact shortest path from the source vertex 's' to vertex 'v' and appends it to out_path.
|
||
|
|
* @param out_path An initialized c_VertexIdList_t container to collect the sequence of global edge_ids.
|
||
|
|
*/
|
||
|
|
c_err_t c_DijkstraUndirectedSP_PathTo(c_DijkstraUndirectedSP_t* self, c_size_t v, c_VertexIdList_t* out_path);
|
||
|
|
|
||
|
|
|
||
|
|
#endif /*INCLUDED_C_DIJKSTRAUNDIRECTEDSP_H*/
|