seq

package
Version: v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: MIT Imports: 7 Imported by: 358

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Time timeSequence

Time is a utility singleton with helper functions for time seq generation.

Functions

func RandomValues

func RandomValues(count int) []float64

RandomValues returns an array of random values.

func RandomValuesWithMax

func RandomValuesWithMax(count int, max float64) []float64

RandomValuesWithMax returns an array of random values with a given average.

func Range

func Range(start, end float64) []float64

Range returns the array values of a linear seq with a given start, end and optional step.

func RangeWithStep

func RangeWithStep(start, end, step float64) []float64

RangeWithStep returns the array values of a linear seq with a given start, end and optional step.

Types

type Array

type Array []float64

Array is a wrapper for an array of floats that implements `ValuesProvider`.

func NewArray

func NewArray(values ...float64) Array

NewArray creates a new array.

func (Array) GetValue

func (a Array) GetValue(index int) float64

GetValue returns the value at a given index.

func (Array) Len

func (a Array) Len() int

Len returns the value provider length.

type Buffer

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

Buffer is a fifo datastructure that is backed by a pre-allocated array. Instead of allocating a whole new node object for each element, array elements are re-used (which saves GC churn). Enqueue can be O(n), Dequeue is generally O(1). Buffer implements `seq.Provider`

func NewBuffer

func NewBuffer(values ...float64) *Buffer

NewBuffer creates a new value buffer with an optional set of values.

func NewBufferWithCapacity

func NewBufferWithCapacity(capacity int) *Buffer

NewBufferWithCapacity creates a new ValueBuffer pre-allocated with the given capacity.

func (*Buffer) Array

func (b *Buffer) Array() Array

Array returns the ring buffer, in order, as an array.

func (*Buffer) Capacity

func (b *Buffer) Capacity() int

Capacity returns the total size of the Buffer, including empty elements.

func (*Buffer) Clear

func (b *Buffer) Clear()

Clear removes all objects from the Buffer.

func (*Buffer) Dequeue

func (b *Buffer) Dequeue() float64

Dequeue removes the first element from the RingBuffer.

func (*Buffer) Each

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

Each calls the consumer for each element in the buffer.

func (*Buffer) Enqueue

func (b *Buffer) Enqueue(value float64)

Enqueue adds an element to the "back" of the Buffer.

func (*Buffer) GetValue

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

GetValue implements seq provider.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the length of the Buffer (as it is currently populated). Actual memory footprint may be different.

func (*Buffer) Peek

func (b *Buffer) Peek() float64

Peek returns but does not remove the first element.

func (*Buffer) PeekBack

func (b *Buffer) PeekBack() float64

PeekBack returns but does not remove the last element.

func (*Buffer) SetCapacity

func (b *Buffer) SetCapacity(capacity int)

SetCapacity sets the capacity of the Buffer.

func (*Buffer) String

func (b *Buffer) String() string

String returns a string representation for value buffers.

func (*Buffer) TrimExcess

func (b *Buffer) TrimExcess()

TrimExcess resizes the capacity of the buffer to better fit the contents.

type Linear

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

Linear is a stepwise generator.

func NewLinear

func NewLinear() *Linear

NewLinear returns a new linear generator.

func (Linear) End

func (lg Linear) End() float64

End returns the end value.

func (Linear) GetValue

func (lg Linear) GetValue(index int) float64

GetValue returns the value at a given index.

func (Linear) Len

func (lg Linear) Len() int

Len returns the number of elements in the seq.

func (Linear) Start

func (lg Linear) Start() float64

Start returns the start value.

func (Linear) Step

func (lg Linear) Step() float64

Step returns the step value.

func (*Linear) WithEnd

func (lg *Linear) WithEnd(end float64) *Linear

WithEnd sets the end and returns the linear generator.

func (*Linear) WithStart

func (lg *Linear) WithStart(start float64) *Linear

WithStart sets the start and returns the linear generator.

func (*Linear) WithStep

func (lg *Linear) WithStep(step float64) *Linear

WithStep sets the step and returns the linear generator.

type Provider

type Provider interface {
	Len() int
	GetValue(int) float64
}

Provider is a provider for values for a seq.

type Random

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

Random is a random number seq generator.

func NewRandom

func NewRandom() *Random

NewRandom creates a new random seq.

func (*Random) GetValue

func (r *Random) GetValue(_ int) float64

GetValue returns the value.

func (*Random) Len

func (r *Random) Len() int

Len returns the number of elements that will be generated.

func (Random) Max

func (r Random) Max() *float64

Max returns the maximum value.

func (Random) Min

func (r Random) Min() *float64

Min returns the minimum value.

func (*Random) WithLen

func (r *Random) WithLen(length int) *Random

WithLen sets a maximum len

func (*Random) WithMax

func (r *Random) WithMax(max float64) *Random

WithMax sets the average and returns the Random.

func (*Random) WithMin

func (r *Random) WithMin(min float64) *Random

WithMin sets the scale and returns the Random.

type Seq

type Seq struct {
	Provider
}

Seq is a utility wrapper for seq providers.

func New

func New(provider Provider) Seq

New wraps a provider with a seq.

func Values

func Values(values ...float64) Seq

Values returns a new seq composed of a given set of values.

func (Seq) Array

func (s Seq) Array() (output []float64)

Array enumerates the seq into a slice.

func (Seq) Average

func (s Seq) Average() float64

Average returns the float average of the values in the buffer.

func (Seq) Each

func (s Seq) Each(mapfn func(int, float64))

Each applies the `mapfn` to all values in the value provider.

func (Seq) FoldLeft

func (s Seq) FoldLeft(mapfn func(i int, v0, v float64) float64) (v0 float64)

FoldLeft collapses a seq from left to right.

func (Seq) FoldRight

func (s Seq) FoldRight(mapfn func(i int, v0, v float64) float64) (v0 float64)

FoldRight collapses a seq from right to left.

func (Seq) Map

func (s Seq) Map(mapfn func(i int, v float64) float64) Seq

Map applies the `mapfn` to all values in the value provider, returning a new seq.

func (Seq) Max

func (s Seq) Max() float64

Max returns the maximum value in the seq.

func (Seq) Median

func (s Seq) Median() (median float64)

Median returns the median or middle value in the sorted seq.

func (Seq) Min

func (s Seq) Min() float64

Min returns the minimum value in the seq.

func (Seq) MinMax

func (s Seq) MinMax() (min, max float64)

MinMax returns the minimum and the maximum in one pass.

func (Seq) Normalize

func (s Seq) Normalize() Seq

Normalize maps every value to the interval [0, 1.0].

func (Seq) Percentile

func (s Seq) Percentile(percent float64) (percentile float64)

Percentile finds the relative standing in a slice of floats. `percent` should be given on the interval [0,1.0).

func (Seq) Sort

func (s Seq) Sort() Seq

Sort returns the seq sorted in ascending order. This fully enumerates the seq.

func (Seq) StdDev

func (s Seq) StdDev() float64

StdDev returns the standard deviation.

func (Seq) Sum

func (s Seq) Sum() (accum float64)

Sum adds all the elements of a series together.

func (Seq) Variance

func (s Seq) Variance() float64

Variance computes the variance of the buffer.

Jump to

Keyboard shortcuts

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