binaryheap

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2017 License: BSD-2-Clause, ISC Imports: 6 Imported by: 0

Documentation

Overview

Package binaryheap implements a binary heap backed by array list.

Comparator defines this heap as either min or max heap.

Structure is not thread safe.

References: http://en.wikipedia.org/wiki/Binary_heap

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
}

Heap holds elements in an array-list

func NewWith

func NewWith(comparator utils.Comparator) *Heap

NewWith instantiates a new empty heap tree with the custom comparator.

func NewWithIntComparator

func NewWithIntComparator() *Heap

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

func NewWithStringComparator

func NewWithStringComparator() *Heap

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

func (*Heap) Clear

func (heap *Heap) Clear()

Clear removes all elements from the heap.

func (*Heap) Empty

func (heap *Heap) Empty() bool

Empty returns true if heap does not contain any elements.

func (*Heap) Iterator

func (heap *Heap) Iterator() 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)

Peek 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)

Pop 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(values ...interface{})

Push adds a value onto the heap and bubbles it up accordingly.

func (*Heap) Size

func (heap *Heap) Size() int

Size returns number of elements within the heap.

func (*Heap) String

func (heap *Heap) String() string

String returns a string representation of container

func (*Heap) Values

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

Values returns all elements in the heap.

type Iterator

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

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

func (*Iterator) Begin added in v1.2.0

func (iterator *Iterator) Begin()

Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.

func (*Iterator) End added in v1.2.0

func (iterator *Iterator) End()

End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.

func (*Iterator) First added in v1.2.0

func (iterator *Iterator) First() bool

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

func (*Iterator) Index

func (iterator *Iterator) Index() int

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

func (*Iterator) Last added in v1.2.0

func (iterator *Iterator) Last() bool

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

func (*Iterator) Next

func (iterator *Iterator) Next() bool

Next 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(). If Next() was called for the first time, then it will point the iterator to the first element if it exists. Modifies the state of the iterator.

func (*Iterator) Prev added in v1.1.0

func (iterator *Iterator) Prev() bool

Prev moves the iterator to the previous element and returns true if there was a previous element in the container. If Prev() returns true, then previous 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{}

Value 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