package pqueue import ( "github.com/474420502/focus/compare" "github.com/davecgh/go-spew/spew" ) type PriorityQueue struct { queue *vbTree } func (pq *PriorityQueue) Iterator() *Iterator { return NewIterator(pq.queue.top) } func New(Compare compare.Compare) *PriorityQueue { return &PriorityQueue{queue: newVBT(Compare)} } func (pq *PriorityQueue) Size() int { return pq.queue.Size() } func (pq *PriorityQueue) Push(value interface{}) { pq.queue.Put(value) } func (pq *PriorityQueue) Top() (result interface{}, ok bool) { if pq.queue.top != nil { return pq.queue.top.value, true } return nil, false } func (pq *PriorityQueue) Pop() (result interface{}, ok bool) { if pq.queue.top != nil { result = pq.queue.top.value pq.queue.removeNode(pq.queue.top) return result, true } return nil, false } func (pq *PriorityQueue) Index(idx int) (interface{}, bool) { return pq.queue.Index(idx) } func (pq *PriorityQueue) IndexNode(idx int) (*Node, bool) { n := pq.queue.indexNode(idx) return n, n != nil } func (pq *PriorityQueue) Get(value interface{}) (interface{}, bool) { return pq.queue.Get(value) } func (pq *PriorityQueue) GetNode(value interface{}) (*Node, bool) { return pq.queue.GetNode(value) } func (pq *PriorityQueue) GetAround(value interface{}) [3]interface{} { return pq.queue.GetAround(value) } func (pq *PriorityQueue) GetAroundNode(value interface{}) [3]*Node { return pq.queue.getArounNode(value) } func (pq *PriorityQueue) GetRange(k1, k2 interface{}) []interface{} { return pq.queue.GetRange(k1, k2) } func (pq *PriorityQueue) RemoveIndex(idx int) (interface{}, bool) { return pq.queue.RemoveIndex(idx) } func (pq *PriorityQueue) Remove(vlaue interface{}) (interface{}, bool) { return pq.queue.Remove(vlaue) } func (pq *PriorityQueue) RemoveNode(node *Node) { pq.queue.removeNode(node) } func (pq *PriorityQueue) Values() []interface{} { return pq.queue.Values() } func (pq *PriorityQueue) String() string { return spew.Sprint(pq.queue.Values()) }