Documentation
¶
Index ¶
- Variables
- type GenericQueue
- func (fq *GenericQueue[T]) Append(elements []T) error
- func (fq *GenericQueue[T]) Available() int
- func (fq *GenericQueue[T]) Cap() int
- func (fq *GenericQueue[T]) Clear()
- func (fq *GenericQueue[T]) Get(size int) []T
- func (fq *GenericQueue[T]) GetAvailable() []T
- func (fq *GenericQueue[T]) GetBlocking(size int) []T
- func (fq *GenericQueue[T]) IsEmpty() bool
- func (fq *GenericQueue[T]) IsFull() bool
- func (fq *GenericQueue[T]) Len() int
- func (fq *GenericQueue[T]) Peek(size int) []T
- func (fq *GenericQueue[T]) TryAppend(elements []T) int
Constants ¶
This section is empty.
Variables ¶
var ( // ErrQueueFull is returned when trying to append to a full queue ErrQueueFull = errors.New("queue is full") )
Functions ¶
This section is empty.
Types ¶
type GenericQueue ¶
type GenericQueue[T any] struct { // contains filtered or unexported fields }
GenericQueue is a thread-safe bounded queue for elements of type T that supports appending slices at the end and retrieving fixed-size chunks from the beginning. It has a maximum size to prevent unbounded memory growth.
func NewGenericQueue ¶
func NewGenericQueue[T any](capacity int) *GenericQueue[T]
NewGenericQueue creates a new GenericQueue with specified capacity
func (*GenericQueue[T]) Append ¶
func (fq *GenericQueue[T]) Append(elements []T) error
Append adds all elements from the input slice to the end of the queue. Returns ErrQueueFull if adding the elements would exceed the maximum size. This operation is thread-safe and will wake up any goroutines waiting for data.
func (*GenericQueue[T]) Available ¶
func (fq *GenericQueue[T]) Available() int
Available returns the number of elements that can still be added to the queue
func (*GenericQueue[T]) Cap ¶
func (fq *GenericQueue[T]) Cap() int
Cap returns the maximum size of the queue (list-based implementation doesn't have a separate capacity concept)
func (*GenericQueue[T]) Clear ¶
func (fq *GenericQueue[T]) Clear()
Clear removes all elements from the queue
func (*GenericQueue[T]) Get ¶
func (fq *GenericQueue[T]) Get(size int) []T
Get retrieves up to 'size' elements from the beginning of the queue. Returns the actual elements retrieved (may be fewer than requested if queue is smaller). This operation removes the retrieved elements from the queue. Returns empty slice if queue is empty.
func (*GenericQueue[T]) GetAvailable ¶
func (fq *GenericQueue[T]) GetAvailable() []T
GetAvailable retrieves all currently available elements from the queue. This operation removes all elements from the queue. Returns empty slice if queue is empty.
func (*GenericQueue[T]) GetBlocking ¶
func (fq *GenericQueue[T]) GetBlocking(size int) []T
GetBlocking retrieves exactly 'size' elements from the beginning of the queue. If fewer than 'size' elements are available, it blocks until enough elements arrive. This operation removes the retrieved elements from the queue.
func (*GenericQueue[T]) IsEmpty ¶
func (fq *GenericQueue[T]) IsEmpty() bool
IsEmpty returns true if the queue has no elements
func (*GenericQueue[T]) IsFull ¶
func (fq *GenericQueue[T]) IsFull() bool
IsFull returns true if the queue is at maximum capacity
func (*GenericQueue[T]) Len ¶
func (fq *GenericQueue[T]) Len() int
Len returns the current number of elements in the queue
func (*GenericQueue[T]) Peek ¶
func (fq *GenericQueue[T]) Peek(size int) []T
Peek returns up to 'size' elements from the beginning without removing them. This is useful for examining data without consuming it.
func (*GenericQueue[T]) TryAppend ¶
func (fq *GenericQueue[T]) TryAppend(elements []T) int
TryAppend attempts to add elements to the queue, but only adds as many as possible without exceeding the maximum size. Returns the number of elements actually added. This operation is thread-safe and will wake up any goroutines waiting for data.