2013-04-22 18:11:34 +05:30
|
|
|
#ifndef SPAN_ITERATOR_H
|
|
|
|
#define SPAN_ITERATOR_H
|
|
|
|
|
|
|
|
#include "persistent-data/space_map.h"
|
2013-07-09 15:55:09 +05:30
|
|
|
#include "persistent-data/run_set.h"
|
2013-04-22 18:11:34 +05:30
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace persistent_data {
|
|
|
|
class subtracting_span_iterator : public space_map::span_iterator {
|
|
|
|
public:
|
2013-07-09 15:55:09 +05:30
|
|
|
typedef typename base::run_set<block_address> block_set;
|
2013-04-22 18:11:34 +05:30
|
|
|
typedef space_map::span span;
|
|
|
|
|
2013-07-09 15:55:09 +05:30
|
|
|
subtracting_span_iterator(block_address max,
|
|
|
|
span_iterator &sub_it,
|
2013-04-22 18:11:34 +05:30
|
|
|
block_set const &forbidden_blocks)
|
2013-07-09 15:55:09 +05:30
|
|
|
: max_(max) {
|
|
|
|
for (maybe_span ms = sub_it.first(); ms; ms = sub_it.next())
|
|
|
|
runs_.add(ms->first, ms->second);
|
|
|
|
|
|
|
|
block_set bs(forbidden_blocks);
|
|
|
|
runs_.negate();
|
|
|
|
runs_.merge(bs);
|
|
|
|
runs_.negate();
|
2013-04-22 18:11:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual maybe_span first() {
|
2013-07-09 15:55:09 +05:30
|
|
|
current_ = runs_.begin();
|
|
|
|
return get_current();
|
2013-04-22 18:11:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual maybe_span next() {
|
2013-07-09 15:55:09 +05:30
|
|
|
if (current_ != runs_.end())
|
|
|
|
++current_;
|
2013-04-22 18:11:34 +05:30
|
|
|
|
2013-07-09 15:55:09 +05:30
|
|
|
return get_current();
|
2013-04-22 18:11:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-07-09 15:55:09 +05:30
|
|
|
maybe_span get_current() {
|
|
|
|
// FIXME: unsafe deref of begin and end
|
|
|
|
return (current_ == runs_.end()) ?
|
|
|
|
maybe_span() :
|
|
|
|
maybe_span(std::make_pair(maybe_default(current_->begin_, 0ULL),
|
|
|
|
maybe_default(current_->end_, max_)));
|
2013-04-22 18:11:34 +05:30
|
|
|
}
|
|
|
|
|
2013-07-09 15:55:09 +05:30
|
|
|
typedef boost::optional<block_address> maybe;
|
|
|
|
static block_address maybe_default(maybe const &m, block_address default_) {
|
|
|
|
return m ? *m : default_;
|
2013-04-22 18:11:34 +05:30
|
|
|
}
|
|
|
|
|
2013-07-09 15:55:09 +05:30
|
|
|
block_address max_;
|
|
|
|
block_set runs_;
|
|
|
|
block_set::const_iterator current_;
|
2013-04-22 18:11:34 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|