strategy

package
v0.0.0-...-9f34108 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List() []string

List returns a list of all registered reduce strategy names.

func NewLinear

func NewLinear(root token.Token) (chan struct{}, chan<- ReduceFeedbackType, error)

NewLinear implements a reduce strategy that reduces the data through a linear search algorithm. Every step of the strategy generates a new valid token graph state. The generation is deterministic. The algorithm starts by deactivating all optional tokens, this includes for example reducing lists to their minimum repetition. Each step uses the feedback to determine which tokens to reactivate next.

func Register

func Register(name string, strat Strategy)

Register registers a reduce strategy instance function with the given name.

Types

type Error

type Error struct {
	Message string
	Type    ErrorType
}

Error holds a reduce strategy error

func (*Error) Error

func (err *Error) Error() string

type ErrorType

type ErrorType int

ErrorType the reduce strategy error type

const (
	// ErrEndlessLoopDetected the token graph has a cycle which is not allowed.
	ErrEndlessLoopDetected ErrorType = iota
)

type ReduceFeedbackType

type ReduceFeedbackType int

ReduceFeedbackType the reduce strategy feedback type

const (
	// Unknown the feedback is of unknown type, this is always a fatal error
	Unknown ReduceFeedbackType = iota
	// Good the reduce step produced a successful result
	Good
	// Bad the reduce step produced an unsuccessful result
	Bad
)

func (ReduceFeedbackType) String

func (i ReduceFeedbackType) String() string

type Strategy

type Strategy func(root token.Token) (chan struct{}, chan<- ReduceFeedbackType, error)

Strategy defines a reduce strategy The function starts the first step of the reduce strategy returning a channel which controls the step flow and a channel for the feedback of the step. The channel returns a value if the step is complete and waits with calculating the next step until a value is put in and feedback is given. The channels are automatically closed when there are no more steps. The error return argument is not nil if an error occurs during the initialization of the reduce strategy.

func New

func New(name string) (Strategy, error)

New returns a new reduce strategy instance given the registered name of the strategy. The error return argument is not nil, if the name does not exist in the registered reduce strategy list.

Jump to

Keyboard shortcuts

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