FedP2P/storage/completion_piece_map.go

29 lines
508 B
Go

package storage
import (
"github.com/anacrolix/torrent/metainfo"
)
type mapPieceCompletion struct {
m map[metainfo.PieceKey]struct{}
}
func (mapPieceCompletion) Close() {}
func (me *mapPieceCompletion) Get(pk metainfo.PieceKey) (bool, error) {
_, ok := me.m[pk]
return ok, nil
}
func (me *mapPieceCompletion) Set(pk metainfo.PieceKey, b bool) error {
if b {
if me.m == nil {
me.m = make(map[metainfo.PieceKey]struct{})
}
me.m[pk] = struct{}{}
} else {
delete(me.m, pk)
}
return nil
}