File: .lake/packages/batteries/Batteries/Data/Array/Match.lean

full_name: Array.PrefixTable
code: /-- Prefix table for the Knuth-Morris-Pratt matching algorithm

  This is an array of the form `t = [(x₀,n₀), (x₁,n₁), (x₂, n₂), ...]` where for each `i`, `nᵢ` is
  the length of the longest proper prefix of `xs = [x₀,x₁,...,xᵢ]` which is also a suffix of `xs`.
-/
structure PrefixTable (α : Type _) extends Array (α × Nat) where
  /-- Validity condition to help with termination proofs -/
  valid : (h : i < toArray.size) → toArray[i].2 ≤ i
goal: Type u_1

full_name: Array.PrefixTable.valid
code: /-- Prefix table for the Knuth-Morris-Pratt matching algorithm

  This is an array of the form `t = [(x₀,n₀), (x₁,n₁), (x₂, n₂), ...]` where for each `i`, `nᵢ` is
  the length of the longest proper prefix of `xs = [x₀,x₁,...,xᵢ]` which is also a suffix of `xs`.
-/
structure PrefixTable (α : Type _) extends Array (α × Nat) where
  /-- Validity condition to help with termination proofs -/
  valid : (h : i < toArray.size) → toArray[i].2 ≤ i
goal: self.toArray[i].snd ≤ i

full_name: Array.instInhabitedPrefixTable
code: instance : Inhabited (PrefixTable α) 
goal: Inhabited (Array.PrefixTable α)

full_name: Array.PrefixTable.size
code: /-- Returns the size of the prefix table -/
abbrev PrefixTable.size (t : PrefixTable α) 
goal: Nat

full_name: Array.PrefixTable.step
code: /-- Transition function for the KMP matcher

  Assuming we have an input `xs` with a suffix that matches the pattern prefix `t.pattern[:len]`
  where `len : Fin (t.size+1)`. Then `xs.push x` has a suffix that matches the pattern prefix
  `t.pattern[:t.step x len]`. If `len` is as large as possible then `t.step x len` will also be
  as large as possible.
-/
def PrefixTable.step [BEq α] (t : PrefixTable α) (x : α) : Fin (t.size+1) → Fin (t.size+1)
  
goal: Fin (t.size + 1) → Fin (t.size + 1)

full_name: Array.PrefixTable.extend
code: /-- Extend a prefix table by one element

  If `t` is the prefix table for `xs` then `t.extend x` is the prefix table for `xs.push x`.
-/
def PrefixTable.extend [BEq α] (t : PrefixTable α) (x : α) : PrefixTable α 
goal: Array.PrefixTable α

full_name: Array.mkPrefixTable
code: /-- Make prefix table from a pattern array -/
def mkPrefixTable [BEq α] (xs : Array α) : PrefixTable α 
goal: Array.PrefixTable α

full_name: Array.mkPrefixTableOfStream
code: /-- Make prefix table from a pattern stream -/
partial def mkPrefixTableOfStream [BEq α] [Stream σ α] (stream : σ) : PrefixTable α 
goal: Array.PrefixTable α

full_name: Array.mkPrefixTableOfStream.loop
code: /-- Make prefix table from a pattern stream -/
partial def mkPrefixTableOfStream [BEq α] [Stream σ α] (stream : σ) : PrefixTable α 
goal: Array.PrefixTable α

full_name: Array.Matcher.table
code: /-- KMP matcher structure -/
structure Matcher (α) where
  /-- Prefix table for the pattern -/
  table : PrefixTable α
  /-- Current longest matching prefix -/
  state : Fin (table.size + 1) := 0
goal: Array.PrefixTable α

full_name: Array.Matcher.state
code: /-- KMP matcher structure -/
structure Matcher (α) where
  /-- Prefix table for the pattern -/
  table : PrefixTable α
  /-- Current longest matching prefix -/
  state : Fin (table.size + 1) := 0
goal: Fin (self.table.size + 1)

full_name: Array.Matcher
code: /-- KMP matcher structure -/
structure Matcher (α) where
  /-- Prefix table for the pattern -/
  table : PrefixTable α
  /-- Current longest matching prefix -/
  state : Fin (table.size + 1) := 0
goal: Type u_1

full_name: Array.Matcher.ofArray
code: /-- Make a KMP matcher for a given pattern array -/
def Matcher.ofArray [BEq α] (pat : Array α) : Matcher α 
goal: Array.Matcher α

full_name: Array.Matcher.ofStream
code: /-- Make a KMP matcher for a given a pattern stream -/
def Matcher.ofStream [BEq α] [Stream σ α] (pat : σ) : Matcher α 
goal: Array.Matcher α

full_name: Array.Matcher.next?
code: /-- Find next match from a given stream

  Runs the stream until it reads a sequence that matches the sought pattern, then returns the stream
  state at that point and an updated matcher state.
-/
partial def Matcher.next? [BEq α] [Stream σ α] (m : Matcher α) (stream : σ) :
    Option (σ × Matcher α) 
goal: Option (σ × Array.Matcher α)