2014-08-27 22:04:41 +00:00
|
|
|
package torrent
|
|
|
|
|
2016-10-31 05:24:48 +00:00
|
|
|
import "container/heap"
|
|
|
|
|
2016-07-05 14:42:16 +00:00
|
|
|
func worseConn(l, r *connection) bool {
|
2018-06-16 07:04:12 +00:00
|
|
|
var ml multiLess
|
|
|
|
ml.NextBool(!l.useful(), !r.useful())
|
|
|
|
ml.StrictNext(
|
|
|
|
l.lastHelpful().Equal(r.lastHelpful()),
|
|
|
|
l.lastHelpful().Before(r.lastHelpful()))
|
|
|
|
ml.StrictNext(
|
|
|
|
l.completedHandshake.Equal(r.completedHandshake),
|
|
|
|
l.completedHandshake.Before(r.completedHandshake))
|
|
|
|
return ml.Final()
|
2014-09-11 10:31:31 +00:00
|
|
|
}
|
2016-10-31 05:24:48 +00:00
|
|
|
|
|
|
|
type worseConnSlice struct {
|
|
|
|
conns []*connection
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ heap.Interface = &worseConnSlice{}
|
|
|
|
|
|
|
|
func (me worseConnSlice) Len() int {
|
|
|
|
return len(me.conns)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (me worseConnSlice) Less(i, j int) bool {
|
|
|
|
return worseConn(me.conns[i], me.conns[j])
|
|
|
|
}
|
|
|
|
|
|
|
|
func (me *worseConnSlice) Pop() interface{} {
|
|
|
|
i := len(me.conns) - 1
|
|
|
|
ret := me.conns[i]
|
|
|
|
me.conns = me.conns[:i]
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (me *worseConnSlice) Push(x interface{}) {
|
|
|
|
me.conns = append(me.conns, x.(*connection))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (me worseConnSlice) Swap(i, j int) {
|
|
|
|
me.conns[i], me.conns[j] = me.conns[j], me.conns[i]
|
|
|
|
}
|