structure_old/priority_list/iterator.go
2019-02-25 02:37:34 +08:00

71 lines
1.0 KiB
Go

package plist
type Iterator struct {
pl *PriorityList
cur *Node
}
func (iter *Iterator) Value() interface{} {
return iter.cur.Value
}
func (iter *Iterator) RingNext() bool {
if iter.pl.size == 0 {
return false
}
iter.cur = iter.cur.next
if iter.cur == iter.pl.tail {
iter.cur = iter.pl.head.next
}
return true
}
func (iter *Iterator) Next() bool {
if iter.cur == iter.pl.tail {
return false
}
if iter.cur.next == iter.pl.tail {
iter.cur = iter.cur.next
return false
}
iter.cur = iter.cur.next
return true
}
func (iter *Iterator) RingPrev() bool {
if iter.pl.size == 0 {
return false
}
iter.cur = iter.cur.prev
if iter.cur == iter.pl.head {
iter.cur = iter.pl.tail.prev
}
return true
}
func (iter *Iterator) Prev() bool {
if iter.cur == iter.pl.head {
return false
}
if iter.cur.prev == iter.pl.head {
iter.cur = iter.cur.prev
return false
}
iter.cur = iter.cur.prev
return true
}
func (iter *Iterator) MoveHead() {
iter.cur = iter.pl.head
}
func (iter *Iterator) MoveTail() {
iter.cur = iter.pl.tail
}