Commit 1489a805 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 250974f7
...@@ -144,44 +144,44 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) { ...@@ -144,44 +144,44 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
// entries in [ilo:jhi) [r.Lo,r.hi) and should be merged into one // entries in [ilo:jhi) [r.Lo,r.hi) and should be merged into one
// XXX check different values // XXX check different values
if (jhi - ilo) > 1 { if (jhi - ilo) > 1 {
lo := S.rangev[ilo].Lo lo := M.entryv[ilo].Lo
hi_ := S.rangev[jhi-1].Hi_ hi_ := M.entryv[jhi-1].Hi_
vReplaceSlice(&S.rangev, ilo,jhi, KeyRange{lo,hi_}) vReplaceSlice(&M.entryv, ilo,jhi, KeyRange{lo,hi_})
debugfRMap("\tmerge S[%d:%d]\t-> %s\n", ilo, jhi, S) debugfRMap("\tmerge M[%d:%d]\t-> %s\n", ilo, jhi, M)
} }
jhi = -1 // no longer valid jhi = -1 // no longer valid
// if [r.lo,r.hi) was outside of any entry - create new entry // if [r.lo,r.hi) was outside of any entry - create new entry
if r.Hi_ < S.rangev[ilo].Lo { if r.Hi_ < M.entryv[ilo].Lo {
vInsert(&S.rangev, ilo, r) vInsert(&M.entryv, ilo, r)
debugfRMap("\tinsert %s\t-> %s\n", r, S) debugfRMap("\tinsert %s\t-> %s\n", r, M)
} }
// now we have covered entries merged as needed into [ilo] // now we have covered entries merged as needed into [ilo]
// extend this entry if r coverage is wider // extend this entry if r coverage is wider
if r.Lo < S.rangev[ilo].Lo { if r.Lo < M.entryv[ilo].Lo {
S.rangev[ilo].Lo = r.Lo M.entryv[ilo].Lo = r.Lo
debugfRMap("\textend left\t-> %s\n", S) debugfRMap("\textend left\t-> %s\n", M)
} }
if r.Hi_ > S.rangev[ilo].Hi_ { if r.Hi_ > M.entryv[ilo].Hi_ {
S.rangev[ilo].Hi_ = r.Hi_ M.entryv[ilo].Hi_ = r.Hi_
debugfRMap("\textend right\t-> %s\n", S) debugfRMap("\textend right\t-> %s\n", M)
} }
// and check if we should merge it with right/left neighbours // and check if we should merge it with right/left neighbours
if ilo+1 < len(S.rangev) { // right if ilo+1 < len(M.entryv) { // right
if S.rangev[ilo].Hi_+1 == S.rangev[ilo+1].Lo { // XXX && .value same if M.entryv[ilo].Hi_+1 == M.entryv[ilo+1].Lo { // XXX && .value same
vReplaceSlice(&S.rangev, ilo,ilo+2, vReplaceSlice(&M.entryv, ilo,ilo+2,
KeyRange{S.rangev[ilo].Lo, S.rangev[ilo+1].Hi_}) KeyRange{M.entryv[ilo].Lo, M.entryv[ilo+1].Hi_})
debugfRMap("\tmerge right\t-> %s\n", S) debugfRMap("\tmerge right\t-> %s\n", M)
} }
} }
if ilo > 0 { // left if ilo > 0 { // left
if S.rangev[ilo-1].Hi_+1 == S.rangev[ilo].Lo { // XXX && .value same if M.entryv[ilo-1].Hi_+1 == M.entryv[ilo].Lo { // XXX && .value same
vReplaceSlice(&S.rangev, ilo-1,ilo+1, vReplaceSlice(&M.entryv, ilo-1,ilo+1,
KeyRange{S.rangev[ilo-1].Lo, S.rangev[ilo].Hi_}) KeyRange{M.entryv[ilo-1].Lo, M.entryv[ilo].Hi_})
debugfRMap("\tmerge left\t-> %s\n", S) debugfRMap("\tmerge left\t-> %s\n", M)
} }
} }
......
...@@ -146,44 +146,44 @@ func (M *_RangedMap_void) SetRange(r KeyRange, v void) { ...@@ -146,44 +146,44 @@ func (M *_RangedMap_void) SetRange(r KeyRange, v void) {
// entries in [ilo:jhi) ∈ [r.Lo,r.hi) and should be merged into one // entries in [ilo:jhi) ∈ [r.Lo,r.hi) and should be merged into one
// XXX check different values // XXX check different values
if (jhi - ilo) > 1 { if (jhi - ilo) > 1 {
lo := S.rangev[ilo].Lo lo := M.entryv[ilo].Lo
hi_ := S.rangev[jhi-1].Hi_ hi_ := M.entryv[jhi-1].Hi_
vReplaceSlice__RangedMap_void(&S.rangev, ilo,jhi, KeyRange{lo,hi_}) vReplaceSlice__RangedMap_void(&M.entryv, ilo,jhi, KeyRange{lo,hi_})
debugf_RangedMap_void("\tmerge S[%d:%d]\t-> %s\n", ilo, jhi, S) debugf_RangedMap_void("\tmerge M[%d:%d]\t-> %s\n", ilo, jhi, M)
} }
jhi = -1 // no longer valid jhi = -1 // no longer valid
// if [r.lo,r.hi) was outside of any entry - create new entry // if [r.lo,r.hi) was outside of any entry - create new entry
if r.Hi_ < S.rangev[ilo].Lo { if r.Hi_ < M.entryv[ilo].Lo {
vInsert__RangedMap_void(&S.rangev, ilo, r) vInsert__RangedMap_void(&M.entryv, ilo, r)
debugf_RangedMap_void("\tinsert %s\t-> %s\n", r, S) debugf_RangedMap_void("\tinsert %s\t-> %s\n", r, M)
} }
// now we have covered entries merged as needed into [ilo] // now we have covered entries merged as needed into [ilo]
// extend this entry if r coverage is wider // extend this entry if r coverage is wider
if r.Lo < S.rangev[ilo].Lo { if r.Lo < M.entryv[ilo].Lo {
S.rangev[ilo].Lo = r.Lo M.entryv[ilo].Lo = r.Lo
debugf_RangedMap_void("\textend left\t-> %s\n", S) debugf_RangedMap_void("\textend left\t-> %s\n", M)
} }
if r.Hi_ > S.rangev[ilo].Hi_ { if r.Hi_ > M.entryv[ilo].Hi_ {
S.rangev[ilo].Hi_ = r.Hi_ M.entryv[ilo].Hi_ = r.Hi_
debugf_RangedMap_void("\textend right\t-> %s\n", S) debugf_RangedMap_void("\textend right\t-> %s\n", M)
} }
// and check if we should merge it with right/left neighbours // and check if we should merge it with right/left neighbours
if ilo+1 < len(S.rangev) { // right if ilo+1 < len(M.entryv) { // right
if S.rangev[ilo].Hi_+1 == S.rangev[ilo+1].Lo { // XXX && .value same if M.entryv[ilo].Hi_+1 == M.entryv[ilo+1].Lo { // XXX && .value same
vReplaceSlice__RangedMap_void(&S.rangev, ilo,ilo+2, vReplaceSlice__RangedMap_void(&M.entryv, ilo,ilo+2,
KeyRange{S.rangev[ilo].Lo, S.rangev[ilo+1].Hi_}) KeyRange{M.entryv[ilo].Lo, M.entryv[ilo+1].Hi_})
debugf_RangedMap_void("\tmerge right\t-> %s\n", S) debugf_RangedMap_void("\tmerge right\t-> %s\n", M)
} }
} }
if ilo > 0 { // left if ilo > 0 { // left
if S.rangev[ilo-1].Hi_+1 == S.rangev[ilo].Lo { // XXX && .value same if M.entryv[ilo-1].Hi_+1 == M.entryv[ilo].Lo { // XXX && .value same
vReplaceSlice__RangedMap_void(&S.rangev, ilo-1,ilo+1, vReplaceSlice__RangedMap_void(&M.entryv, ilo-1,ilo+1,
KeyRange{S.rangev[ilo-1].Lo, S.rangev[ilo].Hi_}) KeyRange{M.entryv[ilo-1].Lo, M.entryv[ilo].Hi_})
debugf_RangedMap_void("\tmerge left\t-> %s\n", S) debugf_RangedMap_void("\tmerge left\t-> %s\n", M)
} }
} }
......
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