heap

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 2 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 is a producer/consumer queue that implements a heap data structure. It can be used to implement priority queues and similar data structures.

func New

func New(keyfunc KeyFunc, lessfunc LessFunc) *Heap

func (*Heap) AddIfNotPresent

func (h *Heap) AddIfNotPresent(obj interface{}) error

AddIfNotPresent inserts an item, and puts it in the queue. If an item with the key is present in the heap, no changes is made to the item.

func (*Heap) AddOrUpdate

func (h *Heap) AddOrUpdate(obj interface{}) error

Add inserts an item, and puts it in the queue. The item is updated if it already exists.

func (*Heap) GetByKey

func (h *Heap) GetByKey(key string) (interface{}, bool)

GetByKey returns the requested item, or sets exists=false.

func (*Heap) Len

func (h *Heap) Len() int

func (*Heap) List

func (h *Heap) List() []interface{}

List returns a list of all the items.

func (*Heap) Peek

func (h *Heap) Peek() interface{}

Peek returns the head of the heap without removing it.

func (*Heap) PeekSecond

func (h *Heap) PeekSecond() interface{}

PeekSecond returns the second item of heap without removing it.

func (*Heap) Pop

func (h *Heap) Pop() interface{}

Pop returns the head of the heap and removes it.

func (*Heap) Range

func (h *Heap) Range(f func(i int, key string, obj interface{}) bool)

Range calls f sequentially for each key and value present in the heap. If f returns false, range stops the iteration.

Range does not guarantee the order.

func (*Heap) Remove

func (h *Heap) Remove(obj interface{}) error

Delete removes an item.

func (*Heap) UpdateIfPresent

func (h *Heap) UpdateIfPresent(obj interface{}) error

UpdateIfPresent update an item's obj and fix the order if it is present in the heap.

type KeyError

type KeyError struct {
	Obj interface{}
	Err error
}

func (KeyError) Error

func (k KeyError) Error() string

Error gives a human-readable description of the error.

type KeyFunc

type KeyFunc func(obj interface{}) (string, error)

KeyFunc is a function type to get the key from an object.

type LessFunc

type LessFunc = func(x, y interface{}) bool

LessFunc is a function that receives two items and returns true if the first item should be placed before the second one when the list is sorted.

Jump to

Keyboard shortcuts

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