package heap

import "k8s.io/kubernetes/pkg/scheduler/backend/heap"

Index

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.

Source Files

heap.go

Version
v1.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
3 packages
Last checked
3 hours ago

Tools for package owners.