1 #ifndef INTERVALRUNNER_HPP
2 #define INTERVALRUNNER_HPP
4 #include "../datastructures/maybe.hpp"
6 template<
class It1,
class It2,
class Po
int,
class Po
intGetter,
class EventHandler,
class DataGetter,
class Data>
7 void process_intervals(It1 start_a, It1 end_a, It2 start_b, It2 end_b, PointGetter &pg, EventHandler &handler, DataGetter &dg) {
8 using CbData = Maybe<Data>;
10 Point last_point = Point();
12 if ((start_a != end_a) && ((start_b == end_b) || (pg(start_a,
true) < pg(start_b,
true)))) {
13 last_point = pg(start_a,
true);
19 if ((start_a != end_a) && (pg(start_a,
true) == last_point)) {
25 if ((start_b != end_b) && (pg(start_b,
true) == last_point)) {
32 event_a ? CbData(dg(start_a)) : CbData(),
34 event_b ? CbData(dg(start_b)) : CbData(),
38 while ((start_a != end_a) || (start_b != end_b)) {
39 Point next_point = last_point;
42 bool a_starts =
false;
44 bool b_starts =
false;
46 if (start_a != end_a) {
47 if (pg(start_a,
true) > last_point) {
49 next_point = pg(start_a,
true);
51 #ifdef ENABLE_ASSERTIONS
52 assert(pg(start_a,
false) > last_point);
55 next_point = pg(start_a,
false);
56 if ((start_a + 1) != end_a) {
57 if (pg((start_a + 1),
true) == next_point) {
64 if (start_b != end_b) {
66 if (pg(start_b,
true) > last_point) {
69 if ((next_point == last_point) || (pg(start_b,
true) < next_point)) {
73 next_point = pg(start_b,
true);
74 }
else if (pg(start_b,
true) == next_point) {
78 #ifdef ENABLE_ASSERTIONS
79 assert(pg(start_b,
false) > last_point);
81 if ((next_point == last_point) || (pg(start_b,
false) < next_point)) {
86 next_point = pg(start_b,
false);
87 }
else if (pg(start_b,
false) == next_point) {
91 if ((b_ends) && ((start_b + 1) != end_b) && (pg((start_b + 1),
true) == next_point)) {
102 a_starts && (!a_ends) ? CbData(dg(start_a)) :
104 a_starts && a_ends ? CbData(dg(start_a + 1)) :
108 a_ends ? CbData(dg(start_a)) : CbData(),
111 b_starts && (!b_ends) ? CbData(dg(start_b)) :
113 b_starts && b_ends ? CbData(dg(start_b + 1)) :
117 b_ends ? CbData(dg(start_b)) : CbData()
120 last_point = next_point;