// TODO: this currently requites a determinized machine,
// but it need not -- we can speed it up by walking the
// NFA instead. it'd still be fail fast.
public static BytesRef getCommonPrefixBytesRef(Automaton a) {
if (a.isSingleton()) return new BytesRef(a.singleton);
BytesRef ref = new BytesRef(10);
HashSet<State> visited = new HashSet<State>();
State s = a.initial;
boolean done;
do {
done = true;
visited.add(s);
if (!s.accept && s.numTransitions() == 1) {
Transition t = s.getTransitions().iterator().next();
if (t.min == t.max && !visited.contains(t.to)) {
ref.grow(++ref.length);
ref.bytes[ref.length - 1] = (byte)t.min;
s = t.to;
done = false;
}
}