diff --git a/roaring/roaring.go b/roaring/roaring.go index 157203c41..f12d3fc38 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -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 diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index 927d7c4b2..16f5e4e7b 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -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") + } +}