src/lemon/smart_graph.h
changeset 1294 2dec219d9ca2
parent 1274 5676e48ca026
child 1307 d4acebef7276
equal deleted inserted replaced
21:c0410ee5752b 22:64acd4bcc2e9
   217       while(e!=-1 && edges[e].target!=v.n) e = edges[e].next_out;
   217       while(e!=-1 && edges[e].target!=v.n) e = edges[e].next_out;
   218       prev.n=e;
   218       prev.n=e;
   219       return prev;
   219       return prev;
   220     }
   220     }
   221 
   221 
       
   222     Node _split(Node n, bool connect = true)
       
   223     {
       
   224       Node b = addNode();
       
   225       nodes[b.n].first_out=nodes[n.n].first_out;
       
   226       nodes[n.n].first_out=-1;
       
   227       for(int i=nodes[b.n].first_out;i!=-1;i++) edges[i].source=b.n;
       
   228       if(connect) addEdge(n,b);
       
   229       return b;
       
   230     }
       
   231 
   222   };
   232   };
   223 
   233 
   224   typedef AlterableGraphExtender<SmartGraphBase> AlterableSmartGraphBase;
   234   typedef AlterableGraphExtender<SmartGraphBase> AlterableSmartGraphBase;
   225   typedef IterableGraphExtender<AlterableSmartGraphBase> IterableSmartGraphBase;
   235   typedef IterableGraphExtender<AlterableSmartGraphBase> IterableSmartGraphBase;
   226   typedef DefaultMappableGraphExtender<IterableSmartGraphBase> MappableSmartGraphBase;
   236   typedef DefaultMappableGraphExtender<IterableSmartGraphBase> MappableSmartGraphBase;
   282 	nodes.pop_back();
   292 	nodes.pop_back();
   283       }
   293       }
   284     }    
   294     }    
   285 
   295 
   286   public:
   296   public:
       
   297 
       
   298     ///Split a node.
       
   299     
       
   300     ///This function splits a node. First a new node is added to the graph,
       
   301     ///then the source of each outgoing edge of \c n is moved to this new node.
       
   302     ///If \c connect is \c true (this is the default value), then a new edge
       
   303     ///from \c n to the newly created node is also added.
       
   304     ///\return The newly created node.
       
   305     ///
       
   306     ///\note The <tt>Edge</tt>s
       
   307     ///referencing a moved edge remain
       
   308     ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
       
   309     ///may be invalidated.
       
   310     ///\warning This functionality cannot be used together with the SnapShot
       
   311     ///feature.
       
   312     ///\todo It could be implemented in a bit faster way.
       
   313     Node split(Node n, bool connect = true) 
       
   314     {
       
   315       return _split(n,connect);
       
   316     }
       
   317   
       
   318 
   287     ///Class to make a snapshot of the graph and to restrore to it later.
   319     ///Class to make a snapshot of the graph and to restrore to it later.
   288 
   320 
   289     ///Class to make a snapshot of the graph and to restrore to it later.
   321     ///Class to make a snapshot of the graph and to restrore to it later.
   290     ///
   322     ///
   291     ///The newly added nodes and edges can be removed using the
   323     ///The newly added nodes and edges can be removed using the