COIN-OR::LEMON - Graph Library

Ticket #311: 311-6-63ba9934ba2f.patch

File 311-6-63ba9934ba2f.patch, 1.7 KB (added by Peter Kovacs, 15 years ago)
  • lemon/list_graph.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1250789004 -7200
    # Node ID 63ba9934ba2f04e2107383ad15af578ace45e5b8
    # Parent  eb8f6284708adfe6ee61f7d457b73cf59499d750
    Much better implementation for node splitting (#311)
    in ListDigraph. This solution is the same as the one that
    is used in SmartDigraph. It is much faster and does not
    invalidate any iterators like the former implementation.
    
    diff --git a/lemon/list_graph.h b/lemon/list_graph.h
    a b  
    3232
    3333namespace lemon {
    3434
     35  class ListDigraph;
     36
    3537  class ListDigraphBase {
    3638
    3739  protected:
     
    6264
    6365    class Node {
    6466      friend class ListDigraphBase;
     67      friend class ListDigraph;
    6568    protected:
    6669
    6770      int id;
     
    7780
    7881    class Arc {
    7982      friend class ListDigraphBase;
     83      friend class ListDigraph;
    8084    protected:
    8185
    8286      int id;
     
    467471    ///is also added.
    468472    ///\return The newly created node.
    469473    ///
    470     ///\note \c ArcIt and \c OutArcIt iterators referencing the outgoing
    471     ///arcs of node \c n are invalidated. Other iterators remain valid.
     474    ///\note All iterators remain valid.
    472475    ///
    473476    ///\warning This functionality cannot be used together with the
    474477    ///Snapshot feature.
    475478    Node split(Node n, bool connect = true) {
    476479      Node b = addNode();
    477       for(OutArcIt e(*this,n);e!=INVALID;) {
    478         OutArcIt f=e;
    479         ++f;
    480         changeSource(e,b);
    481         e=f;
     480      nodes[b.id].first_out=nodes[n.id].first_out;
     481      nodes[n.id].first_out=-1;
     482      for(int i=nodes[b.id].first_out; i!=-1; i=arcs[i].next_out) {
     483        arcs[i].source=b.id;
    482484      }
    483485      if (connect) addArc(n,b);
    484486      return b;