-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrange.h
More file actions
62 lines (48 loc) · 1.18 KB
/
range.h
File metadata and controls
62 lines (48 loc) · 1.18 KB
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
//
// range.h
// SubmatrixQueries
//
// Created by Raphael Bost on 21/02/13.
// Copyright (c) 2013 Raphael Bost. All rights reserved.
//
#ifndef __SubmatrixQueries__range__
#define __SubmatrixQueries__range__
#include <algorithm>
#include <cassert>
/*
* class Breakpoint
* This structure represents a range of indices
*
*/
struct Range {
const size_t min, max;
inline Range(size_t minimun, size_t maximum) : min(minimun), max(maximum){
assert(minimun <= maximum);
}
inline Range(Range const &r) : min(r.min), max(r.max)
{
}
inline bool isInRange(size_t i)
{
return (i >= min) && (i <= max);
}
inline bool intersects(Range r)
{
if (r.max > max) {
return r.min <= max;
}else if (r.max >= min){
return true;
}
return false;
}
inline Range intersection(Range r)
{
assert(intersects(r));
return Range(std::min<size_t>(min,r.min),std::max<size_t>(max,r.max));
}
inline bool contains(Range r)
{
return min <= r.min && max >= r.max;
}
};
#endif /* defined(__SubmatrixQueries__range__) */