private Automaton verifyTopoSort(Automaton a){
  int[] sorted=Operations.topoSortStates(a);
  assertTrue(sorted.length <= a.getNumStates());
  Automaton a2=new Automaton();
  int[] stateMap=new int[a.getNumStates()];
  Arrays.fill(stateMap,-1);
  Transition transition=new Transition();
  for (  int state : sorted) {
    int newState=a2.createState();
    a2.setAccept(newState,a.isAccept(state));
    assertEquals(-1,stateMap[state]);
    stateMap[state]=newState;
  }
  for (  int state : sorted) {
    int count=a.initTransition(state,transition);
    for (int i=0; i < count; i++) {
      a.getNextTransition(transition);
      assert stateMap[transition.dest] > stateMap[state];
      a2.addTransition(stateMap[state],stateMap[transition.dest],transition.min,transition.max);
    }
  }
  a2.finishState();
  return a2;
}

private Automaton verifyTopoSort ( Automaton a ) { int [ ] sorted = Operations . topoSortStates ( a ) ; assertTrue ( sorted . length <= a . getNumStates ( ) ) ; Automaton a2 = new Automaton ( ) ; int [ ] stateMap = new int [ a . getNumStates ( ) ] ; Arrays . fill ( stateMap , - 1 ) ; Transition transition = new Transition ( ) ; for ( int state : sorted ) { int newState = a2 . createState ( ) ; a2 . setAccept ( newState , a . isAccept ( state ) ) ; assertEquals ( - 1 , stateMap [ state ] ) ; stateMap [ state ] = newState ; } for ( int state : sorted ) { int count = a . initTransition ( state , transition ) ; for ( int i = 0 ; i < count ; i ++ ) { a . getNextTransition ( transition ) ; assert stateMap [ transition . dest ] > stateMap [ state ] ; a2 . addTransition ( stateMap [ state ] , stateMap [ transition . dest ] , transition . min , transition . max ) ; } } a2 . finishState ( ) ; return a2 ; }
runs topo sort , verifies transitions then only " go forwards " , and builds and returns new automaton with those remapped toposorted states .
