ErasingFirstGraphWrapper
authormarci
Tue, 16 Nov 2004 13:03:47 +0000
changeset 99889969b303727
parent 997 665ffade9aca
child 999 5c846ec3f787
ErasingFirstGraphWrapper
src/lemon/graph_wrapper.h
src/test/graph_wrapper_test.cc
     1.1 --- a/src/lemon/graph_wrapper.h	Mon Nov 15 16:39:55 2004 +0000
     1.2 +++ b/src/lemon/graph_wrapper.h	Tue Nov 16 13:03:47 2004 +0000
     1.3 @@ -1799,6 +1799,68 @@
     1.4    };
     1.5  
     1.6  
     1.7 +
     1.8 +  template <typename _Graph, typename FirstOutEdgesMap>
     1.9 +  class ErasingFirstGraphWrapperBase : public GraphWrapperBase<_Graph> {
    1.10 +  public:
    1.11 +    typedef _Graph Graph;
    1.12 +    typedef GraphWrapperBase<_Graph> Parent;
    1.13 +  protected:
    1.14 +    FirstOutEdgesMap* first_out_edges;
    1.15 +    ErasingFirstGraphWrapperBase() : Parent(), 
    1.16 +				     first_out_edges(0) { }
    1.17 +
    1.18 +    void setFirstOutEdgesMap(FirstOutEdgesMap& _first_out_edges) {
    1.19 +      first_out_edges=&_first_out_edges;
    1.20 +    }
    1.21 +
    1.22 +  public:
    1.23 +
    1.24 +    typedef typename Parent::Node Node;
    1.25 +    typedef typename Parent::Edge Edge;
    1.26 +
    1.27 +//     using Parent::first;
    1.28 +//     void first(Node& i) const { 
    1.29 +//       Parent::first(i); 
    1.30 +//       while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
    1.31 +//     }
    1.32 +//     void first(Edge& i) const { 
    1.33 +//       Parent::first(i); 
    1.34 +//       while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i); 
    1.35 +//     }
    1.36 +//     void firstIn(Edge& i, const Node& n) const { 
    1.37 +//       Parent::firstIn(i, n); 
    1.38 +//       while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i); 
    1.39 +//     }
    1.40 +    void firstOut(Edge& i, const Node& n) const { 
    1.41 +      i=(*first_out_edges)[n];
    1.42 +    }
    1.43 +
    1.44 +    void erase(const Edge& e) const {
    1.45 +      Node n=source(e);
    1.46 +      Edge f=e;
    1.47 +      Parent::nextOut(f);
    1.48 +      first_out_edges->set(n, f);
    1.49 +    }    
    1.50 +//     void next(Node& i) const { 
    1.51 +//       Parent::next(i); 
    1.52 +//       while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i); 
    1.53 +//     }
    1.54 +//     void next(Edge& i) const { 
    1.55 +//       Parent::next(i); 
    1.56 +//       while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i); 
    1.57 +//     }
    1.58 +//     void nextIn(Edge& i) const { 
    1.59 +//       Parent::nextIn(i); 
    1.60 +//       while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i); 
    1.61 +//     }
    1.62 +//     void nextOut(Edge& i) const { 
    1.63 +//       Parent::nextOut(i); 
    1.64 +//       while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextOut(i); 
    1.65 +//     }
    1.66 +  };
    1.67 +
    1.68 +
    1.69    /// For blocking flows.
    1.70  
    1.71    ///\warning Graph wrappers are in even more experimental state than the other
    1.72 @@ -1813,52 +1875,70 @@
    1.73    /// is called. 
    1.74    ///
    1.75    /// \author Marton Makai
    1.76 -  template<typename Graph, typename FirstOutEdgesMap>
    1.77 -  class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
    1.78 +  template <typename _Graph, typename FirstOutEdgesMap>
    1.79 +  class ErasingFirstGraphWrapper : 
    1.80 +    public IterableGraphExtender<
    1.81 +    ErasingFirstGraphWrapperBase<_Graph, FirstOutEdgesMap> > {
    1.82    public:
    1.83 -    typedef GraphWrapper<Graph> Parent; 
    1.84 -  protected:
    1.85 -    FirstOutEdgesMap* first_out_edges;
    1.86 -  public:
    1.87 +    typedef _Graph Graph;
    1.88 +    typedef IterableGraphExtender<
    1.89 +      ErasingFirstGraphWrapperBase<_Graph, FirstOutEdgesMap> > Parent;
    1.90      ErasingFirstGraphWrapper(Graph& _graph, 
    1.91 -			     FirstOutEdgesMap& _first_out_edges) : 
    1.92 -      GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }  
    1.93 -
    1.94 -    typedef typename GraphWrapper<Graph>::Node Node;
    1.95 -    typedef typename GraphWrapper<Graph>::Edge Edge;
    1.96 -    class OutEdgeIt : public Edge { 
    1.97 -      friend class GraphWrapper<Graph>;
    1.98 -      friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
    1.99 -      const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>* gw;
   1.100 -    public:
   1.101 -      OutEdgeIt() { }
   1.102 -      OutEdgeIt(Invalid i) : Edge(i) { }
   1.103 -      OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
   1.104 -		const Node& n) : 
   1.105 -	Edge((*(_gw.first_out_edges))[n]), gw(&_gw) { }
   1.106 -      OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
   1.107 -		const Edge& e) : 
   1.108 -	Edge(e), gw(&_gw) { }
   1.109 -      OutEdgeIt& operator++() { 
   1.110 -	*(static_cast<Edge*>(this))=
   1.111 -	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
   1.112 -	return *this; 
   1.113 -      }
   1.114 -    };
   1.115 -
   1.116 +			     FirstOutEdgesMap& _first_out_edges) { 
   1.117 +      setGraph(_graph);
   1.118 +      setFirstOutEdgesMap(_first_out_edges);
   1.119 +    } 
   1.120  //     using GraphWrapper<Graph>::first;
   1.121  //     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
   1.122  //       i=OutEdgeIt(*this, p); return i;
   1.123  //     }
   1.124 -    void erase(const Edge& e) const {
   1.125 -      Node n=source(e);
   1.126 -      typename Graph::OutEdgeIt f(*Parent::graph, n);
   1.127 -      ++f;
   1.128 -      first_out_edges->set(n, f);
   1.129 -    }
   1.130 +  };
   1.131 +//   template<typename Graph, typename FirstOutEdgesMap>
   1.132 +//   class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
   1.133 +//   public:
   1.134 +//     typedef GraphWrapper<Graph> Parent; 
   1.135 +//   protected:
   1.136 +//     FirstOutEdgesMap* first_out_edges;
   1.137 +//   public:
   1.138 +//     ErasingFirstGraphWrapper(Graph& _graph, 
   1.139 +// 			     FirstOutEdgesMap& _first_out_edges) : 
   1.140 +//       GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }  
   1.141  
   1.142 -    //    KEEP_MAPS(Parent, ErasingFirstGraphWrapper);
   1.143 -  };
   1.144 +//     typedef typename GraphWrapper<Graph>::Node Node;
   1.145 +//     typedef typename GraphWrapper<Graph>::Edge Edge;
   1.146 +//     class OutEdgeIt : public Edge { 
   1.147 +//       friend class GraphWrapper<Graph>;
   1.148 +//       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
   1.149 +//       const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>* gw;
   1.150 +//     public:
   1.151 +//       OutEdgeIt() { }
   1.152 +//       OutEdgeIt(Invalid i) : Edge(i) { }
   1.153 +//       OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
   1.154 +// 		const Node& n) : 
   1.155 +// 	Edge((*(_gw.first_out_edges))[n]), gw(&_gw) { }
   1.156 +//       OutEdgeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _gw, 
   1.157 +// 		const Edge& e) : 
   1.158 +// 	Edge(e), gw(&_gw) { }
   1.159 +//       OutEdgeIt& operator++() { 
   1.160 +// 	*(static_cast<Edge*>(this))=
   1.161 +// 	  ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
   1.162 +// 	return *this; 
   1.163 +//       }
   1.164 +//     };
   1.165 +
   1.166 +// //     using GraphWrapper<Graph>::first;
   1.167 +// //     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
   1.168 +// //       i=OutEdgeIt(*this, p); return i;
   1.169 +// //     }
   1.170 +//     void erase(const Edge& e) const {
   1.171 +//       Node n=source(e);
   1.172 +//       typename Graph::OutEdgeIt f(*Parent::graph, n);
   1.173 +//       ++f;
   1.174 +//       first_out_edges->set(n, f);
   1.175 +//     }
   1.176 +
   1.177 +//     //    KEEP_MAPS(Parent, ErasingFirstGraphWrapper);
   1.178 +//   };
   1.179  
   1.180    ///@}
   1.181  
     2.1 --- a/src/test/graph_wrapper_test.cc	Mon Nov 15 16:39:55 2004 +0000
     2.2 +++ b/src/test/graph_wrapper_test.cc	Tue Nov 16 13:03:47 2004 +0000
     2.3 @@ -42,26 +42,26 @@
     2.4  int main() 
     2.5  {
     2.6    {
     2.7 -    checkConcept<StaticGraph, GraphWrapper<StaticGraph> >();
     2.8 +    typedef StaticGraph Graph;
     2.9 +    checkConcept<StaticGraph, GraphWrapper<Graph> >();
    2.10  
    2.11 -    checkConcept<StaticGraph, RevGraphWrapper<StaticGraph> >();
    2.12 +    checkConcept<StaticGraph, RevGraphWrapper<Graph> >();
    2.13  
    2.14 -    checkConcept<StaticGraph, SubGraphWrapper<StaticGraph, 
    2.15 -      StaticGraph::NodeMap<bool> , StaticGraph::EdgeMap<bool> > >();
    2.16 -    checkConcept<StaticGraph, NodeSubGraphWrapper<StaticGraph, 
    2.17 -      StaticGraph::NodeMap<bool> > >();
    2.18 -    checkConcept<StaticGraph, EdgeSubGraphWrapper<StaticGraph, 
    2.19 -      StaticGraph::EdgeMap<bool> > >();
    2.20 +    checkConcept<StaticGraph, SubGraphWrapper<Graph, 
    2.21 +      Graph::NodeMap<bool> , Graph::EdgeMap<bool> > >();
    2.22 +    checkConcept<StaticGraph, NodeSubGraphWrapper<Graph, 
    2.23 +      Graph::NodeMap<bool> > >();
    2.24 +    checkConcept<StaticGraph, EdgeSubGraphWrapper<Graph, 
    2.25 +      Graph::EdgeMap<bool> > >();
    2.26      
    2.27 -    checkConcept<StaticGraph, SubBidirGraphWrapper<StaticGraph, 
    2.28 -      StaticGraph::EdgeMap<bool>, StaticGraph::EdgeMap<bool> > >();
    2.29 +    checkConcept<StaticGraph, SubBidirGraphWrapper<Graph, 
    2.30 +      Graph::EdgeMap<bool>, Graph::EdgeMap<bool> > >();
    2.31 +    checkConcept<StaticGraph, BidirGraph<Graph> >();
    2.32 +    checkConcept<StaticGraph, ResGraphWrapper<Graph, int, 
    2.33 +      Graph::EdgeMap<int>, Graph::EdgeMap<int> > >();
    2.34  
    2.35 -    checkConcept<StaticGraph, BidirGraph<StaticGraph> >();
    2.36 -
    2.37 -    checkConcept<StaticGraph, ResGraphWrapper<StaticGraph, int, 
    2.38 -      StaticGraph::EdgeMap<int>, StaticGraph::EdgeMap<int> > >();
    2.39 -
    2.40 -//     function_requires<StaticGraphConcept<ErasingFirstGraphWrapper<Graph, Graph::NodeMap<Graph::Edge> > > >();
    2.41 +    checkConcept<StaticGraph, ErasingFirstGraphWrapper<Graph, 
    2.42 +      Graph::NodeMap<Graph::Edge> > >(); 
    2.43    }
    2.44    std::cout << __FILE__ ": All tests passed.\n";
    2.45