lemon/static_graph.h
author Peter Kovacs <kpeter@inf.elte.hu>
Sat, 07 Oct 2017 15:48:00 +0200
changeset 1191 d9f79b81ef6c
parent 1124 d51126dc39fa
permissions -rw-r--r--
Change the default graph type of Vf2 and Vf2pp (#597)
alpar@877
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
kpeter@773
     2
 *
alpar@877
     3
 * This file is a part of LEMON, a generic C++ optimization library.
kpeter@773
     4
 *
alpar@877
     5
 * Copyright (C) 2003-2010
kpeter@773
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
kpeter@773
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
kpeter@773
     8
 *
kpeter@773
     9
 * Permission to use, modify and distribute this software is granted
kpeter@773
    10
 * provided that this copyright notice appears in all copies. For
kpeter@773
    11
 * precise terms see the accompanying LICENSE file.
kpeter@773
    12
 *
kpeter@773
    13
 * This software is provided "AS IS" with no warranty of any kind,
kpeter@773
    14
 * express or implied, and with no claim as to its suitability for any
kpeter@773
    15
 * purpose.
kpeter@773
    16
 *
kpeter@773
    17
 */
kpeter@773
    18
kpeter@773
    19
#ifndef LEMON_STATIC_GRAPH_H
kpeter@773
    20
#define LEMON_STATIC_GRAPH_H
kpeter@773
    21
kpeter@773
    22
///\ingroup graphs
kpeter@773
    23
///\file
kpeter@773
    24
///\brief StaticDigraph class.
kpeter@773
    25
kpeter@773
    26
#include <lemon/core.h>
kpeter@773
    27
#include <lemon/bits/graph_extender.h>
kpeter@773
    28
kpeter@773
    29
namespace lemon {
kpeter@773
    30
kpeter@773
    31
  class StaticDigraphBase {
gabriel@1157
    32
kpeter@773
    33
  public:
kpeter@773
    34
alpar@877
    35
    StaticDigraphBase()
alpar@877
    36
      : built(false), node_num(0), arc_num(0),
kpeter@773
    37
        node_first_out(NULL), node_first_in(NULL),
alpar@877
    38
        arc_source(NULL), arc_target(NULL),
kpeter@773
    39
        arc_next_in(NULL), arc_next_out(NULL) {}
alpar@877
    40
kpeter@773
    41
    ~StaticDigraphBase() {
kpeter@774
    42
      if (built) {
kpeter@773
    43
        delete[] node_first_out;
kpeter@773
    44
        delete[] node_first_in;
kpeter@773
    45
        delete[] arc_source;
kpeter@773
    46
        delete[] arc_target;
kpeter@773
    47
        delete[] arc_next_out;
kpeter@773
    48
        delete[] arc_next_in;
kpeter@773
    49
      }
kpeter@773
    50
    }
kpeter@773
    51
kpeter@773
    52
    class Node {
kpeter@773
    53
      friend class StaticDigraphBase;
kpeter@773
    54
    protected:
kpeter@773
    55
      int id;
kpeter@773
    56
      Node(int _id) : id(_id) {}
kpeter@773
    57
    public:
kpeter@773
    58
      Node() {}
kpeter@773
    59
      Node (Invalid) : id(-1) {}
kpeter@773
    60
      bool operator==(const Node& node) const { return id == node.id; }
kpeter@773
    61
      bool operator!=(const Node& node) const { return id != node.id; }
kpeter@773
    62
      bool operator<(const Node& node) const { return id < node.id; }
kpeter@773
    63
    };
kpeter@773
    64
kpeter@773
    65
    class Arc {
alpar@877
    66
      friend class StaticDigraphBase;
kpeter@773
    67
    protected:
kpeter@773
    68
      int id;
kpeter@773
    69
      Arc(int _id) : id(_id) {}
kpeter@773
    70
    public:
kpeter@773
    71
      Arc() { }
kpeter@773
    72
      Arc (Invalid) : id(-1) {}
kpeter@773
    73
      bool operator==(const Arc& arc) const { return id == arc.id; }
kpeter@773
    74
      bool operator!=(const Arc& arc) const { return id != arc.id; }
kpeter@773
    75
      bool operator<(const Arc& arc) const { return id < arc.id; }
kpeter@773
    76
    };
kpeter@773
    77
kpeter@773
    78
    Node source(const Arc& e) const { return Node(arc_source[e.id]); }
kpeter@773
    79
    Node target(const Arc& e) const { return Node(arc_target[e.id]); }
kpeter@773
    80
kpeter@773
    81
    void first(Node& n) const { n.id = node_num - 1; }
kpeter@773
    82
    static void next(Node& n) { --n.id; }
kpeter@773
    83
kpeter@773
    84
    void first(Arc& e) const { e.id = arc_num - 1; }
kpeter@773
    85
    static void next(Arc& e) { --e.id; }
kpeter@773
    86
alpar@877
    87
    void firstOut(Arc& e, const Node& n) const {
alpar@877
    88
      e.id = node_first_out[n.id] != node_first_out[n.id + 1] ?
kpeter@773
    89
        node_first_out[n.id] : -1;
kpeter@773
    90
    }
kpeter@773
    91
    void nextOut(Arc& e) const { e.id = arc_next_out[e.id]; }
kpeter@773
    92
kpeter@773
    93
    void firstIn(Arc& e, const Node& n) const { e.id = node_first_in[n.id]; }
kpeter@773
    94
    void nextIn(Arc& e) const { e.id = arc_next_in[e.id]; }
kpeter@773
    95
kpeter@778
    96
    static int id(const Node& n) { return n.id; }
kpeter@778
    97
    static Node nodeFromId(int id) { return Node(id); }
kpeter@773
    98
    int maxNodeId() const { return node_num - 1; }
kpeter@773
    99
kpeter@778
   100
    static int id(const Arc& e) { return e.id; }
kpeter@778
   101
    static Arc arcFromId(int id) { return Arc(id); }
kpeter@773
   102
    int maxArcId() const { return arc_num - 1; }
kpeter@773
   103
kpeter@773
   104
    typedef True NodeNumTag;
kpeter@773
   105
    typedef True ArcNumTag;
kpeter@773
   106
kpeter@773
   107
    int nodeNum() const { return node_num; }
kpeter@773
   108
    int arcNum() const { return arc_num; }
kpeter@773
   109
kpeter@773
   110
  private:
kpeter@773
   111
kpeter@773
   112
    template <typename Digraph, typename NodeRefMap>
kpeter@773
   113
    class ArcLess {
kpeter@773
   114
    public:
kpeter@773
   115
      typedef typename Digraph::Arc Arc;
kpeter@773
   116
alpar@877
   117
      ArcLess(const Digraph &_graph, const NodeRefMap& _nodeRef)
kpeter@773
   118
        : digraph(_graph), nodeRef(_nodeRef) {}
alpar@877
   119
kpeter@773
   120
      bool operator()(const Arc& left, const Arc& right) const {
alpar@877
   121
        return nodeRef[digraph.target(left)] < nodeRef[digraph.target(right)];
kpeter@773
   122
      }
kpeter@773
   123
    private:
kpeter@773
   124
      const Digraph& digraph;
kpeter@773
   125
      const NodeRefMap& nodeRef;
kpeter@773
   126
    };
alpar@877
   127
kpeter@773
   128
  public:
kpeter@773
   129
kpeter@773
   130
    typedef True BuildTag;
alpar@877
   131
kpeter@774
   132
    void clear() {
kpeter@774
   133
      if (built) {
kpeter@773
   134
        delete[] node_first_out;
kpeter@773
   135
        delete[] node_first_in;
kpeter@773
   136
        delete[] arc_source;
kpeter@773
   137
        delete[] arc_target;
kpeter@773
   138
        delete[] arc_next_out;
kpeter@773
   139
        delete[] arc_next_in;
kpeter@773
   140
      }
kpeter@774
   141
      built = false;
kpeter@774
   142
      node_num = 0;
kpeter@774
   143
      arc_num = 0;
kpeter@774
   144
    }
alpar@877
   145
kpeter@774
   146
    template <typename Digraph, typename NodeRefMap, typename ArcRefMap>
kpeter@774
   147
    void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
kpeter@773
   148
      typedef typename Digraph::Node GNode;
kpeter@773
   149
      typedef typename Digraph::Arc GArc;
kpeter@773
   150
kpeter@774
   151
      built = true;
kpeter@774
   152
kpeter@773
   153
      node_num = countNodes(digraph);
kpeter@773
   154
      arc_num = countArcs(digraph);
kpeter@773
   155
kpeter@773
   156
      node_first_out = new int[node_num + 1];
kpeter@773
   157
      node_first_in = new int[node_num];
kpeter@773
   158
kpeter@773
   159
      arc_source = new int[arc_num];
kpeter@773
   160
      arc_target = new int[arc_num];
kpeter@773
   161
      arc_next_out = new int[arc_num];
kpeter@773
   162
      arc_next_in = new int[arc_num];
kpeter@773
   163
kpeter@773
   164
      int node_index = 0;
kpeter@773
   165
      for (typename Digraph::NodeIt n(digraph); n != INVALID; ++n) {
kpeter@773
   166
        nodeRef[n] = Node(node_index);
kpeter@773
   167
        node_first_in[node_index] = -1;
kpeter@773
   168
        ++node_index;
kpeter@773
   169
      }
kpeter@773
   170
kpeter@773
   171
      ArcLess<Digraph, NodeRefMap> arcLess(digraph, nodeRef);
kpeter@773
   172
kpeter@773
   173
      int arc_index = 0;
kpeter@773
   174
      for (typename Digraph::NodeIt n(digraph); n != INVALID; ++n) {
kpeter@773
   175
        int source = nodeRef[n].id;
kpeter@773
   176
        std::vector<GArc> arcs;
kpeter@773
   177
        for (typename Digraph::OutArcIt e(digraph, n); e != INVALID; ++e) {
kpeter@773
   178
          arcs.push_back(e);
kpeter@773
   179
        }
kpeter@773
   180
        if (!arcs.empty()) {
kpeter@773
   181
          node_first_out[source] = arc_index;
kpeter@773
   182
          std::sort(arcs.begin(), arcs.end(), arcLess);
kpeter@773
   183
          for (typename std::vector<GArc>::iterator it = arcs.begin();
kpeter@773
   184
               it != arcs.end(); ++it) {
kpeter@773
   185
            int target = nodeRef[digraph.target(*it)].id;
kpeter@773
   186
            arcRef[*it] = Arc(arc_index);
alpar@877
   187
            arc_source[arc_index] = source;
kpeter@773
   188
            arc_target[arc_index] = target;
kpeter@773
   189
            arc_next_in[arc_index] = node_first_in[target];
kpeter@773
   190
            node_first_in[target] = arc_index;
kpeter@773
   191
            arc_next_out[arc_index] = arc_index + 1;
kpeter@773
   192
            ++arc_index;
kpeter@773
   193
          }
kpeter@773
   194
          arc_next_out[arc_index - 1] = -1;
kpeter@773
   195
        } else {
kpeter@773
   196
          node_first_out[source] = arc_index;
kpeter@773
   197
        }
kpeter@773
   198
      }
kpeter@773
   199
      node_first_out[node_num] = arc_num;
kpeter@773
   200
    }
alpar@877
   201
kpeter@777
   202
    template <typename ArcListIterator>
kpeter@777
   203
    void build(int n, ArcListIterator first, ArcListIterator last) {
kpeter@777
   204
      built = true;
kpeter@777
   205
kpeter@777
   206
      node_num = n;
alpar@1124
   207
      arc_num = static_cast<int>(std::distance(first, last));
kpeter@777
   208
kpeter@777
   209
      node_first_out = new int[node_num + 1];
kpeter@777
   210
      node_first_in = new int[node_num];
kpeter@777
   211
kpeter@777
   212
      arc_source = new int[arc_num];
kpeter@777
   213
      arc_target = new int[arc_num];
kpeter@777
   214
      arc_next_out = new int[arc_num];
kpeter@777
   215
      arc_next_in = new int[arc_num];
alpar@877
   216
kpeter@777
   217
      for (int i = 0; i != node_num; ++i) {
kpeter@777
   218
        node_first_in[i] = -1;
alpar@877
   219
      }
alpar@877
   220
kpeter@777
   221
      int arc_index = 0;
kpeter@777
   222
      for (int i = 0; i != node_num; ++i) {
kpeter@777
   223
        node_first_out[i] = arc_index;
kpeter@777
   224
        for ( ; first != last && (*first).first == i; ++first) {
kpeter@777
   225
          int j = (*first).second;
kpeter@777
   226
          LEMON_ASSERT(j >= 0 && j < node_num,
kpeter@777
   227
            "Wrong arc list for StaticDigraph::build()");
kpeter@777
   228
          arc_source[arc_index] = i;
kpeter@777
   229
          arc_target[arc_index] = j;
kpeter@777
   230
          arc_next_in[arc_index] = node_first_in[j];
kpeter@777
   231
          node_first_in[j] = arc_index;
kpeter@777
   232
          arc_next_out[arc_index] = arc_index + 1;
kpeter@777
   233
          ++arc_index;
kpeter@777
   234
        }
kpeter@777
   235
        if (arc_index > node_first_out[i])
kpeter@777
   236
          arc_next_out[arc_index - 1] = -1;
kpeter@777
   237
      }
kpeter@777
   238
      LEMON_ASSERT(first == last,
kpeter@777
   239
        "Wrong arc list for StaticDigraph::build()");
kpeter@777
   240
      node_first_out[node_num] = arc_num;
kpeter@777
   241
    }
kpeter@773
   242
kpeter@773
   243
  protected:
kpeter@773
   244
kpeter@773
   245
    void fastFirstOut(Arc& e, const Node& n) const {
kpeter@773
   246
      e.id = node_first_out[n.id];
kpeter@773
   247
    }
kpeter@773
   248
kpeter@773
   249
    static void fastNextOut(Arc& e) {
kpeter@773
   250
      ++e.id;
kpeter@773
   251
    }
kpeter@773
   252
    void fastLastOut(Arc& e, const Node& n) const {
kpeter@773
   253
      e.id = node_first_out[n.id + 1];
kpeter@773
   254
    }
kpeter@773
   255
kpeter@774
   256
  protected:
kpeter@774
   257
    bool built;
kpeter@773
   258
    int node_num;
kpeter@773
   259
    int arc_num;
kpeter@773
   260
    int *node_first_out;
kpeter@773
   261
    int *node_first_in;
kpeter@773
   262
    int *arc_source;
kpeter@773
   263
    int *arc_target;
kpeter@773
   264
    int *arc_next_in;
kpeter@773
   265
    int *arc_next_out;
kpeter@773
   266
  };
kpeter@773
   267
kpeter@773
   268
  typedef DigraphExtender<StaticDigraphBase> ExtendedStaticDigraphBase;
kpeter@773
   269
kpeter@773
   270
kpeter@775
   271
  /// \ingroup graphs
kpeter@775
   272
  ///
kpeter@775
   273
  /// \brief A static directed graph class.
kpeter@775
   274
  ///
kpeter@775
   275
  /// \ref StaticDigraph is a highly efficient digraph implementation,
kpeter@775
   276
  /// but it is fully static.
kpeter@775
   277
  /// It stores only two \c int values for each node and only four \c int
kpeter@775
   278
  /// values for each arc. Moreover it provides faster item iteration than
kpeter@775
   279
  /// \ref ListDigraph and \ref SmartDigraph, especially using \c OutArcIt
kpeter@775
   280
  /// iterators, since its arcs are stored in an appropriate order.
kpeter@775
   281
  /// However it only provides build() and clear() functions and does not
kpeter@775
   282
  /// support any other modification of the digraph.
kpeter@775
   283
  ///
kpeter@776
   284
  /// Since this digraph structure is completely static, its nodes and arcs
kpeter@776
   285
  /// can be indexed with integers from the ranges <tt>[0..nodeNum()-1]</tt>
alpar@877
   286
  /// and <tt>[0..arcNum()-1]</tt>, respectively.
kpeter@776
   287
  /// The index of an item is the same as its ID, it can be obtained
kpeter@776
   288
  /// using the corresponding \ref index() or \ref concepts::Digraph::id()
kpeter@776
   289
  /// "id()" function. A node or arc with a certain index can be obtained
kpeter@776
   290
  /// using node() or arc().
kpeter@776
   291
  ///
kpeter@775
   292
  /// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
kpeter@775
   293
  /// Most of its member functions and nested classes are documented
kpeter@775
   294
  /// only in the concept class.
kpeter@775
   295
  ///
kpeter@787
   296
  /// This class provides constant time counting for nodes and arcs.
kpeter@787
   297
  ///
kpeter@775
   298
  /// \sa concepts::Digraph
kpeter@773
   299
  class StaticDigraph : public ExtendedStaticDigraphBase {
gabriel@1157
   300
gabriel@1157
   301
  private:
gabriel@1157
   302
    /// Graphs are \e not copy constructible. Use DigraphCopy instead.
gabriel@1157
   303
    StaticDigraph(const StaticDigraph &) : ExtendedStaticDigraphBase() {};
gabriel@1157
   304
    /// \brief Assignment of a graph to another one is \e not allowed.
gabriel@1157
   305
    /// Use DigraphCopy instead.
gabriel@1157
   306
    void operator=(const StaticDigraph&) {}
gabriel@1157
   307
kpeter@773
   308
  public:
kpeter@773
   309
kpeter@773
   310
    typedef ExtendedStaticDigraphBase Parent;
alpar@877
   311
kpeter@774
   312
  public:
alpar@877
   313
kpeter@776
   314
    /// \brief Constructor
kpeter@775
   315
    ///
kpeter@776
   316
    /// Default constructor.
kpeter@776
   317
    StaticDigraph() : Parent() {}
kpeter@776
   318
kpeter@776
   319
    /// \brief The node with the given index.
kpeter@776
   320
    ///
kpeter@776
   321
    /// This function returns the node with the given index.
kpeter@776
   322
    /// \sa index()
kpeter@778
   323
    static Node node(int ix) { return Parent::nodeFromId(ix); }
kpeter@776
   324
kpeter@776
   325
    /// \brief The arc with the given index.
kpeter@776
   326
    ///
kpeter@776
   327
    /// This function returns the arc with the given index.
kpeter@776
   328
    /// \sa index()
kpeter@778
   329
    static Arc arc(int ix) { return Parent::arcFromId(ix); }
kpeter@776
   330
kpeter@776
   331
    /// \brief The index of the given node.
kpeter@776
   332
    ///
kpeter@776
   333
    /// This function returns the index of the the given node.
kpeter@776
   334
    /// \sa node()
kpeter@778
   335
    static int index(Node node) { return Parent::id(node); }
kpeter@776
   336
kpeter@776
   337
    /// \brief The index of the given arc.
kpeter@776
   338
    ///
kpeter@776
   339
    /// This function returns the index of the the given arc.
kpeter@776
   340
    /// \sa arc()
kpeter@778
   341
    static int index(Arc arc) { return Parent::id(arc); }
kpeter@776
   342
kpeter@776
   343
    /// \brief Number of nodes.
kpeter@776
   344
    ///
kpeter@776
   345
    /// This function returns the number of nodes.
kpeter@776
   346
    int nodeNum() const { return node_num; }
kpeter@776
   347
kpeter@776
   348
    /// \brief Number of arcs.
kpeter@776
   349
    ///
kpeter@776
   350
    /// This function returns the number of arcs.
kpeter@776
   351
    int arcNum() const { return arc_num; }
kpeter@776
   352
kpeter@775
   353
    /// \brief Build the digraph copying another digraph.
kpeter@775
   354
    ///
kpeter@775
   355
    /// This function builds the digraph copying another digraph of any
kpeter@775
   356
    /// kind. It can be called more than once, but in such case, the whole
kpeter@775
   357
    /// structure and all maps will be cleared and rebuilt.
kpeter@775
   358
    ///
kpeter@775
   359
    /// This method also makes possible to copy a digraph to a StaticDigraph
kpeter@775
   360
    /// structure using \ref DigraphCopy.
alpar@877
   361
    ///
kpeter@775
   362
    /// \param digraph An existing digraph to be copied.
kpeter@775
   363
    /// \param nodeRef The node references will be copied into this map.
kpeter@775
   364
    /// Its key type must be \c Digraph::Node and its value type must be
kpeter@775
   365
    /// \c StaticDigraph::Node.
kpeter@775
   366
    /// It must conform to the \ref concepts::ReadWriteMap "ReadWriteMap"
kpeter@775
   367
    /// concept.
kpeter@775
   368
    /// \param arcRef The arc references will be copied into this map.
kpeter@775
   369
    /// Its key type must be \c Digraph::Arc and its value type must be
kpeter@775
   370
    /// \c StaticDigraph::Arc.
kpeter@775
   371
    /// It must conform to the \ref concepts::WriteMap "WriteMap" concept.
kpeter@775
   372
    ///
kpeter@775
   373
    /// \note If you do not need the arc references, then you could use
kpeter@775
   374
    /// \ref NullMap for the last parameter. However the node references
kpeter@775
   375
    /// are required by the function itself, thus they must be readable
kpeter@775
   376
    /// from the map.
kpeter@774
   377
    template <typename Digraph, typename NodeRefMap, typename ArcRefMap>
kpeter@774
   378
    void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
kpeter@774
   379
      if (built) Parent::clear();
kpeter@774
   380
      Parent::build(digraph, nodeRef, arcRef);
kpeter@774
   381
    }
alpar@877
   382
kpeter@777
   383
    /// \brief Build the digraph from an arc list.
kpeter@777
   384
    ///
kpeter@777
   385
    /// This function builds the digraph from the given arc list.
kpeter@777
   386
    /// It can be called more than once, but in such case, the whole
kpeter@777
   387
    /// structure and all maps will be cleared and rebuilt.
kpeter@777
   388
    ///
kpeter@777
   389
    /// The list of the arcs must be given in the range <tt>[begin, end)</tt>
kpeter@777
   390
    /// specified by STL compatible itartors whose \c value_type must be
kpeter@777
   391
    /// <tt>std::pair<int,int></tt>.
kpeter@777
   392
    /// Each arc must be specified by a pair of integer indices
kpeter@777
   393
    /// from the range <tt>[0..n-1]</tt>. <i>The pairs must be in a
kpeter@777
   394
    /// non-decreasing order with respect to their first values.</i>
kpeter@777
   395
    /// If the k-th pair in the list is <tt>(i,j)</tt>, then
kpeter@777
   396
    /// <tt>arc(k-1)</tt> will connect <tt>node(i)</tt> to <tt>node(j)</tt>.
kpeter@777
   397
    ///
kpeter@777
   398
    /// \param n The number of nodes.
kpeter@777
   399
    /// \param begin An iterator pointing to the beginning of the arc list.
kpeter@777
   400
    /// \param end An iterator pointing to the end of the arc list.
kpeter@777
   401
    ///
kpeter@777
   402
    /// For example, a simple digraph can be constructed like this.
kpeter@777
   403
    /// \code
kpeter@777
   404
    ///   std::vector<std::pair<int,int> > arcs;
kpeter@777
   405
    ///   arcs.push_back(std::make_pair(0,1));
kpeter@777
   406
    ///   arcs.push_back(std::make_pair(0,2));
kpeter@777
   407
    ///   arcs.push_back(std::make_pair(1,3));
kpeter@777
   408
    ///   arcs.push_back(std::make_pair(1,2));
kpeter@777
   409
    ///   arcs.push_back(std::make_pair(3,0));
kpeter@777
   410
    ///   StaticDigraph gr;
kpeter@777
   411
    ///   gr.build(4, arcs.begin(), arcs.end());
kpeter@777
   412
    /// \endcode
kpeter@777
   413
    template <typename ArcListIterator>
kpeter@777
   414
    void build(int n, ArcListIterator begin, ArcListIterator end) {
kpeter@777
   415
      if (built) Parent::clear();
kpeter@777
   416
      StaticDigraphBase::build(n, begin, end);
kpeter@777
   417
      notifier(Node()).build();
kpeter@777
   418
      notifier(Arc()).build();
kpeter@777
   419
    }
kpeter@777
   420
kpeter@776
   421
    /// \brief Clear the digraph.
kpeter@776
   422
    ///
kpeter@776
   423
    /// This function erases all nodes and arcs from the digraph.
kpeter@776
   424
    void clear() {
kpeter@776
   425
      Parent::clear();
kpeter@776
   426
    }
kpeter@773
   427
kpeter@773
   428
  protected:
kpeter@773
   429
kpeter@773
   430
    using Parent::fastFirstOut;
kpeter@773
   431
    using Parent::fastNextOut;
kpeter@773
   432
    using Parent::fastLastOut;
alpar@877
   433
kpeter@773
   434
  public:
kpeter@773
   435
kpeter@773
   436
    class OutArcIt : public Arc {
kpeter@773
   437
    public:
kpeter@773
   438
kpeter@773
   439
      OutArcIt() { }
kpeter@773
   440
kpeter@773
   441
      OutArcIt(Invalid i) : Arc(i) { }
kpeter@773
   442
kpeter@773
   443
      OutArcIt(const StaticDigraph& digraph, const Node& node) {
alpar@877
   444
        digraph.fastFirstOut(*this, node);
alpar@877
   445
        digraph.fastLastOut(last, node);
kpeter@773
   446
        if (last == *this) *this = INVALID;
kpeter@773
   447
      }
kpeter@773
   448
kpeter@773
   449
      OutArcIt(const StaticDigraph& digraph, const Arc& arc) : Arc(arc) {
kpeter@773
   450
        if (arc != INVALID) {
kpeter@773
   451
          digraph.fastLastOut(last, digraph.source(arc));
kpeter@773
   452
        }
kpeter@773
   453
      }
kpeter@773
   454
alpar@877
   455
      OutArcIt& operator++() {
kpeter@773
   456
        StaticDigraph::fastNextOut(*this);
kpeter@773
   457
        if (last == *this) *this = INVALID;
alpar@877
   458
        return *this;
kpeter@773
   459
      }
kpeter@773
   460
kpeter@773
   461
    private:
kpeter@773
   462
      Arc last;
kpeter@773
   463
    };
kpeter@773
   464
kpeter@774
   465
    Node baseNode(const OutArcIt &arc) const {
kpeter@774
   466
      return Parent::source(static_cast<const Arc&>(arc));
kpeter@774
   467
    }
kpeter@774
   468
kpeter@774
   469
    Node runningNode(const OutArcIt &arc) const {
kpeter@774
   470
      return Parent::target(static_cast<const Arc&>(arc));
kpeter@774
   471
    }
kpeter@774
   472
kpeter@774
   473
    Node baseNode(const InArcIt &arc) const {
kpeter@774
   474
      return Parent::target(static_cast<const Arc&>(arc));
kpeter@774
   475
    }
kpeter@774
   476
kpeter@774
   477
    Node runningNode(const InArcIt &arc) const {
kpeter@774
   478
      return Parent::source(static_cast<const Arc&>(arc));
kpeter@774
   479
    }
kpeter@774
   480
kpeter@773
   481
  };
kpeter@773
   482
kpeter@773
   483
}
kpeter@773
   484
kpeter@773
   485
#endif