window

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2015 License: Apache-2.0, BSD-3-Clause Imports: 0 Imported by: 0

Documentation

Overview

source: https://github.com/jbrukh/window

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MovingWindow

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

An array-based moving window; a moving window is a queue with a maximum size and the property that when the size is reached, pushing a new element into the queue causes the head to be popped.

You can optimize the amount of slice copying that the MovingWindow will be doing by trading off with space complexity. Namely, the underlying array is allocated with a size that is the multiple of the intended capacity of the queue so that copying is less frequent.

func New

func New(size, multiple int) *MovingWindow

New creates a new moving window, with the size and multiple specified.

This data structures trades off space and copying complexity; more precisely, the number of moving windows that can be displayed without having to do any array copying is proportional to approx 1/M, where M is the multiple.

func (*MovingWindow) PushBack

func (m *MovingWindow) PushBack(v interface{})

PushBack will push a new piece of data into the moving window

func (*MovingWindow) Size

func (m *MovingWindow) Size() int

Size returns the size of the moving window, which is set at initialization

func (*MovingWindow) Slice

func (m *MovingWindow) Slice() []interface{}

Slice will present the MovingWindow in the form of a slice. This operation never requires array copying of any kind.

Note that this value is guaranteed to be good only until the next call to push. If you wish to save the reference, you should make a copy.

Jump to

Keyboard shortcuts

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