Documentation ¶
Overview ¶
Package prque implements a priority queue data structure supporting arbitrary value types and float priorities.
The reasoning behind using floats for the priorities vs. ints or interfaces was larger flexibility without sacrificing too much performance or code complexity.
If you would like to use a min-priority queue, simply negate the priorities.
Internally the queue is based on the standard heap package working on a sortable version of the block based stack.
Example (Usage) ¶
Insert some data into a priority queue and pop them out in prioritized order.
package main import ( "fmt" "gopkg.in/karalabe/cookiejar.v2/collections/prque" ) func main() { // Define some data to push into the priority queue prio := []float32{77.7, 22.2, 44.4, 55.5, 11.1, 88.8, 33.3, 99.9, 0.0, 66.6} data := []string{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"} // Create the priority queue and insert the prioritized data pq := prque.New() for i := 0; i < len(data); i++ { pq.Push(data[i], prio[i]) } // Pop out the data and print them for !pq.Empty() { val, prio := pq.Pop() fmt.Printf("%.1f:%s ", prio, val) } }
Output: 99.9:seven 88.8:five 77.7:zero 66.6:nine 55.5:three 44.4:two 33.3:six 22.2:one 11.1:four 0.0:eight
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Prque ¶
type Prque struct {
// contains filtered or unexported fields
}
Priority queue data structure.
func (*Prque) Pop ¶
Pops the value with the greates priority off the stack and returns it. Currently no shrinking is done.
func (*Prque) PopItem ¶
func (p *Prque) PopItem() interface{}
Pops only the item from the queue, dropping the associated priority value.