forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bounds.go
42 lines (31 loc) · 1 KB
/
bounds.go
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
package tsdb
import (
"math"
"github.com/prometheus/common/model"
)
type Bounded interface {
Bounds() (model.Time, model.Time)
}
// InclusiveBounds will ensure the underlying Bounded implementation
// is turned into [lower,upper] inclusivity.
// Generally, we consider bounds to be `[lower,upper)` inclusive
// This helper will account for integer overflow.
// Because model.Time is millisecond-precise, but Loki uses nanosecond precision,
// be careful usage can handle an extra millisecond being added.
func inclusiveBounds(b Bounded) (model.Time, model.Time) {
lower, upper := b.Bounds()
if int64(upper) < math.MaxInt64 {
upper++
}
return lower, upper
}
type bounds struct {
mint, maxt model.Time
}
func newBounds(mint, maxt model.Time) bounds { return bounds{mint: mint, maxt: maxt} }
func (b bounds) Bounds() (model.Time, model.Time) { return b.mint, b.maxt }
func Overlap(a, b Bounded) bool {
aFrom, aThrough := a.Bounds()
bFrom, bThrough := b.Bounds()
return aFrom < bThrough && aThrough > bFrom
}