ring

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 2 more Imports: 6 Imported by: 0

Documentation

Overview

Package ring provides a concurrent-safe circular queue, supports multiple read/write.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrQueueFull happens when the queue is full.
	ErrQueueFull = errors.New("queue is full")
)

Functions

This section is empty.

Types

type Ring

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

Ring a concurrent-safe circular queue, based on the idea of Disruptor(simplified). https://lmax-exchange.github.io/disruptor/disruptor.html

func New

func New[T any](capacity uint32) *Ring[T]

New creates a circular queue.

func (*Ring[T]) Cap

func (r *Ring[T]) Cap() uint32

Cap retrieves the number of elements the circular queue can hold.

func (*Ring[T]) Get

func (r *Ring[T]) Get() (T, uint32)

Get gets an element from the circular queue, return element value and the remaining number of elements.

func (*Ring[T]) Gets

func (r *Ring[T]) Gets(val *[]T) (uint32, uint32)

Gets acquires elements from the circular queue and appends then into v, return the number of elements acquired and remained.

func (*Ring[T]) IsEmpty

func (r *Ring[T]) IsEmpty() bool

IsEmpty checks whether the queue is empty.

func (*Ring[T]) IsFull

func (r *Ring[T]) IsFull() bool

IsFull checks whether the queue is full.

func (*Ring[T]) Put

func (r *Ring[T]) Put(val T) error

Put puts element into the circular queue. Directly return if the queue is full.

func (*Ring[T]) Size

func (r *Ring[T]) Size() uint32

Size retrieves the number of elements in the circular queue.

func (*Ring[T]) String

func (r *Ring[T]) String() string

String prints the structure of Ring.

Jump to

Keyboard shortcuts

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