Automaton

class Automaton @JvmOverloads constructor(numStates: Int = 2, numTransitions: Int = 2) : Accountable, TransitionAccessor

Represents an automaton and all its states and transitions. States are integers and must be created using .createState. Mark a state as an accept state using .setAccept. Add transitions using .addTransition. Each state must have all of its transitions added at once; if this is too restrictive then use Automaton.Builder instead. State 0 is always the initial state. Once a state is finished, either because you've starting adding transitions to another state or you call .finishState, then that states transitions are sorted (first by min, then max, then dest) and reduced (transitions with adjacent labels going to the same dest are combined).

Constructors

Link copied to clipboard
constructor(numStates: Int = 2, numTransitions: Int = 2)

Types

Link copied to clipboard
class Builder @JvmOverloads constructor(numStates: Int = 16, numTransitions: Int = 16)

Records new states and transitions and then .finish creates the Automaton. Use this when you cannot create the Automaton directly because it's too restrictive to have to add all transitions leaving each state at once.

Link copied to clipboard
data class BuilderFinishTimingSnapshot(val enabled: Boolean, val finishTotalNs: Long, val createStatesNs: Long, val sortTransitionsNs: Long, val emitTransitionsNs: Long, val finishStateNs: Long)
Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Returns nested resources of this class. The result should be a point-in-time snapshot (to avoid race conditions).

Link copied to clipboard

True if no state has two transitions leaving with the same label.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun addEpsilon(source: Int, dest: Int)

Add a virtual epsilon transition between source and dest. Dest state must already have all transitions added because this method simply copies those same transitions over to source.

Link copied to clipboard
fun addTransition(source: Int, dest: Int, label: Int)

Add a new transition with min = max = label.

fun addTransition(source: Int, dest: Int, min: Int, max: Int)

Add a new transition with the specified source, dest, min, max.

Link copied to clipboard
fun copy(other: Automaton)

Copies over all states/transitions from other. The states numbers are sequentially assigned (appended).

Link copied to clipboard

Create a new state.

Link copied to clipboard

Finishes the current state; call this once you are done adding transitions for a state. This is automatically called if you start adding transitions to a new source state, but for the last state you add you need to this method yourself.

Link copied to clipboard
open override fun getNextTransition(t: Transition)

Iterate to the next transition after the provided one

Link copied to clipboard
open override fun getNumTransitions(state: Int): Int

How many transitions this state has.

Link copied to clipboard

Returns sorted array of all interval start points.

Link copied to clipboard
open override fun getTransition(state: Int, index: Int, t: Transition)

Fill the provided Transition with the index'th transition leaving the specified state.

Link copied to clipboard
open override fun initTransition(state: Int, t: Transition): Int

Initialize the provided Transition to iterate through all transitions leaving the specified state. You must call .getNextTransition to get each transition. Returns the number of transitions leaving this state.

Link copied to clipboard
fun isAccept(state: Int): Boolean

Returns true if this state is an accept state.

Link copied to clipboard
fun next(transition: Transition, label: Int): Int

Looks for the next transition that matches the provided label, assuming determinism.

Link copied to clipboard
open override fun ramBytesUsed(): Long

Return the memory usage of this object in bytes. Negative values are illegal.

Link copied to clipboard
fun setAccept(state: Int, accept: Boolean)

Set or clear this state as an accept state.

Link copied to clipboard
fun step(state: Int, label: Int): Int

Performs lookup in transitions, assuming determinism.

Link copied to clipboard
fun toDot(): String

Returns the dot (graphviz) representation of this automaton. This is extremely useful for visualizing the automaton.