Involved Source Files
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
iterator.goserialization.go
Package-Level Type Names (total 2, both are exported)
/* sort exporteds by: | */
Heap holds elements in an array-list
Comparatorutils.Comparatorlist*arraylist.List
Clear removes all elements from the heap.
Empty returns true if heap does not contain any elements.
FromJSON populates the heap from the input JSON representation.
Iterator returns a stateful iterator whose values can be fetched by an index.
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.
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.
Push adds a value onto the heap and bubbles it up accordingly.
Size returns number of elements within the heap.
String returns a string representation of container
ToJSON outputs the JSON representation of the heap.
Values returns all elements in the heap.
Performs the "bubble down" operation. This is to place the element that is at the root
of the heap in its correct place so that the heap maintains the min/max-heap order property.
Performs the "bubble down" operation. This is to place the element that is at the index
of the heap in its correct place so that the heap maintains the min/max-heap order property.
Performs the "bubble up" operation. This is to place a newly inserted
element (i.e. last element in the list) in its correct place so that
the heap maintains the min/max-heap order property.
Check that the index is within bounds of the list
*T : github.com/emirpasic/gods/trees.Tree
*T : github.com/emirpasic/gods/containers.Container
*T : github.com/emirpasic/gods/containers.JSONDeserializer
*T : github.com/emirpasic/gods/containers.JSONSerializer
*T : expvar.Var
*T : fmt.Stringer
*T : context.stringer
*T : runtime.stringer
func NewWith(comparator utils.Comparator) *Heap
func NewWithIntComparator() *Heap
func NewWithStringComparator() *Heap
Iterator returns a stateful iterator whose values can be fetched by an index.
heap*Heapindexint
Begin resets the iterator to its initial state (one-before-first)
Call Next() to fetch the first element if any.
End moves the iterator past the last element (one-past-the-end).
Call Prev() to fetch the last element if any.
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.
Index returns the current element's index.
Does not modify the state of the iterator.
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.
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.
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.
Value returns the current element's value.
Does not modify the state of the iterator.
*T : github.com/emirpasic/gods/containers.IteratorWithIndex
*T : github.com/emirpasic/gods/containers.ReverseIteratorWithIndex
func (*Heap).Iterator() Iterator
Package-Level Functions (total 6, in which 3 are exported)
NewWith instantiates a new empty heap tree with the custom comparator.
NewWithIntComparator instantiates a new empty heap with the IntComparator, i.e. elements are of type int.
NewWithStringComparator instantiates a new empty heap with the StringComparator, i.e. elements are of type string.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.