queue

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: BSD-3-Clause Imports: 1 Imported by: 1

Documentation

Overview

Package queue implements an array-based FIFO queue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue is an array-based first-in, first-out sequence of values. A zero Queue is ready for use.

Add and Pop operations take amortized O(1) time and storage. All other operations on a Queue are constant time.

func New added in v0.8.1

func New[T any]() *Queue[T]

New constructs a new empty queue.

func NewSize added in v0.8.1

func NewSize[T any](n int) *Queue[T]

NewSize constructs a new empty queue with storage pre-allocated for n items. The queue will automatically grow beyond the initial size as needed.

func (*Queue[T]) Add

func (q *Queue[T]) Add(v T)

Add adds v to the end of q.

func (*Queue[T]) Clear

func (q *Queue[T]) Clear()

Clear discards all the values in q, leaving it empty.

func (*Queue[T]) Each

func (q *Queue[T]) Each(f func(T) bool) bool

Each calls f with each value in q, in order from oldest to newest. If f returns false, Each stops and returns false. Otherwise, Each returns true after visiting all elements of q.

func (*Queue[T]) Front

func (q *Queue[T]) Front() T

Front returns the frontmost (oldest) element of q. If q is empty, Front returns a zero value.

func (*Queue[T]) IsEmpty

func (q *Queue[T]) IsEmpty() bool

IsEmpty reports whether q is empty.

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

Len reports the number of entries in q.

func (*Queue[T]) Peek

func (q *Queue[T]) Peek(n int) (T, bool)

Peek reports whether q has a value at offset n from the front of the queue, and if so returns its value. Peek(0) returns the same value as Front.

func (*Queue[T]) Pop

func (q *Queue[T]) Pop() (T, bool)

Pop reports whether q is non-empty, and if so removes and returns its frontmost (oldest) value. If q is empty, Pop returns a zero value.

func (*Queue[T]) Slice

func (q *Queue[T]) Slice() []T

Slice returns a slice of the values of q in order from oldest to newest. If q is empty, Slice returns nil.

Jump to

Keyboard shortcuts

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