minheap

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MinHeap

type MinHeap[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

Array implementation of heap

func New

func New[T constraints.Ordered](values ...T) *MinHeap[T]

Returns a new MinHeap implementation

func (*MinHeap[T]) Add

func (mh *MinHeap[T]) Add(element T)

Add an element to the Heap

func (*MinHeap[T]) Clear

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

Remove all elements from the heap

func (*MinHeap[T]) GetLeftChildIndex

func (mh *MinHeap[T]) GetLeftChildIndex(parent int) int

Get left child index of the given element

func (*MinHeap[T]) GetParentIndex

func (mh *MinHeap[T]) GetParentIndex(child int) int

Get parent index of the given element

func (*MinHeap[T]) GetRightChildIndex

func (mh *MinHeap[T]) GetRightChildIndex(parent int) int

Get right child index of the given element

func (*MinHeap[T]) HasLeftChild

func (mh *MinHeap[T]) HasLeftChild(parent int) bool

Check if current element has a left child

func (*MinHeap[T]) HasParent

func (mh *MinHeap[T]) HasParent(child int) bool

Check if current element has a parent

func (*MinHeap[T]) HasRightChild

func (mh *MinHeap[T]) HasRightChild(parent int) bool

Check if current element has a right child

func (*MinHeap[T]) IsEmpty

func (mh *MinHeap[T]) IsEmpty() bool

Return true when there are no nodes in the heap

func (*MinHeap[T]) LeftChild

func (mh *MinHeap[T]) LeftChild(parent int) T

Get the left child of a given element

func (*MinHeap[T]) Parent

func (mh *MinHeap[T]) Parent(child int) T

Get the parent of the given element

func (*MinHeap[T]) Peek

func (mh *MinHeap[T]) Peek() (T, error)

Peek at the top element of the Heap

func (*MinHeap[T]) Poll

func (mh *MinHeap[T]) Poll() (T, error)

Pop out the top element of the Heap

func (*MinHeap[T]) RightChild

func (mh *MinHeap[T]) RightChild(parent int) T

Get the right child of the given element

func (*MinHeap[T]) Size

func (mh *MinHeap[T]) Size() int

Returns the size of the heap

func (*MinHeap[T]) String

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

Returns a string representation of the heap Improve to show a tree like structure?

   p
 /  \
cl   cr

func (*MinHeap[T]) Values

func (mh *MinHeap[T]) Values() []T

Return all the elements of the heap

Jump to

Keyboard shortcuts

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