def remove_state(self, state: str) -> None:
""" Removes a state """
# may not remove initial state
if state != self._initial_state:
self._states.discard(state)
self._final_states.discard(state)
for symbol in self._alphabet:
# remove useless transitions that come from the removed state
if (state, symbol) in self._transitions:
del self._transitions[state, symbol]
empty_transitions = set() # type Set[Tuple[str, str]]
for actual_state, next_state in self._transitions.items():
# remove transitions that go to the removed state
next_state.discard(state)
if not next_state:
empty_transitions.add(actual_state)
for transition in empty_transitions:
del self._transitions[transition]
评论列表
文章目录