Idris2Doc : Data.ByteString.Search.KnuthMorrisPratt.Internal

Data.ByteString.Search.KnuthMorrisPratt.Internal

(source)
Utilities for the Knuth-Morris-Pratt string searching algorithm.

Definitions

recordKMPBorderTable : Type->Bits32->Type
  Mutable storage for the KMP border table.

The table contains one entry for every DFA state. Both table indices and
stored border values are represented by `DFAState`, so their bounds are
established once and carried as erased evidence.

The underlying storage is an Idris primitive array.

Totality: total
Visibility: public export
Constructor: 
MkKMPBorderTable : AnyPtr->KMPBorderTablesstates

Projection: 
.arr : KMPBorderTablesstates->AnyPtr
.arr : KMPBorderTablesstates->AnyPtr
Totality: total
Visibility: public export
arr : KMPBorderTablesstates->AnyPtr
Totality: total
Visibility: public export
recordKMPBorders : Type->Type
  A constructed KMP border table together with the DFA state space to
which its indices and values belong.

Packaging the state space with the table allows `automaton` to reuse the
exact same state-space witness rather than independently reconstructing
and validating the pattern's state count.

Totality: total
Visibility: public export
Constructor: 
MkKMPBorders : (space : DFAStateSpace) ->KMPBorderTables (space.states) ->KMPBorderss

Projections:
.space : KMPBorderss->DFAStateSpace
.table : ({rec:0} : KMPBorderss) ->KMPBorderTables ((space{rec:0}) .states)
.space : KMPBorderss->DFAStateSpace
Totality: total
Visibility: public export
space : KMPBorderss->DFAStateSpace
Totality: total
Visibility: public export
.table : ({rec:0} : KMPBorderss) ->KMPBorderTables ((space{rec:0}) .states)
Totality: total
Visibility: public export
table : ({rec:0} : KMPBorderss) ->KMPBorderTables ((space{rec:0}) .states)
Totality: total
Visibility: public export
newKMPBorderTable : F1s (KMPBorderTablesstates)
  Allocate an uninitialized KMP border table.

The table contains exactly one entry for each DFA state.

Totality: total
Visibility: export
kmpBorder : KMPBorderTablesstates->DFAStatestates->F1s (DFAStatestates)
  Read a border value from the KMP border table.

The supplied index is already a valid `DFAState`, so no dynamic bounds
validation is required. The stored result is itself another valid DFA
state.

Totality: total
Visibility: export
setKMPBorder : KMPBorderTablesstates->DFAStatestates->DFAStatestates->F1's
  Write a border value to the KMP border table.

Both the destination index and stored border value are already bounded by
the same DFA state space, so no `Fin` conversion or runtime bounds check
is required.

Totality: total
Visibility: export
nextDFAState : (space : DFAStateSpace) ->DFAState (space.states) ->Maybe (DFAState (space.states))
  Construct the successor of a DFA state during DFA preprocessing.

This check occurs only while constructing preprocessing tables. It is
never executed by the target-scanning DFA hot path.

Totality: total
Visibility: export
kmpBorders : ByteString->F1s (Maybe (KMPBorderss))
  Computes the suffix-oriented KMP border table for a given pattern.

Each entry associated with DFA state `i` stores the length of the longest
proper prefix of `pattern[0..i-1]` that is also a suffix.

Unlike the previous implementation, table indices and border values are
represented directly by bounded `DFAState` values rather than `Nat`
values indexed through `Fin`.

Consequently, accesses to the border table require no `tryNatToFin` or
equivalent dynamic table-bounds conversion.

The result packages the table together with its `DFAStateSpace`, allowing
construction of the DFA transition table to reuse exactly the same state
space.

Example: "ANPANMAN"

Indices: 0 1 2 3 4 5 6 7 8
Borders: 0 0 0 0 1 2 0 1 2

Totality: total
Visibility: export