ringbuffer

package
v0.0.0-...-de2953b Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIsEmpty = errors.New("ringbuffer is empty")

Functions

This section is empty.

Types

type RingBuffer

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

https://github.com/smallnest/chanx/blob/main/ringbuffer.go http://media.newbmiao.com//algorithm/ringbuffer.png RingBuffer is a ring buffer for common types. It never is full and always grows if it will be full. It is not thread-safe(goroutine-safe) so you must use the lock-like synchronization primitive to use it in multiple writers and multiple readers.

func NewRingBuffer

func NewRingBuffer(initialSize int) *RingBuffer

func (*RingBuffer) Capacity

func (r *RingBuffer) Capacity() int

Capacity returns the size of the underlying buffer.

func (*RingBuffer) IsEmpty

func (r *RingBuffer) IsEmpty() bool

func (*RingBuffer) Len

func (r *RingBuffer) Len() int

func (*RingBuffer) Peek

func (r *RingBuffer) Peek() T

func (*RingBuffer) Pop

func (r *RingBuffer) Pop() T

func (*RingBuffer) Read

func (r *RingBuffer) Read() (T, error)

func (*RingBuffer) Reset

func (r *RingBuffer) Reset()

func (*RingBuffer) Write

func (r *RingBuffer) Write(v T)

type T

type T interface{}

Jump to

Keyboard shortcuts

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