q

package
v1.2.14 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed is returned when attempting to operate on a closed queue
	ErrClosed = errors.New("pipe.q.closed")

	// ErrQueueFull is returned when attempting to push to a full queue
	ErrQueueFull = errors.New("pipe.q.full")
)

Functions

This section is empty.

Types

type Q

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

Q represents a thread-safe queue with dynamic capacity using linked list It provides the same interface as SliceQueue but uses container/list for storage

func NewQ

func NewQ[T any](capacity int) *Q[T]

NewQ creates a new list-based queue with specified capacity If capacity is 0, the queue has unlimited capacity

func (*Q[T]) Cap added in v1.2.11

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

Cap returns the maximum capacity of the queue (0 means unlimited)

func (*Q[T]) Close

func (q *Q[T]) Close()

Close closes the queue, all subsequent operations will return ErrClosed

func (*Q[T]) IsClosed added in v1.2.11

func (q *Q[T]) IsClosed() bool

IsClosed returns true if the queue is closed

func (*Q[T]) IsEmpty added in v1.2.11

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

IsEmpty returns true if the queue has no items

func (*Q[T]) IsFull added in v1.2.11

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

IsFull returns true if the queue is at capacity (always false for unlimited capacity)

func (*Q[T]) Len added in v1.2.11

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

Len returns the current number of items in the queue

func (*Q[T]) Pop

func (q *Q[T]) Pop() (T, error)

Pop removes and returns an item from the front of the queue Blocks if queue is empty until an item is available or queue is closed

func (*Q[T]) Push added in v1.2.11

func (q *Q[T]) Push(item T) error

Push adds an item to the end of the queue Returns ErrQueueFull if queue is at capacity (when capacity > 0)

func (*Q[T]) Reset added in v1.2.11

func (q *Q[T]) Reset()

Reset clears all items from the queue (useful for reusing the queue)

type Queue added in v1.2.11

type Queue[T any] interface {
	// Push adds an item to the queue
	Push(item T) error

	// Pop removes and returns an item from the queue
	// Blocks if queue is empty until an item is available or queue is closed
	Pop() (T, error)

	// Close closes the queue
	Close()

	// Len returns the current number of items in the queue
	Len() int

	// Cap returns the maximum capacity of the queue
	Cap() int

	// IsClosed returns true if the queue is closed
	IsClosed() bool

	// IsFull returns true if the queue is at capacity
	IsFull() bool

	// IsEmpty returns true if the queue has no items
	IsEmpty() bool

	// Reset clears all items from the queue
	Reset()
}

Queue defines the common interface for all queue implementations

type RingQ added in v1.2.11

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

RingQ represents a thread-safe ring buffer queue with fixed capacity using pre-allocated slice The slice is allocated at creation time with the specified capacity

func NewRingQ added in v1.2.11

func NewRingQ[T any](capacity int) *RingQ[T]

NewRingQ creates a new slice-based ring queue with fixed capacity The slice is pre-allocated with the specified capacity

func (*RingQ[T]) Cap added in v1.2.11

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

Cap returns the maximum capacity of the queue

func (*RingQ[T]) Close added in v1.2.11

func (q *RingQ[T]) Close()

Close closes the queue, all subsequent operations will return ErrClosed

func (*RingQ[T]) IsClosed added in v1.2.11

func (q *RingQ[T]) IsClosed() bool

IsClosed returns true if the queue is closed

func (*RingQ[T]) IsEmpty added in v1.2.11

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

IsEmpty returns true if the queue has no items

func (*RingQ[T]) IsFull added in v1.2.11

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

IsFull returns true if the queue is at capacity

func (*RingQ[T]) Len added in v1.2.11

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

Len returns the current number of items in the queue

func (*RingQ[T]) Pop added in v1.2.11

func (q *RingQ[T]) Pop() (T, error)

Pop removes and returns an item from the front of the queue Blocks if queue is empty until an item is available or queue is closed

func (*RingQ[T]) Push added in v1.2.11

func (q *RingQ[T]) Push(item T) error

Push adds an item to the end of the queue Returns ErrQueueFull if queue is at capacity

func (*RingQ[T]) Reset added in v1.2.11

func (q *RingQ[T]) Reset()

Reset clears all items from the queue (useful for reusing the queue)

Jump to

Keyboard shortcuts

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