lemon/list_graph.h
changeset 2126 2c8adbee9fa6
parent 2117 96efb4fa0736
child 2128 509846825ddf
equal deleted inserted replaced
32:9a07540a3ebc 33:243bd05dbd2b
   164     static Node nodeFromId(int id) { return Node(id);}
   164     static Node nodeFromId(int id) { return Node(id);}
   165     static Edge edgeFromId(int id) { return Edge(id);}
   165     static Edge edgeFromId(int id) { return Edge(id);}
   166 
   166 
   167     /// Adds a new node to the graph.
   167     /// Adds a new node to the graph.
   168 
   168 
       
   169     /// Adds a new node to the graph.
       
   170     ///
   169     /// \warning It adds the new node to the front of the list.
   171     /// \warning It adds the new node to the front of the list.
   170     /// (i.e. the lastly added node becomes the first.)
   172     /// (i.e. the lastly added node becomes the first.)
   171     Node addNode() {     
   173     Node addNode() {     
   172       int n;
   174       int n;
   173       
   175       
   347     /// Changes the target of \c e to \c n
   349     /// Changes the target of \c e to \c n
   348     ///
   350     ///
   349     ///\note The <tt>Edge</tt>s and <tt>OutEdgeIt</tt>s referencing
   351     ///\note The <tt>Edge</tt>s and <tt>OutEdgeIt</tt>s referencing
   350     ///the changed edge remain valid. However <tt>InEdgeIt</tt>s are
   352     ///the changed edge remain valid. However <tt>InEdgeIt</tt>s are
   351     ///invalidated.
   353     ///invalidated.
       
   354     ///\warning This functionality cannot be used together with the Snapshot
       
   355     ///feature.
   352     void changeTarget(Edge e, Node n) { 
   356     void changeTarget(Edge e, Node n) { 
   353       Parent::changeTarget(e,n); 
   357       Parent::changeTarget(e,n); 
   354     }
   358     }
   355     /// Changes the source of \c e to \c n
   359     /// Changes the source of \c e to \c n
   356 
   360 
   357     /// Changes the source of \c e to \c n
   361     /// Changes the source of \c e to \c n
   358     ///
   362     ///
   359     ///\note The <tt>Edge</tt>s and <tt>InEdgeIt</tt>s referencing
   363     ///\note The <tt>Edge</tt>s and <tt>InEdgeIt</tt>s referencing
   360     ///the changed edge remain valid. However <tt>OutEdgeIt</tt>s are
   364     ///the changed edge remain valid. However <tt>OutEdgeIt</tt>s are
   361     ///invalidated.
   365     ///invalidated.
       
   366     ///\warning This functionality cannot be used together with the Snapshot
       
   367     ///feature.
   362     void changeSource(Edge e, Node n) { 
   368     void changeSource(Edge e, Node n) { 
   363       Parent::changeSource(e,n);
   369       Parent::changeSource(e,n);
   364     }
   370     }
   365 
   371 
   366     /// Invert the direction of an edge.
   372     /// Invert the direction of an edge.
   367 
   373 
   368     ///\note The <tt>Edge</tt>s referencing the changed edge remain
   374     ///\note The <tt>Edge</tt>s referencing the changed edge remain
   369     ///valid. However <tt>OutEdgeIt</tt>s and <tt>InEdgeIt</tt>s are
   375     ///valid. However <tt>OutEdgeIt</tt>s and <tt>InEdgeIt</tt>s are
   370     ///invalidated.
   376     ///invalidated.
       
   377     ///\warning This functionality cannot be used together with the Snapshot
       
   378     ///feature.
   371     void reverseEdge(Edge e) {
   379     void reverseEdge(Edge e) {
   372       Node t=target(e);
   380       Node t=target(e);
   373       changeTarget(e,source(e));
   381       changeTarget(e,source(e));
   374       changeSource(e,t);
   382       changeSource(e,t);
   375     }
   383     }
   377     /// \brief Using this it is possible to avoid the superfluous memory
   385     /// \brief Using this it is possible to avoid the superfluous memory
   378     /// allocation.
   386     /// allocation.
   379 
   387 
   380     ///Using this it is possible to avoid the superfluous memory
   388     ///Using this it is possible to avoid the superfluous memory
   381     ///allocation: if you know that the graph you want to build will
   389     ///allocation: if you know that the graph you want to build will
   382     ///contain at least 10 million nodes then it is worth to reserve
   390     ///contain at least 10 million nodes then it is worth reserving
   383     ///space for this amount before starting to build the graph.
   391     ///space for this amount before starting to build the graph.
   384     void reserveNode(int n) { nodes.reserve(n); };
   392     void reserveNode(int n) { nodes.reserve(n); };
   385 
   393 
   386     /// \brief Using this it is possible to avoid the superfluous memory
   394     /// \brief Using this it is possible to avoid the superfluous memory
   387     /// allocation.
   395     /// allocation.
   402     ///
   410     ///
   403     ///\note The <tt>Edge</tt>s
   411     ///\note The <tt>Edge</tt>s
   404     ///referencing a moved edge remain
   412     ///referencing a moved edge remain
   405     ///valid. However <tt>InEdge</tt>s and <tt>OutEdge</tt>s
   413     ///valid. However <tt>InEdge</tt>s and <tt>OutEdge</tt>s
   406     ///may be invalidated.
   414     ///may be invalidated.
       
   415     ///\warning This functionality cannot be used together with the Snapshot
       
   416     ///feature.
   407     void contract(Node a, Node b, bool r = true) 
   417     void contract(Node a, Node b, bool r = true) 
   408     {
   418     {
   409       for(OutEdgeIt e(*this,b);e!=INVALID;) {
   419       for(OutEdgeIt e(*this,b);e!=INVALID;) {
   410 	OutEdgeIt f=e;
   420 	OutEdgeIt f=e;
   411 	++f;
   421 	++f;
   678         attach(_graph);
   688         attach(_graph);
   679       }
   689       }
   680       
   690       
   681       /// \brief Undo the changes until the last snapshot.
   691       /// \brief Undo the changes until the last snapshot.
   682       // 
   692       // 
   683       /// Undo the changes until last snapshot created by save().
   693       /// Undo the changes until the last snapshot created by save().
   684       ///
       
   685       /// \todo This function might be called undo().
       
   686       void restore() {
   694       void restore() {
   687 	detach();
   695 	detach();
   688 	while(!added_edges.empty()) {
   696 	while(!added_edges.empty()) {
   689 	  graph->erase(added_edges.front());
   697 	  graph->erase(added_edges.front());
   690 	  added_edges.pop_front();
   698 	  added_edges.pop_front();