maxheap

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 MaxHeap

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

Array implementation of heap

func New

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

Returns a new MinHeap implementation

func (*MaxHeap[T]) Add

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

Add and element to the Heap

func (*MaxHeap[T]) Clear

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

Remove all elements from the heap

func (*MaxHeap[T]) GetLeftChildIndex

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

Get the left child index of a given node

func (*MaxHeap[T]) GetParentIndex

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

Get the parent index of a node

func (*MaxHeap[T]) GetRightChildIndex

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

Get the right child index of a given node

func (*MaxHeap[T]) HasLeftChild

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

Check if the current node has a left child

func (*MaxHeap[T]) HasParent

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

Check if the current node has a parent

func (*MaxHeap[T]) HasRightChild

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

Check if current node has a right child

func (*MaxHeap[T]) IsEmpty

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

Return true when there are no nodes in the heap

func (*MaxHeap[T]) LeftChild

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

Get the left child of the given node

func (*MaxHeap[T]) Parent

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

Get the parent of the given node

func (*MaxHeap[T]) Peek

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

Peek at the top element of the Heap

func (*MaxHeap[T]) Poll

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

Pop out the top element of the Heap

func (*MaxHeap[T]) RightChild

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

Get the right child of the given node

func (*MaxHeap[T]) Size

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

Returns the size of the heap

func (*MaxHeap[T]) String

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

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

   p
 /  \
cl   cr

func (*MaxHeap[T]) Values

func (mh *MaxHeap[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