structure/priority_queue/priority_queue.go

62 lines
1.2 KiB
Go

package pqueue
import (
"474420502.top/eson/structure/compare"
)
type PriorityQueue struct {
queue *vbTree
}
func (pq *PriorityQueue) Iterator() *Iterator {
return nil
}
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) Get(key interface{}) (interface{}, bool) {
return pq.queue.Get(key)
}
func (pq *PriorityQueue) RemoveWithIndex(idx int) bool {
return pq.queue.RemoveIndex(idx)
}
func (pq *PriorityQueue) Remove(key interface{}) bool {
return pq.queue.Remove(key)
}
func (pq *PriorityQueue) Values() []interface{} {
return pq.queue.Values()
}