Changeset 3345


Ignore:
Timestamp:
Nov 6, 2014, 1:30:45 PM (7 years ago)
Author:
Peter
Message:

new function SegmentSet::insert_merge(first, last). closes #818

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/segment.cc

    r3344 r3345  
    199199    suite.err() << "error: set.size(): " << set.size() << " expected 1\n";
    200200  set.insert_merge(set.end(), Segment<double>(200, 1000));
     201
     202  SegmentSet<double> set2;
     203  set2.insert_merge(set.begin(), set.end());
     204  std::vector<Segment<double> > vec(set.size());
     205  std::copy(set.begin(), set.end(), vec.begin());
     206  set2.insert_merge(vec.begin(), vec.end());
    201207}
    202208
  • trunk/yat/utility/SegmentSet.h

    r3344 r3345  
    113113    }
    114114
     115    /**
     116       Insert range [first, last). Same result as inserting them
     117       individually, but inserting a range is potentially faster,
     118       especially if range is sorted and set is sparse compared to
     119       range.
     120
     121      \since new in yat 0.13
     122     */
     123    template<typename Iterator>
     124    void insert_merge(Iterator first, Iterator last)
     125    {
     126      typename me::iterator it = this->end();
     127      for ( ; first!=last; ++first) {
     128        it = insert_merge(it, *first);
     129        ++it;
     130      }
     131    }
    115132  private:
    116133    // used by public functions insert_merge.
Note: See TracChangeset for help on using the changeset viewer.