Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert change to reindex_edge_list. #269

Merged
merged 6 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/boost/graph/detail/adjacency_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,15 +2069,20 @@ namespace detail
inline void reindex_edge_list(
EdgeList& el, vertex_descriptor u, boost::disallow_parallel_edge_tag)
{
for (typename EdgeList::iterator ei = el.begin(); ei != el.end(); ++ei)
typename EdgeList::iterator ei = el.begin(), e_end = el.end();
while (ei != e_end)
{
if (ei->get_target() > u)
{
typename EdgeList::value_type ce = *ei;
++ei;
el.erase(ce);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
el.erase(ce);
ei = el.erase(ce);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. It indeed looks like a better approach; however, I was not able to get this code to compile:

#include <boost/graph/adjacency_list.hpp>

using Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS>;

int main() {
  Graph g(3);
  boost::add_edge(2, 0, g);
  boost::remove_vertex(1, g);
}

The gist of the error is that erase does not return an iterator in this case, but a long unsigned int.

(The original patch was simply a reversion of a previous commit.)

--ce.get_target();
el.insert(ce);
}
else {
++ei;
}
}
}
} // namespace detail
Expand Down
18 changes: 18 additions & 0 deletions test/delete_edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,23 @@ int main(int argc, char* argv[])

BOOST_TEST(m_graph[ed1] == EDGE_VAL);

// https://github.com/boostorg/graph/issues/268
// 1. Undirected:
{
boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS> g;
boost::add_edge(2, 0, g);
boost::remove_vertex(1, g);
BOOST_TEST(num_vertices(g) == 2);
BOOST_TEST(num_edges(g) == 1);
}
// 2. Directed:
{
boost::adjacency_list<boost::setS, boost::vecS, boost::directedS> g;
boost::add_edge(2, 0, g);
boost::remove_vertex(1, g);
BOOST_TEST(num_vertices(g) == 2);
BOOST_TEST(num_edges(g) == 1);
}

return boost::report_errors();
}