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
use super::groupby::ClosedWindow;
#[derive(Copy, Clone, Debug)]
pub struct Bounds {
pub(crate) start: i64,
pub(crate) stop: i64,
}
impl Bounds {
pub(crate) fn new_checked(start: i64, stop: i64) -> Self {
assert!(
start <= stop,
"boundary start must be smaller than stop; is your time column sorted in ascending order?\
\nIf you did a groupby, note that null values are a separate group."
);
Self::new(start, stop)
}
pub(crate) fn new(start: i64, stop: i64) -> Self {
Bounds { start, stop }
}
pub(crate) fn duration(&self) -> i64 {
self.stop - self.start
}
pub(crate) fn is_member(&self, t: i64, closed: ClosedWindow) -> bool {
match closed {
ClosedWindow::Right => t > self.start && t <= self.stop,
ClosedWindow::Left => t >= self.start && t < self.stop,
ClosedWindow::None => t > self.start && t < self.stop,
ClosedWindow::Both => t >= self.start && t <= self.stop,
}
}
pub(crate) fn is_future(&self, t: i64, closed: ClosedWindow) -> bool {
match closed {
ClosedWindow::Left | ClosedWindow::None => self.stop <= t,
ClosedWindow::Both | ClosedWindow::Right => t > self.stop,
}
}
}