queue

package
v1.173.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 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

Overview

* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved. * SPDX-License-Identifier: Apache-2.0

* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved. * SPDX-License-Identifier: Apache-2.0

* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved. * SPDX-License-Identifier: Apache-2.0

* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved. * SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChanQueue

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

ChanQueue is a channel-backed implementation of IQueue.

All methods are safe for concurrent use. Enqueue blocks when the queue is full, while Dequeue and Peek are non-blocking and return the zero value when the queue is empty. The queue has a fixed capacity defined at creation time. If performance is not enough, worth looking at https://github.com/alphadose/ZenQ

func (*ChanQueue[T]) Clear

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

Clear removes all elements from the queue.

func (*ChanQueue[T]) Dequeue

func (q *ChanQueue[T]) Dequeue() (element T, ok bool)

Dequeue removes and returns the next element. If the queue is empty, it returns the zero value.

func (*ChanQueue[T]) Enqueue

func (q *ChanQueue[T]) Enqueue(values ...T)

Enqueue adds one or more elements to the queue. This blocks if the queue is full.

func (*ChanQueue[T]) EnqueueSequence

func (q *ChanQueue[T]) EnqueueSequence(seq iter.Seq[T])

EnqueueSequence adds a sequence to the queue. This blocks if the queue is full.

func (*ChanQueue[T]) IsEmpty

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

IsEmpty reports whether the queue is empty.

func (*ChanQueue[T]) Len

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

Len returns the number of elements currently in the queue.

func (*ChanQueue[T]) Peek

func (q *ChanQueue[T]) Peek() (element T, ok bool)

Peek returns the next element without removing it. If the queue is empty, it returns the zero value.

func (*ChanQueue[T]) Values

func (q *ChanQueue[T]) Values() iter.Seq[T]

Values returns all elements in FIFO order and drains the queue.

type IQueue

type IQueue[T any] interface {
	// Enqueue adds an element to the queue.
	Enqueue(value ...T)
	// EnqueueSequence adds an element to the queue.
	EnqueueSequence(value iter.Seq[T])
	// Dequeue removes and returns an element from the queue. It returns ok true if the queue is not empty.
	Dequeue() (element T, ok bool)
	// Peek returns the element at the front of the queue without removing it. It returns ok true if the queue is not empty.
	Peek() (element T, ok bool)
	// IsEmpty states whether the queue is empty.
	IsEmpty() bool
	// Clear removes all elements from the queue.
	Clear()
	// Values returns all the elements in the queue. The queue will be empty as a result.
	Values() iter.Seq[T]
	// Len returns the number of elements in the queue.
	Len() int
}

IQueue specifies the behaviour of a first-in, first-out (FIFO) collection. It is inspired by the work of https://github.com/hayageek/threadsafe/ and https://github.com/golang-collections/collections.

func NewChannelQueue

func NewChannelQueue[T any](capacity int) (IQueue[T], error)

NewChannelQueue creates a new channel-backed queue with the given capacity. Capacity must be > 0.

func NewQueue

func NewQueue[T any]() IQueue[T]

NewQueue returns a Queue which is not thread safe

func NewThreadSafeQueue

func NewThreadSafeQueue[T any]() IQueue[T]

NewThreadSafeQueue returns a thread safe queue using mutex. This is inspired from https://github.com/hayageek/threadsafe.

type Queue

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

func (*Queue[T]) Clear

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

func (*Queue[T]) Dequeue

func (s *Queue[T]) Dequeue() (element T, ok bool)

func (*Queue[T]) Enqueue

func (s *Queue[T]) Enqueue(value ...T)

func (*Queue[T]) EnqueueSequence

func (s *Queue[T]) EnqueueSequence(seq iter.Seq[T])

func (*Queue[T]) IsEmpty

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

func (*Queue[T]) Len

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

func (*Queue[T]) Peek

func (s *Queue[T]) Peek() (element T, ok bool)

func (*Queue[T]) Values

func (s *Queue[T]) Values() iter.Seq[T]

type SafeQueue

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

SafeQueue is a mutex-backed implementation of IQueue.

All methods are safe for concurrent use. Operations do not block on capacity; Enqueue always succeeds. Dequeue and Peek return the zero value when the queue is empty.

func (*SafeQueue[T]) Clear

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

func (*SafeQueue[T]) Dequeue

func (q *SafeQueue[T]) Dequeue() (T, bool)

func (*SafeQueue[T]) Enqueue

func (q *SafeQueue[T]) Enqueue(value ...T)

func (*SafeQueue[T]) EnqueueSequence

func (q *SafeQueue[T]) EnqueueSequence(seq iter.Seq[T])

func (*SafeQueue[T]) IsEmpty

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

func (*SafeQueue[T]) Len

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

func (*SafeQueue[T]) Peek

func (q *SafeQueue[T]) Peek() (T, bool)

func (*SafeQueue[T]) Values

func (q *SafeQueue[T]) Values() iter.Seq[T]

Jump to

Keyboard shortcuts

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