# HG changeset patch # User alpar # Date 1112275745 0 # Node ID 164ca6938d092ec15d9439071805adccd799621e # Parent f2255b96c19c4e4bdc6910e9ca8d12dbaa292a85 - split() added diff -r f2255b96c19c -r 164ca6938d09 src/lemon/list_graph.h --- a/src/lemon/list_graph.h Thu Mar 31 09:33:52 2005 +0000 +++ b/src/lemon/list_graph.h Thu Mar 31 13:29:05 2005 +0000 @@ -368,7 +368,7 @@ ///means that loops will be removed. /// ///\note The Edges - ///referencing the moved edge remain + ///referencing a moved edge remain ///valid. However InEdge's and OutEdge'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 Edges + ///referencing a moved edge remain + ///valid. However InEdge's and OutEdge'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.