Commit 9631b4e6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 42b6e542
......@@ -102,7 +102,7 @@ func (S *RangeSet) AddRange(r Range) {
S.rangev[:ilo], append([]Range{
Range{lo, hi_}},
S.rangev[jhi:]...)...)
debugfRSet("\tmerge [%d:%d]\t-> %s\n", ilo, jhi, S)
debugfRSet("\tmerge S[%d:%d]\t-> %s\n", ilo, jhi, S)
}
jhi = -1 // no longer valid
......@@ -162,7 +162,63 @@ func (S *RangeSet) DelRange(r Range) {
S.verify()
defer S.verify()
panic("TODO") // XXX
// find first ilo: r.lo < [ilo].hi
l := len(S.rangev)
ilo := sort.Search(l, func(i int) bool {
return r.lo <= S.rangev[i].hi_
})
debugfRSet("\tilo: %d\n", ilo)
if ilo == l { // not found
debugfRSet("\tnon-overlap right")
return
}
// find last jhi: [jhi].lo < r.hi
jhi := ilo
for ;; jhi++ {
if jhi == l {
break
}
if S.rangev[jhi].lo <= r.hi_ {
continue
}
break
}
debugfRSet("\tjhi: %d\n", jhi)
if jhi == 0 {
debugfRSet("\tnon-overlap left")
return
}
// [ilo+1:jhi-1] should be deleted
// [ilo] and [jhi-1] overlap with [r.lo,r.hi) - they shuold be deleted or shrinked.
if S.rangev[ilo].lo < r.lo { // shrink left
S.rangev = append(
S.rangev[:ilo], append([]Range{
Range{S.rangev[ilo].lo, r.lo-1}},
S.rangev[ilo+1:]...)...)
ilo++
debugfRSet("\tshrink left\t-> %s\n", S)
}
if r.hi_ < S.rangev[jhi-1].hi_ { // shrink right
S.rangev = append(
S.rangev[:jhi-1], append([]Range{
Range{r.hi_+1, S.rangev[jhi-1].hi_}},
S.rangev[jhi:]...)...)
jhi--
debugfRSet("\tshrink right\t-> %s\n", S)
}
if (jhi - ilo) > 1 {
S.rangev = append(
S.rangev[:ilo],
S.rangev[jhi:]...)
debugfRSet("\tdelete S[%d:%d]\t-> %s\n", ilo, jhi, S)
}
// done
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment