quick fix for Bitmap.Any bug

Want to make empty containers a thing of the past, but that can wait for another
day.
This commit is contained in:
Matt Jaffee 2019-03-21 15:46:19 -05:00
parent 7550b5445a
commit d202e6a1a0
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
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")
}
}