src/lemon/graph_utils.h
changeset 970 09f9abe22df2
parent 964 2c0c20e90116
child 977 48962802d168
equal deleted inserted replaced
2:82f1df591912 3:8204117518a9
    87     int num = 0;
    87     int num = 0;
    88     for (DegIt it(_g, _n); it != INVALID; ++it) {
    88     for (DegIt it(_g, _n); it != INVALID; ++it) {
    89       ++num;
    89       ++num;
    90     }
    90     }
    91     return num;
    91     return num;
       
    92   }
       
    93 
       
    94   /// Finds an edge between two nodes of a graph.
       
    95 
       
    96   /// Finds an edge from node \c u to node \c v in graph \c g.
       
    97   ///
       
    98   /// If \c prev is \ref INVALID (this is the default value), then
       
    99   /// it finds the first edge from \c u to \c v. Otherwise it looks for
       
   100   /// the next edge from \c u to \c v after \c prev.
       
   101   /// \return The found edge or \ref INVALID if there is no such an edge.
       
   102   ///
       
   103   /// Thus you can iterate through each edge from \c u to \c v as it follows.
       
   104   /// \code
       
   105   /// for(Edge e=findEdge(g,u,v);e!=INVALID;e=findEdge(g,u,v,e)) {
       
   106   ///   ...
       
   107   /// }
       
   108   /// \endcode
       
   109   /// \todo We may want to use the \ref concept::GraphBase "GraphBase"
       
   110   /// interface here...
       
   111   /// \bug Untested ...
       
   112   template <typename Graph>
       
   113   typename Graph::Edge findEdge(const Graph &g,
       
   114 		typename Graph::Node u, typename Graph::Node v,
       
   115 		typename Graph::Edge prev = INVALID) 
       
   116   {
       
   117     typename Graph::OutEdgeIt e(g,prev);
       
   118     if(prev==INVALID) g.first(e,u);
       
   119     else ++e;
       
   120     while(e!=INVALID && g.tail(e)!=v) ++e;
       
   121     return e;
    92   }
   122   }
    93   
   123   
    94   ///\e
   124   ///\e
    95 
   125 
    96   ///\todo Please document.
   126   ///\todo Please document.