Commit 68374523 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix bug with all_edge_iterator and reversed graphs

This fixes issue #728
parent 02e1ca46
......@@ -93,11 +93,6 @@ std::pair<typename adj_list<Vertex>::all_edge_iterator,
typename adj_list<Vertex>::all_edge_iterator>
all_edges(Vertex v, const adj_list<Vertex>& g);
template <class Vertex>
std::pair<typename adj_list<Vertex>::all_edge_iterator_reversed,
typename adj_list<Vertex>::all_edge_iterator_reversed>
_all_edges_reversed(Vertex v, const adj_list<Vertex>& g);
template <class Vertex>
std::pair<typename adj_list<Vertex>::adjacency_iterator,
typename adj_list<Vertex>::adjacency_iterator>
......@@ -318,7 +313,7 @@ public:
typedef base_edge_iterator<make_in_edge> in_edge_iterator;
template <class Iter, bool reversed>
template <class Iter>
struct make_in_or_out_edge
{
template <class I>
......@@ -328,38 +323,31 @@ public:
const I& i)
{
const Iter& iter = reinterpret_cast<const Iter&>(i);
if ((iter._iter < iter._pos) != reversed)
if (iter._iter < iter._pos)
return edge_descriptor(u, v.first, v.second);
else
return edge_descriptor(v.first, u, v.second);
}
};
template <bool reversed>
struct all_edge_iterator_base:
public base_edge_iterator<make_in_or_out_edge<all_edge_iterator_base<reversed>,
reversed>>
struct all_edge_iterator:
public base_edge_iterator<make_in_or_out_edge<all_edge_iterator>>
{
all_edge_iterator_base() {}
all_edge_iterator() {}
[[gnu::always_inline]]
all_edge_iterator_base(vertex_t v,
all_edge_iterator(vertex_t v,
typename edge_list_t::const_iterator&& iter,
const typename edge_list_t::const_iterator& pos)
: base_edge_iterator<make_in_or_out_edge<all_edge_iterator_base,
reversed>>
: base_edge_iterator<make_in_or_out_edge<all_edge_iterator>>
(v, std::forward<typename edge_list_t::const_iterator>(iter)),
_pos(pos)
{}
private:
friend struct make_in_or_out_edge<all_edge_iterator_base<reversed>,
reversed>;
friend struct make_in_or_out_edge<all_edge_iterator>;
typename edge_list_t::const_iterator _pos;
};
typedef all_edge_iterator_base<false> all_edge_iterator;
typedef all_edge_iterator_base<true> all_edge_iterator_reversed;
class edge_iterator:
public boost::iterator_facade<edge_iterator,
edge_descriptor,
......@@ -611,9 +599,6 @@ private:
friend std::pair<all_edge_iterator, all_edge_iterator>
all_edges<>(Vertex v, const adj_list<Vertex>& g);
friend std::pair<all_edge_iterator_reversed, all_edge_iterator_reversed>
_all_edges_reversed<>(Vertex v, const adj_list<Vertex>& g);
friend std::pair<adjacency_iterator, adjacency_iterator>
adjacent_vertices<>(Vertex v, const adj_list<Vertex>& g);
......@@ -874,19 +859,6 @@ all_edges(Vertex v, const adj_list<Vertex>& g)
return {ei_t(v, es.begin(), pos), ei_t(v, es.end(), pos)};
}
template <class Vertex>
[[gnu::always_inline]] [[gnu::flatten]] inline
std::pair<typename adj_list<Vertex>::all_edge_iterator_reversed,
typename adj_list<Vertex>::all_edge_iterator_reversed>
_all_edges_reversed(Vertex v, const adj_list<Vertex>& g)
{
typedef typename adj_list<Vertex>::all_edge_iterator_reversed ei_t;
const auto& pes = g._edges[v];
auto& es = pes.second;
auto pos = es.begin() + pes.first;
return {ei_t(v, es.begin(), pos), ei_t(v, es.end(), pos)};
}
template <class Vertex>
[[gnu::always_inline]] [[gnu::flatten]] inline
std::pair<typename adj_list<Vertex>::adjacency_iterator,
......
......@@ -174,10 +174,6 @@ public:
EdgePred, typename Graph::all_edge_iterator
> all_edge_iterator;
typedef filter_iterator<
EdgePred, typename Graph::all_edge_iterator_reversed
> all_edge_iterator_reversed;
typedef typename inv_adjacency_iterator_generator<self,
vertex_descriptor,
in_edge_iterator>::type
......
......@@ -59,8 +59,7 @@ class reversed_graph {
// BidirectionalGraph requirements
typedef typename Traits::out_edge_iterator in_edge_iterator;
typedef typename BidirectionalGraph::all_edge_iterator_reversed all_edge_iterator;
typedef typename BidirectionalGraph::all_edge_iterator all_edge_iterator_reversed;
typedef typename BidirectionalGraph::all_edge_iterator all_edge_iterator;
// AdjacencyGraph requirements
typedef typename BidirectionalGraph::in_adjacency_iterator adjacency_iterator;
......@@ -195,7 +194,7 @@ inline std::pair<typename reversed_graph<BidirectionalGraph>::all_edge_iterator,
all_edges(const typename graph_traits<BidirectionalGraph>::vertex_descriptor u,
const reversed_graph<BidirectionalGraph,GRef>& g)
{
return _all_edges_reversed(u, g._g);
return all_edges(u, g._g);
}
template <class BidirectionalGraph, class GRef>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment