heap v1.0.0 Heap

A heap is a special tree data structure. Good for sorting and other magic.

See also: Heap (data structure) on Wikipedia.

Summary

Functions

Test if the heap is empty

Create an empty max heap

Test it the heap contains the element

Create an empty min heap

Create an empty heap

Pop the root element off the heap and discard it

Push a new element into the heap

Return the element at the root of the heap

Return the number of elements in the heap

Quickly sort an enumerable with a heap

Types

t :: %Heap{d: term, h: term, n: term}

Functions

empty?(heap)

Specs

empty?(Heap.t) :: boolean

Test if the heap is empty.

max()

Specs

max :: Heap.t

Create an empty max heap.

A max heap is a heap tree which always has the largest value at the root.

member?(heap, value)

Specs

member?(Heap.t, any) :: boolean

Test it the heap contains the element

min()

Specs

min :: Heap.t

Create an empty min heap.

A min heap is a heap tree which always has the smallest value at the root.

new(direction \\ :>)

Specs

new(:> | :<) :: Heap.t

Create an empty heap.

pop(heap)

Specs

pop(Heap.t) :: Heap.t

Pop the root element off the heap and discard it.

push(heap, v)

Specs

push(Heap.t, any) :: Heap.t

Push a new element into the heap.

root(heap)

Specs

root(Heap.t) :: any

Return the element at the root of the heap.

size(heap)

Specs

size(Heap.t) :: non_neg_integer

Return the number of elements in the heap.

sort(enum, direction \\ :>)

Specs

sort(Enum.t, :< | :>) :: List.t

Quickly sort an enumerable with a heap.