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 NewSize ¶ added in v0.8.1
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]) Clear ¶
func (q *Queue[T]) Clear()
Clear discards all the values in q, leaving it empty.
func (*Queue[T]) Each ¶
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]) Peek ¶
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.