datastructure

package
v2.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package datastructure implements some data structure. MaxHeap is a binary max heap.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MaxHeap

type MaxHeap[T any] struct {
	// contains filtered or unexported fields
}

MaxHeap implements a binary max heap type T should implements Compare function in constraints.Comparator interface.

func BuildMaxHeap added in v2.1.5

func BuildMaxHeap[T any](data []T, comparator constraints.Comparator) *MaxHeap[T]

BuildMaxHeap builds a MaxHeap instance with data and given comparator.

func NewMaxHeap

func NewMaxHeap[T any](comparator constraints.Comparator) *MaxHeap[T]

NewMaxHeap returns a MaxHeap instance with the given comparator.

func (*MaxHeap[T]) Data

func (h *MaxHeap[T]) Data() []T

Data return data of the heap

func (*MaxHeap[T]) Peek

func (h *MaxHeap[T]) Peek() (T, bool)

Peek returns the largest element from the heap without removing it. if heap is empty, it returns zero value and false.

func (*MaxHeap[T]) Pop

func (h *MaxHeap[T]) Pop() (T, bool)

Pop return the largest value, and remove it from the heap if heap is empty, return zero value and fasle

func (*MaxHeap[T]) PrintStructure

func (h *MaxHeap[T]) PrintStructure()

PrintStructure print the structure of the heap

func (*MaxHeap[T]) Push

func (h *MaxHeap[T]) Push(value T)

Push value into the heap

func (*MaxHeap[T]) Size

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

Size return the number of elements in the heap

Jump to

Keyboard shortcuts

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