gods: github.com/emirpasic/gods/trees/binaryheap Index | Files

package binaryheap

import "github.com/emirpasic/gods/trees/binaryheap"

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

Package Files

binaryheap.go iterator.go serialization.go

type Heap Uses

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

Heap holds elements in an array-list

func NewWith Uses

func NewWith(comparator utils.Comparator) *Heap

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

func NewWithIntComparator Uses

func NewWithIntComparator() *Heap

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

func NewWithStringComparator Uses

func NewWithStringComparator() *Heap

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

func (*Heap) Clear Uses

func (heap *Heap) Clear()

Clear removes all elements from the heap.

func (*Heap) Empty Uses

func (heap *Heap) Empty() bool

Empty returns true if heap does not contain any elements.

func (*Heap) FromJSON Uses

func (heap *Heap) FromJSON(data []byte) error

FromJSON populates the heap from the input JSON representation.

func (*Heap) Iterator Uses

func (heap *Heap) Iterator() Iterator

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

func (*Heap) Peek Uses

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 Uses

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 Uses

func (heap *Heap) Push(values ...interface{})

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

func (*Heap) Size Uses

func (heap *Heap) Size() int

Size returns number of elements within the heap.

func (*Heap) String Uses

func (heap *Heap) String() string

String returns a string representation of container

func (*Heap) ToJSON Uses

func (heap *Heap) ToJSON() ([]byte, error)

ToJSON outputs the JSON representation of the heap.

func (*Heap) Values Uses

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

Values returns all elements in the heap.

type Iterator Uses

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

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

func (*Iterator) Begin Uses

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 Uses

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 Uses

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 Uses

func (iterator *Iterator) Index() int

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

func (*Iterator) Last Uses

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 Uses

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 Uses

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 Uses

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

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

Package binaryheap imports 6 packages (graph) and is imported by 16 packages. Updated 2018-09-25. Refresh now. Tools for package owners.