public static int[] topoSortStates(Automaton a){
  if (a.getNumStates() == 0) {
    return new int[0];
  }
  int numStates=a.getNumStates();
  int[] states=new int[numStates];
  final BitSet visited=new BitSet(numStates);
  int upto=topoSortStatesRecurse(a,visited,states,0,0);
  if (upto < states.length) {
    int[] newStates=new int[upto];
    System.arraycopy(states,0,newStates,0,upto);
    states=newStates;
  }
  for (int i=0; i < states.length / 2; i++) {
    int s=states[i];
    states[i]=states[states.length - 1 - i];
    states[states.length - 1 - i]=s;
  }
  return states;
}

public static int [ ] topoSortStates ( Automaton a ) { if ( a . getNumStates ( ) == 0 ) { return new int [ 0 ] ; } int numStates = a . getNumStates ( ) ; int [ ] states = new int [ numStates ] ; final BitSet visited = new BitSet ( numStates ) ; int upto = topoSortStatesRecurse ( a , visited , states , 0 , 0 ) ; if ( upto < states . length ) { int [ ] newStates = new int [ upto ] ; System . arraycopy ( states , 0 , newStates , 0 , upto ) ; states = newStates ; } for ( int i = 0 ; i < states . length / 2 ; i ++ ) { int s = states [ i ] ; states [ i ] = states [ states . length - 1 - i ] ; states [ states . length - 1 - i ] = s ; } return states ; }
returns the topological sort of all states reachable from the initial state . behavior is undefined if this automaton has cycles . cpu cost is o ( numtransitions ) , and the implementation is recursive so an automaton matching long strings may exhaust the java stack .
