Added inclusive / exclusive functionality

This commit is contained in:
Daniel Gil
2018-05-29 16:08:17 +02:00
parent 6fdaa341ff
commit 6702d50231
12 changed files with 345 additions and 67 deletions

12
find.go
View File

@@ -1,14 +1,20 @@
package interval
func (intvls *intervals) FindIntervalsForValue(value int) []*Interval {
// sort intervals (if necessary)
intvls.Sort()
var matches []*Interval
for _, intvl := range intvls.Intervals {
if intvl.Low > value {
// due to the intervals are sorted, we can confirm that we will not find more matches
// convert if necessary exclusive low/high values into inclusive ones
low, high := intvls.getInclusives(intvl.Low, intvl.High)
// check if we have to stop searching
if low > value {
// due to the intervals are sorted byLow, we can confirm that we will not find more matches
break
}
if inBetweenInclusive(value, intvl.Low, intvl.High) {
if inBetweenInclusive(value, low, high) {
matches = append(matches, intvl)
}
}