minheap

package
v0.3.0-alpha.2.9 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package min heap provides an implementation of a min binary heap.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MinHeap

type MinHeap[T types.Comparable[T]] struct {
	// contains filtered or unexported fields
}

MinHeap an implementation of a max heap based on a slice.

func New

func New[T types.Comparable[T]]() *MinHeap[T]

New creates an empty min heap.

func (*MinHeap[T]) Clear

func (heap *MinHeap[T]) Clear()

Clear clears the heap.

func (*MinHeap[T]) Collect

func (heap *MinHeap[T]) Collect() []T

Collect returns the heap is a slice with no particular ordering.

func (*MinHeap[T]) Delete

func (heap *MinHeap[T]) Delete(element T) bool

Delete deletes the element from the heap.

func (*MinHeap[T]) DeleteTop

func (heap *MinHeap[T]) DeleteTop() T

DeleteTop deletes and returns the element at the top of the heap. Will panic if heap has no top element.

func (*MinHeap[T]) Empty

func (heap *MinHeap[T]) Empty() bool

Empty checks if the heap is empty.

func (*MinHeap[T]) Insert

func (heap *MinHeap[T]) Insert(element T)

Insert insert the element into the heap.

func (*MinHeap[T]) Len

func (heap *MinHeap[T]) Len() int

Len returns the size of the heap.

func (*MinHeap[T]) Search

func (heap *MinHeap[T]) Search(element T) bool

Search checks if the element is in the heap.

func (*MinHeap[T]) String

func (heap *MinHeap[T]) String() string

String for printing the heap.

func (*MinHeap[T]) Top

func (heap *MinHeap[T]) Top() T

Top returns the top element of the heap. Will panic if no top element.

func (*MinHeap[T]) Update

func (heap *MinHeap[T]) Update(old T, new T) bool

Update updates the old element in the heap with the new element.

Jump to

Keyboard shortcuts

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