minheap

package
Version: v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2014 License: Apache-2.0, Apache-2.0 Imports: 1 Imported by: 0

README

Build Status

minheap

Slightly more user-friendly heap on top of containers/heap.


import "github.com/mailgun/minheap"
	

func toEl(i int) interface{} {
	return &i
}

func fromEl(i interface{}) int {
	return *(i.(*int))
}

mh := minheap.NewMinHeap()

el := &minheap.Element{
   Value:    toEl(1),
   Priority: 5,
}

mh.PushEl(el)
mh.PeekEl()
mh.Len()
mh.PopEl()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	Value    interface{}
	Priority int // The priority of the item in the queue.
	// contains filtered or unexported fields
}

An Element is something we manage in a priority queue.

type MinHeap

type MinHeap []*Element

A PriorityQueue implements heap.Interface and holds Items.

func NewMinHeap

func NewMinHeap() *MinHeap

func (MinHeap) Len

func (mh MinHeap) Len() int

func (MinHeap) Less

func (mh MinHeap) Less(i, j int) bool

func (*MinHeap) PeekEl

func (mh *MinHeap) PeekEl() *Element

func (*MinHeap) Pop

func (mh *MinHeap) Pop() interface{}

func (*MinHeap) PopEl

func (mh *MinHeap) PopEl() *Element

func (*MinHeap) Push

func (mh *MinHeap) Push(x interface{})

func (*MinHeap) PushEl

func (mh *MinHeap) PushEl(el *Element)

func (*MinHeap) RemoveEl

func (mh *MinHeap) RemoveEl(el *Element)

func (MinHeap) Swap

func (mh MinHeap) Swap(i, j int)

func (*MinHeap) UpdateEl

func (mh *MinHeap) UpdateEl(el *Element, priority int)

update modifies the priority and value of an Item in the queue.

Source Files

Jump to

Keyboard shortcuts

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