21#ifndef GCC_SHORTEST_PATHS_H
22#define GCC_SHORTEST_PATHS_H
47template <
typename GraphTraits,
typename Path_t>
51 typedef typename GraphTraits::graph_t
graph_t;
52 typedef typename GraphTraits::node_t
node_t;
53 typedef typename GraphTraits::edge_t
edge_t;
87template <
typename GraphTraits,
typename Path_t>
95 m_dist (
graph.m_nodes.length ()),
96 m_best_edge (
graph.m_nodes.length ())
102 for (
unsigned i = 0;
i <
graph.m_nodes.length ();
i++)
108 m_dist[given_node->m_index] = 0;
110 while (
queue.length () > 0)
114 int idx_with_min_dist = -1;
115 int idx_in_queue_with_min_dist = -1;
117 for (
unsigned i = 0;
i <
queue.length ();
i++)
123 idx_with_min_dist = idx;
124 idx_in_queue_with_min_dist =
i;
127 if (idx_with_min_dist == -1)
129 gcc_assert (idx_in_queue_with_min_dist != -1);
133 queue.unordered_remove (idx_in_queue_with_min_dist);
136 =
static_cast <node_t *
> (
m_graph.m_nodes[idx_with_min_dist]);
145 node_t *dest = succ->m_dest;
146 int alt =
m_dist[n->m_index] + 1;
147 if (alt <
m_dist[dest->m_index])
149 m_dist[dest->m_index] = alt;
161 node_t *src = pred->m_src;
162 int alt =
m_dist[n->m_index] + 1;
163 if (alt <
m_dist[src->m_index])
165 m_dist[src->m_index] = alt;
181template <
typename GraphTraits,
typename Path_t>
188 while (m_best_edge[other_node->m_index])
190 result.m_edges.safe_push (m_best_edge[other_node->m_index]);
192 other_node = m_best_edge[other_node->m_index]->m_src;
194 other_node = m_best_edge[other_node->m_index]->m_dest;
198 result.m_edges.reverse ();
207template <
typename GraphTraits,
typename Path_t>
212 return m_dist[other_node->m_index];
Definition shortest-paths.h:49
GraphTraits::node_t node_t
Definition shortest-paths.h:52
auto_vec< const edge_t * > m_best_edge
Definition shortest-paths.h:76
enum shortest_path_sense m_sense
Definition shortest-paths.h:65
shortest_paths(const graph_t &graph, const node_t *given_node, enum shortest_path_sense sense)
Definition shortest-paths.h:90
const graph_t & m_graph
Definition shortest-paths.h:63
int get_shortest_distance(const node_t *other_node) const
Definition shortest-paths.h:210
GraphTraits::graph_t graph_t
Definition shortest-paths.h:51
Path_t path_t
Definition shortest-paths.h:54
auto_vec< int > m_dist
Definition shortest-paths.h:69
path_t get_shortest_path(const node_t *other_node) const
Definition shortest-paths.h:184
GraphTraits::edge_t edge_t
Definition shortest-paths.h:53
#define INT_MAX
Definition glimits.h:85
static vec< tree, va_gc > * queue
Definition godump.cc:57
i
Definition poly-int.h:776
shortest_path_sense
Definition shortest-paths.h:27
@ SPS_TO_GIVEN_TARGET
Definition shortest-paths.h:34
@ SPS_FROM_GIVEN_ORIGIN
Definition shortest-paths.h:30
#define NULL
Definition system.h:50
#define gcc_assert(EXPR)
Definition system.h:814
#define FOR_EACH_VEC_ELT(V, I, P)
Definition vec.h:1884