binaryheap

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2016 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

type Heap struct {
	Comparator utils.Comparator
	// contains filtered or unexported fields
}

func NewWith

func NewWith(comparator utils.Comparator) *Heap

Instantiates a new empty heap tree with the custom comparator.

func NewWithIntComparator

func NewWithIntComparator() *Heap

Instantiates a new empty heap with the IntComparator, i.e. elements are of type int.

func NewWithStringComparator

func NewWithStringComparator() *Heap

Instantiates a new empty heap with the StringComparator, i.e. elements are of type string.

func (*Heap) Clear

func (heap *Heap) Clear()

Removes all elements from the heap.

func (*Heap) Empty

func (heap *Heap) Empty() bool

Returns true if heap does not contain any elements.

func (*Heap) Iterator

func (heap *Heap) Iterator() Iterator

Returns a stateful iterator whose values can be fetched by an index.

func (*Heap) Peek

func (heap *Heap) Peek() (value interface{}, ok bool)

Returns top element on the heap without removing it, or nil if heap is empty. Second return parameter is true, unless the heap was empty and there was nothing to peek.

func (*Heap) Pop

func (heap *Heap) Pop() (value interface{}, ok bool)

Pops (removes) top element on heap and returns it, or nil if heap is empty. Second return parameter is true, unless the heap was empty and there was nothing to pop.

func (*Heap) Push

func (heap *Heap) Push(value interface{})

Pushes a value onto the heap and bubbles it up accordingly.

func (*Heap) Size

func (heap *Heap) Size() int

Returns number of elements within the heap.

func (*Heap) String

func (heap *Heap) String() string

func (*Heap) Values

func (heap *Heap) Values() []interface{}

Returns all elements in the heap.

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

func (*Iterator) Index

func (iterator *Iterator) Index() int

Returns the current element's index. Does not modify the state of the iterator.

func (*Iterator) Next

func (iterator *Iterator) Next() bool

Moves the iterator to the next element and returns true if there was a next element in the container. If Next() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.

func (*Iterator) Value

func (iterator *Iterator) Value() interface{}

Returns the current element's value. Does not modify the state of the iterator.

Jump to

Keyboard shortcuts

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