- split() added
authoralpar
Thu, 31 Mar 2005 13:29:05 +0000
changeset 1281164ca6938d09
parent 1280 f2255b96c19c
child 1282 81e89e2b90d1
- split() added
src/lemon/list_graph.h
     1.1 --- a/src/lemon/list_graph.h	Thu Mar 31 09:33:52 2005 +0000
     1.2 +++ b/src/lemon/list_graph.h	Thu Mar 31 13:29:05 2005 +0000
     1.3 @@ -368,7 +368,7 @@
     1.4      ///means that loops will be removed.
     1.5      ///
     1.6      ///\note The <tt>Edge</tt>s
     1.7 -    ///referencing the moved edge remain
     1.8 +    ///referencing a moved edge remain
     1.9      ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
    1.10      ///may be invalidated.
    1.11      void contract(Node a,Node b,bool r=true) 
    1.12 @@ -390,7 +390,32 @@
    1.13        erase(b);
    1.14      }
    1.15  
    1.16 +    ///Split a node.
    1.17  
    1.18 +    ///This function splits a node. First new node is added to the graph, then
    1.19 +    ///the source of each outgoing edge of \c n is moved to this new node.
    1.20 +    ///If \c connect is \c true (this is the default value), then a new edge
    1.21 +    ///from \c n to the newly created node is also added.
    1.22 +    ///\return The newly created node.
    1.23 +    ///
    1.24 +    ///\note The <tt>Edge</tt>s
    1.25 +    ///referencing a moved edge remain
    1.26 +    ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
    1.27 +    ///may be invalidated.
    1.28 +    ///\todo It could be implemented in a bit faster way.
    1.29 +    Node split(Node n, bool connect = true) 
    1.30 +    {
    1.31 +      Node b = addNode();
    1.32 +      for(OutEdgeIt e(*this,n);e!=INVALID;) {
    1.33 + 	OutEdgeIt f=e;
    1.34 +	++f;
    1.35 +	moveSource(e,b);
    1.36 +	e=f;
    1.37 +      }
    1.38 +      if(connect) addEdge(n,b);
    1.39 +      return b;
    1.40 +    }
    1.41 +      
    1.42      ///Class to make a snapshot of the graph and to restrore to it later.
    1.43  
    1.44      ///Class to make a snapshot of the graph and to restrore to it later.