4 #include <forward_list>
13 template <
typename T1,
typename T2>
19 begin =
static_cast<T
>(b);
20 end =
static_cast<T
>(e);
31 return r1.begin == r2.begin && r1.end == r2.end;
69 : regions_(regions) {}
71 auto&
get() {
return regions_; }
72 const auto&
get()
const {
return regions_; }
83 return regions_.empty();
94 while (std::next(it) != regions_.end() &&
95 std::next(it)->end < r.
begin) it++;
97 if (std::next(it) == regions_.end() ||
98 r.
end < std::next(it)->begin) {
100 it = regions_.insert_after(it, r);
106 while (std::next(it) != regions_.end() &&
107 it->end >= std::next(it)->begin) {
109 regions_.erase_after(it);
118 return add(r, regions_.before_begin());
122 auto it = regions_.before_begin();
124 while (std::next(it) != regions_.end()) {
125 if (r.
end <= std::next(it)->begin)
break;
127 if (std::next(it)->
end <= r.
begin) {
130 }
else if (r.
begin <= std::next(it)->begin && std::next(it)->end <= r.
end) {
132 regions_.erase_after(it);
134 }
else if (r.
begin <= std::next(it)->begin && r.
end <= std::next(it)->end) {
136 std::next(it)->begin = r.
end;
138 }
else if (std::next(it)->
begin <= r.
begin && std::next(it)->end <= r.
end) {
140 std::next(it)->end = r.
begin;
142 }
else if (std::next(it)->
begin <= r.
begin && r.
end <= std::next(it)->end) {
145 std::next(it)->begin = r.
end;
146 regions_.insert_after(it, new_r);
149 common::die(
"Something is wrong in region<T>s::remove()\n");
155 for (
const auto& r_ : regions_) {
156 if (r.
begin < r_.begin)
break;
157 if (r.
end <= r_.end)
return true;
164 std::forward_list<region<T>>& regs = ret.regions_;
166 auto it = regs.before_begin();
167 for (
auto [b, e] : regions_) {
177 regs.insert_after(it, r);
184 std::forward_list<region<T>>& regs = ret.
get();
186 auto it_ret = regs.before_begin();
187 auto it = regions_.begin();
189 while (it != regions_.end()) {
190 if (it->end <= r.
begin) {
195 if (r.
end <= it->begin) {
201 if (r.
end < it->end) {
213 std::forward_list<region<T>>& regs = ret.
get();
215 auto it_ret = regs.before_begin();
216 auto it1 = regions_.begin();
217 auto it2 = rs.
begin();
219 while (it1 != regions_.end() && it2 != rs.
end()) {
220 if (it1->end <= it2->begin) {
225 if (it2->end <= it1->begin) {
232 if (it1->end <= it2->end) {
244 for (
auto&& reg : regions_) {
251 std::forward_list<region<T>> regions_;
254 template <
typename T>
256 return rs1.get() == rs2.get();
259 template <
typename T>
261 return !(rs1 == rs2);
264 template <
typename T>
269 template <
typename T>
274 template <
typename T>
282 ITYR_TEST_CASE(
"[ityr::ori::block_region_set] add") {
320 ITYR_TEST_CASE(
"[ityr::ori::block_region_set] remove") {
326 brs.remove({70, 80});
328 brs.remove({18, 55});
330 brs.remove({10, 110});
338 ITYR_TEST_CASE(
"[ityr::ori::block_region_set] include") {
353 ITYR_TEST_CASE(
"[ityr::ori::block_region_set] complement") {
355 ITYR_CHECK(brs.complement({0, 120}) ==
block_region_set({{0, 2}, {5, 6}, {9, 11}, {20, 50}, {100, 120}}));
368 ITYR_TEST_CASE(
"[ityr::ori::block_region_set] intersection") {
Definition: block_region_set.hpp:62
auto & get()
Definition: block_region_set.hpp:71
void remove(const region< T > &r)
Definition: block_region_set.hpp:121
region_set< T > intersection(const region_set< T > &rs) const
Definition: block_region_set.hpp:211
region_set< T > complement(region< T > r) const
Definition: block_region_set.hpp:162
iterator before_begin()
Definition: block_region_set.hpp:74
bool empty() const
Definition: block_region_set.hpp:82
iterator end()
Definition: block_region_set.hpp:76
const_iterator before_begin() const
Definition: block_region_set.hpp:78
const auto & get() const
Definition: block_region_set.hpp:72
iterator add(const region< T > &r, iterator begin_it)
Definition: block_region_set.hpp:90
iterator add(const region< T > &r)
Definition: block_region_set.hpp:117
region_set< T > intersection(const region< T > &r) const
Definition: block_region_set.hpp:182
iterator begin()
Definition: block_region_set.hpp:75
const_iterator end() const
Definition: block_region_set.hpp:80
typename std::forward_list< region< T > >::iterator iterator
Definition: block_region_set.hpp:64
void clear()
Definition: block_region_set.hpp:86
region_set(std::initializer_list< region< T >> regions)
Definition: block_region_set.hpp:68
const_iterator begin() const
Definition: block_region_set.hpp:79
bool include(const region< T > &r) const
Definition: block_region_set.hpp:154
typename std::forward_list< region< T > >::const_iterator const_iterator
Definition: block_region_set.hpp:65
std::size_t size() const
Definition: block_region_set.hpp:242
region_set()
Definition: block_region_set.hpp:67
#define ITYR_CHECK(cond)
Definition: util.hpp:48
Definition: block_region_set.hpp:9
region< T > get_union(const region< T > &r1, const region< T > &r2)
Definition: block_region_set.hpp:50
region_set< block_size_t > block_region_set
Definition: block_region_set.hpp:280
bool contiguous(const region< T > &r1, const region< T > &r2)
Definition: block_region_set.hpp:45
bool overlap(const region< T > &r1, const region< T > &r2)
Definition: block_region_set.hpp:40
region_set< T > get_complement(const region_set< T > &rs, const region< T > &r)
Definition: block_region_set.hpp:265
bool operator==(const region< T > &r1, const region< T > &r2) noexcept
Definition: block_region_set.hpp:30
region< T > get_intersection(const region< T > &r1, const region< T > &r2)
Definition: block_region_set.hpp:56
bool operator!=(const region< T > &r1, const region< T > &r2) noexcept
Definition: block_region_set.hpp:35
monoid< T, min_functor<>, highest< T > > min
Definition: reducer.hpp:101
monoid< T, max_functor<>, lowest< T > > max
Definition: reducer.hpp:104
Definition: block_region_set.hpp:12
std::size_t size() const
Definition: block_region_set.hpp:23
region(T1 b, T2 e)
Definition: block_region_set.hpp:14
T begin
Definition: block_region_set.hpp:25
T end
Definition: block_region_set.hpp:26