arrayqueue

package
v0.0.0-...-22d297c Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option[E any] func(*Queue[E]) error

func WithSafe

func WithSafe[E any]() Option[E]

WithSafe creates a Option that make the array-backed queue safe for concurrent use.

type Queue

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

Queue represents a queue backed by a slice. This queue implements the FIFO (first-in, first-out) behavior.

func New

func New[E any](ops ...Option[E]) (*Queue[E], error)

New creates and initializes a empty queue. Options can be provided to customize the queue's properties (e.g., thread safety).

func NewFromMapKeys

func NewFromMapKeys[K comparable, V any](m map[K]V, ops ...Option[K]) (*Queue[K], error)

NewFromMapKeys creates and initializes a queue from the provided map keys. Options can be provided to customize the queue's properties (e.g., thread safety).

func NewFromMapValues

func NewFromMapValues[K comparable, V any](m map[K]V, ops ...Option[V]) (*Queue[V], error)

NewFromMapValues creates and initializes a queue from the provided map values. Options can be provided to customize the queue's properties (e.g., thread safety).

func NewFromSlice

func NewFromSlice[E any](slice []E, ops ...Option[E]) (*Queue[E], error)

NewFromSlice creates and initializes a queue from the provided slice. Options can be provided to customize the queue's properties (e.g., thread safety).

func (*Queue[E]) Clear

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

Clear removes all elements from the queue.

func (*Queue[E]) Clone

func (q *Queue[E]) Clone() *Queue[E]

Clone returns a deep copy of the queue.

func (*Queue[E]) Dequeue

func (q *Queue[E]) Dequeue() (E, bool)

Dequeue removes first element of the queue. Returns zero value of element and false if queue is empty.

func (*Queue[E]) Enqueue

func (q *Queue[E]) Enqueue(e E)

Enqueue adds a element to the end of the queue.

func (*Queue[E]) IsEmpty

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

IsEmpty reports whether the queue has no element.

func (*Queue[E]) Len

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

Len returns the number of elements currently in the queue.

func (*Queue[E]) MarshalJSON

func (q *Queue[E]) MarshalJSON() ([]byte, error)

MarshalJSON will marshal the queue into a JSON-based representation.

func (*Queue[E]) Peek

func (q *Queue[E]) Peek() (E, bool)

Peek returns first element of the queue without remove it. Returns zero value of element and false if queue is empty.

func (*Queue[E]) String

func (q *Queue[E]) String() string

String returns a string representation of the queue.

func (*Queue[E]) UnmarshalJSON

func (q *Queue[E]) UnmarshalJSON(data []byte) error

UnmarshalJSON will unmarshal a JSON-based representation byte slice into the queue.

func (*Queue[E]) Values

func (q *Queue[E]) Values() []E

Values returns all elements in the queue in FIFO(first-in, first-out) order. If the queue is empty, it returns an empty slice (not nil).

Jump to

Keyboard shortcuts

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