18 # define DEBUG_IFELSE(Then, Else) Then
20 # define DEBUG_IFELSE(Then, Else) Else
23 #define DEBUG_IF(Then) DEBUG_IFELSE(Then,)
30 template <
typename Aut>
52 static symbol res(
"expression_automaton<"
59 o <<
"expression_automaton<";
65 using smap = std::unordered_map<expression_t, state_t,
66 vcsn::hash<expressionset_t>,
67 vcsn::equal_to<expressionset_t>>;
71 state_t state(const expression_t& r)
73 // Benches show that the map_.emplace technique is slower, and
74 // then that operator[] is faster than emplace.
76 auto i = map_.find(r);
77 if (i == std::end(map_))
80 std::cerr << "New state: ";
81 rs_.print(r, std::cerr) << '\n
';
83 res = super_t::new_state();
92 using super_t::add_transition;
94 add_transition(state_t src, const expression_t& dst,
95 label_t l, const weight_t& w)
97 super_t::add_transition(src, state(dst), l, w);
100 using super_t::new_transition;
102 new_transition(state_t src, const expression_t& dst,
103 label_t l, const weight_t& w)
105 super_t::new_transition(src, state(dst), l, w);
108 using super_t::set_initial;
110 set_initial(const expression_t& s, const weight_t& w)
112 super_t::set_initial(state(s), w);
115 bool state_has_name(state_t s) const
117 return has(origins(), s);
121 print_state_name(state_t s, std::ostream& o,
125 auto i = origins().find(s);
126 if (i == std::end(origins()))
127 this->print_state(s, o);
129 rs_.print(i->second, o, fmt);
134 using origins_t = std::map<state_t, expression_t>;
135 mutable origins_t origins_;
139 if (origins_.empty())
140 for (const auto& p: map_)
141 origins_[p.second] = p.first;
148 std::stack<expression_t, std::vector<expression_t>> todo_;
typename expressionset_t::value_t expression_t
typename detail::label_t_of_impl< base_t< ValueSet >>::type label_t_of
An incremental automaton whose states are expressions.
expression_automaton_impl(const expressionset_t &rs)
state_t_of< super_t > state_t
typename detail::state_t_of_impl< base_t< ValueSet >>::type state_t_of
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
Aggregate an automaton, and forward calls to it.
auto print_set(Args &&...args) const -> decltype(aut_-> print_set(std::forward< Args >(args)...))
expressionset_t rs_
The expression's set.
Provide a variadic mul on top of a binary mul(), and one().
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
label_t_of< super_t > label_t
static symbol sname()
Static name.
weight_t_of< super_t > weight_t
std::ostream & print_set(std::ostream &o, format fmt={}) const
context_t_of< automaton_t > context_t
typename detail::weight_t_of_impl< base_t< ValueSet >>::type weight_t_of