types

package
v0.0.0-...-0ccfc62 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2018 License: GPL-3.0 Imports: 2 Imported by: 4

Documentation

Overview

A circular buffer data type for floating point values.

A circular buffer data type for generic values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer holds the values within the buffer plus a collection of metadata.

func NewBuffer

func NewBuffer(capacity int) *Buffer

NewBuffer creates a new circular buffer of a given maximum size.

func (*Buffer) Clear

func (b *Buffer) Clear()

Clear resets the buffer to being empty

func (*Buffer) Each

func (b *Buffer) Each(cb func(int, float64))

Each applies a given function to all the values in the buffer, from least recent first, ending at the most recent.

func (*Buffer) GetFromEnd

func (b *Buffer) GetFromEnd(index int) float64

GetFromEnd returns the most recent buffer values. 0 returns the most recently pushed, the least recent being b.size - 1

func (*Buffer) GoPushChannel

func (b *Buffer) GoPushChannel(values <-chan float64, sampleRate int)

GoPushChannel constantly pushes values from a channel, in a separate thread, optionally only sampling 1 every sampleRate values.

func (*Buffer) IsFinished

func (b *Buffer) IsFinished() bool

IsFinished returns whether there is nothing more to be added to the buffer

func (*Buffer) IsFull

func (b *Buffer) IsFull() bool

IsFull returns whether the buffer is full, in that adding more entries will delete older ones.

func (*Buffer) Push

func (b *Buffer) Push(value float64) float64

Push adds a new value at the end of the buffer.

func (*Buffer) Size

func (b *Buffer) Size() int

Size returns how many entries are currently in the buffer.

type TypedBuffer

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

Buffer holds the values within the buffer plus a collection of metadata.

func NewTypedBuffer

func NewTypedBuffer(capacity int) *TypedBuffer

NewTypedBuffer creates a new circular buffer of a given maximum size.

func (*TypedBuffer) Clear

func (b *TypedBuffer) Clear()

Clear resets the buffer to being empty

func (*TypedBuffer) Each

func (b *TypedBuffer) Each(cb func(int, interface{}))

Each applies a given function to all the values in the buffer, from least recent first, ending at the most recent.

func (*TypedBuffer) GetFromEnd

func (b *TypedBuffer) GetFromEnd(index int) interface{}

GetFromEnd returns the most recent buffer values. 0 returns the most recently pushed, the least recent being b.size - 1

func (*TypedBuffer) GoPushChannel

func (b *TypedBuffer) GoPushChannel(values <-chan interface{}, sampleRate int)

GoPushChannel constantly pushes values from a channel, in a separate thread, optionally only sampling 1 every sampleRate values.

func (*TypedBuffer) IsFinished

func (b *TypedBuffer) IsFinished() bool

IsFinished returns whether there is nothing more to be added to the buffer

func (*TypedBuffer) IsFull

func (b *TypedBuffer) IsFull() bool

IsFull returns whether the buffer is full, in that adding more entries will delete older ones.

func (*TypedBuffer) Push

func (b *TypedBuffer) Push(value interface{}) interface{}

Push adds a new value at the end of the buffer.

func (*TypedBuffer) Size

func (b *TypedBuffer) Size() int

Size returns the number of values in the buffer.

Jump to

Keyboard shortcuts

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