-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterval.h
executable file
·75 lines (58 loc) · 1.33 KB
/
Interval.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef INTERVAL_H
#define INTERVAL_H
#include <cassert>
#include <iostream>
class Interval
{
public:
Interval(int start, int end)
: start(start),
end(end)
{
//std::cout << start << "\t" << end << std::endl;
CheckRep();
}
Interval()
: Interval(0, 0)
{}
int GetStart() const { return start; }
int GetEnd() const { return end; }
int Length() const { return end - start + 1; }
void SetStart(int newStart)
{
assert(newStart <= end);
start = newStart;
}
void SetEnd(int newEnd)
{
assert(start <= newEnd);
end = newEnd;
}
Interval& operator += (int x)
{
start += x;
end += x;
return *this;
}
bool operator == (const Interval& other) const
{
return start == other.start && end == other.end;
}
bool operator != (const Interval& other) const
{
return !(*this == other);
}
void Flip(int origLength);
Interval merge(const Interval &other) const;
bool overlaps(const Interval &other) const;
friend std::ostream& operator <<(std::ostream& stream, const Interval& interval);
private:
int start;
int end;
void CheckRep()
{
assert(start <= end);
}
};
const Interval operator + (const Interval& one, int x);
#endif // INTERVAL_H