pqueue

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

README

pqueue

Priority queue built using the heap interface

USING

// Some items and their priorities.
items := map[int]int{
1: 10, 2: 20, 3: 5,
}

// Create a priority queue, put the items in it, and
// establish the priority queue (heap) invariants.
pq := make(Priority, len(items))
i := 0
pq.Push(&Item{value: 0, priority: 0})
for value, priority := range items {
pq[i] = &Item{
value:    value,
priority: priority,
index:    i,
}
i++
}
heap.Init(&pq)

// Take the items out; they arrive in decreasing priority order.

fmt.Println(heap.Pop(&pq).(*Item))
fmt.Println(heap.Pop(&pq).(*Item))
fmt.Println(heap.Pop(&pq).(*Item))
fmt.Println(heap.Pop(&pq).(*Item))

Documentation

Overview

Package pqueue - a priority queue built using the heap interface.

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
}

An Item is something we manage in a priority queue.

func NewItem

func NewItem(value uint32, priority int64) *Item

func (*Item) Value

func (item *Item) Value() uint32

type Priority

type Priority []*Item

A Priority implements heap.Interface and holds Items.

func (Priority) Len

func (pq Priority) Len() int

func (Priority) Less

func (pq Priority) Less(i, j int) bool

func (*Priority) Pop

func (pq *Priority) Pop() interface{}

func (*Priority) Push

func (pq *Priority) Push(x interface{})

func (Priority) Swap

func (pq Priority) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL