mmheap

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package mmheap provides a drop-in replacement for the container/heap package that provides min-max heap semantics.

The package interface is a superset of container/heap; any existing type that implements heap.Interface can be used with mmheap.

min-max heaps provide efficient inspection and removal of both the minimum and maximum elements. The data structure is described in detail here:

http://www.cs.otago.ac.nz/staffpriv/mike/Papers/MinMaxHeaps/MinMaxHeaps.pdf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fix

func Fix(h heap.Interface, i int)

Fix re-establishes the heap ordering after the element at index i has changed its value.

Changing the value of the element at index i and then calling Fix is equivalent to, but less expensive than, calling Remove(h, i) followed by a Push of the new value.

func Init

func Init(h heap.Interface)

Init establishes the heap invariants required by the other routines in this package.

Init is idempotent with respect to the heap invariants and may be called whenever the heap invariants may have been invalidated.

func Max

func Max(h heap.Interface) int

Max returns index of the maximum element in h.

Unlike the minimum element, which is the root node at index 0, the maximum element may be either the left-hand or right-hand child of the root node.

If h is empty it returns -1.

The complexity is O(1).

func Pop

func Pop(h heap.Interface) interface{}

Pop removes and returns the minimum element (according to Less) from the heap.

func PopMax

func PopMax(h heap.Interface) interface{}

PopMax removes and returns the maximum element (according to Less) from the heap.

func Push

func Push(h heap.Interface, x interface{})

Push pushes the element x onto the heap.

func Remove

func Remove(h heap.Interface, i int) interface{}

Remove removes and returns the element at index i from the heap.

Types

This section is empty.

Jump to

Keyboard shortcuts

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