# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1518907472 3600
# Sat Feb 17 23:44:32 2018 +0100
# Node ID dbf9eee91ed21dd350637aaac416cc8d930f6101
# Parent ba6afb21b6fd147e765de15c3b197f40cd608afb
Add operator[] to Path structures (#250)
diff git a/lemon/path.h b/lemon/path.h
a

b


164  164  return ArcIt(*this, n); 
165  165  } 
166  166  
 167  /// \brief The nth arc. 
 168  /// 
 169  /// Gives back the nth arc. This operator is just an alias for \ref nth(), 
 170  /// it runs in O(1) time. 
 171  /// \pre \c n is in the range <tt>[0..length()  1]</tt>. 
 172  const Arc& operator[](int n) const { 
 173  return nth(n); 
 174  } 
 175  
167  176  /// \brief The first arc of the path 
168  177  const Arc& front() const { 
169  178  return head.empty() ? tail.front() : head.back(); 
… 
… 

367  376  return ArcIt(*this, n); 
368  377  } 
369  378  
 379  /// \brief The nth arc. 
 380  /// 
 381  /// Gives back the nth arc. This operator is just an alias for \ref nth(), 
 382  /// it runs in O(1) time. 
 383  /// \pre \c n is in the range <tt>[0..length()  1]</tt>. 
 384  const Arc& operator[](int n) const { 
 385  return data[n]; 
 386  } 
 387  
370  388  /// \brief The first arc of the path. 
371  389  const Arc& front() const { 
372  390  return data.front(); 
… 
… 

897  915  return ArcIt(*this, n); 
898  916  } 
899  917  
 918  /// \brief The nth arc. 
 919  /// 
 920  /// Gives back the nth arc. This operator is just an alias for \ref nth(), 
 921  /// it runs in O(1) time. 
 922  /// \pre \c n is in the range <tt>[0..length()  1]</tt>. 
 923  const Arc& operator[](int n) const { 
 924  return arcs[n]; 
 925  } 
 926  
900  927  /// \brief The length of the path. 
901  928  int length() const { return len; } 
902  929  
diff git a/test/path_test.cc b/test/path_test.cc
a

b


108  108  checkBackAndFrontInsertablePath<ListPath<GR> >(); 
109  109  checkBackInsertablePath<SimplePath<GR> >(); 
110  110  
 111  checkSubscriptOperator<Path<GR> >(); 
 112  checkSubscriptOperator<SimplePath<GR> >(); 
 113  checkSubscriptOperator<StaticPath<GR> >(); 
 114  
111  115  checkListPathSplitAndSplice(); 
112  116  } 
113  117  
… 
… 

273  277  check(checkPath(cgr, cp), "Wrong checkPath()"); 
274  278  } 
275  279  
 280  template <typename P> 
 281  void checkSubscriptOperator() { 
 282  SimplePath<GR> p0; 
 283  p0.addBack(a1); 
 284  p0.addBack(a3); 
 285  p0.addBack(a2); 
 286  P p = p0; 
 287  check(!p.empty(), "Wrong empty()"); 
 288  check(p.length() == 3, "Wrong length"); 
 289  check(p.front() == a1, "Wrong front()"); 
 290  check(p.back() == a2, "Wrong back()"); 
 291  check(p.nth(0) == a1, "Wrong nth()"); 
 292  check(p.nth(1) == a3, "Wrong nth()"); 
 293  check(p.nth(2) == a2, "Wrong nth()"); 
 294  check(p[0] == a1, "Wrong operator[]"); 
 295  check(p[1] == a3, "Wrong operator[]"); 
 296  check(p[2] == a2, "Wrong operator[]"); 
 297  } 
 298  
276  299  void checkListPathSplitAndSplice() { 
277  300  
278  301  // Build a path with spliceFront() and spliceBack() 