SmartGraph can also split() a node!
authoralpar
Thu, 31 Mar 2005 14:04:13 +0000
changeset 1284b941d044f87b
parent 1283 fc20371677b9
child 1285 bf1840562c67
SmartGraph can also split() a node!
src/lemon/list_graph.h
src/lemon/smart_graph.h
     1.1 --- a/src/lemon/list_graph.h	Thu Mar 31 13:31:39 2005 +0000
     1.2 +++ b/src/lemon/list_graph.h	Thu Mar 31 14:04:13 2005 +0000
     1.3 @@ -392,8 +392,8 @@
     1.4  
     1.5      ///Split a node.
     1.6  
     1.7 -    ///This function splits a node. First new node is added to the graph, then
     1.8 -    ///the source of each outgoing edge of \c n is moved to this new node.
     1.9 +    ///This function splits a node. First a new node is added to the graph,
    1.10 +    ///then the source of each outgoing edge of \c n is moved to this new node.
    1.11      ///If \c connect is \c true (this is the default value), then a new edge
    1.12      ///from \c n to the newly created node is also added.
    1.13      ///\return The newly created node.
    1.14 @@ -402,6 +402,8 @@
    1.15      ///referencing a moved edge remain
    1.16      ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
    1.17      ///may be invalidated.
    1.18 +    ///\warning This functionality cannot be used together with the SnapShot
    1.19 +    ///feature.
    1.20      ///\todo It could be implemented in a bit faster way.
    1.21      Node split(Node n, bool connect = true) 
    1.22      {
     2.1 --- a/src/lemon/smart_graph.h	Thu Mar 31 13:31:39 2005 +0000
     2.2 +++ b/src/lemon/smart_graph.h	Thu Mar 31 14:04:13 2005 +0000
     2.3 @@ -219,6 +219,16 @@
     2.4        return prev;
     2.5      }
     2.6  
     2.7 +    Node _split(Node n, bool connect = true)
     2.8 +    {
     2.9 +      Node b = addNode();
    2.10 +      nodes[b.n].first_out=nodes[n.n].first_out;
    2.11 +      nodes[n.n].first_out=-1;
    2.12 +      for(int i=nodes[b.n].first_out;i!=-1;i++) edges[i].source=b.n;
    2.13 +      if(connect) addEdge(n,b);
    2.14 +      return b;
    2.15 +    }
    2.16 +
    2.17    };
    2.18  
    2.19    typedef AlterableGraphExtender<SmartGraphBase> AlterableSmartGraphBase;
    2.20 @@ -284,6 +294,28 @@
    2.21      }    
    2.22  
    2.23    public:
    2.24 +
    2.25 +    ///Split a node.
    2.26 +    
    2.27 +    ///This function splits a node. First a new node is added to the graph,
    2.28 +    ///then the source of each outgoing edge of \c n is moved to this new node.
    2.29 +    ///If \c connect is \c true (this is the default value), then a new edge
    2.30 +    ///from \c n to the newly created node is also added.
    2.31 +    ///\return The newly created node.
    2.32 +    ///
    2.33 +    ///\note The <tt>Edge</tt>s
    2.34 +    ///referencing a moved edge remain
    2.35 +    ///valid. However <tt>InEdge</tt>'s and <tt>OutEdge</tt>'s
    2.36 +    ///may be invalidated.
    2.37 +    ///\warning This functionality cannot be used together with the SnapShot
    2.38 +    ///feature.
    2.39 +    ///\todo It could be implemented in a bit faster way.
    2.40 +    Node split(Node n, bool connect = true) 
    2.41 +    {
    2.42 +      return _split(n,connect);
    2.43 +    }
    2.44 +  
    2.45 +
    2.46      ///Class to make a snapshot of the graph and to restrore to it later.
    2.47  
    2.48      ///Class to make a snapshot of the graph and to restrore to it later.