limitring

package
v0.0.0-...-a9f3ac3 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinCap = 1 << 7
	MaxCap = 1 << 20
)

Variables

View Source
var ErrCollision = errors.New("ring buffer collision, retry later")
View Source
var ErrOverflow = errors.New("ring buffer overflow, retry later after Pop")

Functions

This section is empty.

Types

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Ring is optimal for many writers (go-routines B-n) and a single reader (go-routine A). It is not thread safe for multiple readers.

func New

func New(n uint64) *Ring

New creates a new diode (ring buffer). The Ring diode is optimized for many writers (on go-routines B-n) and a single reader (on go-routine A).

ring size = 2 ^ x.

func (*Ring) Pop

func (r *Ring) Pop() (data unsafe.Pointer, ok bool)

Pop will attempt to read from the next slot of the ring buffer. If there is no data available, it will return (nil, false).

func (*Ring) Push

func (r *Ring) Push(data unsafe.Pointer) error

Push pushes the data in the next slot of the ring buffer. If Ring is almost full or there is a collision, return error.

Jump to

Keyboard shortcuts

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