heap

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 1 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 (*Heap[T]) Delete

func (h *Heap[T]) Delete(key string)

Delete removes an item.

func (*Heap[T]) GetByKey

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

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

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]) Pop

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

Pop returns the head of the heap and removes it.

func (*Heap[T]) PushIfNotPresent

func (h *Heap[T]) PushIfNotPresent(obj *T) (added bool)

PushIfNotPresent inserts an item to the queue. If an item with the key is present in the map, no changes is made to the item.

func (*Heap[T]) PushOrUpdate

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

PushOrUpdate inserts an item to the queue. The item will be updated if it already exists.

Jump to

Keyboard shortcuts

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