heap

package module
v0.0.0-...-ffb1134 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 2 Imported by: 0

README

Golang generic heap that works with any type that can be compared

  • Use MinHeap and MaxHeap for types that sastify Ordered constraint.
  • Use LessHeap for types that implement Lessable interface.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

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

func NewLessHeap

func NewLessHeap[T Lessable[T]](data ...T) *Heap[T]

func NewMaxHeap

func NewMaxHeap[T constraints.Ordered](data ...T) *Heap[T]

func NewMinHeap

func NewMinHeap[T constraints.Ordered](data ...T) *Heap[T]

func (Heap[T]) Len

func (h Heap[T]) Len() int

func (*Heap[T]) Pop

func (h *Heap[T]) Pop() T

func (*Heap[T]) Push

func (h *Heap[T]) Push(x T)

func (Heap[T]) Top

func (h Heap[T]) Top() T

type HeapInterface

type HeapInterface interface {
	heap.Interface
	Top() any
}

type LessHeap

type LessHeap[T Lessable[T]] struct {
	OrderedHeap[T]
}

func (LessHeap[T]) Less

func (h LessHeap[T]) Less(i, j int) bool

type Lessable

type Lessable[T any] interface {
	Less(T) bool
}

type MaxHeap

type MaxHeap[T constraints.Ordered] struct {
	OrderedHeap[T]
}

func (MaxHeap[T]) Less

func (h MaxHeap[T]) Less(i, j int) bool

type MinHeap

type MinHeap[T constraints.Ordered] struct {
	OrderedHeap[T]
}

func (MinHeap[T]) Less

func (h MinHeap[T]) Less(i, j int) bool

type OrderedHeap

type OrderedHeap[T any] []T

func (OrderedHeap[T]) Len

func (h OrderedHeap[T]) Len() int

func (*OrderedHeap[T]) Pop

func (h *OrderedHeap[T]) Pop() any

func (*OrderedHeap[T]) Push

func (h *OrderedHeap[T]) Push(x any)

func (OrderedHeap[T]) Swap

func (h OrderedHeap[T]) Swap(i, j int)

func (OrderedHeap[T]) Top

func (h OrderedHeap[T]) Top() any

Jump to

Keyboard shortcuts

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