Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66098 - trunk/boost/graph
From: jewillco_at_[hidden]
Date: 2010-10-19 11:55:28


Author: jewillco
Date: 2010-10-19 11:55:27 EDT (Tue, 19 Oct 2010)
New Revision: 66098
URL: http://svn.boost.org/trac/boost/changeset/66098

Log:
Fixed remove_edge_if and clear_vertex for subgraphs; commented out remove_vertex; refs #4752; fixes #4753
Text files modified:
   trunk/boost/graph/subgraph.hpp | 32 ++++++++++++++++++++++++++------
   1 files changed, 26 insertions(+), 6 deletions(-)

Modified: trunk/boost/graph/subgraph.hpp
==============================================================================
--- trunk/boost/graph/subgraph.hpp (original)
+++ trunk/boost/graph/subgraph.hpp 2010-10-19 11:55:27 EDT (Tue, 19 Oct 2010)
@@ -677,17 +677,35 @@
     }
 }
 
-// TODO: This is wrong...
+// This is slow, but there may not be a good way to do it safely otherwise
 template <typename Predicate, typename G>
 void
-remove_edge_if(Predicate p, subgraph<G>& g)
-{ remove_edge_if(p, g.m_graph); }
+remove_edge_if(Predicate p, subgraph<G>& g) {
+ while (true) {
+ bool any_removed = false;
+ typedef typename subgraph<G>::edge_iterator ei_type;
+ for (std::pair<ei_type, ei_type> ep = edges(g);
+ ep.first != ep.second; ++ep.first) {
+ if (p(*ep.first)) {
+ any_removed = true;
+ remove_edge(*ep.first, g);
+ continue; /* Since iterators may be invalidated */
+ }
+ }
+ if (!any_removed) break;
+ }
+}
 
-// TODO: Ths is wrong
 template <typename G>
 void
-clear_vertex(typename subgraph<G>::vertex_descriptor v, subgraph<G>& g)
-{ clear_vertex(v, g.m_graph); }
+clear_vertex(typename subgraph<G>::vertex_descriptor v, subgraph<G>& g) {
+ while (true) {
+ typedef typename subgraph<G>::out_edge_iterator oei_type;
+ std::pair<oei_type, oei_type> p = out_edges(v, g);
+ if (p.first == p.second) break;
+ remove_edge(*p.first, g);
+ }
+}
 
 namespace detail {
     template <typename G>
@@ -727,10 +745,12 @@
 }
 
 
+#if 0
 // TODO: Under Construction
 template <typename G>
 void remove_vertex(typename subgraph<G>::vertex_descriptor u, subgraph<G>& g)
 { assert(false); }
+#endif
 
 //===========================================================================
 // Functions required by the PropertyGraph concept


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk