priorityqueue

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: BSD-2-Clause, ISC Imports: 6 Imported by: 24

Documentation

Overview

Package priorityqueue implements a priority queue backed by binary queue.

An unbounded priority queue based on a priority queue. The elements of the priority queue are ordered by a comparator provided at queue construction time.

The heap of this queue is the least/smallest element with respect to the specified ordering. If multiple elements are tied for least value, the heap is one of those elements arbitrarily.

Structure is not thread safe.

References: https://en.wikipedia.org/wiki/Priority_queue

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

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

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

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

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

func (iterator *Iterator) NextTo(f func(index int, value interface{}) bool) bool

NextTo moves the iterator to the next element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value(). Modifies the state of the iterator.

func (*Iterator) Prev

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

func (iterator *Iterator) PrevTo(f func(index int, value interface{}) bool) bool

PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the passed function, and returns true if there was a next element in the container. If PrevTo() 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{}

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

type Queue

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

Queue holds elements in an array-list

func NewWith

func NewWith(comparator utils.Comparator) *Queue

NewWith instantiates a new empty queue with the custom comparator.

func (*Queue) Clear

func (queue *Queue) Clear()

Clear removes all elements from the queue.

func (*Queue) Dequeue

func (queue *Queue) Dequeue() (value interface{}, ok bool)

Dequeue removes first element of the queue and returns it, or nil if queue is empty. Second return parameter is true, unless the queue was empty and there was nothing to dequeue.

func (*Queue) Empty

func (queue *Queue) Empty() bool

Empty returns true if queue does not contain any elements.

func (*Queue) Enqueue

func (queue *Queue) Enqueue(value interface{})

Enqueue adds a value to the end of the queue

func (*Queue) FromJSON

func (queue *Queue) FromJSON(data []byte) error

FromJSON populates the queue from the input JSON representation.

func (*Queue) Iterator

func (queue *Queue) Iterator() Iterator

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

func (*Queue) MarshalJSON

func (queue *Queue) MarshalJSON() ([]byte, error)

MarshalJSON @implements json.Marshaler

func (*Queue) Peek

func (queue *Queue) Peek() (value interface{}, ok bool)

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

func (*Queue) Size

func (queue *Queue) Size() int

Size returns number of elements within the queue.

func (*Queue) String

func (queue *Queue) String() string

String returns a string representation of container

func (*Queue) ToJSON

func (queue *Queue) ToJSON() ([]byte, error)

ToJSON outputs the JSON representation of the queue.

func (*Queue) UnmarshalJSON

func (queue *Queue) UnmarshalJSON(bytes []byte) error

UnmarshalJSON @implements json.Unmarshaler

func (*Queue) Values

func (queue *Queue) Values() []interface{}

Values returns all elements in the queue.

Jump to

Keyboard shortcuts

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