github.com/anacrolix/torrent@v1.61.0/undirtied-chunks-iter.go (about)

     1  package torrent
     2  
     3  import (
     4  	typedRoaring "github.com/anacrolix/torrent/typed-roaring"
     5  )
     6  
     7  func iterBitmapUnsetInRange[T typedRoaring.BitConstraint](
     8  	it *typedRoaring.Iterator[T],
     9  	start, end T,
    10  	f func(T),
    11  ) {
    12  	it.AdvanceIfNeeded(start)
    13  	lastDirty := start - 1
    14  	for it.HasNext() {
    15  		next := it.Next()
    16  		if next >= end {
    17  			break
    18  		}
    19  		for index := lastDirty + 1; index < next; index++ {
    20  			f(index)
    21  		}
    22  		lastDirty = next
    23  	}
    24  	for index := lastDirty + 1; index < end; index++ {
    25  		f(index)
    26  	}
    27  }