diff --git a/roaring/roaring.go b/roaring/roaring.go index 39e29de57..2c74306bc 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -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 { diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index 62aacf467..ecc87c786 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -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)]) }