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

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


Author: alpar
Date: Thu Mar 31 16:04:13 2005
New Revision: 1716

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

Log:
SmartGraph can also split() a node!

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 16:04:13 2005
@@ -392,8 +392,8 @@
 
     ///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.
+    ///This function splits a node. First a 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.
@@ -402,6 +402,8 @@
     ///referencing a moved edge remain
     ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
     ///may be invalidated.
+    ///\warning This functionality cannot be used together with the SnapShot
+    ///feature.
     ///\todo It could be implemented in a bit faster way.
     Node split(Node n, bool connect = true) 
     {

Modified: hugo/trunk/src/lemon/smart_graph.h
==============================================================================
--- hugo/trunk/src/lemon/smart_graph.h	(original)
+++ hugo/trunk/src/lemon/smart_graph.h	Thu Mar 31 16:04:13 2005
@@ -219,6 +219,16 @@
       return prev;
     }
 
+    Node _split(Node n, bool connect = true)
+    {
+      Node b = addNode();
+      nodes[b.n].first_out=nodes[n.n].first_out;
+      nodes[n.n].first_out=-1;
+      for(int i=nodes[b.n].first_out;i!=-1;i++) edges[i].source=b.n;
+      if(connect) addEdge(n,b);
+      return b;
+    }
+
   };
 
   typedef AlterableGraphExtender<SmartGraphBase> AlterableSmartGraphBase;
@@ -284,6 +294,28 @@
     }    
 
   public:
+
+    ///Split a node.
+    
+    ///This function splits a node. First a 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.
+    ///\warning This functionality cannot be used together with the SnapShot
+    ///feature.
+    ///\todo It could be implemented in a bit faster way.
+    Node split(Node n, bool connect = true) 
+    {
+      return _split(n,connect);
+    }
+  
+
     ///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