|
2 | 2 | Representation of a deterministic finite automaton
|
3 | 3 | """
|
4 | 4 |
|
5 |
| -from typing import Dict, List, Iterable, AbstractSet, Optional, Hashable, Any |
6 |
| -from numpy import empty |
| 5 | +from typing import Iterable, AbstractSet, Optional, Hashable, Any |
7 | 6 |
|
8 | 7 | from .state import State
|
9 |
| -from .symbol import Symbol |
10 | 8 | from .deterministic_transition_function import DeterministicTransitionFunction
|
11 | 9 | from .epsilon_nfa import EpsilonNFA
|
12 | 10 | from .nondeterministic_finite_automaton import NondeterministicFiniteAutomaton
|
13 | 11 | from .hopcroft_processing_list import HopcroftProcessingList
|
14 | 12 | from .partition import Partition
|
15 |
| -from .utils import to_state, to_symbol, to_single_state |
16 |
| - |
17 |
| - |
18 |
| -class PreviousTransitions: |
19 |
| - """For internal usage""" |
20 |
| - |
21 |
| - def __init__(self, |
22 |
| - states: AbstractSet[State], |
23 |
| - symbols: AbstractSet[Symbol]) -> None: |
24 |
| - self._to_index_state: Dict[Optional[State], int] = {} |
25 |
| - self._to_index_state[None] = 0 |
26 |
| - for i, state in enumerate(states): |
27 |
| - self._to_index_state[state] = i + 1 |
28 |
| - self._to_index_symbol: Dict[Optional[Symbol], int] = {} |
29 |
| - for i, symbol in enumerate(symbols): |
30 |
| - self._to_index_symbol[symbol] = i |
31 |
| - self._conversion = empty((len(states) + 1, len(symbols)), |
32 |
| - dtype=object) |
33 |
| - |
34 |
| - def add(self, |
35 |
| - next0: Optional[State], |
36 |
| - symbol: Symbol, |
37 |
| - state: Optional[State]) -> None: |
38 |
| - """ Internal """ |
39 |
| - i_next0 = self._to_index_state[next0] |
40 |
| - i_symbol = self._to_index_symbol[symbol] |
41 |
| - if self._conversion[i_next0, i_symbol] is None: |
42 |
| - self._conversion[i_next0, i_symbol] = [state] |
43 |
| - else: |
44 |
| - self._conversion[i_next0, i_symbol].append(state) |
45 |
| - |
46 |
| - def get(self, next0: State, symbol: Symbol) -> List[object]: |
47 |
| - """ Internal """ |
48 |
| - i_next0 = self._to_index_state[next0] |
49 |
| - i_symbol = self._to_index_symbol[symbol] |
50 |
| - return self._conversion[i_next0, i_symbol] or [] |
| 13 | +from .utils import to_state, to_symbol, to_single_state, PreviousTransitions |
51 | 14 |
|
52 | 15 |
|
53 | 16 | class DeterministicFiniteAutomaton(NondeterministicFiniteAutomaton):
|
@@ -263,8 +226,6 @@ def _get_previous_transitions(self) -> PreviousTransitions:
|
263 | 226 | for symbol in self._input_symbols:
|
264 | 227 | next0 = self._transition_function.get_next_state(state, symbol)
|
265 | 228 | previous_transitions.add(next0, symbol, state)
|
266 |
| - for symbol in self._input_symbols: |
267 |
| - previous_transitions.add(None, symbol, None) |
268 | 229 | return previous_transitions
|
269 | 230 |
|
270 | 231 | def minimize(self) -> "DeterministicFiniteAutomaton":
|
|
0 commit comments