[run_set] improve run merging

This commit is contained in:
Joe Thornber
2013-07-09 10:36:30 +01:00
parent 31686fbb17
commit 8523314a7f
2 changed files with 39 additions and 2 deletions

View File

@@ -12,6 +12,10 @@ namespace base {
template <typename T>
class run_set {
public:
void clear() {
runs_.clear();
}
void add(T const &b) {
add(run<T>(b, b + 1));
}
@@ -28,14 +32,14 @@ namespace base {
const_iterator it = runs_.cbegin();
// Skip all blocks that end before r
while (it != runs_.end() && it->end_ <= r.begin_)
while (it != runs_.end() && it->end_ < r.begin_)
++it;
// work out which runs overlap
if (it != runs_.end()) {
r.begin_ = min_maybe(it->begin_, r.begin_);
const_iterator first = it;
while (it != runs_.end() && it->begin_ < r.end_) {
while (it != runs_.end() && it->begin_ <= r.end_) {
r.end_ = max_maybe(it->end_, r.end_);
++it;
}