Documentation ¶
Overview ¶
Package pq provides a priority queue, implemented as a heap
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item is an element of a priority queue.
func (*Item) UpdatePriority ¶
func (i *Item) UpdatePriority(newPriority int, pq *PriorityQueue)
UpdatePriority updates priorty of Item i in PriorityQueue pq
type PriorityQueue ¶
type PriorityQueue []*Item
PriorityQueue is stored as a list of Items
func New ¶
func New(reservedSize int) *PriorityQueue
New returns an empty priority queue with initial size 0 and reserved size reservedSize
func (*PriorityQueue) Contains ¶
func (pq *PriorityQueue) Contains(el interface{}, same func(a, b interface{}) bool) *Item
Contains checks whether PriorityQueue pq contains element el, using function same for comparison
func (*PriorityQueue) Len ¶
func (pq *PriorityQueue) Len() int
Len returns number of elements in the priority queue pq
func (*PriorityQueue) Less ¶
func (pq *PriorityQueue) Less(i, j int) bool
Less returns true if priority of element on index i is smaller than priority of element on index j
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() interface{}
Pop returns the first element is the priority queue pq
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(el interface{})
Push adds el to the priority queue pq
func (*PriorityQueue) Swap ¶
func (pq *PriorityQueue) Swap(i, j int)
Swap swaps elements with indices i and j in pq