2016-06-20 15:51:05 +08:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
|
|
)
|
|
|
|
|
|
|
|
type mapPieceCompletion struct {
|
|
|
|
m map[metainfo.PieceKey]struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mapPieceCompletion) Close() {}
|
|
|
|
|
2016-08-26 18:29:05 +08:00
|
|
|
func (me *mapPieceCompletion) Get(pk metainfo.PieceKey) (bool, error) {
|
|
|
|
_, ok := me.m[pk]
|
2016-07-12 14:45:22 +08:00
|
|
|
return ok, nil
|
2016-06-20 15:51:05 +08:00
|
|
|
}
|
|
|
|
|
2016-08-26 18:29:05 +08:00
|
|
|
func (me *mapPieceCompletion) Set(pk metainfo.PieceKey, b bool) error {
|
2016-06-20 15:51:05 +08:00
|
|
|
if b {
|
|
|
|
if me.m == nil {
|
|
|
|
me.m = make(map[metainfo.PieceKey]struct{})
|
|
|
|
}
|
2016-08-26 18:29:05 +08:00
|
|
|
me.m[pk] = struct{}{}
|
2016-06-20 15:51:05 +08:00
|
|
|
} else {
|
2016-08-26 18:29:05 +08:00
|
|
|
delete(me.m, pk)
|
2016-06-20 15:51:05 +08:00
|
|
|
}
|
2016-07-12 14:45:22 +08:00
|
|
|
return nil
|
2016-06-20 15:51:05 +08:00
|
|
|
}
|