heap

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 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[T any] 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[T any](keyFn KeyFunc[T], lessFn LessFunc[T]) *Heap[T]

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

func NewWithRecorder

func NewWithRecorder[T any](keyFn KeyFunc[T], lessFn LessFunc[T], metricRecorder metrics.MetricRecorder) *Heap[T]

NewWithRecorder wraps an optional metricRecorder to compose a Heap object.

func (*Heap[T]) AddOrUpdate

func (h *Heap[T]) AddOrUpdate(obj T)

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

func (*Heap[T]) Delete

func (h *Heap[T]) Delete(obj T) error

Delete removes an item.

func (*Heap[T]) Get

func (h *Heap[T]) Get(obj T) (T, bool)

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

func (*Heap[T]) GetByKey

func (h *Heap[T]) GetByKey(key string) (T, bool)

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

func (*Heap[T]) Has

func (h *Heap[T]) Has(obj T) bool

func (*Heap[T]) Len

func (h *Heap[T]) Len() int

Len returns the number of items in the heap.

func (*Heap[T]) List

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

List returns a list of all the items.

func (*Heap[T]) Peek

func (h *Heap[T]) Peek() (T, bool)

Peek returns the head of the heap without removing it.

func (*Heap[T]) Pop

func (h *Heap[T]) Pop() (T, error)

Pop returns the head of the heap and removes it.

type KeyFunc

type KeyFunc[T any] func(obj T) string

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

type LessFunc

type LessFunc[T any] func(item1, item2 T) 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