fsa

package
v0.0.0-...-293c848 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

The only method available from the outside are FSA and its API

The only struct available from the outside is Transition and its own API adn related enum

Index

Constants

View Source
const (
	// State.Id error value
	Unknown = -1
	// FSA.AddTransition() default values for "from" and "to"
	NewState = -2
	Current  = -3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FSA

type FSA struct {
	FinalStates *list.List // A list containing the ids of the final/accepting states
	// contains filtered or unexported fields
}

A FSA is a directed multigraph that represents all the possible transition from a state to the others. In Choreia is used to represent the execution flow of a single function, a whole Goroutine or the full choreography of the whole concurrent system

A struct containing a basic graph implementation that keeps track of the transition that occurs subsequently during the execution flow of a function (or scope).

func New

func New() *FSA

Generates a new empty FSA and returns a pointer reference to it

func (*FSA) AddTransition

func (fsa *FSA) AddTransition(from, to int, t Transition)

Adds a new Transition to the FSA on which is called. The user can specify a special flag for the "to" argument and the "from" one (respectively NewState and Current) to create a new node as destination of "t" or use the last generated node as starting point of "t" itself

func (*FSA) Copy

func (original *FSA) Copy() *FSA

This function generates an independent copy of the given FSA and returns it

func (*FSA) Export

func (fsa *FSA) Export(outputFile string, format graphviz.Format)

Exports the referenced FSA to a given path and in the given format/encoding. Some supported encoding/format are: SVG, PNG, DOT, etc... The funcion doesn't do any check about the given path and wil straight up fail if the path is invalid or it will overwrite the current file saved at that location

func (*FSA) ForEachState

func (fsa *FSA) ForEachState(callback func(id int))

Allows functional iteration over each state currently available in the FSA. The callback of the user can change and interact with FSA but the changes made will not be available in this method since it considers a "frozen" version of the adjency matrix

func (*FSA) ForEachTransition

func (fsa *FSA) ForEachTransition(callback func(from, to int, t Transition))

Allows functional iteration over each transition currently available in the FSA. The callback of the user can change and interact with FSA but the changes made will not be available in this method since it considers a "frozen" version of the adjency matrix

func (*FSA) GetLastId

func (fsa *FSA) GetLastId() int

Returns the id of the last state generated

func (*FSA) RemoveTransition

func (fsa *FSA) RemoveTransition(from, to int, t Transition)

Removes a transition "from" and "to" the specified states with a matching Move and Label. If no such label that fullfills the match criteria is found then the procedure returns without provinding any kind of error

func (*FSA) SetRootId

func (fsa *FSA) SetRootId(newRootId int)

Sets the state identified by the given id as the new root of the FSA, this means that the next transition added with the "Current" flag will start from this node, this is valid until a new state is generated with the NewState flag which, in that case, will override the current root id

type MoveKind

type MoveKind string

Type alias to abstact the MoveKind enum

const (
	// Transition type enum
	Call  MoveKind = "Call"
	Empty MoveKind = "Empty"
	Eps   MoveKind = "Epsilon"
	Recv  MoveKind = "Recv"
	Send  MoveKind = "Send"
	Spawn MoveKind = "Spawn"
)

type Transition

type Transition struct {
	Move    MoveKind    // The MoveType of Transition (Call, Eps, Recv, Send, Spawn)
	Label   string      // An explicative label of the action that is being executed
	Payload interface{} // A generic payload container for further info memorization
}

A Transition struct is a basic representation of a transition made inside a FSA

The transition has an associated Kind/Move/Type associated to it, a label for simple explanation on the transition itself and a optional generic payload container

func (Transition) String

func (t Transition) String() string

Converts the Transition struct to a general pourpose string format.

Jump to

Keyboard shortcuts

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