Commit 29584df7 authored by POTTIER Francois's avatar POTTIER Francois

No need to tabulate [transition]! It is already memoized.

parent e1d65d4b
......@@ -424,17 +424,31 @@ let dfa (e : regexp) : dfa =
in
(* The initial state is the encoding of [e]. *)
let init = encode e in
(* The transition function is as follows. *)
let transition q a = encode (delta a (decode q)) in
(*
(* There remains to tabulate the transition function. *)
let transition =
let module Q = Tabulate.ForIntSegment(N) in
let module T = Tabulate.ForHashedType(Char)(Char) in
Q.tabulate (fun q -> T.tabulate (fun a ->
encode (delta a (decode q))
))
in
*)
(* We are done. *)
{ n; init; decode; transition }
(* The transition function uses [decode], [delta], and [encode]. All of these
functions are memoized, so taking a transition is a matter of just a few
table lookups (four of them, I think). In other words, at automaton runtime,
no Brzozowski derivatives are computed. (That would be a bit expensive.)
That said, if desired, the number of table lookups involved in a transition
could be reduced by tabulating the transition function, as follows:
let transition =
let module Q = Tabulate.ForIntSegment(N) in
let module T = Tabulate.ForHashedType(Char)(Char) in
Q.tabulate (fun q -> T.tabulate (fun a -> transition q a))
in
...
*)
(* -------------------------------------------------------------------------- *)
(* Running a DFA. *)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment