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

circular

package
v2.50.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

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 a bounded FIFO queue implemented using a circular array. It uses head and tail pointers to avoid slice re-allocations. When full, new elements are rejected rather than overwriting old ones.

func New

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

New creates a new circular queue with the given capacity.

func (*Queue[T]) Cap

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

Cap returns the capacity of the queue.

func (*Queue[T]) Clear

func (q *Queue[T]) Clear() iter.Seq[T]

Clear removes all elements from the queue. Returns an iterator over the removed elements.

func (*Queue[T]) DeleteFunc

func (q *Queue[T]) DeleteFunc(shouldRemove func(T) bool) (removed iter.Seq[T])

DeleteFunc removes elements from the queue based on a predicate function. Returns an iterator over the removed elements. Elements for which shouldRemove returns true are removed from the queue.

func (*Queue[T]) IsEmpty

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

IsEmpty returns true if the queue is empty.

func (*Queue[T]) IsFull

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

IsFull returns true if the queue is at capacity.

func (*Queue[T]) Len

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

Len returns the number of elements in the queue.

func (*Queue[T]) Pull

func (q *Queue[T]) Pull() (value T, ok bool)

Pull removes and returns an element from the head of the queue. Returns the zero value and false if the queue is empty.

func (*Queue[T]) Push

func (q *Queue[T]) Push(value T) bool

Push adds an element to the tail of the queue. Returns false if the queue is full.

Jump to

Keyboard shortcuts

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