From 4e73c4c20419deaae1546b293b8516b00a89bc6a Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Mon, 18 Mar 2013 19:04:25 -0700 Subject: [PATCH] Include interval test. --- model/metric.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/model/metric.go b/model/metric.go index 8073e29e5..49e3140ae 100644 --- a/model/metric.go +++ b/model/metric.go @@ -102,6 +102,24 @@ func (v Values) Swap(i, j int) { v[i], v[j] = v[j], v[i] } +// InsideInterval indicates whether a given range of sorted values could contain +// a value for a given time. +func (v Values) InsideInterval(t time.Time) (s bool) { + if v.Len() == 0 { + return + } + + if t.Before(v[0]).Timestamp { + return + } + + if !v[v.Len()-1].Timestamp.Before(t) { + return + } + + return true +} + type SampleSet struct { Metric Metric Values Values