Move undirtiedChunksIter into its own file
This commit is contained in:
parent
e90037216c
commit
daff06cf20
30
piece.go
30
piece.go
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/anacrolix/torrent/metainfo"
|
"github.com/anacrolix/torrent/metainfo"
|
||||||
pp "github.com/anacrolix/torrent/peer_protocol"
|
pp "github.com/anacrolix/torrent/peer_protocol"
|
||||||
"github.com/anacrolix/torrent/storage"
|
"github.com/anacrolix/torrent/storage"
|
||||||
"github.com/anacrolix/torrent/typed-roaring"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Piece struct {
|
type Piece struct {
|
||||||
@ -249,35 +248,6 @@ func init() {
|
|||||||
gob.Register(undirtiedChunksIter{})
|
gob.Register(undirtiedChunksIter{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
|
||||||
for it.HasNext() {
|
|
||||||
next := it.Next()
|
|
||||||
if next >= endIndex {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
for index := lastDirty + 1; index < next; index++ {
|
|
||||||
f(index - startIndex)
|
|
||||||
}
|
|
||||||
lastDirty = next
|
|
||||||
}
|
|
||||||
for index := lastDirty + 1; index < endIndex; index++ {
|
|
||||||
f(index - startIndex)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Piece) requestIndexOffset() RequestIndex {
|
func (p *Piece) requestIndexOffset() RequestIndex {
|
||||||
return p.t.pieceRequestIndexOffset(p.index)
|
return p.t.pieceRequestIndexOffset(p.index)
|
||||||
}
|
}
|
||||||
|
34
undirtied-chunks-iter.go
Normal file
34
undirtied-chunks-iter.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package torrent
|
||||||
|
|
||||||
|
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
|
||||||
|
for it.HasNext() {
|
||||||
|
next := it.Next()
|
||||||
|
if next >= endIndex {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
for index := lastDirty + 1; index < next; index++ {
|
||||||
|
f(index - startIndex)
|
||||||
|
}
|
||||||
|
lastDirty = next
|
||||||
|
}
|
||||||
|
for index := lastDirty + 1; index < endIndex; index++ {
|
||||||
|
f(index - startIndex)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user