Documentation
¶
Overview ¶
Package pq implements a priority queue data structure on top of golang's sort.Interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option represents the option
func WithMaxPrioSize ¶
WithMaxPrioSize limits the size of the priority queue to 'size' by keeping the elements with the highest priorities.
func WithMinPrioSize ¶
WithMinPrioSize limits the size of the priority queue to 'size' by keeping the elements with the lowest priorities.
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue represents the queue
func NewPriorityQueue ¶
func NewPriorityQueue(options ...Option) *PriorityQueue
NewPriorityQueue returns an initialized PriorityQueue with the given options
func (*PriorityQueue) Get ¶
func (p *PriorityQueue) Get(i int) (interface{}, float64)
Get returns the element with the i-th priority (from low to high). So the element with the lowest priority has the index 0. And the element with the highest priority has the index queue.Len()-1.
func (*PriorityQueue) Insert ¶
func (p *PriorityQueue) Insert(v interface{}, priority float64)
Insert inserts a new element into the queue.
func (*PriorityQueue) Len ¶
func (p *PriorityQueue) Len() int
Len returns the number of elements in the queue.
func (*PriorityQueue) PopHighest ¶
func (p *PriorityQueue) PopHighest() interface{}
PopHighest removes the element with the highest priority from the queue and returns it. If the queue is empty, nil is returned.
func (*PriorityQueue) PopLowest ¶
func (p *PriorityQueue) PopLowest() interface{}
PopLowest removes the element with the lowest priority from the queue and returns it. If the queue is empty, nil is returned.