1 #ifndef VCSN_ALGOS_COMPLETE_HH
2 # define VCSN_ALGOS_COMPLETE_HH
5 # include <unordered_map>
15 template <
typename Aut>
20 "complete: requires free labelset");
22 using automaton_t = Aut;
27 state_t sink = aut->null_state();
28 const auto& ls = *aut->labelset();
30 if (aut->num_initials() == 0)
32 sink = aut->new_state();
33 aut->set_initial(sink);
37 std::unordered_set<letter_t> labels_met;
38 for (
auto st : aut->states())
41 for (
auto tr : aut->out(st))
42 labels_met.insert(aut->label_of(tr));
44 for (
auto letter : ls.genset())
45 if (!
has(labels_met, letter))
47 if (sink == aut->null_state())
48 sink = aut->new_state();
49 aut->new_transition(st, sink, letter);
55 if (sink != aut->null_state())
56 for (
auto letter : ls.genset())
57 aut->new_transition(sink, sink, letter);
62 template <
typename Aut>
77 template <
typename Aut>
81 const auto& a = aut->as<Aut>();
92 #endif // !VCSN_ALGOS_COMPLETE_HH
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
Aut & complete_here(Aut &aut)
Complete aut and return it.
AutOut copy(const AutIn &input, Pred keep_state)
A copy of input keeping only its states that are accepted by keep_state.
auto complete(const Aut &aut) -> decltype(::vcsn::copy(aut))
automaton complete(const automaton &aut)
Bridge.
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
bool has(const std::map< Key, Value, Compare, Alloc > &s, const Key &e)