15 template <
typename Context>
16 mutable_automaton<Context>
19 const auto& ls = *ctx.labelset();
20 const auto& gens = ls.generators();
21 size_t sz = boost::distance(gens);
22 require(2 <= sz,
"de_bruijn: the alphabet needs at least 2 letters");
23 using context_t = Context;
25 automaton_t
res = make_shared_ptr<automaton_t>(
ctx);
27 auto init = res->new_state();
28 res->set_initial(init);
30 res->new_transition(init, init, ls.value(l));
32 auto prev = res->new_state();
33 res->new_transition(init, prev, ls.value(
detail::front(gens)));
37 auto next = res->new_state();
39 res->new_transition(prev, next, ls.value(l));
55 template <
typename Ctx,
typename Un
signed>
59 const auto& c = ctx->
as<Ctx>();
std::shared_ptr< detail::mutable_automaton_impl< Context >> mutable_automaton
automaton de_bruijn(const dyn::context &ctx, unsigned n)
Bridge.
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
auto & as()
Downcast to the exact type.
Template-less root for contexts.
Container::value_type front(const Container &container)
The first member of this Container.
mutable_automaton< Context > de_bruijn(const Context &ctx, unsigned n)