splited big file into smaller files by functionality

This commit is contained in:
Daniel Gil
2018-05-25 13:02:52 +02:00
parent 941fe9746a
commit 786bcb162b
10 changed files with 308 additions and 175 deletions

32
merge.go Normal file
View File

@@ -0,0 +1,32 @@
package interval
func (intvls *intervals) Merge() []*Interval {
if intvls.MergeList == nil {
intvls.MergeList = intvls.calculateMerged()
}
return intvls.MergeList
}
func (intvls *intervals) calculateMerged() []*Interval {
intvls.Sort()
list := []*Interval{}
var lastLow int
var lastHigh int
for i, intvl := range intvls.Intervals {
if i == 0 {
lastLow = intvl.Low
lastHigh = intvl.High
continue
}
if inBetweenInclusive(intvl.Low, lastLow, lastHigh) {
// because the intervals are previously sorted, we just need to take care of the High value
if intvl.High > lastHigh {
lastHigh = intvl.High
}
continue
}
list = append(list, &Interval{Low: lastLow, High: lastHigh})
}
list = append(list, &Interval{Low: lastLow, High: lastHigh})
return list
}