heap

package
v0.0.0-...-0ca6807 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeapNode

type HeapNode interface {
	Value() int
}

HeapNode is an interface making the type for a Min/MaxHeap node flexible nodes must be be able to state their value to be sorted by

type MaxHeap

type MaxHeap struct {
	// contains filtered or unexported fields
}

MaxHeap is an implementation of max heap

func NewMaxHeap

func NewMaxHeap() *MaxHeap

NewMaxHeap initializes a heap with a closerToRootFunction that simply returns true if the first arg is larger than the second

func (*MaxHeap) Add

func (h *MaxHeap) Add(newNode HeapNode)

Add appends a new node onto the heap and heapifies it to ensure correct ordering

func (*MaxHeap) Front

func (h *MaxHeap) Front() HeapNode

Front returns the first node in the heap, nil if the heap is empty

func (*MaxHeap) Length

func (h *MaxHeap) Length() int

func (*MaxHeap) Remove

func (h *MaxHeap) Remove() HeapNode

Remove returns the node at the root, i.e. the minimum value node

type MinHeap

type MinHeap struct {
	// contains filtered or unexported fields
}

MinHeap is an implementation of a min heap

func NewMinHeap

func NewMinHeap() *MinHeap

NewMinHeap initializes a heap with a closerToRootFunction that simply returns true if the first arg is smaller than the second

func (*MinHeap) Add

func (h *MinHeap) Add(newNode HeapNode)

Add appends a new node onto the heap and heapifies it to ensure correct ordering

func (*MinHeap) Front

func (h *MinHeap) Front() HeapNode

Front returns the first node in the heap, nil if the heap is empty

func (*MinHeap) Length

func (h *MinHeap) Length() int

func (*MinHeap) Remove

func (h *MinHeap) Remove() HeapNode

Remove returns the node at the root, i.e. the minimum value node

Jump to

Keyboard shortcuts

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