heap

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package heap provides an implementation of heap data structure in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element[T any] struct {
	Value T
	// contains filtered or unexported fields
}

Element is an element in the heap.

type Heap

type Heap[T comparable] struct {
	// contains filtered or unexported fields
}

Heap represents a heap.

func New

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

New creates a new heap of T.

func NewFunc

func NewFunc[T comparable](less algorithm.LessFunc[T]) *Heap[T]

NewFunc creates a new heap of T using less.

func (*Heap[T]) Fix

func (h *Heap[T]) Fix(e *Element[T])

Fix fixes the position of value in the heap data structure. It should be called after its data changes.

func (*Heap[T]) Len

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

Size returns the size of the queue.

func (*Heap[T]) Pop

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

Pop pops a value from the heap.

func (*Heap[T]) Push

func (h *Heap[T]) Push(value T) *Element[T]

Push pushes a value into the heap. It returns the created element for the provided value.

func (*Heap[T]) Top

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

Top returns the element at the top of the heap.

Jump to

Keyboard shortcuts

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