Class mata::nfa::Delta¶
-
class Delta¶
Delta is a data structure for representing transition relation.
Transition is represented as a triple Trans(source state, symbol, target state). Move is the part (symbol, target state), specified for a single source state. Its underlying data structure is vector of StatePost classes. Each index to the vector corresponds to one source state, that is, a number for a certain state is an index to the vector of state posts. Transition relation (delta) in Mata stores a set of transitions in a four-level hierarchical structure: Delta, StatePost, SymbolPost, and a set of target states. A vector of ‘StatePost’s indexed by a source states on top, where the StatePost for a state ‘q’ (whose number is ‘q’ and it is the index to the vector of ‘StatePost’s) stores a set of ‘Move’s from the source state ‘q’. Namely, ‘StatePost’ has a vector of ‘SymbolPost’s, where each ‘SymbolPost’ stores a symbol ‘a’ and a vector of target states of ‘a’-moves from state ‘q’. ‘SymbolPost’s are ordered by the symbol, target states are ordered by the state number.
Public Functions
-
inline const StatePost &state_post(const State source) const¶
Get constant reference to the state post of
source.If we try to access a state post of a
sourcewhich is present in the automaton as an initial/final state, yet does not have allocated space inDelta, anempty_postis returned. Hence, the function has no side effects (no allocation is performed; iterators remain valid).- Parameters:
source[in] – Source state of a state post to access.
- Returns:
State post of
source.
-
inline const StatePost &operator[](const State source) const¶
Get constant reference to the state post of
source.If we try to access a state post of a
sourcewhich is present in the automaton as an initial/final state, yet does not have allocated space inDelta, anempty_postis returned. Hence, the function has no side effects (no allocation is performed; iterators remain valid).- Parameters:
source[in] – Source state of a state post to access.
- Returns:
State post of
source.
-
StatePost &mutable_state_post(State source)¶
Get mutable (non-constant) reference to the state post of
source.The function allows modifying the state post.
BEWARE, IT HAS A SIDE EFFECT.
If we try to access a state post of a
sourcewhich is present in the automaton as an initial/final state, yet does not have allocated space inDelta, a new state post forsourcewill be allocated along with all state posts for all previous states. This in turn may cause that the entire post data structure is re-allocated. Iterators toDeltawill get invalidated. Use the constant ‘state_post()’ is possible. Or, to prevent the side effect from causing issues, one might want to make sure that posts of all states in the automaton are allocated, e.g., write an NFA method that allocateDeltafor all states of the NFA.- Parameters:
source[in] – Source state of a state post to access.
- Returns:
State post of
source.
-
inline void allocate(const size_t num_of_states)¶
Allocate state posts up to
num_of_statesstates, creating emptyStatePostfor yet unallocated state posts.- Parameters:
num_of_states – [in] Number of states in
Deltato allocate state posts for. Have to be at least num_of_states() + 1.
-
inline size_t num_of_states() const¶
- Returns:
Number of states in the whole Delta, including both source and target states.
-
bool contains(State source, Symbol symbol, State target) const¶
Check whether
Deltacontains a passed transition.
-
bool contains(const Transition &transition) const¶
Check whether
Deltacontains a transition passed as a triple.
-
bool empty() const¶
Check whether automaton contains no transitions.
- Returns:
True if there are no transitions in the automaton, false otherwise.
-
inline void append(const std::vector<StatePost> &post_vector)¶
Append post vector to the delta.
- Parameters:
post_vector – Vector of posts to be appended.
-
std::vector<StatePost> renumber_targets(const std::function<State(State)> &target_renumberer) const¶
Copy posts of delta and apply a lambda update function on each state from targets.
IMPORTANT: In order to work properly, the lambda function needs to be monotonic, that is, the order of states in targets cannot change.
- Parameters:
target_renumberer – Monotonic lambda function mapping states to different states.
- Returns:
std::vector<Post> Copied posts.
-
void add(const State source, const Symbol symbol, const StateSet &targets)¶
Add transitions to multiple destinations.
- Parameters:
source – From
symbol – Symbol
targets – Set of states to
-
Transitions transitions() const¶
Iterator over transitions represented as
Transitioninstances.
-
std::vector<Transition> get_transitions_to(State state_to) const¶
Get transitions leading to
state_to.Operation is slow, traverses over all symbol posts.
- Parameters:
state_to[in] – Target state for transitions to get.
- Returns:
Transitions leading to
state_to.
-
std::vector<Transition> get_transitions_between(State state_from, State state_to) const¶
Get transitions from
state_fromtostate_to.Operation is slow, traverses over all symbol posts.
- Parameters:
state_from[in] – Source state.
state_from[in] – Target state.
- Returns:
Transitions from
sourcetostate_to.
-
StateSet get_successors(State state) const¶
Get the set of states that are successors of the given
state.- Parameters:
state – [in] State from which successors are checked.
- Returns:
Set of states that are successors of the given
state.
-
StatePost::const_iterator epsilon_symbol_posts(State state, Symbol epsilon = EPSILON) const¶
Iterate over
epsilonsymbol posts under the givenstate.- Parameters:
state – [in] State from which epsilon transitions are checked.
epsilon – [in] User can define his favourite epsilon or used default.
- Returns:
An iterator to
SymbolPostwith epsilon symbol. End iterator when there are no epsilon transitions.
-
void add_symbols_to(OnTheFlyAlphabet &target_alphabet) const¶
Expand
target_alphabetby symbols from this delta.The value of the already existing symbols will NOT be overwritten.
Public Static Functions
-
static StatePost::const_iterator epsilon_symbol_posts(const StatePost &state_post, Symbol epsilon = EPSILON)¶
Iterate over
epsilonsymbol posts under the givenstate_post.- Parameters:
state_post – [in] State post from which epsilon transitions are checked.
epsilon – [in] User can define his favourite epsilon or used default.
- Returns:
An iterator to
SymbolPostwith epsilon symbol. End iterator when there are no epsilon transitions.
-
inline const StatePost &state_post(const State source) const¶