Linearize all states, putting <code>states</code> in front of the automaton
and calculating stable state offsets.
357557
private int linearizeAndCalculateOffsets(FSA fsa, IntArrayList states, IntArrayList linearized,
      IntIntHashMap offsets) throws IOException {
    final BitSet visited = new BitSet();
    final IntStack nodes = new IntStack();
    linearized.clear();

    /*
     * Linearize states with most inlinks first.
     */
    for (int i = 0; i < states.size(); i++) {
      linearizeState(fsa, nodes, linearized, visited, states.get(i));
    }

    /*
     * Linearize the remaining states by chaining them one after another, in depth-order.
     */
    nodes.push(fsa.getRootNode());
    while (!nodes.isEmpty()) {
      final int node = nodes.pop();
      if (visited.get(node))
        continue;

      linearizeState(fsa, nodes, linearized, visited, node);
    }

    /*
     * Calculate new state offsets. This is iterative. We start with 
     * maximum potential offsets and recalculate until converged.
     */
    int MAX_OFFSET = Integer.MAX_VALUE;
    for (IntCursor c : linearized) {
      offsets.put(c.value, MAX_OFFSET);
    }

    int i, j = 0;
    while ((i = emitNodes(fsa, null, linearized)) > 0) {
      j = i;
    }
    return j;
  }
1233110
def _add_epsilon_states(self, stateset, gathered_epsilons):
    '''
    
    '''
    for i in list(stateset):
      if i not in gathered_epsilons:
        gathered_epsilons[i] = {}
        q = _otq()
        q.append(i)
        while q:
          s = q.popleft()
          for j in self._transitions.setdefault(s, {}).setdefault(NFA.EPSILON, set()):
            gathered_epsilons[i][j] = s if j not in gathered_epsilons[i] else self.choose(s, j)
            q.append(j)
      stateset.update(gathered_epsilons[i].keys())
293232
def _epsilon_closure(self, state):
        
        closure = set([state.stateid])
        stack = [state]
        while True:
            if not stack:
                break
            s = stack.pop()
            for arc in s:
                if self.isyms.find(arc.ilabel) != EPSILON or \
                        arc.nextstate in closure:
                    continue
                closure.add(arc.nextstate)
                stack.append(self.states[arc.nextstate])
        return closure
1256536
def main():
    """"""
    if len(argv) < 2:
        targetfile = 'target.y'
    else:
        targetfile = argv[1]
    print 'Parsing ruleset: ' + targetfile,
    flex_a = Flexparser()
    mma = flex_a.yyparse(targetfile)
    print 'OK'
    print 'Perform minimization on initial automaton:',
    mma.minimize()
    print 'OK'
    print 'Perform StateRemoval on minimal automaton:',
    state_removal = StateRemoval(mma)
    mma_regex = state_removal.get_regex()
    print mma_regex
235833
function ResortStates()
    {
        for ($i = 0; $i < $this->nstate; $i++) {
            $stp = $this->sorted[$i]->data;
            $stp->nTknAct = $stp->nNtAct = 0;
            $stp->iDflt = $this->nstate + $this->nrule;
            $stp->iTknOfst = PHP_ParserGenerator_Data::NO_OFFSET;
            $stp->iNtOfst = PHP_ParserGenerator_Data::NO_OFFSET;
            for ($ap = $stp->ap; $ap; $ap = $ap->next) {
                if ($this->compute_action($ap) >= 0) {
                    if ($ap->sp->index < $this->nterminal) {
                        $stp->nTknAct++;
                    } elseif ($ap->sp->index < $this->nsymbol) {
                        $stp->nNtAct++;
                    } else {
                        $stp->iDflt = $this->compute_action($ap);
                    }
                }
            }
            $this->sorted[$i] = $stp;
        }
        $save = $this->sorted[0];
        unset($this->sorted[0]);
        usort($this->sorted, array('PHP_ParserGenerator_State', 'stateResortCompare'));
        array_unshift($this->sorted, $save);
        for($i = 0; $i < $this->nstate; $i++) {
            $this->sorted[$i]->statenum = $i;
        }
    }
685592
function (parser, compiler, actions, scope, state) {
	this.state    = state || {};
	this.scope    = scope;
	this.parser   = parser;
	this.actions  = actions;
	this.compiler = compiler;
}
118164
def determinize(self) -> DFA:
        

        nfa = self

        new_states = {macro_state for macro_state in powerset(nfa._states)}
        initial_state = frozenset([nfa._initial_state])
        final_states = {q for q in new_states if len(q.intersection(nfa._accepting_states)) != 0}
        transition_function = {}

        for state_set in new_states:
            for action in nfa._alphabet:

                next_macrostate = set()
                for s in state_set:
                    for next_state in nfa._transition_function.get(s, {}).get(action, set()):
                        next_macrostate.add(next_state)

                next_macrostate = frozenset(next_macrostate)
                transition_function.setdefault(state_set, {})[action] = next_macrostate

        return DFA(new_states, set(nfa._alphabet), initial_state, set(final_states), transition_function)
1273258
function InputState() {
      this.prefixRepeat = [];
      this.motionRepeat = [];

      this.operator = null;
      this.operatorArgs = null;
      this.motion = null;
      this.motionArgs = null;
      this.keyBuffer = []; // For matching multi-key commands.
      this.registerName = null; // Defaults to the unamed register.
    }
128232
private Set<NFAState<T>>  epsilonTransitions(StateVisitSet<NFAState<T>> marked)
    {
        marked.add(this);
        Set<NFAState<T>> set = new HashSet<>();
        for (NFAState<T> nfa : epsilonTransit())
        {
            if (!marked.contains(nfa))
            {
                set.add(nfa);
                set.addAll(nfa.epsilonTransitions(marked));
            }
        }
        return set;
    }
61714
function updateStates()
    {
        var numVertices = graph.vertexCount();
        var newStates = [];

        // Calculate new states without changing current states
        for(var i = 0; i < numVertices; i++)
        {
            var currentVertex = graph.getVertex(topologicalSortOrder[i]);

            if(currentVertex.state == "NOT_READY")
            {
                if(graph.indegree(currentVertex.id) == 0)
                {
                    newStates.push("READY");
                }
                else
                {
                    var parents = graph.getParentVertexIds(currentVertex.id);
                    var numParents = parents.length;
                    var allParentsAreSuccess = true;
                    var someParentFailed = false;

                    for(var j = 0; j < numParents; j++)
                    {
                        var currentParent = graph.getVertex(parents[j]);
                        allParentsAreSuccess = allParentsAreSuccess && currentParent.state == "SUCCESS";
                        someParentFailed = someParentFailed || currentParent.state == "FAIL";
                    }

                    if(allParentsAreSuccess)
                    {
                        newStates.push("READY");
                    }
                    else if(someParentFailed)
                    {
                        newStates.push("FAIL");
                    }
                    else
                    {
                        newStates.push("NOT_READY");
                    }
                }
            }
            else
            {
                newStates.push(currentVertex.state);
            }
        }

        // Transfer new states to the vertices
        for(var i = 0; i < numVertices; i++)
        {
            var currentVertex = graph.getVertex(topologicalSortOrder[i]);
            currentVertex.setState(newStates[i]);
        }
    }
1357817
private void serializeComputationStates(Queue<ComputationState> states, DataOutputView target) throws IOException {
		target.writeInt(states.size());
		for (ComputationState computationState : states) {
			serializeSingleComputationState(computationState, target);
		}
	}
670846
void addState(State<S, L> state) {
        ElementReference ref = states.referencedAdd(state);
        state.setBlockReference(ref);
        state.setBlock(this);
    }
726735
function uniqStates(states) {
    var seen = {}, a = [], path, i, n;

    for (i = 0, n = states.length; i < n; i++) {
      if (!states[i]) { continue; }
      path = states[i].path();
      if (!seen[path]) {
        a.push(states[i]);
        seen[path] = true;
      }
    }

    return a;
  }
1240988
def determinize(m):
    """"""
    if not m.is_finite():
        raise TypeError("machine must be a finite automaton")

    transitions = collections.defaultdict(lambda: collections.defaultdict(set))
    alphabet = set()
    for transition in m.get_transitions():
        [[lstate], read] = transition.lhs
        [[rstate]] = transition.rhs
        if len(read) > 1:
            raise NotSupportedException("multiple input symbols on transition not supported")
        if len(read) == 1:
            alphabet.add(read[0])
        transitions[lstate][tuple(read)].add(rstate)

    class Set(frozenset):
        def __str__(self):
            return "{{{}}}".format(",".join(map(str, sorted(self))))
        def _repr_html_(self):
            return "{{{}}}".format(",".join(x._repr_html_() for x in sorted(self)))

    def eclosure(states):
        """Find epsilon-closure of set of states"""
        states = set(states)
        frontier = set(states)
        while len(frontier) > 0:
            lstate = frontier.pop()
            for rstate in transitions[lstate][()]:
                if rstate not in states:
                    states.add(rstate)
                    frontier.add(rstate)
        return states

    dm = FiniteAutomaton()

    start_state = Set(eclosure([m.get_start_state()]))
    dm.set_start_state(start_state)

    frontier = {start_state}
    visited = set()
    while len(frontier) > 0:
        lstates = frontier.pop()
        if lstates in visited:
            continue
        visited.add(lstates)
        dtransitions = collections.defaultdict(set)
        for lstate in lstates:
            for read in alphabet:
                dtransitions[read] |= transitions[lstate][(read,)]
        for read in alphabet:
            rstates = Set(eclosure(dtransitions[read]))
            dm.add_transition([[lstates], read], [[rstates]])
            frontier.add(rstates)

    accept_states = set(m.get_accept_states())
    for states in visited:
        if len(states & accept_states) > 0:
            dm.add_accept_state(states)

    return dm
1370634
def stationarystate(self, k):
        """"""
        assert 0 <= k < self.ncats
        return self._models[k].stationarystate
137024
function(state,roundKey)
		{
			for (var i = 0; i < 16; i++)
				state[i] ^= roundKey[i];
			return state;
		}
418829
def set_states(self, states):
        """"""
        states = pickle.loads(states)
        if isinstance(states, tuple) and len(states) == 2:
            self.states, self.optimizer = states
        else:
            self.states = states
        self.states_synced = dict.fromkeys(self.states.keys(), False)