buffer

package
v0.0.0-...-6b453b2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 0 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CircularInt

type CircularInt struct {
	BufSize   int   // BufSize is the fixed number of ints maintained in memory
	Count     int   // Count is the number of ints in memory. Will always be <= BufSize
	TotalSeen int64 // TotalSeen is the total number of times Add has been called
	// contains filtered or unexported fields
}

CircularInt is a circular buffer of ints with the ability to iterate over the first and second halves of the integers collected in the order that they were appended.

func NewCircularInt

func NewCircularInt(totalSize int) *CircularInt

NewCircularInt creates a new circular buffer of totalSize. If totalSize is not a multiple of 2, it will be adjusted.

func (*CircularInt) Add

func (c *CircularInt) Add(i int) error

Add appends the given int to the buffer, overwriting the oldest entry

func (*CircularInt) FirstHalf

func (c *CircularInt) FirstHalf() *CircularIntIterator

FirstHalf returns an iterator over the first (oldest) half of the stored values. Will not return a valid iterator until Add has been called at least BufSize times

func (*CircularInt) SecondHalf

func (c *CircularInt) SecondHalf() *CircularIntIterator

SecondHalf returns an iterator over the second (most recent) half of the stored values. Will not return a valid iterator until Add has been called at least BufSize times

type CircularIntIterator

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

CircularIntIterator provides an iterator over a CircularInt buffer

func (*CircularIntIterator) Next

func (i *CircularIntIterator) Next() bool

Next returns True when there are more values to read via Value

func (*CircularIntIterator) Value

func (i *CircularIntIterator) Value() int

Value return the next integer to be read. Should only be called if Next() is True

Jump to

Keyboard shortcuts

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