torrent/undirtied-chunks-iter.go

24 lines
473 B
Go
Raw Normal View History

package torrent
import (
"github.com/anacrolix/torrent/typed-roaring"
)
2022-05-11 01:20:52 +00:00
func iterBitmapUnsetInRange[T typedRoaring.BitConstraint](it *typedRoaring.Iterator[T], start, end T, f func(T)) {
it.AdvanceIfNeeded(start)
lastDirty := start - 1
for it.HasNext() {
next := it.Next()
2022-05-11 01:20:52 +00:00
if next >= end {
break
}
for index := lastDirty + 1; index < next; index++ {
2022-05-11 01:20:52 +00:00
f(index)
}
lastDirty = next
}
2022-05-11 01:20:52 +00:00
for index := lastDirty + 1; index < end; index++ {
f(index)
}
}