Knuth-Morris-Pratt matcher type
This type is used to keep data for running the Knuth-Morris-Pratt (KMP) string matching algorithm. KMP is a linear time algorithm to locate all substrings of a string that match a given pattern. Generating the algorithm data is also linear in the length of the pattern but the data can be re-used to match the same pattern over different strings.
The KMP data for a pattern string can be generated using Matcher.ofString
. Then Matcher.find?
and Matcher.findAll
can be used to run the algorithm on an input string.
def m := Matcher.ofString "abba"
#eval Option.isSome <| m.find? "AbbabbA" -- false
#eval Option.isSome <| m.find? "aabbaa" -- true
#eval Array.size <| m.findAll "abbabba" -- 2
#eval Array.size <| m.findAll "abbabbabba" -- 3
- pattern : Substring
The pattern for the matcher
Instances For
@[inline]
Make KMP matcher from pattern substring
Equations
Instances For
@[inline]
Make KMP matcher from pattern string
Equations
Instances For
@[reducible, inline]
The byte size of the string pattern for the matcher
Equations
Instances For
partial def
String.Matcher.findAll.loop
(m : Matcher)
(s : Substring)
(am : Array.Matcher Char)
(occs : Array Substring)
:
Accumulator loop for String.Matcher.findAll