maxheap

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package maxheap provides an interface and implementations for the max heap data structure

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MaxHeap

type MaxHeap[T cmp.Ordered] interface {
	Insert(i T)
	Extract() (T, bool)
	Size() int
	Peek() (T, bool)
}

type MaxHeapArray

type MaxHeapArray[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

func NewMaxHeapArray

func NewMaxHeapArray[T cmp.Ordered](i ...T) *MaxHeapArray[T]

NewMaxHeap instantiates a max heap and returns a pointer to it. The variadic argument can be used to insert items into the heap after it is created.

func (*MaxHeapArray[T]) Extract

func (m *MaxHeapArray[T]) Extract() (T, bool)

Extract returns the maximum item from the max heap and swaps the elements as necessary to restore the heap property in the data structure.

func (*MaxHeapArray[T]) Insert

func (m *MaxHeapArray[T]) Insert(i T)

Insert inserts the item into the max heap.

func (*MaxHeapArray[T]) Peek

func (m *MaxHeapArray[T]) Peek() (T, bool)

func (*MaxHeapArray[T]) Size

func (m *MaxHeapArray[T]) Size() int

Jump to

Keyboard shortcuts

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