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:
20
add.go
20
add.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user