Modify signature of bitmap{Set,Zero,Xor}Range to be consistent with similar functions

This commit is contained in:
Alan Bernstein 2017-06-15 11:58:51 -05:00 committed by Matt Jaffee
parent 371f36fb76
commit 5f5a857181
2 changed files with 9 additions and 15 deletions

View file

@ -2290,17 +2290,15 @@ func unionBitmapRun(a, b *container) *container {
}
output := a.clone()
for j := 0; j < len(b.runs); j++ {
output.bitmapSetRange(uint64(b.runs[j].start), uint64(b.runs[j].last))
output.bitmapSetRange(uint64(b.runs[j].start), uint64(b.runs[j].last)+1)
}
return output
}
const maxBitmap = 0xFFFFFFFFFFFFFFFF
// sets all bits in [i, j] (inclusive) (c must be a bitmap container)
// TODO inclusive upper limit is inconsistent with other functions (CountRange, SliceRange, ForEachRange, OffsetRange(?))
// sets all bits in [i, j) (c must be a bitmap container)
func (c *container) bitmapSetRange(i, j uint64) {
j += 1
x := i / 64
y := (j - 1) / 64
var X uint64 = maxBitmap << (i % 64)
@ -2322,10 +2320,8 @@ func (c *container) bitmapSetRange(i, j uint64) {
}
}
// xor's all bits in [i, j] with all true (inclusive) (c must be a bitmap container).
// TODO inclusive upper limit is inconsistent with other functions
// xor's all bits in [i, j) with all true (c must be a bitmap container).
func (c *container) bitmapXorRange(i, j uint64) {
j += 1
x := i / 64
y := (j - 1) / 64
var X uint64 = maxBitmap << (i % 64)
@ -2349,10 +2345,8 @@ func (c *container) bitmapXorRange(i, j uint64) {
}
}
// zeroes all bits in [i, j] (inclusive) (c must be a bitmap container)
// TODO inclusive upper limit is inconsistent with other functions
// zeroes all bits in [i, j) (c must be a bitmap container)
func (c *container) bitmapZeroRange(i, j uint64) {
j += 1
x := i / 64
y := (j - 1) / 64
var X uint64 = maxBitmap << (i % 64)
@ -2519,7 +2513,7 @@ func differenceBitmapRun(a, b *container) *container {
output := a.clone()
for j := 0; j < len(b.runs); j++ {
output.bitmapZeroRange(uint64(b.runs[j].start), uint64(b.runs[j].last))
output.bitmapZeroRange(uint64(b.runs[j].start), uint64(b.runs[j].last)+1)
}
return output
}
@ -3343,7 +3337,7 @@ func xorRunRun(a, b *container) *container {
func xorBitmapRun(a, b *container) *container {
output := a.clone()
for j := 0; j < len(b.runs); j++ {
output.bitmapXorRange(uint64(b.runs[j].start), uint64(b.runs[j].last))
output.bitmapXorRange(uint64(b.runs[j].start), uint64(b.runs[j].last)+1)
}
if output.n < ArrayMaxSize && len(output.runs) > output.n/2 {

View file

@ -732,7 +732,7 @@ func TestBitmapSetRange(t *testing.T) {
c.bitmap[i] = v
}
c.n = c.countRange(0, 65535)
c.bitmapSetRange(test.start, test.last)
c.bitmapSetRange(test.start, test.last+1)
if !reflect.DeepEqual(c.bitmap[:len(test.exp)], test.exp) {
t.Fatalf("test %#v expected %x, got %x", i, test.exp, c.bitmap[:len(test.bitmap)])
}
@ -1010,7 +1010,7 @@ func TestBitmapZeroRange(t *testing.T) {
c.bitmap[i] = v
}
c.n = c.countRange(0, 65535)
c.bitmapZeroRange(test.start, test.last)
c.bitmapZeroRange(test.start, test.last+1)
if !reflect.DeepEqual(c.bitmap[:len(test.exp)], test.exp) {
t.Fatalf("test %#v expected %x, got %x", i, test.exp, c.bitmap[:len(test.bitmap)])
}
@ -1528,7 +1528,7 @@ func TestBitmapXorRange(t *testing.T) {
c.bitmap[i] = v
}
c.n = c.countRange(0, 65535)
c.bitmapXorRange(test.start, test.last)
c.bitmapXorRange(test.start, test.last+1)
if !reflect.DeepEqual(c.bitmap[:len(test.exp)], test.exp) {
t.Fatalf("test %#v expected %x, got %x", i, test.exp, c.bitmap[:len(test.bitmap)])
}