Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajsic committed Sep 20, 2023
1 parent 3674529 commit b4bf3ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/mata/nfa/strings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ std::set<Word> get_shortest_words(const Nfa& nfa);
/**
* @brief Get all the one symbol words accepted by @p nfa.
*/
std::set<mata::Symbol> get_accepted_symbols(const Nfa& nfa);
std::set<Symbol> get_accepted_symbols(const Nfa& nfa);

/**
* @brief Get the lengths of all words in the automaton @p aut. The function returns a set of pairs <u,v> where for each
Expand Down
6 changes: 4 additions & 2 deletions src/strings/nfa-strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ std::set<mata::Symbol> mata::strings::get_accepted_symbols(const Nfa& nfa) {
std::set<mata::Symbol> accepted_symbols;
for (State init : nfa.initial) {
for (const SymbolPost& symbol_post_init : nfa.delta[init]) {
if (!accepted_symbols.contains(symbol_post_init.symbol) && nfa.final.intersects_with(symbol_post_init.targets)) {
accepted_symbols.insert(symbol_post_init.symbol);
mata::Symbol sym = symbol_post_init.symbol;
auto symbol_it = accepted_symbols.lower_bound(sym);
if (*symbol_it != sym && nfa.final.intersects_with(symbol_post_init.targets)) {
accepted_symbols.insert(symbol_it, sym);
}
}
}
Expand Down

0 comments on commit b4bf3ab

Please sign in to comment.