github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/utilities/common/prque/prque.go (about) 1 package prque 2 3 import ( 4 "container/heap" 5 ) 6 7 type Prque struct { 8 cont *sstack 9 } 10 11 func New(setIndex setIndexCallback) *Prque { 12 return &Prque{newSstack(setIndex)} 13 } 14 15 func (p *Prque) Push(data interface{}, priority int64) { 16 heap.Push(p.cont, &item{data, priority}) 17 } 18 19 func (p *Prque) Pop() (interface{}, int64) { 20 item := heap.Pop(p.cont).(*item) 21 return item.value, item.priority 22 } 23 24 func (p *Prque) PopItem() interface{} { 25 return heap.Pop(p.cont).(*item).value 26 } 27 28 func (p *Prque) Remove(i int) interface{} { 29 if i < 0 { 30 return nil 31 } 32 return heap.Remove(p.cont, i) 33 } 34 35 func (p *Prque) Empty() bool { 36 return p.cont.Len() == 0 37 } 38 39 func (p *Prque) Size() int { 40 return p.cont.Len() 41 } 42 43 func (p *Prque) Reset() { 44 *p = *New(p.cont.setIndex) 45 }