simpleKMPautomaton
functor
signature simpleKMP
functor simpleKMPautomaton
(LABEL) : simpleKMP
A functor constructing a Knuth-Morris-Pratt search automaton to search for single pattern strings in a text.
structure M : PPCFM
type t
val display : t list -> OS.Process.status
val kmp : t list -> t M.machine
val find : t list -> t list -> int list
type t
display pat
kmp pat
find pat txt
Since our automata assume that the alphabet consists of the letters occurring in the transitions, no letters except those in the input string may appear in the search text.
Example:For the general case without this restriction, see KMPautomaton. For multiple pattern search, see ppMatcher.
- structure IntKmp = simpleKMPautomaton(IntLabels); structure IntKmp : simpleKMP? - IntKmp.find [0,0,1] [0,0,0,1,0,1,0,0,0,1,0]; val it = [1,7] : int listHowever, by the restriction on the alphabet the search stops at the first letter of the text that is not in the pattern:- IntKmp.find [0,0] [0,0,0,1,0,1,0,0,0,1,0]; val it = [0,1] : int list