From b4bf3abf5f1d74a6659abd5c056c4f4e3eb9b897 Mon Sep 17 00:00:00 2001 From: jurajsic Date: Wed, 20 Sep 2023 14:01:32 +0200 Subject: [PATCH] optimization --- include/mata/nfa/strings.hh | 2 +- src/strings/nfa-strings.cc | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/mata/nfa/strings.hh b/include/mata/nfa/strings.hh index a66b28936..3739f80d0 100644 --- a/include/mata/nfa/strings.hh +++ b/include/mata/nfa/strings.hh @@ -116,7 +116,7 @@ std::set get_shortest_words(const Nfa& nfa); /** * @brief Get all the one symbol words accepted by @p nfa. */ -std::set get_accepted_symbols(const Nfa& nfa); +std::set 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 where for each diff --git a/src/strings/nfa-strings.cc b/src/strings/nfa-strings.cc index a5a7aabf8..9d6cf43ea 100644 --- a/src/strings/nfa-strings.cc +++ b/src/strings/nfa-strings.cc @@ -148,8 +148,10 @@ std::set mata::strings::get_accepted_symbols(const Nfa& nfa) { std::set 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); } } }