Table of Contents

Class StateMachine<TState, TInput, TResult>

Namespace
LfrlAnvil.Computable.Automata
Assembly
LfrlAnvil.Computable.Automata.dll

Represents a deterministic finite state machine.

public sealed class StateMachine<TState, TInput, TResult> : IStateMachine<TState, TInput, TResult> where TState : notnull where TInput : notnull

Type Parameters

TState

State type.

TInput

Input type.

TResult

Result type.

Inheritance
StateMachine<TState, TInput, TResult>
Implements
IStateMachine<TState, TInput, TResult>
Inherited Members
Extension Methods

Properties

DefaultResult

Represents the default transition result.

public TResult DefaultResult { get; }

Property Value

TResult

InitialState

public IStateMachineNode<TState, TInput, TResult> InitialState { get; }

Property Value

IStateMachineNode<TState, TInput, TResult>

InputComparer

Input equality comparer.

public IEqualityComparer<TInput> InputComparer { get; }

Property Value

IEqualityComparer<TInput>

Optimization

Specifies the chosen StateMachineOptimization with which this state machine was created.

public StateMachineOptimization Optimization { get; }

Property Value

StateMachineOptimization

StateComparer

State equality comparer.

public IEqualityComparer<TState> StateComparer { get; }

Property Value

IEqualityComparer<TState>

States

Collection that contains all nodes of this state machine.

public IReadOnlyDictionary<TState, IStateMachineNode<TState, TInput, TResult>> States { get; }

Property Value

IReadOnlyDictionary<TState, IStateMachineNode<TState, TInput, TResult>>

Methods

CreateInstance()

Creates a new IStateMachineInstance<TState, TInput, TResult> instance from this state.

[Pure]
public StateMachineInstance<TState, TInput, TResult> CreateInstance()

Returns

StateMachineInstance<TState, TInput, TResult>

New IStateMachineInstance<TState, TInput, TResult> instance.

CreateInstance(TState)

Creates a new IStateMachineInstance<TState, TInput, TResult> instance from this state.

[Pure]
public StateMachineInstance<TState, TInput, TResult> CreateInstance(TState initialState)

Parameters

initialState TState

State to start the created instance in.

Returns

StateMachineInstance<TState, TInput, TResult>

New IStateMachineInstance<TState, TInput, TResult> instance.

Exceptions

StateMachineStateException

When the provided initialState does not exist.

CreateInstanceWithSubject(object)

Creates a new IStateMachineInstance<TState, TInput, TResult> instance from this state.

[Pure]
public StateMachineInstance<TState, TInput, TResult> CreateInstanceWithSubject(object subject)

Parameters

subject object

Custom subject.

Returns

StateMachineInstance<TState, TInput, TResult>

New IStateMachineInstance<TState, TInput, TResult> instance.

CreateInstanceWithSubject(TState, object)

Creates a new IStateMachineInstance<TState, TInput, TResult> instance from this state.

[Pure]
public StateMachineInstance<TState, TInput, TResult> CreateInstanceWithSubject(TState initialState, object subject)

Parameters

initialState TState

State to start the created instance in.

subject object

Custom subject.

Returns

StateMachineInstance<TState, TInput, TResult>

New IStateMachineInstance<TState, TInput, TResult> instance.

Exceptions

StateMachineStateException

When the provided initialState does not exist.

WithOptimization(StateMachineOptimizationParams<TState>)

Creates a new IStateMachine<TState, TInput, TResult> equivalent to this state machine with the provided optimization.

[Pure]
public StateMachine<TState, TInput, TResult> WithOptimization(StateMachineOptimizationParams<TState> optimization)

Parameters

optimization StateMachineOptimizationParams<TState>

Optimization parameters.

Returns

StateMachine<TState, TInput, TResult>

New IStateMachine<TState, TInput, TResult> instance or this when current Optimization level is the same or more advanced than the provided desired optimization.