Added self adjustment minLow and maxHigh values. Renamed Get method to GetIntervals. Removed Report method, moved functionality to the Intervals Springer implementation. Added GetMinLow and GetMaxHigh methods.

This commit is contained in:
Daniel Gil
2018-06-01 10:46:19 +02:00
parent 1d6fd664fa
commit 217eb78ab4
11 changed files with 504 additions and 132 deletions

20
add.go
View File

@@ -1,5 +1,7 @@
package interval
import "math"
func (intvls *intervals) Add(low, high int, obj interface{}) error {
itvl := &Interval{
Low: low,
@@ -10,6 +12,17 @@ func (intvls *intervals) Add(low, high int, obj interface{}) error {
}
func (intvls *intervals) AddInterval(itvl *Interval) error {
// the first time an interval is added, we check if a self adjustment is programmed to update some control variables
if len(intvls.Intervals) == 0 {
if intvls.SelfAdjustMinLow {
intvls.MinLow = math.MaxInt64
}
if intvls.SelfAdjustMaxHigh {
intvls.MaxHigh = math.MinInt64
}
}
low := intvls.getInclusiveLow(itvl.Low)
high := intvls.getInclusiveHigh(itvl.High)
@@ -18,6 +31,13 @@ func (intvls *intervals) AddInterval(itvl *Interval) error {
return err
}
if intvls.SelfAdjustMaxHigh && high > intvls.MaxHigh {
intvls.MaxHigh = high
}
if intvls.SelfAdjustMinLow && low < intvls.MinLow {
intvls.MinLow = low
}
intvls.Intervals = append(intvls.Intervals, itvl)
intvls.reset()
return nil