state

package
v0.0.0-...-6247a41 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutOfBound = errors.New("moving to out of bound of state")

Returned by IncrementPointer and DecrementPointer state method on moving pointer out of state acceptable range

Functions

This section is empty.

Types

type DynamicSize

type DynamicSize[T StateType] struct {
	// contains filtered or unexported fields
}

A dynamic size state, implemented using linked list for flexibility.

func NewDynamicSize

func NewDynamicSize[T StateType](leftExpandable bool) *DynamicSize[T]

Return a dynamic size state. if leftExpandable is false, would return ErrOutOfBound if trying to move pointer left on the first cell

func (*DynamicSize[T]) DecrementPointer

func (s *DynamicSize[T]) DecrementPointer() error

func (*DynamicSize[T]) IncrementPointer

func (s *DynamicSize[T]) IncrementPointer() error

func (*DynamicSize[T]) PointerValue

func (s *DynamicSize[T]) PointerValue() T

func (*DynamicSize[T]) SetPointerValue

func (s *DynamicSize[T]) SetPointerValue(value T)

type FixedSize

type FixedSize[T StateType] struct {
	// contains filtered or unexported fields
}

A fixed size state, implemented using slices for performance

func NewFixedSize

func NewFixedSize[T StateType](size uint) *FixedSize[T]

Return a fixed size state

func (*FixedSize[T]) DecrementPointer

func (s *FixedSize[T]) DecrementPointer() error

func (*FixedSize[T]) IncrementPointer

func (s *FixedSize[T]) IncrementPointer() error

func (*FixedSize[T]) PointerValue

func (s *FixedSize[T]) PointerValue() T

func (*FixedSize[T]) SetPointerValue

func (s *FixedSize[T]) SetPointerValue(value T)

type State

type State[T StateType] interface {
	// get the value which the pointer is pointing to
	PointerValue() T
	// set the value which the pointer is pointing to
	SetPointerValue(T)
	// move pointer right
	IncrementPointer() error
	// move pointer left
	DecrementPointer() error
}

State interface define the set of changes which can be done on a state

type StateType

type StateType interface {
	uint8 | uint16 | uint32 | uint64
}

Generic type of each state word

Jump to

Keyboard shortcuts

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