Mercurial > repos > yufei-luo > s_mart
comparison SMART/Java/Python/Cpp/interval.hpp @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:b0e8584489e6 | 18:94ab73e8a190 |
---|---|
1 #ifndef INTERVAL_HPP | |
2 #define INTERVAL_HPP | |
3 #include <iostream> | |
4 #include <fstream> | |
5 using namespace std; | |
6 | |
7 typedef unsigned int Position; | |
8 | |
9 class Interval { | |
10 | |
11 public: | |
12 Position start; | |
13 Position end; | |
14 | |
15 Interval(unsigned int start = 0, unsigned int end = 0): start(start), end(end) { } | |
16 | |
17 Interval(Interval &i): start(i.start), end(i.end) { } | |
18 | |
19 bool include(Interval &interval) { | |
20 return ((start <= interval.start) && (end >= interval.end)); | |
21 } | |
22 | |
23 void writeBinary(ofstream &stream) { | |
24 stream.write(reinterpret_cast<const char*>(&start), sizeof(Position)); | |
25 stream.write(reinterpret_cast<const char*>(&end), sizeof(Position)); | |
26 } | |
27 | |
28 bool parseBinary(ifstream &stream) { | |
29 stream.read(reinterpret_cast<char*>(&start), sizeof(Position)); | |
30 stream.read(reinterpret_cast<char*>(&end), sizeof(Position)); | |
31 return (! stream.eof()); | |
32 } | |
33 | |
34 friend bool operator==(const Interval &i1, const Interval &i2) { | |
35 return ((i1.start == i2.start) && (i1.start == i2.end)); | |
36 } | |
37 | |
38 friend bool operator<(const Interval &i1, const Interval &i2) { | |
39 if (i1.start < i2.start) return true; | |
40 return ((i1.start == i2.start) && (i1.end > i2.end)); | |
41 } | |
42 | |
43 }; | |
44 | |
45 #endif |