Changeset 1196 for trunk


Ignore:
Timestamp:
Oct 4, 2010, 4:40:13 AM (11 years ago)
Author:
Peter Johansson
Message:

speeding up Vector::back(). refs #475

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Vector.h

    r1195 r1196  
    6161    {
    6262      assert(size()>0);
    63       return (*this)[size()-1];
     63      if (map_.empty() || size()-1 > map_.rbegin()->first)
     64        return policy_.get(map_, map_.end());
     65      // check that size and elements are consistent
     66      assert(size()-1 == map_.rbegin()->first);
     67      return map_.rbegin()->second;
    6468    }
    6569
  • trunk/test/vector.cc

    r1194 r1196  
    7676      suite.out() << "operator+ failed: result: " << vec3[i]
    7777                  << " expected: " << vec[i] + vec2[i] << "\n";
     78
     79  suite.out() << "testing back()\n";
     80  vec.resize(0);
     81  vec.resize(10);
     82  vec.set(9,71);
     83  if (!suite.add(vec.back()==vec[9])) {
     84    suite.out() << "vec.back(): " << vec.back()
     85                << "\nexpected: " << vec[9] << "\n";
     86  }
     87  vec.resize(20);
     88  if (!suite.add(vec.back()==vec[19])) {
     89    suite.out() << "vec.back(): " << vec.back()
     90                << "\nexpected: " << vec[19] << "\n";
     91  }
    7892}
    7993
Note: See TracChangeset for help on using the changeset viewer.