ringbuffer

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: Apache-2.0 Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

package ringbuffer implements a sequential compact FIFO and LILO. Also called a Queue. To Use:

        type myThing ringbuffer.RingElement
        var whatever == myThing("whatever") // Assuming a conversion from string.
        rb := RingBuffer.New(40)
        rb.Write(myThing) // Et cetera
        aThing := rb.Read()
        for 0 < rb.Size() {
            doSomethingWith(rb.Read())
        }

THIS IS NOT CONCURRENT —— ONE GOROUTINE ONLY.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RingBuffer

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

func New

func New(n int) *RingBuffer

New() allocates and initializes a new ring buffer of specified size

func (*RingBuffer) Clear

func (b *RingBuffer) Clear()

Obliterate, Purge, and Remove the contents of the ring buffer. Support your local Garbage Collector!

func (*RingBuffer) Dump

func (b *RingBuffer) Dump()

Dump displays the internal variables and the ENTIRE contents of the ring buffer.

func (*RingBuffer) DumpExt

func (b *RingBuffer) DumpExt() []RingElement

Dump ENTIRE contents of the ring buffer into slices without changing indexes

func (*RingBuffer) Full

func (b *RingBuffer) Full() bool

Is the buffer currently full?

func (*RingBuffer) HasAny

func (b *RingBuffer) HasAny() bool

Any left to read?

func (*RingBuffer) Leng

func (b *RingBuffer) Leng() int

Number of slots currently in use. Total writes - Total reads.

func (*RingBuffer) Read

func (b *RingBuffer) Read() RingElement

Read fetches the next element from the ring buffer.

func (*RingBuffer) Write

func (b *RingBuffer) Write(datum RingElement) error

Write inserts an element into the ring buffer.

type RingBufferError

type RingBufferError struct {
	What string
}

func (*RingBufferError) Error

func (e *RingBufferError) Error() string

"Convert" ringbuffer.RingBufferError into a string.

type RingElement

type RingElement interface{}

A ring buffer is stored in an array of ringbuffer.RingElement, of the size requested.

Jump to

Keyboard shortcuts

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