()
| 84 | } |
| 85 | |
| 86 | func (s IntervalSlice) Normalize() IntervalSlice { |
| 87 | var n IntervalSlice |
| 88 | if len(s) == 0 { |
| 89 | return n |
| 90 | } |
| 91 | |
| 92 | s.Sort() |
| 93 | |
| 94 | n = append(n, s[0]) |
| 95 | |
| 96 | for i := 1; i < len(s); i++ { |
| 97 | last := n[len(n)-1] |
| 98 | if s[i].Start > last.Stop { |
| 99 | n = append(n, s[i]) |
| 100 | continue |
| 101 | } else { |
| 102 | stop := max(last.Stop, s[i].Stop) |
| 103 | n[len(n)-1] = Interval{last.Start, stop} |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return n |
| 108 | } |
| 109 | |
| 110 | // Contain returns true if sub in s |
| 111 | func (s IntervalSlice) Contain(sub IntervalSlice) bool { |