- moveHead() and moveTail() added. Not tested.
authoralpar
Sat, 30 Oct 2004 16:30:12 +0000
changeset 948bc86b64f958e
parent 947 93e9c45703ea
child 949 b16a10926781
- moveHead() and moveTail() added. Not tested.
src/lemon/list_graph.h
     1.1 --- a/src/lemon/list_graph.h	Fri Oct 29 06:04:43 2004 +0000
     1.2 +++ b/src/lemon/list_graph.h	Sat Oct 30 16:30:12 2004 +0000
     1.3 @@ -1,8 +1,26 @@
     1.4 -// -*- c++ -*-
     1.5 +/* -*- C++ -*-
     1.6 + * src/lemon/list_graph.h - Part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     1.9 + * (Egervary Combinatorial Optimization Research Group, EGRES).
    1.10 + *
    1.11 + * Permission to use, modify and distribute this software is granted
    1.12 + * provided that this copyright notice appears in all copies. For
    1.13 + * precise terms see the accompanying LICENSE file.
    1.14 + *
    1.15 + * This software is provided "AS IS" with no warranty of any kind,
    1.16 + * express or implied, and with no claim as to its suitability for any
    1.17 + * purpose.
    1.18 + *
    1.19 + */
    1.20  
    1.21  #ifndef LEMON_LIST_GRAPH_H
    1.22  #define LEMON_LIST_GRAPH_H
    1.23  
    1.24 +///\ingroup graphs
    1.25 +///\file
    1.26 +///\brief ListGraph, SymListGraph, NodeSet and EdgeSet classes.
    1.27 +
    1.28  #include <lemon/erasable_graph_extender.h>
    1.29  #include <lemon/clearable_graph_extender.h>
    1.30  #include <lemon/extendable_graph_extender.h>
    1.31 @@ -82,7 +100,9 @@
    1.32  	first_free_node(-1), edges(), first_free_edge(-1) {}
    1.33  
    1.34      
    1.35 -    ///it possible to avoid the superfluous memory allocation.
    1.36 +    ///Using this it possible to avoid the superfluous memory allocation.
    1.37 +    ///\todo more docs...
    1.38 +    ///\todo It should be defined in ListGraph.
    1.39      void reserveEdge(int n) { edges.reserve(n); };
    1.40      
    1.41      /// Maximum node ID.
    1.42 @@ -267,11 +287,55 @@
    1.43    typedef ClearableGraphExtender<ExtendableListGraphBase> ClearableListGraphBase;
    1.44    typedef ErasableGraphExtender<ClearableListGraphBase> ErasableListGraphBase;
    1.45  
    1.46 -  typedef ErasableListGraphBase ListGraph;
    1.47 +/// \addtogroup graphs
    1.48 +/// @{
    1.49  
    1.50 -}
    1.51 +  ///A list graph class.
    1.52  
    1.53 +  ///This is a simple and fast erasable graph implementation.
    1.54 +  ///
    1.55 +  ///It conforms to the
    1.56 +  ///\ref skeleton::ErasableGraph "ErasableGraph" concept.
    1.57 +  ///\sa skeleton::ErasableGraph.
    1.58  
    1.59 +  class ListGraph : public ErasableListGraphBase 
    1.60 +  {
    1.61 +  public:
    1.62 +    /// Moves the head of \c e to \c n
    1.63 +
    1.64 +    /// Moves the head of \c e to \c n
    1.65 +    ///
    1.66 +    void moveHead(Edge e, Node n) 
    1.67 +    {
    1.68 +      if(edges[e.n].next_in != -1)
    1.69 +	edges[edges[e.n].next_in].prev_in = edges[e.n].prev_in;
    1.70 +      if(edges[e.n].prev_in != -1)
    1.71 +	edges[edges[e.n].prev_in].next_in = edges[e.n].next_in;
    1.72 +      else nodes[edges[e.n].head].first_in = edges[e.n].next_in;
    1.73 +      edges[e.n].head = n.n;
    1.74 +      edges[e.n].prev_in = -1;
    1.75 +      edges[e.n].next_in = nodes[n.n].first_in;
    1.76 +      nodes[n.n].first_in = e.n;
    1.77 +    }
    1.78 +    /// Moves the tail of \c e to \c n
    1.79 +
    1.80 +    /// Moves the tail of \c e to \c n
    1.81 +    ///
    1.82 +    void moveTail(Edge e, Node n) 
    1.83 +    {
    1.84 +      if(edges[e.n].next_out != -1)
    1.85 +	edges[edges[e.n].next_out].prev_out = edges[e.n].prev_out;
    1.86 +      if(edges[e.n].prev_out != -1)
    1.87 +	edges[edges[e.n].prev_out].next_out = edges[e.n].next_out;
    1.88 +      else nodes[edges[e.n].tail].first_out = edges[e.n].next_out;
    1.89 +      edges[e.n].tail = n.n;
    1.90 +      edges[e.n].prev_out = -1;
    1.91 +      edges[e.n].next_out = nodes[n.n].first_out;
    1.92 +      nodes[n.n].first_out = e.n;
    1.93 +    }
    1.94 +  }
    1.95 +  /// @}  
    1.96 +} //namespace lemon
    1.97    
    1.98  
    1.99  #endif