Commit 3b7b69e6 authored by Kirill Smelkov's avatar Kirill Smelkov

X fixes for empty set/range

parent 6342560d
......@@ -116,7 +116,7 @@ func (M *RangedMap) SetRange(r KeyRange, v VALUE) {
defer M.verify()
if r.Empty() {
return // XXX or panic?
return
}
// clear range for r and insert new entry
......@@ -235,11 +235,17 @@ func (M *RangedMap) DelRange(r KeyRange) {
M.verify()
defer M.verify()
if r.Empty() {
return
}
M.delRange(r)
}
// delRange deletes range r from the map and returns .entryv index where r
// should be inserted/appended if needed.
//
// r must be !empty.
func (M *RangedMap) delRange(r KeyRange) (i int) {
// find first ilo: r.Lo < [ilo].hi
l := len(M.entryv)
......@@ -315,6 +321,10 @@ func (M *RangedMap) HasRange(r KeyRange) (yes bool) {
M.verify()
if r.Empty() {
return true
}
// find first ilo: r.lo < [ilo].hi
l := len(M.entryv)
ilo := sort.Search(l, func(i int) bool {
......
......@@ -101,7 +101,7 @@ func TestRangedMap(t *testing.T) {
X(0,0,x), // X
M(), // Set
M(), // Del
n), // Has
y), // Has
// empty vs !empty
E(
......@@ -117,7 +117,7 @@ func TestRangedMap(t *testing.T) {
X(0,0,x), // X
M(1,2,a), // Set
M(1,2,a), // Del
y), // Has XXX ok
y), // Has
// basic change
E(
......@@ -226,7 +226,11 @@ func TestRangedMap(t *testing.T) {
}
assertMapHasRange(t, Mset, r, true)
assertMapHasRange(t, Mdel, r, false)
rInMdel := false
if r.Empty() {
rInMdel = true
}
assertMapHasRange(t, Mdel, r, rInMdel)
verifyGet(t, M)
verifyGet(t, Mset)
......
......@@ -118,7 +118,7 @@ func (M *_RangedMap_str) SetRange(r KeyRange, v string) {
defer M.verify()
if r.Empty() {
return // XXX or panic?
return
}
// clear range for r and insert new entry
......@@ -237,11 +237,17 @@ func (M *_RangedMap_str) DelRange(r KeyRange) {
M.verify()
defer M.verify()
if r.Empty() {
return
}
M.delRange(r)
}
// delRange deletes range r from the map and returns .entryv index where r
// should be inserted/appended if needed.
//
// r must be !empty.
func (M *_RangedMap_str) delRange(r KeyRange) (i int) {
// find first ilo: r.Lo < [ilo].hi
l := len(M.entryv)
......@@ -317,6 +323,10 @@ func (M *_RangedMap_str) HasRange(r KeyRange) (yes bool) {
M.verify()
if r.Empty() {
return true
}
// find first ilo: r.lo < [ilo].hi
l := len(M.entryv)
ilo := sort.Search(l, func(i int) bool {
......
......@@ -118,7 +118,7 @@ func (M *_RangedMap_void) SetRange(r KeyRange, v void) {
defer M.verify()
if r.Empty() {
return // XXX or panic?
return
}
// clear range for r and insert new entry
......@@ -237,11 +237,17 @@ func (M *_RangedMap_void) DelRange(r KeyRange) {
M.verify()
defer M.verify()
if r.Empty() {
return
}
M.delRange(r)
}
// delRange deletes range r from the map and returns .entryv index where r
// should be inserted/appended if needed.
//
// r must be !empty.
func (M *_RangedMap_void) delRange(r KeyRange) (i int) {
// find first ilo: r.Lo < [ilo].hi
l := len(M.entryv)
......@@ -317,6 +323,10 @@ func (M *_RangedMap_void) HasRange(r KeyRange) (yes bool) {
M.verify()
if r.Empty() {
return true
}
// find first ilo: r.lo < [ilo].hi
l := len(M.entryv)
ilo := sort.Search(l, func(i int) bool {
......
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