Remove unused orderedList
This commit is contained in:
parent
8f164ae956
commit
bd7981dc19
47
ordered.go
47
ordered.go
|
@ -1,47 +0,0 @@
|
|||
package torrent
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
)
|
||||
|
||||
// This was used to maintain pieces in order of bytes left to download. I
|
||||
// don't think it's currently in use.
|
||||
|
||||
type orderedList struct {
|
||||
list *list.List
|
||||
lessFunc func(a, b interface{}) bool
|
||||
}
|
||||
|
||||
func (me *orderedList) Len() int {
|
||||
return me.list.Len()
|
||||
}
|
||||
|
||||
func newOrderedList(lessFunc func(a, b interface{}) bool) *orderedList {
|
||||
return &orderedList{
|
||||
list: list.New(),
|
||||
lessFunc: lessFunc,
|
||||
}
|
||||
}
|
||||
|
||||
func (me *orderedList) ValueChanged(e *list.Element) {
|
||||
for prev := e.Prev(); prev != nil && me.lessFunc(e.Value, prev.Value); prev = e.Prev() {
|
||||
me.list.MoveBefore(e, prev)
|
||||
}
|
||||
for next := e.Next(); next != nil && me.lessFunc(next.Value, e.Value); next = e.Next() {
|
||||
me.list.MoveAfter(e, next)
|
||||
}
|
||||
}
|
||||
|
||||
func (me *orderedList) Insert(value interface{}) (ret *list.Element) {
|
||||
ret = me.list.PushFront(value)
|
||||
me.ValueChanged(ret)
|
||||
return
|
||||
}
|
||||
|
||||
func (me *orderedList) Front() *list.Element {
|
||||
return me.list.Front()
|
||||
}
|
||||
|
||||
func (me *orderedList) Remove(e *list.Element) interface{} {
|
||||
return me.list.Remove(e)
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
package torrent
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOrderedList(t *testing.T) {
|
||||
ol := newOrderedList(func(a, b interface{}) bool {
|
||||
return a.(int) < b.(int)
|
||||
})
|
||||
if ol.Len() != 0 {
|
||||
t.FailNow()
|
||||
}
|
||||
e := ol.Insert(0)
|
||||
if ol.Len() != 1 {
|
||||
t.FailNow()
|
||||
}
|
||||
if e.Value.(int) != 0 {
|
||||
t.FailNow()
|
||||
}
|
||||
e = ol.Front()
|
||||
if e.Value.(int) != 0 {
|
||||
t.FailNow()
|
||||
}
|
||||
if e.Next() != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
ol.Insert(1)
|
||||
if e.Next().Value.(int) != 1 {
|
||||
t.FailNow()
|
||||
}
|
||||
ol.Insert(-1)
|
||||
if e.Prev().Value.(int) != -1 {
|
||||
t.FailNow()
|
||||
}
|
||||
e.Value = -2
|
||||
ol.ValueChanged(e)
|
||||
if e.Prev() != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
if e.Next().Value.(int) != -1 {
|
||||
t.FailNow()
|
||||
}
|
||||
if ol.Len() != 3 {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue