while there is another word
word = next word
commonprefix = CommonPrefix(word)
- laststate = $\delta^*(q_0, $commonprefix)
- currentsuffix
+ laststate = delta_star(q0, commonprefix)
+ currentsuffix = word[length(commonprefix)..length(word)]
+ if has_children(laststate)
+ then
+ replace_or_register(last_state)
+ endif
+ add_suffix(laststate, currentsuffix)
+endwhile
+replace_or_register(q0)
+
+function replace_or_register(state)
+ child = last_child(state)
+ if has_children(child)
+ replace_or_register(child)
+ fi
+ if there is an equivalent state q
+ last_child(state = q
+ delete(child)
+ else
+ register.add(child)
+ endif
+endfunction
\end{minted}
\end{listing}