Added inclusive / exclusive functionality
This commit is contained in:
12
find.go
12
find.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user