heap

package
v1.1.0-beta.0...-04608f4 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 3 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[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Heap is a thread-safe producer/consumer queue that implements a heap data structure.

func NewHeap

func NewHeap[K comparable, V any](keyFn KeyFunc[K, V], lessFn LessFunc[V]) *Heap[K, V]

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

func (*Heap[K, V]) Add

func (h *Heap[K, V]) Add(obj V) error

Add adds an object or updates it if it already exists.

func (*Heap[K, V]) AddIfNotPresent

func (h *Heap[K, V]) AddIfNotPresent(obj V) error

AddIfNotPresent adds an object if it does not already exist.

func (*Heap[K, V]) BulkAdd

func (h *Heap[K, V]) BulkAdd(list []V) error

BulkAdd adds a list of objects to the heap.

func (*Heap[K, V]) Close

func (h *Heap[K, V]) Close()

Close closes the heap.

func (*Heap[K, V]) Delete

func (h *Heap[K, V]) Delete(obj V) error

Delete removes an object from the heap.

func (*Heap[K, V]) Get

func (h *Heap[K, V]) Get(obj V) (V, bool, error)

Get returns an object from the heap.

func (*Heap[K, V]) GetByKey

func (h *Heap[K, V]) GetByKey(key K) (V, bool, error)

GetByKey returns an object from the heap by key.

func (*Heap[K, V]) IsClosed

func (h *Heap[K, V]) IsClosed() bool

IsClosed returns true if the heap is closed.

func (*Heap[K, V]) List

func (h *Heap[K, V]) List() []V

List returns a list of all objects in the heap.

func (*Heap[K, V]) ListKeys

func (h *Heap[K, V]) ListKeys() []K

ListKeys returns a list of all keys in the heap.

func (*Heap[K, V]) Peek

func (h *Heap[K, V]) Peek() (V, error)

Peek returns the top object from the heap without removing it.

func (*Heap[K, V]) Pop

func (h *Heap[K, V]) Pop() (V, error)

Pop removes the top object from the heap and returns it.

func (*Heap[K, V]) Update

func (h *Heap[K, V]) Update(obj V) error

Update is an alias for Add.

type KeyFunc

type KeyFunc[K comparable, V any] func(V) (K, error)

KeyFunc is used to generate a key for an object.

type LessFunc

type LessFunc[V any] func(V, V) bool

LessFunc is used to compare two objects in the heap.

Jump to

Keyboard shortcuts

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