fifo

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 2 Imported by: 0

README

fifo

Go Report Card

Thread safe FIFO structures

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ring

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

Ring provides a thread safe length limited ring buffer that operates in a FIFO manner

func NewRing

func NewRing(max int) *Ring

New creates a ring with max n elements this does not actually create the elements

func (*Ring) Avail

func (r *Ring) Avail() int

Avail returns the current space available in the ring

func (*Ring) Do

func (r *Ring) Do(f func(interface{}))

Do calls function f on each element in the ring iterating forward from the current position

func (*Ring) Len

func (r *Ring) Len() int

Len returns the current length of the ring

func (*Ring) Move

func (r *Ring) Move(n int)

Move moves the currnet position n % r.Len() elements backwards (n < 0) or forward (n > 0) in the ring and returns the value at that position. r must not be empty

func (*Ring) Next

func (r *Ring) Next()

Next moves the ring one element forward. r must not be empty

func (*Ring) Pop

func (r *Ring) Pop() interface{}

Pop removes the oldest element from the ring;

func (*Ring) Prev

func (r *Ring) Prev()

Prev returns the previous value from the ring. r must not be empty

func (*Ring) Push

func (r *Ring) Push(val interface{})

Push adds elements to the ring; if the ring is full it replaces the oldest element

func (*Ring) SetValue

func (r *Ring) SetValue(val interface{})

SetValue changes the value of the current ring element

func (*Ring) Value

func (r *Ring) Value() interface{}

Value returns the value of the current ring element

Jump to

Keyboard shortcuts

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