step

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2019 License: Apache-2.0, BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package step implements a step vector type.

A step vector can be used to represent high volume data that would be efficiently stored by run-length encoding.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOutOfRange    = errors.New("step: index out of range")
	ErrInvertedRange = errors.New("step: inverted range")
	ErrZeroLength    = errors.New("step: attempt to create zero length vector")
)

Functions

This section is empty.

Types

type Equaler

type Equaler interface {
	Equal(Equaler) bool
}

An Equaler is a type that can return whether it equals another Equaler.

type Float

type Float float64

A Float is a float64 type satisfying the Equaler interface.

func (Float) Equal

func (f Float) Equal(e Equaler) bool

Equal returns whether f equals e. For the purposes of the step package here, NaN == NaN evaluates to true. Equal assumes the underlying type of e is Float.

type Int

type Int int

An Int is an int type satisfying the Equaler interface.

func (Int) Equal

func (i Int) Equal(e Equaler) bool

Equal returns whether i equals e. Equal assumes the underlying type of e is Int.

type Mutator

type Mutator func(Equaler) Equaler

A Mutator is a function that is used by Apply and ApplyRange to alter values within a Vector.

var (
	IncInt   Mutator = incInt   // Increment an int value.
	DecInt   Mutator = decInt   // Decrement an int value.
	IncFloat Mutator = incFloat // Increment a float64 value.
	DecFloat Mutator = decFloat // Decrement a float64 value.
)

Convenience mutator functions. Mutator functions are used by Apply and ApplyRange to alter step values in a value-dependent manner. These mutators assume the stored type matches the function and will panic is this is not true.

type Operation

type Operation func(start, end int, e Equaler)

An Operation is a non-mutating function that can be applied to a vector using Do and DoRange.

type Vector

type Vector struct {
	Zero    Equaler // Ground state for the step vector.
	Relaxed bool    // If true, dynamic vector resize is allowed.
	// contains filtered or unexported fields
}

A Vector is type that support the storage of array type data in a run-length encoding format.

func New

func New(start, end int, zero Equaler) (*Vector, error)

New returns a new Vector with the extent defined by start and end, and the ground state defined by zero. The Vector's extent is mutable if the Relaxed field is set to true. If a zero length vector is requested an error is returned.

func (*Vector) Apply

func (v *Vector) Apply(m Mutator)

Apply applies the mutator function m to steps stored in the Vector in ascending sort order of start position. Redundant steps resulting from changes in step values are erased.

func (*Vector) ApplyRange

func (v *Vector) ApplyRange(from, to int, m Mutator) error

Apply applies the mutator function m to steps stored in the Vector in over the range [from, to) in ascending sort order of start position. Redundant steps resulting from changes in step values are erased.

func (*Vector) At

func (v *Vector) At(i int) (Equaler, error)

At returns the value of the vector at position i. If i is outside the extent of the vector an error is returned.

func (*Vector) Count

func (v *Vector) Count() int

Count returns the number of steps represented in the vector.

func (*Vector) Do

func (v *Vector) Do(fn Operation)

Do performs the function fn on steps stored in the Vector in ascending sort order of start position. fn is passed the start, end and value of the step.

func (*Vector) DoRange

func (v *Vector) DoRange(from, to int, fn Operation) error

Do performs the function fn on steps stored in the Vector over the range [from, to) in ascending sort order of start position. fn is passed the start, end and value of the step.

func (*Vector) End

func (v *Vector) End() int

End returns the index of lowest position beyond the end of the Vector.

func (*Vector) Len

func (v *Vector) Len() int

Len returns the length of the represented data array, that is the distance between the start and end of the vector.

func (*Vector) Set

func (v *Vector) Set(i int, e Equaler)

Set sets the value of position i to e.

func (*Vector) SetRange

func (v *Vector) SetRange(start, end int, e Equaler)

SetRange sets the value of positions [start, end) to e.

func (*Vector) Start

func (v *Vector) Start() int

Start returns the index of minimum position of the Vector.

func (*Vector) StepAt

func (v *Vector) StepAt(i int) (start, end int, e Equaler, err error)

StepAt returns the value and range of the step at i, where start <= i < end. If i is outside the extent of the vector, an error is returned.

func (*Vector) String

func (v *Vector) String() string

String returns a string representation a Vector, displaying step start positions and values. The last step indicates the end of the vector and always has an associated value of nil.

Jump to

Keyboard shortcuts

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