priorityqueue

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package priorityqueue implements an unbounded priority queue based on a priority heap. The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at PriorityQueue construction time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(q *Queue)

Option option for New.

func WithComparator

func WithComparator(cmp container.Comparator) Option

WithComparator with custom Comparator. default reflect.DeepEqual

func WithItems

func WithItems(item []interface{}) Option

WithItems with item

func WithMaxHeap

func WithMaxHeap() Option

WithMaxHeap with max heap.

type Queue

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

Queue represents an unbounded priority queue based on a priority heap. It implements heap.Interface.

func New

func New(opts ...Option) *Queue

New initializes and returns an Queue, default min heap.

func (*Queue) Add

func (sf *Queue) Add(items interface{})

Add inserts the specified element into this priority queue.

func (*Queue) Clear

func (sf *Queue) Clear()

Clear removes all of the elements from this priority queue.

func (*Queue) Contains

func (sf *Queue) Contains(val interface{}) bool

Contains returns true if this queue contains the specified element.

func (*Queue) IsEmpty

func (sf *Queue) IsEmpty() bool

IsEmpty returns true if this list contains no elements.

func (*Queue) Len

func (sf *Queue) Len() int

Len returns the length of this priority queue.

func (*Queue) Peek

func (sf *Queue) Peek() interface{}

Peek retrieves, but does not remove, the head of this queue, or return nil if this queue is empty.

func (*Queue) Poll

func (sf *Queue) Poll() interface{}

Poll retrieves and removes the head of the this queue, or return nil if this queue is empty.

func (*Queue) Remove

func (sf *Queue) Remove(val interface{})

Remove a single instance of the specified element from this queue, if it is present. It returns false if the target value isn't present, otherwise returns true.

Jump to

Keyboard shortcuts

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