Idris2Doc : Data.ByteString.Search.DFA.Types

Data.ByteString.Search.DFA.Types

(source)
Types for the DFA string searching algorithm.

Definitions

dfaStateLimit : Bits32
  One greater than the maximum number of DFA states whose flattened
256-way transition table can be represented without overflow in
`Bits32`.

A DFA must have fewer than 2^24 states because every state owns 256
transition entries:

states * 256 < 2^32

Totality: total
Visibility: public export
DFAStateCount : Type
  Evidence that a DFA state count can safely be used to construct a
flattened 256-way transition table using `Bits32` indexing.

The proof stored by `Index` is erased at runtime.

Totality: total
Visibility: public export
DFAState : Bits32->Type
  A valid state in a DFA containing `states` states.

The underlying state number is represented by `Index`, so its proof that
the state lies in `[0, states)` is erased at runtime.

Totality: total
Visibility: public export
recordDFAIndex : Bits32->Type
  A valid DFA transition coordinate.

`state` is already known to be within the DFA's state range, while `byte`
is intrinsically limited to the 256 possible byte values.

Totality: total
Visibility: public export
Constructor: 
MkDFAIndex : Indexstates->Bits8->DFAIndexstates

Projections:
.byte : DFAIndexstates->Bits8
.state : DFAIndexstates->Indexstates
.state : DFAIndexstates->Indexstates
Totality: total
Visibility: public export
state : DFAIndexstates->Indexstates
Totality: total
Visibility: public export
.byte : DFAIndexstates->Bits8
Totality: total
Visibility: public export
byte : DFAIndexstates->Bits8
Totality: total
Visibility: public export
dfaIndex : {auto0_ : states<dfaStateLimit} ->DFAIndexstates->Index (states*256)
  Flatten a DFA state and input byte into a transition-table index.

The resulting `Index` is constructed directly from statically carried
bounds evidence. No dynamic range check is performed.

The DFA state-count proof guarantees that multiplication by 256 cannot
overflow `Bits32`.

Totality: total
Visibility: export
dfaStateValue : DFAStatestates->Bits32
  Return the runtime state number represented by a valid DFA state.

The bound proof carried by `Index` is erased, so this operation is
simply extraction of the underlying `Bits32` value.

Totality: total
Visibility: export
dfaTransitionIndex : {auto0_ : states<dfaStateLimit} ->DFAStatestates->Bits8->Index (states*256)
  Construct the valid flattened transition-table index for a DFA state and
input byte.

No dynamic bounds check is performed. The state-count bound and state
bound are carried exclusively as erased evidence.

Totality: total
Visibility: export
recordDFATable : Type->Bits32->Type
  Mutable DFA transition storage.

The underlying pointer is an Idris primitive array containing
`states * 256` transitions.

Totality: total
Visibility: public export
Constructor: 
MkDFATable : AnyPtr->DFATablesstates

Projection: 
.arr : DFATablesstates->AnyPtr
.arr : DFATablesstates->AnyPtr
Totality: total
Visibility: public export
arr : DFATablesstates->AnyPtr
Totality: total
Visibility: public export
newDFATable : {auto0_ : states<dfaStateLimit} ->F1s (DFATablesstates)
  Allocate an uninitialized DFA transition table.

Totality: total
Visibility: export
dfaTransition : {auto0_ : states<dfaStateLimit} ->DFATablesstates->DFAStatestates->Bits8->F1s (DFAStatestates)
  Read the next DFA state for a current state and input byte.

The flattened transition index is already bounded, so no explicit
`tryIndex` or `tryNatToFin` conversion occurs in the search loop.

The primitive array is accessed directly using the prevalidated
flattened `Index`.

Totality: total
Visibility: export
setDFATransition : {auto0_ : states<dfaStateLimit} ->DFATablesstates->DFAStatestates->Bits8->DFAStatestates->F1's
  Write a DFA transition.

The flattened index is derived from an already-bounded DFA state and
byte, avoiding any explicit dynamic bounds conversion.

The primitive array is written directly using the prevalidated
flattened `Index`.

Totality: total
Visibility: export
recordDFAStateSpace : Type
  Runtime description of a valid DFA state space.

`states` is the number of states in the DFA. The erased proofs establish
that the state count is positive and small enough for the flattened
256-way transition table to fit within the `Bits32` index space.

Totality: total
Visibility: public export
Constructor: 
MkDFAStateSpace : (states : Bits32) -> (0_ : 0<states) -> (0_ : states<dfaStateLimit) ->DFAStateSpace

Projections:
.states : DFAStateSpace->Bits32
0.statesBounded : ({rec:0} : DFAStateSpace) ->states{rec:0}<dfaStateLimit
0.statesPositive : ({rec:0} : DFAStateSpace) ->0<states{rec:0}
.states : DFAStateSpace->Bits32
Totality: total
Visibility: public export
states : DFAStateSpace->Bits32
Totality: total
Visibility: public export
0.statesPositive : ({rec:0} : DFAStateSpace) ->0<states{rec:0}
Totality: total
Visibility: public export
0statesPositive : ({rec:0} : DFAStateSpace) ->0<states{rec:0}
Totality: total
Visibility: public export
0.statesBounded : ({rec:0} : DFAStateSpace) ->states{rec:0}<dfaStateLimit
Totality: total
Visibility: public export
0statesBounded : ({rec:0} : DFAStateSpace) ->states{rec:0}<dfaStateLimit
Totality: total
Visibility: public export
dfaStateSpace : ByteString->MaybeDFAStateSpace
  Construct the state space for a DFA matching `bs`.

A pattern of length `n` requires `n + 1` states, including state zero.
The upper-bound check is performed once during DFA construction. All
subsequent state and transition indexing carries erased `Index` proofs
and requires no repeated bounds validation.

Totality: total
Visibility: export
recordDFAutomaton : Type->Type
  A constructed DFA transition automaton.

The runtime state-space description is packaged together with a
transition table indexed by that state count.

Every transition stored in the table is itself a valid `DFAState`,
allowing a lookup result to feed directly into the next lookup.

Totality: total
Visibility: public export
Constructor: 
MkDFAutomaton : (space : DFAStateSpace) ->DFATables (space.states) ->DFAutomatons

Projections:
.space : DFAutomatons->DFAStateSpace
.table : ({rec:0} : DFAutomatons) ->DFATables ((space{rec:0}) .states)
.space : DFAutomatons->DFAStateSpace
Totality: total
Visibility: public export
space : DFAutomatons->DFAStateSpace
Totality: total
Visibility: public export
.table : ({rec:0} : DFAutomatons) ->DFATables ((space{rec:0}) .states)
Totality: total
Visibility: public export
table : ({rec:0} : DFAutomatons) ->DFATables ((space{rec:0}) .states)
Totality: total
Visibility: public export
toDFAState : (space : DFAStateSpace) ->Nat->Maybe (DFAState (space.states))
  Convert a `Nat` state number into a valid state of the supplied DFA
state space.

This helper is used only while constructing the DFA. Search-time
transitions already produce bounded states directly and therefore do not
require this check.

Totality: total
Visibility: export
zeroDFAState : (space : DFAStateSpace) ->DFAState (space.states)
  State zero for a valid DFA state space.

No dynamic check is required because every DFA state space is known to
contain at least one state.

Totality: total
Visibility: export