-
Notifications
You must be signed in to change notification settings - Fork 243
Closed
Labels
Description
I wrote this test:
func TestUnsetIterator(t *testing.T) {
r := rand.New(rand.NewSource(0))
s := NewBitmap()
sz := 150000
initsize := 65000
for i := 0; i < initsize; i++ {
s.Add(uint32(r.Int31n(int32(sz))))
}
wantCount := s.GetCardinality()
s.Flip(0, 0x100000000)
i := s.UnsetIterator(0, 0xffffffff)
gotCount := uint64(0)
for i.HasNext() {
i.Next()
gotCount++
}
assert.Equal(t, wantCount, gotCount)
}This test passes but takes about 30 seconds to run on my machine.
It seems like UnsetIterator is doing work proportional to the number of set bits
rather than the number of unset bits.
That seems rather unfortunate, and doesn't seem inevitable, given that running
Flip and then Iterator takes a fraction of the time.