heapx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT 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(keyFn KeyFunc, lessFn lessFunc) *Heap

New returns a Heap which can be used to queue up items to process.

func (*Heap) Add

func (h *Heap) Add(obj any) error

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

func (*Heap) Delete

func (h *Heap) Delete(obj any) error

Delete removes an item.

func (*Heap) Get

func (h *Heap) Get(obj any) (any, bool, error)

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

func (*Heap) GetByKey

func (h *Heap) GetByKey(key string) (any, bool, error)

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

func (*Heap) Len

func (h *Heap) Len() int

Len returns the number of items in the heap.

func (*Heap) List

func (h *Heap) List() []any

List returns a list of all the items.

func (*Heap) Peek

func (h *Heap) Peek() any

Peek returns the head of the heap without removing it.

func (*Heap) Pop

func (h *Heap) Pop() (any, error)

Pop returns the head of the heap and removes it.

func (*Heap) Update

func (h *Heap) Update(obj any) error

Update is the same as Add in this implementation. When the item does not exist, it is added.

type KeyError

type KeyError struct {
	Obj any
	Err error
}

func (KeyError) Error

func (k KeyError) Error() string

type KeyFunc

type KeyFunc func(obj any) (string, error)

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

Jump to

Keyboard shortcuts

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