[Lemon-commits] deba: r3277 - lemon/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon May 7 10:49:58 CEST 2007


Author: deba
Date: Mon May  7 10:49:57 2007
New Revision: 3277

Modified:
   lemon/trunk/lemon/dfs.h
   lemon/trunk/lemon/dijkstra.h

Log:
Modified start() function in Dfs and Dijkstra classes to give back reached
edge/node.

Patch from Peter Kovacs



Modified: lemon/trunk/lemon/dfs.h
==============================================================================
--- lemon/trunk/lemon/dfs.h	(original)
+++ lemon/trunk/lemon/dfs.h	Mon May  7 10:49:57 2007
@@ -564,14 +564,19 @@
     ///with addSource() before using this function.
     ///
     ///\param em must be a bool (or convertible) edge map. The algorithm
-    ///will stop when it reaches an edge \c e with \code em[e]==true \endcode.
+    ///will stop when it reaches an edge \c e with <tt>em[e]==true<\tt>.
     ///
-    ///\warning Contrary to \ref Dfs and \ref Dijkstra, \c em is an edge map,
+    ///\return The reached edge \c e with <tt>em[e]==true<\tt> or
+    ///\c INVALID if no such edge was found.
+    ///
+    ///\warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an edge map,
     ///not a node map.
     template<class EM>
-    void start(const EM &em)
+    Edge start(const EM &em)
     {
-      while ( !emptyQueue() && !em[_stack[_stack_head]] ) processNextEdge();
+      while ( !emptyQueue() && !em[_stack[_stack_head]] )
+        processNextEdge();
+      return emptyQueue() ? INVALID : _stack[_stack_head];
     }
 
     ///Runs %DFS algorithm to visit all nodes in the graph.
@@ -1441,7 +1446,7 @@
     /// \pre init() must be called and at least one node should be added
     /// with addSource() before using this function.
     void start(Node dest) {
-      while ( !emptyQueue() && _graph->target(_stack[_stack_head]) != dest) 
+      while ( !emptyQueue() && _graph->target(_stack[_stack_head]) != dest ) 
 	processNextEdge();
     }
     
@@ -1453,13 +1458,18 @@
     /// with addSource() before using this function.
     ///
     /// \param em must be a bool (or convertible) edge map. The algorithm
-    /// will stop when it reaches an edge \c e with \code nm[e]==true \endcode.
+    /// will stop when it reaches an edge \c e with <tt>em[e]==true<\tt>.
+    ///
+    ///\return The reached edge \c e with <tt>em[e]==true<\tt> or
+    ///\c INVALID if no such edge was found.
     ///
-    /// \warning Contrary to \ref Dfs and \ref Dijkstra, \c em is an edge map,
+    /// \warning Contrary to \ref Bfs and \ref Dijkstra, \c em is an edge map,
     /// not a node map.
     template <typename EM>
-    void start(const EM &em) {
-      while (!emptyQueue() && !em[_stack[_stack_head]]) processNextEdge();
+    Edge start(const EM &em) {
+      while ( !emptyQueue() && !em[_stack[_stack_head]] )
+        processNextEdge();
+      return emptyQueue() ? INVALID : _stack[_stack_head];
     }
 
     /// \brief Runs %DFSVisit algorithm from node \c s.

Modified: lemon/trunk/lemon/dijkstra.h
==============================================================================
--- lemon/trunk/lemon/dijkstra.h	(original)
+++ lemon/trunk/lemon/dijkstra.h	Mon May  7 10:49:57 2007
@@ -601,7 +601,7 @@
     /// is empty.
     Node nextNode()
     { 
-      return _heap->empty()?_heap->top():INVALID;
+      return !_heap->empty()?_heap->top():INVALID;
     }
  
     ///\brief Returns \c false if there are nodes
@@ -664,11 +664,16 @@
     ///
     ///\param nm must be a bool (or convertible) node map. The algorithm
     ///will stop when it reaches a node \c v with <tt>nm[v]==true</tt>.
+    ///
+    ///\return The reached node \c v with <tt>nm[v]==true<\tt> or
+    ///\c INVALID if no such node was found.
     template<class NodeBoolMap>
-    void start(const NodeBoolMap &nm)
+    Node start(const NodeBoolMap &nm)
     {
       while ( !_heap->empty() && !nm[_heap->top()] ) processNextNode();
-      if ( !_heap->empty() ) finalizeNodeData(_heap->top(),_heap->prio());
+      if ( _heap->empty() ) return INVALID;
+      finalizeNodeData(_heap->top(),_heap->prio());
+      return _heap->top();
     }
     
     ///Runs %Dijkstra algorithm from node \c s.



More information about the Lemon-commits mailing list