internal/pieceordering: Doc
This commit is contained in:
parent
94c01fb565
commit
eb2aefdcdb
|
@ -1,3 +1,5 @@
|
||||||
|
// Implements ordering of torrent piece indices for such purposes as download
|
||||||
|
// prioritization.
|
||||||
package pieceordering
|
package pieceordering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -6,6 +8,7 @@ import (
|
||||||
"github.com/ryszard/goskiplist/skiplist"
|
"github.com/ryszard/goskiplist/skiplist"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Maintains piece integers by their ascending assigned keys.
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
sl *skiplist.SkipList
|
sl *skiplist.SkipList
|
||||||
pieceKeys map[int]int
|
pieceKeys map[int]int
|
||||||
|
@ -17,8 +20,8 @@ func New() *Instance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the piece with the given key. No other piece can have the same key. If
|
// Add the piece with the given key. If the piece is already present, change
|
||||||
// the piece is already present, change its key.
|
// its key.
|
||||||
func (me *Instance) SetPiece(piece, key int) {
|
func (me *Instance) SetPiece(piece, key int) {
|
||||||
if existingKey, ok := me.pieceKeys[piece]; ok {
|
if existingKey, ok := me.pieceKeys[piece]; ok {
|
||||||
if existingKey == key {
|
if existingKey == key {
|
||||||
|
@ -80,6 +83,7 @@ func (me *Instance) DeletePiece(piece int) {
|
||||||
delete(me.pieceKeys, piece)
|
delete(me.pieceKeys, piece)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the piece with the lowest key.
|
||||||
func (me Instance) First() Element {
|
func (me Instance) First() Element {
|
||||||
i := me.sl.SeekToFirst()
|
i := me.sl.SeekToFirst()
|
||||||
if i == nil {
|
if i == nil {
|
||||||
|
|
Loading…
Reference in New Issue