X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=undirtied-chunks-iter.go;h=de0cce0a5e699837153e02646e197bd3f0b1fbd8;hb=790fae6fa168e1d2250d389a3162ab2eba5ee31e;hp=14f88a24f922ee966d7315263f716b41c77130b2;hpb=daff06cf20fcfdeeb0671a2ed42b7cb95ab7070f;p=btrtrc.git diff --git a/undirtied-chunks-iter.go b/undirtied-chunks-iter.go index 14f88a24..de0cce0a 100644 --- a/undirtied-chunks-iter.go +++ b/undirtied-chunks-iter.go @@ -4,31 +4,20 @@ import ( "github.com/anacrolix/torrent/typed-roaring" ) -// Use an iterator to jump between dirty bits. -type undirtiedChunksIter struct { - TorrentDirtyChunks *typedRoaring.Bitmap[RequestIndex] - StartRequestIndex RequestIndex - EndRequestIndex RequestIndex -} - -func (me *undirtiedChunksIter) Iter(f func(chunkIndexType)) { - it := me.TorrentDirtyChunks.Iterator() - startIndex := me.StartRequestIndex - endIndex := me.EndRequestIndex - it.AdvanceIfNeeded(startIndex) - lastDirty := startIndex - 1 +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() - if next >= endIndex { + if next >= end { break } for index := lastDirty + 1; index < next; index++ { - f(index - startIndex) + f(index) } lastDirty = next } - for index := lastDirty + 1; index < endIndex; index++ { - f(index - startIndex) + for index := lastDirty + 1; index < end; index++ { + f(index) } - return }