默认Compare是大于等于

This commit is contained in:
eson 2018-12-22 02:46:37 +08:00
parent c8a741ada7
commit b5ce9ed564
2 changed files with 4 additions and 50 deletions

View File

@ -88,7 +88,7 @@ func (pl *PriorityList) Clear() {
pl.size = 0
}
// GetCompare 获取比较的节点 compare > 11这个节点小的值 [15,12,9,8,6,1] = 9
// GetCompare 获取比较的节点 compare >= 11这个节点小的值 [15,12,9,8,6,1] = 9
func (pl *PriorityList) GetCompare(cNode INode) INode {
cur := pl.head
for cur != nil {
@ -100,7 +100,7 @@ func (pl *PriorityList) GetCompare(cNode INode) INode {
return nil
}
// GetCompareReverse 逆序获取比较的节点 compare > 11这个节点大的值 [15,12,9,8,6,1] = 12
// GetCompareReverse 逆序获取比较的节点 compare >= 11这个节点大的值 [15,12,9,8,6,1] = 12
func (pl *PriorityList) GetCompareReverse(cNode INode) INode {
cur := pl.tail
for cur != nil {
@ -197,52 +197,6 @@ func (pl *PriorityList) RemoveIndex(idx int) INode {
result := pl.Get(idx)
pl.Remove(result)
return result
// if idx >= pl.size {
// return nil
// }
// pl.size--
// var cur INode
// if pl.size == 1 {
// cur = pl.head
// pl.head = nil
// pl.tail = nil
// if cur == nil {
// panic("why cur == nil?")
// }
// return cur
// }
// cur = pl.head
// for i := 0; i < idx; i++ {
// cur = cur.GetNext()
// }
// prev := cur.GetPrev()
// next := cur.GetNext()
// if prev == nil {
// pl.head = next
// pl.head.SetPrev(nil)
// } else if next == nil {
// pl.tail = prev
// pl.tail.SetNext(nil)
// } else {
// prev.SetNext(next)
// next.SetPrev(prev)
// }
// cur.SetNext(nil)
// cur.SetPrev(nil)
// if cur == nil {
// panic("why cur == nil?")
// }
// return cur
}
// RemoveReverseIndex 逆顺序删除节点 并获取该节点

View File

@ -68,8 +68,8 @@ func TestPriority(t *testing.T) {
pl.Insert(NewNodeInt(12))
pl.Insert(NewNodeInt(8))
if pl.GetCompare(NewNodeInt(11)).GetValue() != 9 {
t.Error(pl.String(), pl.GetCompare(NewNodeInt(11)).GetValue())
if pl.GetCompare(NewNodeInt(9)).GetValue() != 9 {
t.Error(pl.String(), pl.GetCompare(NewNodeInt(9)).GetValue())
}
if pl.GetCompareReverse(NewNodeInt(11)).GetValue() != 12 {