COIN-OR::LEMON - Graph Library

Changeset 1202:4fd76139b69e in lemon-main


Ignore:
Timestamp:
02/17/18 23:44:32 (7 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Phase:
public
Message:

Add operator[] to Path structures (#250)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/path.h

    r1201 r1202  
    183183    }
    184184
     185    /// \brief The n-th arc.
     186    ///
     187    /// Gives back the n-th arc. This operator is just an alias for \ref nth(),
     188    /// it runs in O(1) time.
     189    /// \pre \c n is in the range <tt>[0..length() - 1]</tt>.
     190    const Arc& operator[](int n) const {
     191      return nth(n);
     192    }
     193
    185194    /// \brief The first arc of the path
    186195    const Arc& front() const {
     
    403412    }
    404413
     414    /// \brief The n-th arc.
     415    ///
     416    /// Gives back the n-th arc. This operator is just an alias for \ref nth(),
     417    /// it runs in O(1) time.
     418    /// \pre \c n is in the range <tt>[0..length() - 1]</tt>.
     419    const Arc& operator[](int n) const {
     420      return data[n];
     421    }
     422
    405423    /// \brief The first arc of the path.
    406424    const Arc& front() const {
     
    617635      }
    618636      return ArcIt(*this, node);
     637    }
     638
     639    /// \brief The n-th arc.
     640    ///
     641    /// Looks for the n-th arc in O(n) time. This operator is just an alias
     642    /// for \ref nth().
     643    /// \pre \c n is in the range <tt>[0..length() - 1]</tt>.
     644    const Arc& operator[](int n) const {
     645      return nth(n);
    619646    }
    620647
     
    967994    }
    968995
     996    /// \brief The n-th arc.
     997    ///
     998    /// Gives back the n-th arc. This operator is just an alias for \ref nth(),
     999    /// it runs in O(1) time.
     1000    /// \pre \c n is in the range <tt>[0..length() - 1]</tt>.
     1001    const Arc& operator[](int n) const {
     1002      return _arcs[n];
     1003    }
     1004
    9691005    /// \brief The length of the path.
    9701006    int length() const { return len; }
  • test/path_test.cc

    r1092 r1202  
    108108    checkBackAndFrontInsertablePath<ListPath<GR> >();
    109109    checkBackInsertablePath<SimplePath<GR> >();
     110
     111    checkSubscriptOperator<Path<GR> >();
     112    checkSubscriptOperator<SimplePath<GR> >();
     113    checkSubscriptOperator<StaticPath<GR> >();
     114    checkSubscriptOperator<ListPath<GR> >();
    110115
    111116    checkListPathSplitAndSplice();
     
    274279  }
    275280
     281  template <typename P>
     282  void checkSubscriptOperator() {
     283    SimplePath<GR> p0;
     284    p0.addBack(a1);
     285    p0.addBack(a3);
     286    p0.addBack(a2);
     287    P p = p0;
     288    check(!p.empty(), "Wrong empty()");
     289    check(p.length() == 3, "Wrong length");
     290    check(p.front() == a1, "Wrong front()");
     291    check(p.back() == a2, "Wrong back()");
     292    check(p.nth(0) == a1, "Wrong nth()");
     293    check(p.nth(1) == a3, "Wrong nth()");
     294    check(p.nth(2) == a2, "Wrong nth()");
     295    check(p[0] == a1, "Wrong operator[]");
     296    check(p[1] == a3, "Wrong operator[]");
     297    check(p[2] == a2, "Wrong operator[]");
     298  }
     299
    276300  void checkListPathSplitAndSplice() {
    277301
Note: See TracChangeset for help on using the changeset viewer.