Help us shape the future of Go! Take the 2026 Go Developer Survey

queue

package
v0.15.6 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package queue provides FIFO queues and LIFO stacks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fifo

type Fifo[E any] struct {
	// contains filtered or unexported fields
}

A Fifo is a first-in, first-out queue. Its zero value is ready to use.

Front, Shift, and Len take O(1) time, and Unshift takes amortized O(1) time. DeleteOne takes time proportional to the distance between the value it removes and the nearer end of the queue, so O(n) at worst.

func (*Fifo[E]) DeleteOne added in v0.13.0

func (q *Fifo[E]) DeleteOne(f func(E) bool) bool

DeleteOne removes a value for which f returns true, if there is one, and reports whether it did. It checks values in pairs, one from each end, working toward the middle. If f returns true for more than one value, which one DeleteOne removes is unspecified.

func (*Fifo[E]) Front

func (q *Fifo[E]) Front() (v E, ok bool)

Front returns the first value without removing it, or a zero value and false if the queue is empty.

func (*Fifo[E]) Len

func (q *Fifo[E]) Len() int

Len returns the number of values in the queue.

func (*Fifo[E]) Shift

func (q *Fifo[E]) Shift() (v E, ok bool)

Shift removes and returns the first value, or a zero value and false if the queue is empty.

func (*Fifo[E]) Unshift

func (q *Fifo[E]) Unshift(v E)

Unshift adds v to the end of the queue.

func (*Fifo[E]) Values

func (q *Fifo[E]) Values() iter.Seq[E]

Values returns an iterator over the values in queue order.

type Lifo

type Lifo[E any] struct {
	// contains filtered or unexported fields
}

A Lifo is a last-in, first-out stack. Its zero value is ready to use.

Pop and Len take O(1) time, and Push takes amortized O(1) time.

func (*Lifo[E]) Len

func (q *Lifo[E]) Len() int

Len returns the number of values in the stack.

func (*Lifo[E]) Pop

func (q *Lifo[E]) Pop() (v E, ok bool)

Pop removes and returns the top value, or a zero value and false if the stack is empty.

func (*Lifo[E]) Push

func (q *Lifo[E]) Push(v E)

Push adds v to the top of the stack.

Jump to

Keyboard shortcuts

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