COIN-OR::LEMON - Graph Library

Ticket #325: stl-iterators-V2-15af6cbd7751.patch

File stl-iterators-V2-15af6cbd7751.patch, 58.1 KB (added by Gábor Gévay, 11 years ago)
  • contrib/stlit_test/stlit_test.cc

    # HG changeset patch
    # User Gabor Gevay <ggab90@gmail.com>
    # Date 1389902120 -3600
    #      Thu Jan 16 20:55:20 2014 +0100
    # Node ID 15af6cbd77513ccf5ebcff573c1275858c6dd166
    # Parent  be9aea8c23aef50ccebb617f98c7b541b12cd3f2
    Proof of concept implementation of STL style iterators V2 (#325)
    
    diff --git a/contrib/stlit_test/stlit_test.cc b/contrib/stlit_test/stlit_test.cc
    a b  
    44
    55#include <iostream>
    66#include <lemon/list_graph.h>
    7 #include <lemon/stl_iterators.h>
     7#include <lemon/bits/stl_iterators.h>
    88
    99
    1010using namespace std;
     
    2121
    2222
    2323//  //for(ListDigraph::NodeIt u(g); u!=INVALID; ++u)
    24 //  for(auto u: g.nodeColl())
     24//  for(auto u: g.nodes())
    2525//    cout<<g.id(u)<<endl;
    2626
    2727
     
    3030  for(int k=0; k<100000; k++){
    3131    int i=0;
    3232    for(ListDigraph::NodeIt u(g); u!=INVALID; ++u){
    33     //for(auto u: g.nodeColl()){
     33    //for(auto u: g.nodes()){
    3434      v[i]=u;
    3535      i++;
    3636    }
     
    5757  for(int i=0; i<n; i++)
    5858    g.addNode();
    5959
    60   for(auto u: g.nodeColl())
     60  for(auto u: g.nodes())
    6161    cout<<g.id(u)<<endl;
    6262
    63   //Test postincrement
    64 //  for(auto it=g.nodeColl().begin(); it!=g.nodeColl().end(); it++) {
    65 //    auto u=*it;
    66 //    cout<<g.id(u)<<endl;
    67 //  }
    68 
     63  /*//Test postincrement
     64  for(auto it=g.nodes().begin(); it!=g.nodes().end(); it++) {
     65    auto u=*it;
     66    cout<<g.id(u)<<endl;
     67  }*/
    6968
    7069
    7170  cout<<endl;
    7271
    7372  vector<ListDigraph::Node> v1(n);
    74   copy(g.nodeColl().begin(), g.nodeColl().end(), v1.begin());
     73  copy(g.nodes().begin(), g.nodes().end(), v1.begin());
    7574
    76   vector<ListDigraph::Node> v(g.nodeColl().begin(), g.nodeColl().end());
     75  vector<ListDigraph::Node> v(g.nodes().begin(), g.nodes().end());
    7776  g.addArc(v[0],v[1]);
    7877  g.addArc(v[0],v[2]);
    7978
     
    8382  cout<<endl;
    8483
    8584
    86   ToStlit<ListDigraph::NodeIt> st1 = g.nodeColl().begin();
    87   //auto st1 = g.nodeColl().begin();
     85  LemonItWrapper<ListDigraph::NodeIt> st1 = g.nodes().begin();
     86  //auto st1 = g.nodes().begin();
    8887  auto st2 = st1; //test assignment
    8988  ++st1; //test preincrement
    9089  st1++; //test postincrement
     
    9493
    9594  st1->operator==(st2);
    9695
     96
     97  ListGraph g2;
     98  for(auto u: g2.nodes())
     99    cout<<g2.id(u)<<endl;
     100  for(auto a: g2.outArcs(*g2.nodes().begin()))
     101    cout<<g2.id(g2.target(a))<<endl;
     102
    97103  return 0;
    98104}
  • lemon/bits/graph_extender.h

    diff --git a/lemon/bits/graph_extender.h b/lemon/bits/graph_extender.h
    a b  
    2727#include <lemon/concept_check.h>
    2828#include <lemon/concepts/maps.h>
    2929
    30 #include <lemon/stl_iterators.h>
     30#include <lemon/bits/stl_iterators.h>
    3131
    3232//\ingroup graphbits
    3333//\file
     
    118118
    119119    };
    120120
    121     LemonitWrapper1<NodeIt, Digraph> nodeColl() {
    122       return LemonitWrapper1<NodeIt, Digraph>(*this);
     121    LemonRangeWrapper1<NodeIt, Digraph> nodes() const {
     122      return LemonRangeWrapper1<NodeIt, Digraph>(*this);
    123123    }
    124124
     125
    125126    class ArcIt : public Arc {
    126127      const Digraph* _digraph;
    127128    public:
     
    144145
    145146    };
    146147
     148    LemonRangeWrapper1<ArcIt, Digraph> arcs() const {
     149      return LemonRangeWrapper1<ArcIt, Digraph>(*this);
     150    }
     151
    147152
    148153    class OutArcIt : public Arc {
    149154      const Digraph* _digraph;
     
    168173
    169174    };
    170175
    171     LemonitWrapper2<OutArcIt, Digraph, Node> outArcs(const Node& u){
    172       return LemonitWrapper2<OutArcIt, Digraph, Node>(*this, u);
     176    LemonRangeWrapper2<OutArcIt, Digraph, Node> outArcs(const Node& u) const {
     177      return LemonRangeWrapper2<OutArcIt, Digraph, Node>(*this, u);
    173178    }
    174179
    175180
     
    196201
    197202    };
    198203
     204    LemonRangeWrapper2<InArcIt, Digraph, Node> inArcs(const Node& u) const {
     205      return LemonRangeWrapper2<InArcIt, Digraph, Node>(*this, u);
     206    }
     207
    199208    // \brief Base node of the iterator
    200209    //
    201210    // Returns the base node (i.e. the source in this case) of the iterator
     
    445454
    446455    };
    447456
     457    LemonRangeWrapper1<NodeIt, Graph> nodes() const {
     458      return LemonRangeWrapper1<NodeIt, Graph>(*this);
     459    }
     460
    448461
    449462    class ArcIt : public Arc {
    450463      const Graph* _graph;
     
    468481
    469482    };
    470483
     484    LemonRangeWrapper1<ArcIt, Graph> arcs() const {
     485      return LemonRangeWrapper1<ArcIt, Graph>(*this);
     486    }
     487
    471488
    472489    class OutArcIt : public Arc {
    473490      const Graph* _graph;
     
    492509
    493510    };
    494511
     512    LemonRangeWrapper2<OutArcIt, Graph, Node> outArcs(const Node& u) const {
     513      return LemonRangeWrapper2<OutArcIt, Graph, Node>(*this, u);
     514    }
     515
    495516
    496517    class InArcIt : public Arc {
    497518      const Graph* _graph;
     
    516537
    517538    };
    518539
     540    LemonRangeWrapper2<InArcIt, Graph, Node> inArcs(const Node& u) const {
     541      return LemonRangeWrapper2<InArcIt, Graph, Node>(*this, u);
     542    }
     543
    519544
    520545    class EdgeIt : public Parent::Edge {
    521546      const Graph* _graph;
     
    539564
    540565    };
    541566
     567    LemonRangeWrapper1<EdgeIt, Graph> edges() const {
     568      return LemonRangeWrapper1<EdgeIt, Graph>(*this);
     569    }
     570
     571
    542572    class IncEdgeIt : public Parent::Edge {
    543573      friend class GraphExtender;
    544574      const Graph* _graph;
     
    564594      }
    565595    };
    566596
     597    LemonRangeWrapper2<IncEdgeIt, Graph, Node> incEdges(const Node& u) const {
     598      return LemonRangeWrapper2<IncEdgeIt, Graph, Node>(*this, u);
     599    }
     600
     601
    567602    // \brief Base node of the iterator
    568603    //
    569604    // Returns the base node (ie. the source in this case) of the iterator
  • stl_iterators.h

    diff --git a/lemon/stl_iterators.h b/lemon/bits/stl_iterators.h
    rename from lemon/stl_iterators.h
    rename to lemon/bits/stl_iterators.h
    old new  
    11/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 */
    33
    4 #ifndef LEMON_ITERATOR_WRAPPERS_H_
    5 #define LEMON_ITERATOR_WRAPPERS_H_
     4#ifndef STL_ITERATORS_H_
     5#define STL_ITERATORS_H_
    66
    77#include <lemon/core.h>
    88
     
    1616  /// (so that STL algorithms work).
    1717  /// \c T should be the lemon iterator to be decorated.
    1818  template<class T>
    19   struct ToStlit
     19  struct LemonItWrapper
    2020      : public T, public std::iterator<std::input_iterator_tag, T> {
    2121
    22     ToStlit(const T &x) : T(x) {}
     22    LemonItWrapper(const T &x) : T(x) {}
    2323
    2424    //Lemon iterators don't have operator*, (because they rather
    2525    //inherit from their "value_type"),
    2626    //so we add one that just returns the object.
    2727    const T& operator*() const {
    28       return *this;
     28      return static_cast<const T&>(*this);
    2929    }
    3030
    3131    //I can't think of any use case for this with Lemon iterators,
    3232    //but maybe it should be included for completeness.
    33     T* operator->() {
    34       return this;
     33    const T* operator->() {
     34      return static_cast<const T*>(this);
    3535    }
    3636
    3737    //Lemon iterators don't have postincrement.
    3838    void operator++(int) {
    3939      T::operator++();
    4040    }
    41     //We also have to redefine preincrement, because it disappeared
    42     //when postincrement was defined.
    43     T& operator++() {
    44       return T::operator++();
    45     }
     41
     42    using T::operator++;
    4643
    4744  };
    4845
     
    5754  /// \c LIT is the Lemon iterator that will be wrapped
    5855  /// \c P is the type of the parameter of the constructor of \c LIT.
    5956  template<class LIT, class P>
    60   class LemonitWrapper1{
     57  class LemonRangeWrapper1{
    6158    const P &_p;
    62     typedef ToStlit<LIT> It;
     59    typedef LemonItWrapper<LIT> It;
    6360  public:
    64     LemonitWrapper1(const P &p) : _p(p) {}
     61    LemonRangeWrapper1(const P &p) : _p(p) {}
    6562    It begin() const {
    6663      return It(LIT(_p));
    6764    }
     
    7067    }
    7168  };
    7269
    73   /*
    74   /// \brief Gets the collection of nodes of a graph.
    75   ///
    76   /// This function can be used for iterating on
    77   /// the nodes of a graph. It returns a wrapped NodeIt, which looks like
    78   /// an STL container (by having begin() and end())
    79   /// which you can use in range-based for loops, stl algorithms, etc.
    80   /// For example you can write:
    81   ///\code
    82   /// ListDigraph g;
    83   /// for(auto v: nodeColl(g))
    84   ///   doSomething(v);
    85   ///
    86   /// //Using an STL algorithm:
    87   /// copy(nodes(g).begin(), nodes(g).end(), vect);
    88   ///\endcode
    89   template<class GR>
    90   LemonitWrapper1<typename GR::NodeIt, GR> nodeColl(const GR &g){
    91     return LemonitWrapper1<typename GR::NodeIt, GR>(g);
    92   }
    93   */
    9470
    9571  /// \brief A generic wrapper for Lemon iterators for range-based for loops.
    9672  ///
     
    10379  /// \c P1 and \c P2 are the types of the parameters
    10480  /// of the constructor of \c LIT.
    10581  template<class LIT, class P1, class P2>
    106   class LemonitWrapper2{
     82  class LemonRangeWrapper2{
    10783    const P1 &_p1;
    10884    const P2 &_p2;
    109     typedef ToStlit<LIT> It;
     85    typedef LemonItWrapper<LIT> It;
    11086  public:
    111     LemonitWrapper2(const P1 &p1, const P2 &p2) : _p1(p1), _p2(p2) {}
     87    LemonRangeWrapper2(const P1 &p1, const P2 &p2) : _p1(p1), _p2(p2) {}
    11288    It begin() const {
    11389      return It(LIT(_p1, _p2));
    11490    }
     
    11793    }
    11894  };
    11995
    120   /*template<class GR>
    121   LemonitWrapper2<typename GR::OutArcIt, GR, typename GR::Node>
    122   outArcs(const GR &g, typename GR::Node n){
    123     return LemonitWrapper2<typename GR::OutArcIt, GR, typename GR::Node>(g,n);
    124   }*/
    125 
    126 
    127 
    128 
    129 
    130 
    131 /*
    132   //This is a variadic template version of LemonitWrapper,
    133   //to avoid having separate classes for 1 and 2 parameter versions.
    134   //The drawback of this is that it would require a C++11 compiler.
    135 
    136   #include <tuple>
    137 
    138   template<class LIT, class... P>
    139   class LemonitWrapper {
    140     const std::tuple<const P&...> _p;
    141     typedef ToStlit<LIT> It;
    142 
    143     //This is based on http://stackoverflow.com/a/7858971/708357
    144     template<int ...> struct Seq {};
    145     template<int N, int ...S> struct Gens : Gens<N-1, N-1, S...> {};
    146     template<int ...S> struct Gens<0, S...>{ typedef Seq<S...> Type; };
    147     template<int ...S> It callConstr(Seq<S...>) const {
    148       return LIT(std::get<S>(_p)...);
    149     }
    150   public:
    151     LemonitWrapper(const P&... p) : _p(p...) {}
    152 
    153     It begin() const {
    154       return It(callConstr(typename Gens<sizeof...(P)>::Type()));
    155     }
    156     It end() const {
    157       return It(lemon::INVALID);
    158     }
    159   };
    160 
    161 
    162   template<class GR>
    163   LemonitWrapper<typename GR::NodeIt, GR> nodes___var(const GR &g){
    164     return LemonitWrapper<typename GR::NodeIt, GR>(g);
    165   }
    166 
    167   template<class GR>
    168   LemonitWrapper<typename GR::OutArcIt, GR, typename GR::Node>
    169   outArcs___var(const GR &g, typename GR::Node n){
    170     return LemonitWrapper<typename GR::OutArcIt, GR, typename GR::Node>(g,n);
    171   }
    172 */
    17396
    17497}
    17598
    176 #endif /* LEMON_ITERATOR_WRAPPERS_H_ */
     99#endif /* STL_ITERATORS_H_ */
  • lemon/concepts/digraph.h

    diff --git a/lemon/concepts/digraph.h b/lemon/concepts/digraph.h
    a b  
    2727#include <lemon/concepts/maps.h>
    2828#include <lemon/concept_check.h>
    2929#include <lemon/concepts/graph_components.h>
    30 #include <lemon/stl_iterators.h>
     30#include <lemon/bits/stl_iterators.h>
    3131
    3232namespace lemon {
    3333  namespace concepts {
     
    157157      /// For example you can write:
    158158      ///\code
    159159      /// ListDigraph g;
    160       /// for(auto v: g.nodeColl())
     160      /// for(auto v: g.nodes())
    161161      ///   doSomething(v);
    162162      ///
    163163      /// //Using an STL algorithm:
    164       /// copy(g.nodeColl().begin(), g.nodeColl().end(), vect.begin());
     164      /// copy(g.nodes().begin(), g.nodes().end(), vect.begin());
    165165      ///\endcode
    166       LemonitWrapper1<NodeIt, Digraph> nodeColl() {
    167         return LemonitWrapper1<NodeIt, Digraph>(*this);
     166      LemonRangeWrapper1<NodeIt, Digraph> nodes() const {
     167        return LemonRangeWrapper1<NodeIt, Digraph>(*this);
    168168      }
    169169
    170170
     
    257257        OutArcIt& operator++() { return *this; }
    258258      };
    259259
    260       LemonitWrapper2<OutArcIt, Digraph, Node> outArcs(const Node& u){
    261         return LemonitWrapper2<OutArcIt, Digraph, Node>(*this, u);
     260      /// \brief Gets the collection of the outgoing arcs of a certain node
     261      /// of the digraph.
     262      ///
     263      /// This function can be used for iterating on the
     264      /// outgoing arcs of a certain node of the digraph. It returns a wrapped
     265      /// OutArcIt, which looks like an STL container
     266      /// (by having begin() and end()) which you can use in range-based
     267      /// for loops, stl algorithms, etc.
     268      /// For example if g is a Digraph and u is a node, you can write:
     269      ///\code
     270      /// for(auto a: g.outArcs(u))
     271      ///   doSomething(a);
     272      ///
     273      /// //Using an STL algorithm:
     274      /// copy(g.outArcs(u).begin(), g.outArcs(u).end(), vect.begin());
     275      ///\endcode
     276      LemonRangeWrapper2<OutArcIt, Digraph, Node> outArcs(const Node& u) const {
     277        return LemonRangeWrapper2<OutArcIt, Digraph, Node>(*this, u);
    262278      }
    263279
    264280
     
    307323        InArcIt& operator++() { return *this; }
    308324      };
    309325
     326      /// \brief Gets the collection of the incoming arcs of a certain node
     327      /// of the digraph.
     328      ///
     329      /// This function can be used for iterating on the
     330      /// incoming arcs of a certain node of the digraph. It returns a wrapped
     331      /// InArcIt, which looks like an STL container
     332      /// (by having begin() and end()) which you can use in range-based
     333      /// for loops, stl algorithms, etc.
     334      /// For example if g is a Digraph and u is a node, you can write:
     335      ///\code
     336      /// for(auto a: g.inArcs(u))
     337      ///   doSomething(a);
     338      ///
     339      /// //Using an STL algorithm:
     340      /// copy(g.inArcs(u).begin(), g.inArcs(u).end(), vect.begin());
     341      ///\endcode
     342      LemonRangeWrapper2<InArcIt, Digraph, Node> inArcs(const Node& u) const {
     343        return LemonRangeWrapper2<InArcIt, Digraph, Node>(*this, u);
     344      }
     345
     346
    310347      /// Iterator class for the arcs.
    311348
    312349      /// This iterator goes through each arc of the digraph.
     
    352389        ArcIt& operator++() { return *this; }
    353390      };
    354391
     392      /// \brief Gets the collection of the arcs of the digraph.
     393      ///
     394      /// This function can be used for iterating on the
     395      /// arcs of the digraph. It returns a wrapped
     396      /// ArcIt, which looks like an STL container
     397      /// (by having begin() and end()) which you can use in range-based
     398      /// for loops, stl algorithms, etc.
     399      /// For example you can write:
     400      ///\code
     401      /// ListDigraph g;
     402      /// for(auto a: g.arcs())
     403      ///   doSomething(a);
     404      ///
     405      /// //Using an STL algorithm:
     406      /// copy(g.arcs().begin(), g.arcs().end(), vect.begin());
     407      ///\endcode
     408      LemonRangeWrapper1<ArcIt, Digraph> arcs() const {
     409        return LemonRangeWrapper1<ArcIt, Digraph>(*this);
     410      }
     411
     412
    355413      /// \brief The source node of the arc.
    356414      ///
    357415      /// Returns the source node of the given arc.
  • lemon/concepts/graph.h

    diff --git a/lemon/concepts/graph.h b/lemon/concepts/graph.h
    a b  
    180180        NodeIt& operator++() { return *this; }
    181181      };
    182182
     183      /// \brief Gets the collection of the nodes of the graph.
     184      ///
     185      /// This function can be used for iterating on
     186      /// the nodes of the graph. It returns a wrapped NodeIt, which looks
     187      /// like an STL container (by having begin() and end())
     188      /// which you can use in range-based for loops, stl algorithms, etc.
     189      /// For example you can write:
     190      ///\code
     191      /// ListGraph g;
     192      /// for(auto v: g.nodes())
     193      ///   doSomething(v);
     194      ///
     195      /// //Using an STL algorithm:
     196      /// copy(g.nodes().begin(), g.nodes().end(), vect.begin());
     197      ///\endcode
     198      LemonRangeWrapper1<NodeIt, Graph> nodes() const {
     199        return LemonRangeWrapper1<NodeIt, Graph>(*this);
     200      }
     201
    183202
    184203      /// The edge type of the graph
    185204
     
    268287        EdgeIt& operator++() { return *this; }
    269288      };
    270289
     290      /// \brief Gets the collection of the edges of the graph.
     291      ///
     292      /// This function can be used for iterating on the
     293      /// edges of the graph. It returns a wrapped
     294      /// EdgeIt, which looks like an STL container
     295      /// (by having begin() and end()) which you can use in range-based
     296      /// for loops, stl algorithms, etc.
     297      /// For example you can write:
     298      ///\code
     299      /// ListGraph g;
     300      /// for(auto e: g.edges())
     301      ///   doSomething(e);
     302      ///
     303      /// //Using an STL algorithm:
     304      /// copy(g.edges().begin(), g.edges().end(), vect.begin());
     305      ///\endcode
     306      LemonRangeWrapper1<EdgeIt, Graph> edges() const {
     307        return LemonRangeWrapper1<EdgeIt, Graph>(*this);
     308      }
     309
     310
    271311      /// Iterator class for the incident edges of a node.
    272312
    273313      /// This iterator goes trough the incident undirected edges
     
    316356        IncEdgeIt& operator++() { return *this; }
    317357      };
    318358
     359      /// \brief Gets the collection of the incident undirected edges
     360      ///  of a certain node of the graph.
     361      ///
     362      /// This function can be used for iterating on the
     363      /// incident undirected edges of a certain node of the graph.
     364      /// It returns a wrapped
     365      /// IncEdgeIt, which looks like an STL container
     366      /// (by having begin() and end()) which you can use in range-based
     367      /// for loops, stl algorithms, etc.
     368      /// For example if g is a Graph and u is a Node, you can write:
     369      ///\code
     370      /// for(auto e: g.incEdges(u))
     371      ///   doSomething(e);
     372      ///
     373      /// //Using an STL algorithm:
     374      /// copy(g.incEdges(u).begin(), g.incEdges(u).end(), vect.begin());
     375      ///\endcode
     376      LemonRangeWrapper2<IncEdgeIt, Graph, Node> incEdges(const Node& u) const {
     377        return LemonRangeWrapper2<IncEdgeIt, Graph, Node>(*this, u);
     378      }
     379
     380
    319381      /// The arc type of the graph
    320382
    321383      /// This class identifies a directed arc of the graph. It also serves
     
    411473        ArcIt& operator++() { return *this; }
    412474      };
    413475
     476      /// \brief Gets the collection of the directed arcs of the graph.
     477      ///
     478      /// This function can be used for iterating on the
     479      /// arcs of the graph. It returns a wrapped
     480      /// ArcIt, which looks like an STL container
     481      /// (by having begin() and end()) which you can use in range-based
     482      /// for loops, stl algorithms, etc.
     483      /// For example you can write:
     484      ///\code
     485      /// ListGraph g;
     486      /// for(auto a: g.arcs())
     487      ///   doSomething(a);
     488      ///
     489      /// //Using an STL algorithm:
     490      /// copy(g.arcs().begin(), g.arcs().end(), vect.begin());
     491      ///\endcode
     492      LemonRangeWrapper1<ArcIt, Graph> arcs() const {
     493        return LemonRangeWrapper1<ArcIt, Graph>(*this);
     494      }
     495
     496
    414497      /// Iterator class for the outgoing arcs of a node.
    415498
    416499      /// This iterator goes trough the \e outgoing directed arcs of a
     
    459542        OutArcIt& operator++() { return *this; }
    460543      };
    461544
     545      /// \brief Gets the collection of the outgoing directed arcs of a
     546      /// certain node of the graph.
     547      ///
     548      /// This function can be used for iterating on the
     549      /// outgoing arcs of a certain node of the graph. It returns a wrapped
     550      /// OutArcIt, which looks like an STL container
     551      /// (by having begin() and end()) which you can use in range-based
     552      /// for loops, stl algorithms, etc.
     553      /// For example if g is a Graph and u is a Node, you can write:
     554      ///\code
     555      /// for(auto a: g.outArcs(u))
     556      ///   doSomething(a);
     557      ///
     558      /// //Using an STL algorithm:
     559      /// copy(g.outArcs(u).begin(), g.outArcs(u).end(), vect.begin());
     560      ///\endcode
     561      LemonRangeWrapper2<OutArcIt, Graph, Node> outArcs(const Node& u) const {
     562        return LemonRangeWrapper2<OutArcIt, Graph, Node>(*this, u);
     563      }
     564
     565
    462566      /// Iterator class for the incoming arcs of a node.
    463567
    464568      /// This iterator goes trough the \e incoming directed arcs of a
     
    507611        InArcIt& operator++() { return *this; }
    508612      };
    509613
     614      /// \brief Gets the collection of the incoming directed arcs of
     615      /// a certain node of the graph.
     616      ///
     617      /// This function can be used for iterating on the
     618      /// incoming directed arcs of a certain node of the graph. It returns
     619      /// a wrapped InArcIt, which looks like an STL container
     620      /// (by having begin() and end()) which you can use in range-based
     621      /// for loops, stl algorithms, etc.
     622      /// For example if g is a Graph and u is a Node, you can write:
     623      ///\code
     624      /// for(auto a: g.inArcs(u))
     625      ///   doSomething(a);
     626      ///
     627      /// //Using an STL algorithm:
     628      /// copy(g.inArcs(u).begin(), g.inArcs(u).end(), vect.begin());
     629      ///\endcode
     630      LemonRangeWrapper2<InArcIt, Graph, Node> inArcs(const Node& u) const {
     631        return LemonRangeWrapper2<InArcIt, Graph, Node>(*this, u);
     632      }
     633
    510634      /// \brief Standard graph map type for the nodes.
    511635      ///
    512636      /// Standard graph map type for the nodes.
  • lemon/list_graph.h

    diff --git a/lemon/list_graph.h b/lemon/list_graph.h
    a b  
    4848      int next_in, next_out;
    4949    };
    5050
    51     std::vector<NodeT> nodes;
     51    std::vector<NodeT> _nodes;
    5252
    5353    int first_node;
    5454
    5555    int first_free_node;
    5656
    57     std::vector<ArcT> arcs;
     57    std::vector<ArcT> _arcs;
    5858
    5959    int first_free_arc;
    6060
     
    9797
    9898
    9999    ListDigraphBase()
    100       : nodes(), first_node(-1),
    101         first_free_node(-1), arcs(), first_free_arc(-1) {}
    102 
    103 
    104     int maxNodeId() const { return nodes.size()-1; }
    105     int maxArcId() const { return arcs.size()-1; }
    106 
    107     Node source(Arc e) const { return Node(arcs[e.id].source); }
    108     Node target(Arc e) const { return Node(arcs[e.id].target); }
     100      : _nodes(), first_node(-1),
     101        first_free_node(-1), _arcs(), first_free_arc(-1) {}
     102
     103
     104    int maxNodeId() const { return _nodes.size()-1; }
     105    int maxArcId() const { return _arcs.size()-1; }
     106
     107    Node source(Arc e) const { return Node(_arcs[e.id].source); }
     108    Node target(Arc e) const { return Node(_arcs[e.id].target); }
    109109
    110110
    111111    void first(Node& node) const {
     
    113113    }
    114114
    115115    void next(Node& node) const {
    116       node.id = nodes[node.id].next;
     116      node.id = _nodes[node.id].next;
    117117    }
    118118
    119119
    120120    void first(Arc& arc) const {
    121121      int n;
    122122      for(n = first_node;
    123           n != -1 && nodes[n].first_out == -1;
    124           n = nodes[n].next) {}
    125       arc.id = (n == -1) ? -1 : nodes[n].first_out;
     123          n != -1 && _nodes[n].first_out == -1;
     124          n = _nodes[n].next) {}
     125      arc.id = (n == -1) ? -1 : _nodes[n].first_out;
    126126    }
    127127
    128128    void next(Arc& arc) const {
    129       if (arcs[arc.id].next_out != -1) {
    130         arc.id = arcs[arc.id].next_out;
     129      if (_arcs[arc.id].next_out != -1) {
     130        arc.id = _arcs[arc.id].next_out;
    131131      } else {
    132132        int n;
    133         for(n = nodes[arcs[arc.id].source].next;
    134             n != -1 && nodes[n].first_out == -1;
    135             n = nodes[n].next) {}
    136         arc.id = (n == -1) ? -1 : nodes[n].first_out;
     133        for(n = _nodes[_arcs[arc.id].source].next;
     134            n != -1 && _nodes[n].first_out == -1;
     135            n = _nodes[n].next) {}
     136        arc.id = (n == -1) ? -1 : _nodes[n].first_out;
    137137      }
    138138    }
    139139
    140140    void firstOut(Arc &e, const Node& v) const {
    141       e.id = nodes[v.id].first_out;
     141      e.id = _nodes[v.id].first_out;
    142142    }
    143143    void nextOut(Arc &e) const {
    144       e.id=arcs[e.id].next_out;
     144      e.id=_arcs[e.id].next_out;
    145145    }
    146146
    147147    void firstIn(Arc &e, const Node& v) const {
    148       e.id = nodes[v.id].first_in;
     148      e.id = _nodes[v.id].first_in;
    149149    }
    150150    void nextIn(Arc &e) const {
    151       e.id=arcs[e.id].next_in;
     151      e.id=_arcs[e.id].next_in;
    152152    }
    153153
    154154
     
    159159    static Arc arcFromId(int id) { return Arc(id);}
    160160
    161161    bool valid(Node n) const {
    162       return n.id >= 0 && n.id < static_cast<int>(nodes.size()) &&
    163         nodes[n.id].prev != -2;
     162      return n.id >= 0 && n.id < static_cast<int>(_nodes.size()) &&
     163        _nodes[n.id].prev != -2;
    164164    }
    165165
    166166    bool valid(Arc a) const {
    167       return a.id >= 0 && a.id < static_cast<int>(arcs.size()) &&
    168         arcs[a.id].prev_in != -2;
     167      return a.id >= 0 && a.id < static_cast<int>(_arcs.size()) &&
     168        _arcs[a.id].prev_in != -2;
    169169    }
    170170
    171171    Node addNode() {
    172172      int n;
    173173
    174174      if(first_free_node==-1) {
    175         n = nodes.size();
    176         nodes.push_back(NodeT());
     175        n = _nodes.size();
     176        _nodes.push_back(NodeT());
    177177      } else {
    178178        n = first_free_node;
    179         first_free_node = nodes[n].next;
     179        first_free_node = _nodes[n].next;
    180180      }
    181181
    182       nodes[n].next = first_node;
    183       if(first_node != -1) nodes[first_node].prev = n;
     182      _nodes[n].next = first_node;
     183      if(first_node != -1) _nodes[first_node].prev = n;
    184184      first_node = n;
    185       nodes[n].prev = -1;
    186 
    187       nodes[n].first_in = nodes[n].first_out = -1;
     185      _nodes[n].prev = -1;
     186
     187      _nodes[n].first_in = _nodes[n].first_out = -1;
    188188
    189189      return Node(n);
    190190    }
     
    193193      int n;
    194194
    195195      if (first_free_arc == -1) {
    196         n = arcs.size();
    197         arcs.push_back(ArcT());
     196        n = _arcs.size();
     197        _arcs.push_back(ArcT());
    198198      } else {
    199199        n = first_free_arc;
    200         first_free_arc = arcs[n].next_in;
     200        first_free_arc = _arcs[n].next_in;
    201201      }
    202202
    203       arcs[n].source = u.id;
    204       arcs[n].target = v.id;
    205 
    206       arcs[n].next_out = nodes[u.id].first_out;
    207       if(nodes[u.id].first_out != -1) {
    208         arcs[nodes[u.id].first_out].prev_out = n;
     203      _arcs[n].source = u.id;
     204      _arcs[n].target = v.id;
     205
     206      _arcs[n].next_out = _nodes[u.id].first_out;
     207      if(_nodes[u.id].first_out != -1) {
     208        _arcs[_nodes[u.id].first_out].prev_out = n;
    209209      }
    210210
    211       arcs[n].next_in = nodes[v.id].first_in;
    212       if(nodes[v.id].first_in != -1) {
    213         arcs[nodes[v.id].first_in].prev_in = n;
     211      _arcs[n].next_in = _nodes[v.id].first_in;
     212      if(_nodes[v.id].first_in != -1) {
     213        _arcs[_nodes[v.id].first_in].prev_in = n;
    214214      }
    215215
    216       arcs[n].prev_in = arcs[n].prev_out = -1;
    217 
    218       nodes[u.id].first_out = nodes[v.id].first_in = n;
     216      _arcs[n].prev_in = _arcs[n].prev_out = -1;
     217
     218      _nodes[u.id].first_out = _nodes[v.id].first_in = n;
    219219
    220220      return Arc(n);
    221221    }
     
    223223    void erase(const Node& node) {
    224224      int n = node.id;
    225225
    226       if(nodes[n].next != -1) {
    227         nodes[nodes[n].next].prev = nodes[n].prev;
     226      if(_nodes[n].next != -1) {
     227        _nodes[_nodes[n].next].prev = _nodes[n].prev;
    228228      }
    229229
    230       if(nodes[n].prev != -1) {
    231         nodes[nodes[n].prev].next = nodes[n].next;
     230      if(_nodes[n].prev != -1) {
     231        _nodes[_nodes[n].prev].next = _nodes[n].next;
    232232      } else {
    233         first_node = nodes[n].next;
     233        first_node = _nodes[n].next;
    234234      }
    235235
    236       nodes[n].next = first_free_node;
     236      _nodes[n].next = first_free_node;
    237237      first_free_node = n;
    238       nodes[n].prev = -2;
     238      _nodes[n].prev = -2;
    239239
    240240    }
    241241
    242242    void erase(const Arc& arc) {
    243243      int n = arc.id;
    244244
    245       if(arcs[n].next_in!=-1) {
    246         arcs[arcs[n].next_in].prev_in = arcs[n].prev_in;
     245      if(_arcs[n].next_in!=-1) {
     246        _arcs[_arcs[n].next_in].prev_in = _arcs[n].prev_in;
    247247      }
    248248
    249       if(arcs[n].prev_in!=-1) {
    250         arcs[arcs[n].prev_in].next_in = arcs[n].next_in;
     249      if(_arcs[n].prev_in!=-1) {
     250        _arcs[_arcs[n].prev_in].next_in = _arcs[n].next_in;
    251251      } else {
    252         nodes[arcs[n].target].first_in = arcs[n].next_in;
     252        _nodes[_arcs[n].target].first_in = _arcs[n].next_in;
    253253      }
    254254
    255255
    256       if(arcs[n].next_out!=-1) {
    257         arcs[arcs[n].next_out].prev_out = arcs[n].prev_out;
     256      if(_arcs[n].next_out!=-1) {
     257        _arcs[_arcs[n].next_out].prev_out = _arcs[n].prev_out;
    258258      }
    259259
    260       if(arcs[n].prev_out!=-1) {
    261         arcs[arcs[n].prev_out].next_out = arcs[n].next_out;
     260      if(_arcs[n].prev_out!=-1) {
     261        _arcs[_arcs[n].prev_out].next_out = _arcs[n].next_out;
    262262      } else {
    263         nodes[arcs[n].source].first_out = arcs[n].next_out;
     263        _nodes[_arcs[n].source].first_out = _arcs[n].next_out;
    264264      }
    265265
    266       arcs[n].next_in = first_free_arc;
     266      _arcs[n].next_in = first_free_arc;
    267267      first_free_arc = n;
    268       arcs[n].prev_in = -2;
     268      _arcs[n].prev_in = -2;
    269269    }
    270270
    271271    void clear() {
    272       arcs.clear();
    273       nodes.clear();
     272      _arcs.clear();
     273      _nodes.clear();
    274274      first_node = first_free_node = first_free_arc = -1;
    275275    }
    276276
    277277  protected:
    278278    void changeTarget(Arc e, Node n)
    279279    {
    280       if(arcs[e.id].next_in != -1)
    281         arcs[arcs[e.id].next_in].prev_in = arcs[e.id].prev_in;
    282       if(arcs[e.id].prev_in != -1)
    283         arcs[arcs[e.id].prev_in].next_in = arcs[e.id].next_in;
    284       else nodes[arcs[e.id].target].first_in = arcs[e.id].next_in;
    285       if (nodes[n.id].first_in != -1) {
    286         arcs[nodes[n.id].first_in].prev_in = e.id;
     280      if(_arcs[e.id].next_in != -1)
     281        _arcs[_arcs[e.id].next_in].prev_in = _arcs[e.id].prev_in;
     282      if(_arcs[e.id].prev_in != -1)
     283        _arcs[_arcs[e.id].prev_in].next_in = _arcs[e.id].next_in;
     284      else _nodes[_arcs[e.id].target].first_in = _arcs[e.id].next_in;
     285      if (_nodes[n.id].first_in != -1) {
     286        _arcs[_nodes[n.id].first_in].prev_in = e.id;
    287287      }
    288       arcs[e.id].target = n.id;
    289       arcs[e.id].prev_in = -1;
    290       arcs[e.id].next_in = nodes[n.id].first_in;
    291       nodes[n.id].first_in = e.id;
     288      _arcs[e.id].target = n.id;
     289      _arcs[e.id].prev_in = -1;
     290      _arcs[e.id].next_in = _nodes[n.id].first_in;
     291      _nodes[n.id].first_in = e.id;
    292292    }
    293293    void changeSource(Arc e, Node n)
    294294    {
    295       if(arcs[e.id].next_out != -1)
    296         arcs[arcs[e.id].next_out].prev_out = arcs[e.id].prev_out;
    297       if(arcs[e.id].prev_out != -1)
    298         arcs[arcs[e.id].prev_out].next_out = arcs[e.id].next_out;
    299       else nodes[arcs[e.id].source].first_out = arcs[e.id].next_out;
    300       if (nodes[n.id].first_out != -1) {
    301         arcs[nodes[n.id].first_out].prev_out = e.id;
     295      if(_arcs[e.id].next_out != -1)
     296        _arcs[_arcs[e.id].next_out].prev_out = _arcs[e.id].prev_out;
     297      if(_arcs[e.id].prev_out != -1)
     298        _arcs[_arcs[e.id].prev_out].next_out = _arcs[e.id].next_out;
     299      else _nodes[_arcs[e.id].source].first_out = _arcs[e.id].next_out;
     300      if (_nodes[n.id].first_out != -1) {
     301        _arcs[_nodes[n.id].first_out].prev_out = e.id;
    302302      }
    303       arcs[e.id].source = n.id;
    304       arcs[e.id].prev_out = -1;
    305       arcs[e.id].next_out = nodes[n.id].first_out;
    306       nodes[n.id].first_out = e.id;
     303      _arcs[e.id].source = n.id;
     304      _arcs[e.id].prev_out = -1;
     305      _arcs[e.id].next_out = _nodes[n.id].first_out;
     306      _nodes[n.id].first_out = e.id;
    307307    }
    308308
    309309  };
     
    486486    ///Snapshot feature.
    487487    Node split(Node n, bool connect = true) {
    488488      Node b = addNode();
    489       nodes[b.id].first_out=nodes[n.id].first_out;
    490       nodes[n.id].first_out=-1;
    491       for(int i=nodes[b.id].first_out; i!=-1; i=arcs[i].next_out) {
    492         arcs[i].source=b.id;
     489      _nodes[b.id].first_out=_nodes[n.id].first_out;
     490      _nodes[n.id].first_out=-1;
     491      for(int i=_nodes[b.id].first_out; i!=-1; i=_arcs[i].next_out) {
     492        _arcs[i].source=b.id;
    493493      }
    494494      if (connect) addArc(n,b);
    495495      return b;
     
    532532    /// then it is worth reserving space for this amount before starting
    533533    /// to build the digraph.
    534534    /// \sa reserveArc()
    535     void reserveNode(int n) { nodes.reserve(n); };
     535    void reserveNode(int n) { _nodes.reserve(n); };
    536536
    537537    /// Reserve memory for arcs.
    538538
     
    542542    /// then it is worth reserving space for this amount before starting
    543543    /// to build the digraph.
    544544    /// \sa reserveNode()
    545     void reserveArc(int m) { arcs.reserve(m); };
     545    void reserveArc(int m) { _arcs.reserve(m); };
    546546
    547547    /// \brief Class to make a snapshot of the digraph and restore
    548548    /// it later.
     
    803803      int prev_out, next_out;
    804804    };
    805805
    806     std::vector<NodeT> nodes;
     806    std::vector<NodeT> _nodes;
    807807
    808808    int first_node;
    809809
    810810    int first_free_node;
    811811
    812     std::vector<ArcT> arcs;
     812    std::vector<ArcT> _arcs;
    813813
    814814    int first_free_arc;
    815815
     
    867867    };
    868868
    869869    ListGraphBase()
    870       : nodes(), first_node(-1),
    871         first_free_node(-1), arcs(), first_free_arc(-1) {}
    872 
    873 
    874     int maxNodeId() const { return nodes.size()-1; }
    875     int maxEdgeId() const { return arcs.size() / 2 - 1; }
    876     int maxArcId() const { return arcs.size()-1; }
    877 
    878     Node source(Arc e) const { return Node(arcs[e.id ^ 1].target); }
    879     Node target(Arc e) const { return Node(arcs[e.id].target); }
    880 
    881     Node u(Edge e) const { return Node(arcs[2 * e.id].target); }
    882     Node v(Edge e) const { return Node(arcs[2 * e.id + 1].target); }
     870      : _nodes(), first_node(-1),
     871        first_free_node(-1), _arcs(), first_free_arc(-1) {}
     872
     873
     874    int maxNodeId() const { return _nodes.size()-1; }
     875    int maxEdgeId() const { return _arcs.size() / 2 - 1; }
     876    int maxArcId() const { return _arcs.size()-1; }
     877
     878    Node source(Arc e) const { return Node(_arcs[e.id ^ 1].target); }
     879    Node target(Arc e) const { return Node(_arcs[e.id].target); }
     880
     881    Node u(Edge e) const { return Node(_arcs[2 * e.id].target); }
     882    Node v(Edge e) const { return Node(_arcs[2 * e.id + 1].target); }
    883883
    884884    static bool direction(Arc e) {
    885885      return (e.id & 1) == 1;
     
    894894    }
    895895
    896896    void next(Node& node) const {
    897       node.id = nodes[node.id].next;
     897      node.id = _nodes[node.id].next;
    898898    }
    899899
    900900    void first(Arc& e) const {
    901901      int n = first_node;
    902       while (n != -1 && nodes[n].first_out == -1) {
    903         n = nodes[n].next;
     902      while (n != -1 && _nodes[n].first_out == -1) {
     903        n = _nodes[n].next;
    904904      }
    905       e.id = (n == -1) ? -1 : nodes[n].first_out;
     905      e.id = (n == -1) ? -1 : _nodes[n].first_out;
    906906    }
    907907
    908908    void next(Arc& e) const {
    909       if (arcs[e.id].next_out != -1) {
    910         e.id = arcs[e.id].next_out;
     909      if (_arcs[e.id].next_out != -1) {
     910        e.id = _arcs[e.id].next_out;
    911911      } else {
    912         int n = nodes[arcs[e.id ^ 1].target].next;
    913         while(n != -1 && nodes[n].first_out == -1) {
    914           n = nodes[n].next;
     912        int n = _nodes[_arcs[e.id ^ 1].target].next;
     913        while(n != -1 && _nodes[n].first_out == -1) {
     914          n = _nodes[n].next;
    915915        }
    916         e.id = (n == -1) ? -1 : nodes[n].first_out;
     916        e.id = (n == -1) ? -1 : _nodes[n].first_out;
    917917      }
    918918    }
    919919
    920920    void first(Edge& e) const {
    921921      int n = first_node;
    922922      while (n != -1) {
    923         e.id = nodes[n].first_out;
     923        e.id = _nodes[n].first_out;
    924924        while ((e.id & 1) != 1) {
    925           e.id = arcs[e.id].next_out;
     925          e.id = _arcs[e.id].next_out;
    926926        }
    927927        if (e.id != -1) {
    928928          e.id /= 2;
    929929          return;
    930930        }
    931         n = nodes[n].next;
     931        n = _nodes[n].next;
    932932      }
    933933      e.id = -1;
    934934    }
    935935
    936936    void next(Edge& e) const {
    937       int n = arcs[e.id * 2].target;
    938       e.id = arcs[(e.id * 2) | 1].next_out;
     937      int n = _arcs[e.id * 2].target;
     938      e.id = _arcs[(e.id * 2) | 1].next_out;
    939939      while ((e.id & 1) != 1) {
    940         e.id = arcs[e.id].next_out;
     940        e.id = _arcs[e.id].next_out;
    941941      }
    942942      if (e.id != -1) {
    943943        e.id /= 2;
    944944        return;
    945945      }
    946       n = nodes[n].next;
     946      n = _nodes[n].next;
    947947      while (n != -1) {
    948         e.id = nodes[n].first_out;
     948        e.id = _nodes[n].first_out;
    949949        while ((e.id & 1) != 1) {
    950           e.id = arcs[e.id].next_out;
     950          e.id = _arcs[e.id].next_out;
    951951        }
    952952        if (e.id != -1) {
    953953          e.id /= 2;
    954954          return;
    955955        }
    956         n = nodes[n].next;
     956        n = _nodes[n].next;
    957957      }
    958958      e.id = -1;
    959959    }
    960960
    961961    void firstOut(Arc &e, const Node& v) const {
    962       e.id = nodes[v.id].first_out;
     962      e.id = _nodes[v.id].first_out;
    963963    }
    964964    void nextOut(Arc &e) const {
    965       e.id = arcs[e.id].next_out;
     965      e.id = _arcs[e.id].next_out;
    966966    }
    967967
    968968    void firstIn(Arc &e, const Node& v) const {
    969       e.id = ((nodes[v.id].first_out) ^ 1);
     969      e.id = ((_nodes[v.id].first_out) ^ 1);
    970970      if (e.id == -2) e.id = -1;
    971971    }
    972972    void nextIn(Arc &e) const {
    973       e.id = ((arcs[e.id ^ 1].next_out) ^ 1);
     973      e.id = ((_arcs[e.id ^ 1].next_out) ^ 1);
    974974      if (e.id == -2) e.id = -1;
    975975    }
    976976
    977977    void firstInc(Edge &e, bool& d, const Node& v) const {
    978       int a = nodes[v.id].first_out;
     978      int a = _nodes[v.id].first_out;
    979979      if (a != -1 ) {
    980980        e.id = a / 2;
    981981        d = ((a & 1) == 1);
     
    985985      }
    986986    }
    987987    void nextInc(Edge &e, bool& d) const {
    988       int a = (arcs[(e.id * 2) | (d ? 1 : 0)].next_out);
     988      int a = (_arcs[(e.id * 2) | (d ? 1 : 0)].next_out);
    989989      if (a != -1 ) {
    990990        e.id = a / 2;
    991991        d = ((a & 1) == 1);
     
    10041004    static Edge edgeFromId(int id) { return Edge(id);}
    10051005
    10061006    bool valid(Node n) const {
    1007       return n.id >= 0 && n.id < static_cast<int>(nodes.size()) &&
    1008         nodes[n.id].prev != -2;
     1007      return n.id >= 0 && n.id < static_cast<int>(_nodes.size()) &&
     1008        _nodes[n.id].prev != -2;
    10091009    }
    10101010
    10111011    bool valid(Arc a) const {
    1012       return a.id >= 0 && a.id < static_cast<int>(arcs.size()) &&
    1013         arcs[a.id].prev_out != -2;
     1012      return a.id >= 0 && a.id < static_cast<int>(_arcs.size()) &&
     1013        _arcs[a.id].prev_out != -2;
    10141014    }
    10151015
    10161016    bool valid(Edge e) const {
    1017       return e.id >= 0 && 2 * e.id < static_cast<int>(arcs.size()) &&
    1018         arcs[2 * e.id].prev_out != -2;
     1017      return e.id >= 0 && 2 * e.id < static_cast<int>(_arcs.size()) &&
     1018        _arcs[2 * e.id].prev_out != -2;
    10191019    }
    10201020
    10211021    Node addNode() {
    10221022      int n;
    10231023
    10241024      if(first_free_node==-1) {
    1025         n = nodes.size();
    1026         nodes.push_back(NodeT());
     1025        n = _nodes.size();
     1026        _nodes.push_back(NodeT());
    10271027      } else {
    10281028        n = first_free_node;
    1029         first_free_node = nodes[n].next;
     1029        first_free_node = _nodes[n].next;
    10301030      }
    10311031
    1032       nodes[n].next = first_node;
    1033       if (first_node != -1) nodes[first_node].prev = n;
     1032      _nodes[n].next = first_node;
     1033      if (first_node != -1) _nodes[first_node].prev = n;
    10341034      first_node = n;
    1035       nodes[n].prev = -1;
    1036 
    1037       nodes[n].first_out = -1;
     1035      _nodes[n].prev = -1;
     1036
     1037      _nodes[n].first_out = -1;
    10381038
    10391039      return Node(n);
    10401040    }
     
    10431043      int n;
    10441044
    10451045      if (first_free_arc == -1) {
    1046         n = arcs.size();
    1047         arcs.push_back(ArcT());
    1048         arcs.push_back(ArcT());
     1046        n = _arcs.size();
     1047        _arcs.push_back(ArcT());
     1048        _arcs.push_back(ArcT());
    10491049      } else {
    10501050        n = first_free_arc;
    1051         first_free_arc = arcs[n].next_out;
     1051        first_free_arc = _arcs[n].next_out;
    10521052      }
    10531053
    1054       arcs[n].target = u.id;
    1055       arcs[n | 1].target = v.id;
    1056 
    1057       arcs[n].next_out = nodes[v.id].first_out;
    1058       if (nodes[v.id].first_out != -1) {
    1059         arcs[nodes[v.id].first_out].prev_out = n;
     1054      _arcs[n].target = u.id;
     1055      _arcs[n | 1].target = v.id;
     1056
     1057      _arcs[n].next_out = _nodes[v.id].first_out;
     1058      if (_nodes[v.id].first_out != -1) {
     1059        _arcs[_nodes[v.id].first_out].prev_out = n;
    10601060      }
    1061       arcs[n].prev_out = -1;
    1062       nodes[v.id].first_out = n;
    1063 
    1064       arcs[n | 1].next_out = nodes[u.id].first_out;
    1065       if (nodes[u.id].first_out != -1) {
    1066         arcs[nodes[u.id].first_out].prev_out = (n | 1);
     1061      _arcs[n].prev_out = -1;
     1062      _nodes[v.id].first_out = n;
     1063
     1064      _arcs[n | 1].next_out = _nodes[u.id].first_out;
     1065      if (_nodes[u.id].first_out != -1) {
     1066        _arcs[_nodes[u.id].first_out].prev_out = (n | 1);
    10671067      }
    1068       arcs[n | 1].prev_out = -1;
    1069       nodes[u.id].first_out = (n | 1);
     1068      _arcs[n | 1].prev_out = -1;
     1069      _nodes[u.id].first_out = (n | 1);
    10701070
    10711071      return Edge(n / 2);
    10721072    }
     
    10741074    void erase(const Node& node) {
    10751075      int n = node.id;
    10761076
    1077       if(nodes[n].next != -1) {
    1078         nodes[nodes[n].next].prev = nodes[n].prev;
     1077      if(_nodes[n].next != -1) {
     1078        _nodes[_nodes[n].next].prev = _nodes[n].prev;
    10791079      }
    10801080
    1081       if(nodes[n].prev != -1) {
    1082         nodes[nodes[n].prev].next = nodes[n].next;
     1081      if(_nodes[n].prev != -1) {
     1082        _nodes[_nodes[n].prev].next = _nodes[n].next;
    10831083      } else {
    1084         first_node = nodes[n].next;
     1084        first_node = _nodes[n].next;
    10851085      }
    10861086
    1087       nodes[n].next = first_free_node;
     1087      _nodes[n].next = first_free_node;
    10881088      first_free_node = n;
    1089       nodes[n].prev = -2;
     1089      _nodes[n].prev = -2;
    10901090    }
    10911091
    10921092    void erase(const Edge& edge) {
    10931093      int n = edge.id * 2;
    10941094
    1095       if (arcs[n].next_out != -1) {
    1096         arcs[arcs[n].next_out].prev_out = arcs[n].prev_out;
     1095      if (_arcs[n].next_out != -1) {
     1096        _arcs[_arcs[n].next_out].prev_out = _arcs[n].prev_out;
    10971097      }
    10981098
    1099       if (arcs[n].prev_out != -1) {
    1100         arcs[arcs[n].prev_out].next_out = arcs[n].next_out;
     1099      if (_arcs[n].prev_out != -1) {
     1100        _arcs[_arcs[n].prev_out].next_out = _arcs[n].next_out;
    11011101      } else {
    1102         nodes[arcs[n | 1].target].first_out = arcs[n].next_out;
     1102        _nodes[_arcs[n | 1].target].first_out = _arcs[n].next_out;
    11031103      }
    11041104
    1105       if (arcs[n | 1].next_out != -1) {
    1106         arcs[arcs[n | 1].next_out].prev_out = arcs[n | 1].prev_out;
     1105      if (_arcs[n | 1].next_out != -1) {
     1106        _arcs[_arcs[n | 1].next_out].prev_out = _arcs[n | 1].prev_out;
    11071107      }
    11081108
    1109       if (arcs[n | 1].prev_out != -1) {
    1110         arcs[arcs[n | 1].prev_out].next_out = arcs[n | 1].next_out;
     1109      if (_arcs[n | 1].prev_out != -1) {
     1110        _arcs[_arcs[n | 1].prev_out].next_out = _arcs[n | 1].next_out;
    11111111      } else {
    1112         nodes[arcs[n].target].first_out = arcs[n | 1].next_out;
     1112        _nodes[_arcs[n].target].first_out = _arcs[n | 1].next_out;
    11131113      }
    11141114
    1115       arcs[n].next_out = first_free_arc;
     1115      _arcs[n].next_out = first_free_arc;
    11161116      first_free_arc = n;
    1117       arcs[n].prev_out = -2;
    1118       arcs[n | 1].prev_out = -2;
     1117      _arcs[n].prev_out = -2;
     1118      _arcs[n | 1].prev_out = -2;
    11191119
    11201120    }
    11211121
    11221122    void clear() {
    1123       arcs.clear();
    1124       nodes.clear();
     1123      _arcs.clear();
     1124      _nodes.clear();
    11251125      first_node = first_free_node = first_free_arc = -1;
    11261126    }
    11271127
    11281128  protected:
    11291129
    11301130    void changeV(Edge e, Node n) {
    1131       if(arcs[2 * e.id].next_out != -1) {
    1132         arcs[arcs[2 * e.id].next_out].prev_out = arcs[2 * e.id].prev_out;
     1131      if(_arcs[2 * e.id].next_out != -1) {
     1132        _arcs[_arcs[2 * e.id].next_out].prev_out = _arcs[2 * e.id].prev_out;
    11331133      }
    1134       if(arcs[2 * e.id].prev_out != -1) {
    1135         arcs[arcs[2 * e.id].prev_out].next_out =
    1136           arcs[2 * e.id].next_out;
     1134      if(_arcs[2 * e.id].prev_out != -1) {
     1135        _arcs[_arcs[2 * e.id].prev_out].next_out =
     1136          _arcs[2 * e.id].next_out;
    11371137      } else {
    1138         nodes[arcs[(2 * e.id) | 1].target].first_out =
    1139           arcs[2 * e.id].next_out;
     1138        _nodes[_arcs[(2 * e.id) | 1].target].first_out =
     1139          _arcs[2 * e.id].next_out;
    11401140      }
    11411141
    1142       if (nodes[n.id].first_out != -1) {
    1143         arcs[nodes[n.id].first_out].prev_out = 2 * e.id;
     1142      if (_nodes[n.id].first_out != -1) {
     1143        _arcs[_nodes[n.id].first_out].prev_out = 2 * e.id;
    11441144      }
    1145       arcs[(2 * e.id) | 1].target = n.id;
    1146       arcs[2 * e.id].prev_out = -1;
    1147       arcs[2 * e.id].next_out = nodes[n.id].first_out;
    1148       nodes[n.id].first_out = 2 * e.id;
     1145      _arcs[(2 * e.id) | 1].target = n.id;
     1146      _arcs[2 * e.id].prev_out = -1;
     1147      _arcs[2 * e.id].next_out = _nodes[n.id].first_out;
     1148      _nodes[n.id].first_out = 2 * e.id;
    11491149    }
    11501150
    11511151    void changeU(Edge e, Node n) {
    1152       if(arcs[(2 * e.id) | 1].next_out != -1) {
    1153         arcs[arcs[(2 * e.id) | 1].next_out].prev_out =
    1154           arcs[(2 * e.id) | 1].prev_out;
     1152      if(_arcs[(2 * e.id) | 1].next_out != -1) {
     1153        _arcs[_arcs[(2 * e.id) | 1].next_out].prev_out =
     1154          _arcs[(2 * e.id) | 1].prev_out;
    11551155      }
    1156       if(arcs[(2 * e.id) | 1].prev_out != -1) {
    1157         arcs[arcs[(2 * e.id) | 1].prev_out].next_out =
    1158           arcs[(2 * e.id) | 1].next_out;
     1156      if(_arcs[(2 * e.id) | 1].prev_out != -1) {
     1157        _arcs[_arcs[(2 * e.id) | 1].prev_out].next_out =
     1158          _arcs[(2 * e.id) | 1].next_out;
    11591159      } else {
    1160         nodes[arcs[2 * e.id].target].first_out =
    1161           arcs[(2 * e.id) | 1].next_out;
     1160        _nodes[_arcs[2 * e.id].target].first_out =
     1161          _arcs[(2 * e.id) | 1].next_out;
    11621162      }
    11631163
    1164       if (nodes[n.id].first_out != -1) {
    1165         arcs[nodes[n.id].first_out].prev_out = ((2 * e.id) | 1);
     1164      if (_nodes[n.id].first_out != -1) {
     1165        _arcs[_nodes[n.id].first_out].prev_out = ((2 * e.id) | 1);
    11661166      }
    1167       arcs[2 * e.id].target = n.id;
    1168       arcs[(2 * e.id) | 1].prev_out = -1;
    1169       arcs[(2 * e.id) | 1].next_out = nodes[n.id].first_out;
    1170       nodes[n.id].first_out = ((2 * e.id) | 1);
     1167      _arcs[2 * e.id].target = n.id;
     1168      _arcs[(2 * e.id) | 1].prev_out = -1;
     1169      _arcs[(2 * e.id) | 1].next_out = _nodes[n.id].first_out;
     1170      _nodes[n.id].first_out = ((2 * e.id) | 1);
    11711171    }
    11721172
    11731173  };
     
    13441344    /// then it is worth reserving space for this amount before starting
    13451345    /// to build the graph.
    13461346    /// \sa reserveEdge()
    1347     void reserveNode(int n) { nodes.reserve(n); };
     1347    void reserveNode(int n) { _nodes.reserve(n); };
    13481348
    13491349    /// Reserve memory for edges.
    13501350
     
    13541354    /// then it is worth reserving space for this amount before starting
    13551355    /// to build the graph.
    13561356    /// \sa reserveNode()
    1357     void reserveEdge(int m) { arcs.reserve(2 * m); };
     1357    void reserveEdge(int m) { _arcs.reserve(2 * m); };
    13581358
    13591359    /// \brief Class to make a snapshot of the graph and restore
    13601360    /// it later.
  • lemon/smart_graph.h

    diff --git a/lemon/smart_graph.h b/lemon/smart_graph.h
    a b  
    4747      ArcT() {}
    4848    };
    4949
    50     std::vector<NodeT> nodes;
    51     std::vector<ArcT> arcs;
     50    std::vector<NodeT> _nodes;
     51    std::vector<ArcT> _arcs;
    5252
    5353  public:
    5454
     
    5959
    6060  public:
    6161
    62     SmartDigraphBase() : nodes(), arcs() { }
     62    SmartDigraphBase() : _nodes(), _arcs() { }
    6363    SmartDigraphBase(const SmartDigraphBase &_g)
    64       : nodes(_g.nodes), arcs(_g.arcs) { }
     64      : _nodes(_g._nodes), _arcs(_g._arcs) { }
    6565
    6666    typedef True NodeNumTag;
    6767    typedef True ArcNumTag;
    6868
    69     int nodeNum() const { return nodes.size(); }
    70     int arcNum() const { return arcs.size(); }
     69    int nodeNum() const { return _nodes.size(); }
     70    int arcNum() const { return _arcs.size(); }
    7171
    72     int maxNodeId() const { return nodes.size()-1; }
    73     int maxArcId() const { return arcs.size()-1; }
     72    int maxNodeId() const { return _nodes.size()-1; }
     73    int maxArcId() const { return _arcs.size()-1; }
    7474
    7575    Node addNode() {
    76       int n = nodes.size();
    77       nodes.push_back(NodeT());
    78       nodes[n].first_in = -1;
    79       nodes[n].first_out = -1;
     76      int n = _nodes.size();
     77      _nodes.push_back(NodeT());
     78      _nodes[n].first_in = -1;
     79      _nodes[n].first_out = -1;
    8080      return Node(n);
    8181    }
    8282
    8383    Arc addArc(Node u, Node v) {
    84       int n = arcs.size();
    85       arcs.push_back(ArcT());
    86       arcs[n].source = u._id;
    87       arcs[n].target = v._id;
    88       arcs[n].next_out = nodes[u._id].first_out;
    89       arcs[n].next_in = nodes[v._id].first_in;
    90       nodes[u._id].first_out = nodes[v._id].first_in = n;
     84      int n = _arcs.size();
     85      _arcs.push_back(ArcT());
     86      _arcs[n].source = u._id;
     87      _arcs[n].target = v._id;
     88      _arcs[n].next_out = _nodes[u._id].first_out;
     89      _arcs[n].next_in = _nodes[v._id].first_in;
     90      _nodes[u._id].first_out = _nodes[v._id].first_in = n;
    9191
    9292      return Arc(n);
    9393    }
    9494
    9595    void clear() {
    96       arcs.clear();
    97       nodes.clear();
     96      _arcs.clear();
     97      _nodes.clear();
    9898    }
    9999
    100     Node source(Arc a) const { return Node(arcs[a._id].source); }
    101     Node target(Arc a) const { return Node(arcs[a._id].target); }
     100    Node source(Arc a) const { return Node(_arcs[a._id].source); }
     101    Node target(Arc a) const { return Node(_arcs[a._id].target); }
    102102
    103103    static int id(Node v) { return v._id; }
    104104    static int id(Arc a) { return a._id; }
     
    107107    static Arc arcFromId(int id) { return Arc(id);}
    108108
    109109    bool valid(Node n) const {
    110       return n._id >= 0 && n._id < static_cast<int>(nodes.size());
     110      return n._id >= 0 && n._id < static_cast<int>(_nodes.size());
    111111    }
    112112    bool valid(Arc a) const {
    113       return a._id >= 0 && a._id < static_cast<int>(arcs.size());
     113      return a._id >= 0 && a._id < static_cast<int>(_arcs.size());
    114114    }
    115115
    116116    class Node {
     
    145145    };
    146146
    147147    void first(Node& node) const {
    148       node._id = nodes.size() - 1;
     148      node._id = _nodes.size() - 1;
    149149    }
    150150
    151151    static void next(Node& node) {
     
    153153    }
    154154
    155155    void first(Arc& arc) const {
    156       arc._id = arcs.size() - 1;
     156      arc._id = _arcs.size() - 1;
    157157    }
    158158
    159159    static void next(Arc& arc) {
     
    161161    }
    162162
    163163    void firstOut(Arc& arc, const Node& node) const {
    164       arc._id = nodes[node._id].first_out;
     164      arc._id = _nodes[node._id].first_out;
    165165    }
    166166
    167167    void nextOut(Arc& arc) const {
    168       arc._id = arcs[arc._id].next_out;
     168      arc._id = _arcs[arc._id].next_out;
    169169    }
    170170
    171171    void firstIn(Arc& arc, const Node& node) const {
    172       arc._id = nodes[node._id].first_in;
     172      arc._id = _nodes[node._id].first_in;
    173173    }
    174174
    175175    void nextIn(Arc& arc) const {
    176       arc._id = arcs[arc._id].next_in;
     176      arc._id = _arcs[arc._id].next_in;
    177177    }
    178178
    179179  };
     
    266266    Node split(Node n, bool connect = true)
    267267    {
    268268      Node b = addNode();
    269       nodes[b._id].first_out=nodes[n._id].first_out;
    270       nodes[n._id].first_out=-1;
    271       for(int i=nodes[b._id].first_out; i!=-1; i=arcs[i].next_out) {
    272         arcs[i].source=b._id;
     269      _nodes[b._id].first_out=_nodes[n._id].first_out;
     270      _nodes[n._id].first_out=-1;
     271      for(int i=_nodes[b._id].first_out; i!=-1; i=_arcs[i].next_out) {
     272        _arcs[i].source=b._id;
    273273      }
    274274      if(connect) addArc(n,b);
    275275      return b;
     
    291291    /// then it is worth reserving space for this amount before starting
    292292    /// to build the digraph.
    293293    /// \sa reserveArc()
    294     void reserveNode(int n) { nodes.reserve(n); };
     294    void reserveNode(int n) { _nodes.reserve(n); };
    295295
    296296    /// Reserve memory for arcs.
    297297
     
    301301    /// then it is worth reserving space for this amount before starting
    302302    /// to build the digraph.
    303303    /// \sa reserveNode()
    304     void reserveArc(int m) { arcs.reserve(m); };
     304    void reserveArc(int m) { _arcs.reserve(m); };
    305305
    306306  public:
    307307
     
    311311
    312312    void restoreSnapshot(const Snapshot &s)
    313313    {
    314       while(s.arc_num<arcs.size()) {
    315         Arc arc = arcFromId(arcs.size()-1);
     314      while(s.arc_num<_arcs.size()) {
     315        Arc arc = arcFromId(_arcs.size()-1);
    316316        Parent::notifier(Arc()).erase(arc);
    317         nodes[arcs.back().source].first_out=arcs.back().next_out;
    318         nodes[arcs.back().target].first_in=arcs.back().next_in;
    319         arcs.pop_back();
     317        _nodes[_arcs.back().source].first_out=_arcs.back().next_out;
     318        _nodes[_arcs.back().target].first_in=_arcs.back().next_in;
     319        _arcs.pop_back();
    320320      }
    321       while(s.node_num<nodes.size()) {
    322         Node node = nodeFromId(nodes.size()-1);
     321      while(s.node_num<_nodes.size()) {
     322        Node node = nodeFromId(_nodes.size()-1);
    323323        Parent::notifier(Node()).erase(node);
    324         nodes.pop_back();
     324        _nodes.pop_back();
    325325      }
    326326    }
    327327
     
    362362      ///This constructor immediately makes a snapshot of the given digraph.
    363363      ///
    364364      Snapshot(SmartDigraph &gr) : _graph(&gr) {
    365         node_num=_graph->nodes.size();
    366         arc_num=_graph->arcs.size();
     365        node_num=_graph->_nodes.size();
     366        arc_num=_graph->_arcs.size();
    367367      }
    368368
    369369      ///Make a snapshot.
     
    373373      ///call, the previous snapshot gets lost.
    374374      void save(SmartDigraph &gr) {
    375375        _graph=&gr;
    376         node_num=_graph->nodes.size();
    377         arc_num=_graph->arcs.size();
     376        node_num=_graph->_nodes.size();
     377        arc_num=_graph->_arcs.size();
    378378      }
    379379
    380380      ///Undo the changes until a snapshot.
     
    402402      int next_out;
    403403    };
    404404
    405     std::vector<NodeT> nodes;
    406     std::vector<ArcT> arcs;
     405    std::vector<NodeT> _nodes;
     406    std::vector<ArcT> _arcs;
    407407
    408408  public:
    409409
     
    465465
    466466
    467467    SmartGraphBase()
    468       : nodes(), arcs() {}
     468      : _nodes(), _arcs() {}
    469469
    470470    typedef True NodeNumTag;
    471471    typedef True EdgeNumTag;
    472472    typedef True ArcNumTag;
    473473
    474     int nodeNum() const { return nodes.size(); }
    475     int edgeNum() const { return arcs.size() / 2; }
    476     int arcNum() const { return arcs.size(); }
     474    int nodeNum() const { return _nodes.size(); }
     475    int edgeNum() const { return _arcs.size() / 2; }
     476    int arcNum() const { return _arcs.size(); }
    477477
    478     int maxNodeId() const { return nodes.size()-1; }
    479     int maxEdgeId() const { return arcs.size() / 2 - 1; }
    480     int maxArcId() const { return arcs.size()-1; }
     478    int maxNodeId() const { return _nodes.size()-1; }
     479    int maxEdgeId() const { return _arcs.size() / 2 - 1; }
     480    int maxArcId() const { return _arcs.size()-1; }
    481481
    482     Node source(Arc e) const { return Node(arcs[e._id ^ 1].target); }
    483     Node target(Arc e) const { return Node(arcs[e._id].target); }
     482    Node source(Arc e) const { return Node(_arcs[e._id ^ 1].target); }
     483    Node target(Arc e) const { return Node(_arcs[e._id].target); }
    484484
    485     Node u(Edge e) const { return Node(arcs[2 * e._id].target); }
    486     Node v(Edge e) const { return Node(arcs[2 * e._id + 1].target); }
     485    Node u(Edge e) const { return Node(_arcs[2 * e._id].target); }
     486    Node v(Edge e) const { return Node(_arcs[2 * e._id + 1].target); }
    487487
    488488    static bool direction(Arc e) {
    489489      return (e._id & 1) == 1;
     
    494494    }
    495495
    496496    void first(Node& node) const {
    497       node._id = nodes.size() - 1;
     497      node._id = _nodes.size() - 1;
    498498    }
    499499
    500500    static void next(Node& node) {
     
    502502    }
    503503
    504504    void first(Arc& arc) const {
    505       arc._id = arcs.size() - 1;
     505      arc._id = _arcs.size() - 1;
    506506    }
    507507
    508508    static void next(Arc& arc) {
     
    510510    }
    511511
    512512    void first(Edge& arc) const {
    513       arc._id = arcs.size() / 2 - 1;
     513      arc._id = _arcs.size() / 2 - 1;
    514514    }
    515515
    516516    static void next(Edge& arc) {
     
    518518    }
    519519
    520520    void firstOut(Arc &arc, const Node& v) const {
    521       arc._id = nodes[v._id].first_out;
     521      arc._id = _nodes[v._id].first_out;
    522522    }
    523523    void nextOut(Arc &arc) const {
    524       arc._id = arcs[arc._id].next_out;
     524      arc._id = _arcs[arc._id].next_out;
    525525    }
    526526
    527527    void firstIn(Arc &arc, const Node& v) const {
    528       arc._id = ((nodes[v._id].first_out) ^ 1);
     528      arc._id = ((_nodes[v._id].first_out) ^ 1);
    529529      if (arc._id == -2) arc._id = -1;
    530530    }
    531531    void nextIn(Arc &arc) const {
    532       arc._id = ((arcs[arc._id ^ 1].next_out) ^ 1);
     532      arc._id = ((_arcs[arc._id ^ 1].next_out) ^ 1);
    533533      if (arc._id == -2) arc._id = -1;
    534534    }
    535535
    536536    void firstInc(Edge &arc, bool& d, const Node& v) const {
    537       int de = nodes[v._id].first_out;
     537      int de = _nodes[v._id].first_out;
    538538      if (de != -1) {
    539539        arc._id = de / 2;
    540540        d = ((de & 1) == 1);
     
    544544      }
    545545    }
    546546    void nextInc(Edge &arc, bool& d) const {
    547       int de = (arcs[(arc._id * 2) | (d ? 1 : 0)].next_out);
     547      int de = (_arcs[(arc._id * 2) | (d ? 1 : 0)].next_out);
    548548      if (de != -1) {
    549549        arc._id = de / 2;
    550550        d = ((de & 1) == 1);
     
    563563    static Edge edgeFromId(int id) { return Edge(id);}
    564564
    565565    bool valid(Node n) const {
    566       return n._id >= 0 && n._id < static_cast<int>(nodes.size());
     566      return n._id >= 0 && n._id < static_cast<int>(_nodes.size());
    567567    }
    568568    bool valid(Arc a) const {
    569       return a._id >= 0 && a._id < static_cast<int>(arcs.size());
     569      return a._id >= 0 && a._id < static_cast<int>(_arcs.size());
    570570    }
    571571    bool valid(Edge e) const {
    572       return e._id >= 0 && 2 * e._id < static_cast<int>(arcs.size());
     572      return e._id >= 0 && 2 * e._id < static_cast<int>(_arcs.size());
    573573    }
    574574
    575575    Node addNode() {
    576       int n = nodes.size();
    577       nodes.push_back(NodeT());
    578       nodes[n].first_out = -1;
     576      int n = _nodes.size();
     577      _nodes.push_back(NodeT());
     578      _nodes[n].first_out = -1;
    579579
    580580      return Node(n);
    581581    }
    582582
    583583    Edge addEdge(Node u, Node v) {
    584       int n = arcs.size();
    585       arcs.push_back(ArcT());
    586       arcs.push_back(ArcT());
     584      int n = _arcs.size();
     585      _arcs.push_back(ArcT());
     586      _arcs.push_back(ArcT());
    587587
    588       arcs[n].target = u._id;
    589       arcs[n | 1].target = v._id;
     588      _arcs[n].target = u._id;
     589      _arcs[n | 1].target = v._id;
    590590
    591       arcs[n].next_out = nodes[v._id].first_out;
    592       nodes[v._id].first_out = n;
     591      _arcs[n].next_out = _nodes[v._id].first_out;
     592      _nodes[v._id].first_out = n;
    593593
    594       arcs[n | 1].next_out = nodes[u._id].first_out;
    595       nodes[u._id].first_out = (n | 1);
     594      _arcs[n | 1].next_out = _nodes[u._id].first_out;
     595      _nodes[u._id].first_out = (n | 1);
    596596
    597597      return Edge(n / 2);
    598598    }
    599599
    600600    void clear() {
    601       arcs.clear();
    602       nodes.clear();
     601      _arcs.clear();
     602      _nodes.clear();
    603603    }
    604604
    605605  };
     
    701701    /// then it is worth reserving space for this amount before starting
    702702    /// to build the graph.
    703703    /// \sa reserveEdge()
    704     void reserveNode(int n) { nodes.reserve(n); };
     704    void reserveNode(int n) { _nodes.reserve(n); };
    705705
    706706    /// Reserve memory for edges.
    707707
     
    711711    /// then it is worth reserving space for this amount before starting
    712712    /// to build the graph.
    713713    /// \sa reserveNode()
    714     void reserveEdge(int m) { arcs.reserve(2 * m); };
     714    void reserveEdge(int m) { _arcs.reserve(2 * m); };
    715715
    716716  public:
    717717
     
    722722    void saveSnapshot(Snapshot &s)
    723723    {
    724724      s._graph = this;
    725       s.node_num = nodes.size();
    726       s.arc_num = arcs.size();
     725      s.node_num = _nodes.size();
     726      s.arc_num = _arcs.size();
    727727    }
    728728
    729729    void restoreSnapshot(const Snapshot &s)
    730730    {
    731       while(s.arc_num<arcs.size()) {
    732         int n=arcs.size()-1;
     731      while(s.arc_num<_arcs.size()) {
     732        int n=_arcs.size()-1;
    733733        Edge arc=edgeFromId(n/2);
    734734        Parent::notifier(Edge()).erase(arc);
    735735        std::vector<Arc> dir;
    736736        dir.push_back(arcFromId(n));
    737737        dir.push_back(arcFromId(n-1));
    738738        Parent::notifier(Arc()).erase(dir);
    739         nodes[arcs[n-1].target].first_out=arcs[n].next_out;
    740         nodes[arcs[n].target].first_out=arcs[n-1].next_out;
    741         arcs.pop_back();
    742         arcs.pop_back();
     739        _nodes[_arcs[n-1].target].first_out=_arcs[n].next_out;
     740        _nodes[_arcs[n].target].first_out=_arcs[n-1].next_out;
     741        _arcs.pop_back();
     742        _arcs.pop_back();
    743743      }
    744       while(s.node_num<nodes.size()) {
    745         int n=nodes.size()-1;
     744      while(s.node_num<_nodes.size()) {
     745        int n=_nodes.size()-1;
    746746        Node node = nodeFromId(n);
    747747        Parent::notifier(Node()).erase(node);
    748         nodes.pop_back();
     748        _nodes.pop_back();
    749749      }
    750750    }
    751751