heap

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

type Heap struct {
	// contains filtered or unexported fields
}

Heap uses items to build a heap which always pops the min weight item first. It uses weight of item to sort items which may overflow because weight is an uint64 integer. When overflow happens, its weight will turn to 0 and become one of the lightest items in heap.

func New

func New(initialCap int) *Heap

New creates a heap with initialCap of underlying slice.

func (*Heap) Pop

func (h *Heap) Pop() *Item

Pop pops the min item.

func (*Heap) Push

func (h *Heap) Push(weight uint64, value interface{}) *Item

Push pushes a value with weight to item and returns the item.

func (*Heap) Remove

func (h *Heap) Remove(item *Item) interface{}

Remove removes item from heap and returns its value.

func (*Heap) Size

func (h *Heap) Size() int

Size returns how many items storing in heap.

type Item

type Item struct {

	// Value is the exact data storing in heap.
	Value interface{}
	// contains filtered or unexported fields
}

Item stores all information needed by heap including value.

func (*Item) Adjust

func (i *Item) Adjust(weight uint64)

Adjust adjusts weight of item in order to adjust heap.

func (*Item) Weight

func (i *Item) Weight() uint64

Weight returns the weight of item.

Jump to

Keyboard shortcuts

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