heap

package
v0.0.0-...-a4a72b7 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 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[T any] struct {
	// contains filtered or unexported fields
}

Heap heap implementation using generic.

func New

func New[T constraints.Ordered]() *Heap[T]

New gives a new heap object.

func NewAny

func NewAny[T any](less func(a, b T) bool) (*Heap[T], error)

NewAny gives a new heap object. element can be anything, but must provide less function.

func (*Heap[T]) Empty

func (h *Heap[T]) Empty() bool

Empty returns the heap is empty or not.

func (*Heap[T]) Pop

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

Pop removes the minimum element (according to Less) from the heap. The complexity is O(log n) where n = h.Len().

func (*Heap[T]) Push

func (h *Heap[T]) Push(t T)

Push pushes the element t onto the heap. The complexity is O(log n) where n = h.Len().

func (*Heap[T]) Size

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

Size returns the size of the heap

func (*Heap[T]) Top

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

Top returns the minimum element (according to Less) from the heap. Top panics if the heap is empty.

Jump to

Keyboard shortcuts

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