Merge pull request #1908 from jaffee/bitmap-any-quick-fix

quick fix for Bitmap.Any bug [no changelog]
This commit is contained in:
Matthew Jaffee 2019-03-21 16:09:59 -05:00 committed by GitHub
commit 86ea040639
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View file

@ -331,7 +331,7 @@ func (b *Bitmap) Any() bool {
// TODO (jaffee) I'm not sure if it's possible/legal to have an empty
// container, so this loop may be totally unnecessary. In theory, any empty
// container should be removed from the bitmap though.
for b := iter.Next(); b; iter.Next() {
for iter.Next() {
_, c := iter.Value()
if c.n > 0 {
return true

View file

@ -3818,3 +3818,31 @@ func BenchmarkUnionInPlaceRegression(b *testing.B) {
}
})
}
func TestBitmapAny(t *testing.T) {
bm := NewBTreeBitmap()
if bm.Any() {
t.Error("empty bitmap should have Any()==false")
}
bm.Add(1)
if !bm.Any() {
t.Error("bitmap with 1 bit should have Any()==true")
}
bm.Add(100000)
if !bm.Any() {
t.Error("bitmap with 2 bits should have Any()==true")
}
bm.Remove(1)
if !bm.Any() {
t.Error("bitmap with 1 bit left after removing 1 should have Any()==true")
}
bm.Add(1)
bm = bm.Difference(NewBTreeBitmap(1))
if !bm.Any() {
t.Error("bitmap with 1 bit left after differencing 1 should have Any()==true")
}
bm.Remove(100000)
if bm.Any() {
t.Error("shouldn't be any left")
}
}