[Lemon-commits] [lemon_svn] alpar: r1713 - hugo/trunk/src/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:47:08 CET 2006


Author: alpar
Date: Thu Mar 31 15:29:05 2005
New Revision: 1713

Modified:
   hugo/trunk/src/lemon/list_graph.h

Log:
- split() added

Modified: hugo/trunk/src/lemon/list_graph.h
==============================================================================
--- hugo/trunk/src/lemon/list_graph.h	(original)
+++ hugo/trunk/src/lemon/list_graph.h	Thu Mar 31 15:29:05 2005
@@ -368,7 +368,7 @@
     ///means that loops will be removed.
     ///
     ///\note The <tt>Edge</tt>s
-    ///referencing the moved edge remain
+    ///referencing a moved edge remain
     ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
     ///may be invalidated.
     void contract(Node a,Node b,bool r=true) 
@@ -390,7 +390,32 @@
       erase(b);
     }
 
+    ///Split a node.
 
+    ///This function splits a node. First new node is added to the graph, then
+    ///the source of each outgoing edge of \c n is moved to this new node.
+    ///If \c connect is \c true (this is the default value), then a new edge
+    ///from \c n to the newly created node is also added.
+    ///\return The newly created node.
+    ///
+    ///\note The <tt>Edge</tt>s
+    ///referencing a moved edge remain
+    ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
+    ///may be invalidated.
+    ///\todo It could be implemented in a bit faster way.
+    Node split(Node n, bool connect = true) 
+    {
+      Node b = addNode();
+      for(OutEdgeIt e(*this,n);e!=INVALID;) {
+ 	OutEdgeIt f=e;
+	++f;
+	moveSource(e,b);
+	e=f;
+      }
+      if(connect) addEdge(n,b);
+      return b;
+    }
+      
     ///Class to make a snapshot of the graph and to restrore to it later.
 
     ///Class to make a snapshot of the graph and to restrore to it later.



More information about the Lemon-commits mailing list