默认Compare是大于等于
This commit is contained in:
parent
c8a741ada7
commit
b5ce9ed564
@ -88,7 +88,7 @@ func (pl *PriorityList) Clear() {
|
|||||||
pl.size = 0
|
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 {
|
func (pl *PriorityList) GetCompare(cNode INode) INode {
|
||||||
cur := pl.head
|
cur := pl.head
|
||||||
for cur != nil {
|
for cur != nil {
|
||||||
@ -100,7 +100,7 @@ func (pl *PriorityList) GetCompare(cNode INode) INode {
|
|||||||
return nil
|
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 {
|
func (pl *PriorityList) GetCompareReverse(cNode INode) INode {
|
||||||
cur := pl.tail
|
cur := pl.tail
|
||||||
for cur != nil {
|
for cur != nil {
|
||||||
@ -197,52 +197,6 @@ func (pl *PriorityList) RemoveIndex(idx int) INode {
|
|||||||
result := pl.Get(idx)
|
result := pl.Get(idx)
|
||||||
pl.Remove(result)
|
pl.Remove(result)
|
||||||
return 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 逆顺序删除节点 并获取该节点
|
// RemoveReverseIndex 逆顺序删除节点 并获取该节点
|
||||||
|
@ -68,8 +68,8 @@ func TestPriority(t *testing.T) {
|
|||||||
pl.Insert(NewNodeInt(12))
|
pl.Insert(NewNodeInt(12))
|
||||||
pl.Insert(NewNodeInt(8))
|
pl.Insert(NewNodeInt(8))
|
||||||
|
|
||||||
if pl.GetCompare(NewNodeInt(11)).GetValue() != 9 {
|
if pl.GetCompare(NewNodeInt(9)).GetValue() != 9 {
|
||||||
t.Error(pl.String(), pl.GetCompare(NewNodeInt(11)).GetValue())
|
t.Error(pl.String(), pl.GetCompare(NewNodeInt(9)).GetValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
if pl.GetCompareReverse(NewNodeInt(11)).GetValue() != 12 {
|
if pl.GetCompareReverse(NewNodeInt(11)).GetValue() != 12 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user